From de7d821aaaf0ae3fefef3e8f5d346969443d0781 Mon Sep 17 00:00:00 2001 From: zhang zhuo Date: Mon, 23 Jun 2025 13:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E9=80=9F=E6=B7=BB=E5=8A=A0=E8=8F=9C?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/Admin/System.php | 11 +++++++++++ app/Model/Menu.php | 34 +++++++++++++++++++++++++++++++++ app/Request/Menu.php | 7 ++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/app/Controller/Admin/System.php b/app/Controller/Admin/System.php index a020a75..b01f81d 100644 --- a/app/Controller/Admin/System.php +++ b/app/Controller/Admin/System.php @@ -69,6 +69,17 @@ class System extends Base return $res ? $this->success("操作成功") : $this->error("操作失败"); } + #[PostMapping(path: "menu/quick")] + #[Auth(needAuth: false, auth: "menu:quick")] + public function menuQuickAdd() + { + $data = Param::only(['pid' => 0, 'title' => '', 'flag', 'name', 'path', 'icon'], $this->request->post()); + $request = $this->container->get(mRequest::class); + $request->scene('quick')->validateResolved(); + $res = mModel::quickAdd($data); + return $res ? $this->success("操作成功") : $this->error("操作失败"); + } + #[GetMapping(path: "dept/index")] #[Auth(auth: "dept:index")] public function deptIndex(): ResponseInterface diff --git a/app/Model/Menu.php b/app/Model/Menu.php index 2b48a9d..14b5136 100644 --- a/app/Model/Menu.php +++ b/app/Model/Menu.php @@ -209,4 +209,38 @@ class Menu extends Model ->get() ->toArray(); } + + public static function quickAdd(array $data): bool + { + Db::beginTransaction(); + // 1.菜单 + $data1 = ['pid' => $data['pid'], 'title' => $data['title'] . "管理", 'account_type' => $data['account_type'], 'type' => 0, 'name' => $data['name'], 'path' => $data['path'], 'icon' => $data['icon']]; + $pid = self::add($data1); + // 2.添加按钮 + $data2 = ['pid' => $pid, 'title' => $data['title'] . '添加', 'account_type' => $data1['account_type'], 'type' => 1, 'flag' => $data['flag'] . ":add"]; + $pid2 = self::add($data2); + // 3.添加接口 + $data3 = ['pid' => $pid2, 'title' => $data['title'] . '添加', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":add", 'method' => 'post']; + $pid3 = self::add($data3); + // 4.修改按钮 + $data2 = ['pid' => $pid, 'title' => $data['title'] . '修改', 'account_type' => $data1['account_type'], 'type' => 1, 'flag' => $data['flag'] . ":edit"]; + $pid2 = self::add($data2); + // 5.修改接口 + $data3 = ['pid' => $pid2, 'title' => $data['title'] . '修改', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":edit", 'method' => 'put']; + $pid3 = self::add($data3); + // 6.删除按钮 + $data2 = ['pid' => $pid, 'title' => $data['title'] . '删除', 'account_type' => $data1['account_type'], 'type' => 1, 'flag' => $data['flag'] . ":del"]; + $pid2 = self::add($data2); + // 7.删除接口 + $data3 = ['pid' => $pid2, 'title' => $data['title'] . '删除', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":del", 'method' => 'delete']; + $pid3 = self::add($data3); + // 8.列表接口 + $data3 = ['pid' => $pid, 'title' => $data['title'] . '列表', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":list", 'method' => 'get']; + $pid3 = self::add($data3); + // 9.选择接口 + $data3 = ['pid' => $pid, 'title' => $data['title'] . '选项', 'account_type' => $data1['account_type'], 'type' => 2, 'flag' => $data['flag'] . ":option", 'method' => 'get']; + $pid3 = self::add($data3); + Db::commit(); + return true; + } } diff --git a/app/Request/Menu.php b/app/Request/Menu.php index 4a93bc5..c9e5a34 100644 --- a/app/Request/Menu.php +++ b/app/Request/Menu.php @@ -12,6 +12,7 @@ class Menu extends FormRequest protected array $scenes = [ 'add' => ['pid', 'title', 'type'], 'edit' => ['pid', 'title', 'type','menu_id'], + 'quick' => ['pid', 'title', 'name', 'flag', 'path', 'icon'] ]; /** @@ -31,7 +32,11 @@ class Menu extends FormRequest 'menu_id' => 'required', 'pid' => 'required', 'title' => 'required', - 'type' => 'required' + 'type' => 'required', + 'name' => 'required', + 'path' => 'required', + 'icon' => 'required', + 'flag' => 'required' ]; }