From 37527bdab52e54f5d757af6e1b729750f8e97a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E5=92=8Csa0ChunLuyu?= Date: Tue, 13 Jun 2023 23:26:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'LuCodeAdminMix=20?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E4=BD=BF=E7=94=A8=E8=AF=B4=E6=98=8E=E6=96=87?= =?UTF-8?q?=E6=A1=A3'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...%A8%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md | 296 ++++++++++++++++++ LuCodeAdminMix.md | 1 - 2 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 LuCodeAdminMix-%E6%A1%86%E6%9E%B6%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md delete mode 100644 LuCodeAdminMix.md diff --git a/LuCodeAdminMix-%E6%A1%86%E6%9E%B6%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md b/LuCodeAdminMix-%E6%A1%86%E6%9E%B6%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md new file mode 100644 index 0000000..bd26674 --- /dev/null +++ b/LuCodeAdminMix-%E6%A1%86%E6%9E%B6%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md @@ -0,0 +1,296 @@ +# 准备开发 + +## 开发环境 + +* 推荐本地安装 `composer` 、 `php 7.3+`、 `pnpm` +* 本地必须安装 `node` +* 需要学会使用 `Laravel 8`、 `Vue 3` + +## 相关文档 + +* [Laravel 8 中文文档](https://learnku.com/docs/laravel/8.5) +* [IconPark](https://iconpark.oceanengine.com/official) + * 后台图标库 +* [Naive UI](https://www.naiveui.com/zh-CN/os-theme/components/avatar) + * 后台 ui 组件库 +* [Tailwind CSS](https://www.tailwindcss.cn/docs) + * 后台 css 框架 +* [Vitesse Lite](https://github.com/antfu/vitesse-lite/blob/main/README.zh-CN.md) + * 后台是在这个模板基础上魔改的 js 版本 + * 意味着它使用的黑魔法在后台都支持 + * 基于文件的路由 + * 组件自动化加载 + * UnoCSS - 高性能且极具灵活性的即时原子化 CSS 引擎 + +## Nginx + +* 目录请指向 `/public` +* 追加伪静态配置 + +``` +location / { + try_files $uri $uri/ /index.php$is_args$query_string; +} +``` + +## 后台 +* 代码仓库 [sa0ChunLuyu/LuCodeVueAdmin](https://gitee.com/sa0ChunLuyu/lu-code-vue-admin) +* `pnpm i` +* `pnpm dev` +* `pnpm build` +* `npm install -g pnpm` + +# Mix后台 + +## 仓库 +* Gitea代码仓库 [sa0ChunLuyu/LuCodeAdminMix](http://gitea.pi.sa0.online:3000/sa0ChunLuyu/LuCodeAdminMix) +* Gitee代码仓库 暂不对外开放 + +## 部署流程 +* 通过模板创建仓库 +* 创建本地测试环境 + * 本地clone项目 + * `mysql.server start` + * 创建数据库 `utf8mb4_general_ci` + * 创建`.env`文件,修改内容 + * `composer install` + * `php artisan key:generate` + * `php artisan storage:link` + * `php artisan migrate` + * `php artisan serve` +* 部署服务器 + * 服务器clone项目 + * 部署宝塔,创建数据库 + * 创建`.env`文件,修改内容 + * `composer install` + * `chown www.www storage/ -R` + * `php artisan storage:link` + * `php artisan migrate` +* 部署后台 + * 本地修改后台域名 + * `pnpm build` + * `git push` +* 配置Git + * `vim .git/config` +```angular2html +[credential] + helper = store +``` + +# 常用命令行 +* `php artisan make:model User -mc` 创建 控制器 + 数据库 +* 生成数据库 + * `php artisan migrate` 追加 + * `php artisan migrate:fresh` 初始化 +* `php artisan make:controller YoController` 创建控制器 + + +# 常用代码段 + +## 接口 +### Yo +#### return +```php +Yo::echo($data = []); +Yo::create_echo($id); +Yo::update_echo($id); +Yo::delete_echo($id); + +// 输出 +{ + "code": 200, + "message": "增加成功", + "data": { + "id": 12 + } +} +``` + +#### exit +```php +Yo::exit($data); // 会以 JSON 的形式输出 $data 的内容。 +Yo::error_echo($code, $replace = []); +// code 在 /config/code.php 中配置 +// $replace 为 ? 替换字符 + +// Yo::error_echo(100001, ['替换内容']); +// 在 code.php 中 100001 => '?固定内容', +// 输出 +{ + "code": 100001, + "message": "替换内容固定内容" +} + +// Yo::error_echo(100002); +// 输出 +{ + "code": 100002, + "message": "错误信息" +} +``` +### Lu +* `Lu::ssl()` 返回是不是 HTTPS +* `Lu::ip()` 返回用户 IP +* `Lu::ge($str)` 去掉字符串空格 +* `Lu::fp($path)` 返回当前域名完整路径 +* `Lu::date($time = false, $format = "Y-m-d H:i:s")` 返回格式化时间 +* `Lu::time()` 返回毫秒时间戳 +* `Lu::post($url, $data, $type = 'json')` 发送 POST 请求 + + +### Login +* `Login::admin($auth_id = 0)` 检查权限,在数据库 `db.auths` 中配置,没有权限会直接退出 +* `Login::admin_check($auth_id = 0)` 检查权限,没有权限会 `return` + +### 增删改查 + +```php +post('name'); + $order = $request->post('order'); + $user = new User(); + $user->name = $name; + $user->order = $order; + $user->save(); + return Yo::create_echo($user->id); + } + + public function delete() + { + Login::admin(11); + $id = request()->post('id'); + User::where('id', $id)->delete(); + return Yo::delete_echo($id); + } + + public function update(EditWordBankInput $request) + { + Login::admin(11); + $id = request()->post('id'); + $name = $request->post('name'); + $order = $request->post('order'); + $user = User::find($id); + if (!$user) Yo::error_echo(100021, ['用户']); + $user->name = $name; + $user->order = $order; + $user->save(); + return Yo::update_echo($user->id); + } + + public function list() + { + $user_list = User::orderBy('order', 'desc')->get(); + return Yo::echo(['list' => $list]); + } +} + +``` + +### Requests + +```php + ['required', 'between:1,30'], + ]; + } + + public function messages() + { + return [ + 'name.required' => 100001, + 'name.between' => 100002, + ]; + } + + public function failedValidation(Validator $validator) + { + Yo::error_echo($validator->errors()->first()); + } +} + +``` + +## 后台 + +* 新建页面 `b` 时需要创建 `a.vue` 和 `a/b.vue` 两个文件 + +### a.vue +```vue + + + +{redirect: '/a/b',"meta":{"title":"多级菜单"}} + +``` + +### a/b.vue + +```vue + + + + +{"meta":{"title":"多级菜单"}} + + + +``` + + + diff --git a/LuCodeAdminMix.md b/LuCodeAdminMix.md deleted file mode 100644 index 30e821a..0000000 --- a/LuCodeAdminMix.md +++ /dev/null @@ -1 +0,0 @@ -使用说明文档 \ No newline at end of file