From 0840443190917eabe9a09287642a3c78c8cf22e1 Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Wed, 26 Apr 2023 16:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B7=BB=E5=8A=A0=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=98=AF=E6=9D=83=E9=99=90=E8=A7=84=E5=88=99=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/setting/SystemMenus.php | 33 ++++++++++++++++++- crmeb/app/model/system/SystemCrud.php | 3 +- .../services/system/SystemCrudServices.php | 1 - 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemMenus.php b/crmeb/app/adminapi/controller/v1/setting/SystemMenus.php index ee3956221..f69d1bef8 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemMenus.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemMenus.php @@ -130,14 +130,45 @@ class SystemMenus extends AuthController } $data = []; + $uniqueAuthAll = $this->services->getColumn(['is_del' => 0, 'is_show' => 1], 'unique_auth'); + $uniqueAuthAll = array_filter($uniqueAuthAll, function ($item) { + return !!$item; + }); + $uniqueAuthAll = array_unique($uniqueAuthAll); + + $uniqueFn = function ($path) use ($uniqueAuthAll) { + $attPath = explode('/', $path); + $uniqueAuth = ''; + if ($attPath) { + $pathData = []; + foreach ($attPath as $vv) { + if (strstr($vv, '<') === false || strstr($vv, '?>') === false) { + $pathData[] = $vv; + } + } + $uniqueAuth = implode('-', $pathData); + } + + if (in_array($uniqueAuth, $uniqueAuthAll)) { + $uniqueAuth .= '-' . uniqid(); + } + + array_push($uniqueAuthAll, $uniqueAuth); + + return $uniqueAuth; + }; + foreach ($menus as $menu) { if (empty($menu['menu_name'])) { return app('json')->fail(400198); } + if (isset($menu['unique_auth']) && $menu['unique_auth']) { + $menu['unique_auth'] = explode('/', $menu['api_url']); + } $data[] = [ 'methods' => $menu['method'], 'menu_name' => $menu['menu_name'], - 'unique_auth' => $menu['unique_auth'] ?? '', + 'unique_auth' => !empty($menu['unique_auth']) ? $menu['unique_auth'] : $uniqueFn($menu['api_url']), 'api_url' => $menu['api_url'], 'pid' => $menu['path'], 'auth_type' => 2, diff --git a/crmeb/app/model/system/SystemCrud.php b/crmeb/app/model/system/SystemCrud.php index 585cd79db..0a9f1065a 100644 --- a/crmeb/app/model/system/SystemCrud.php +++ b/crmeb/app/model/system/SystemCrud.php @@ -56,8 +56,7 @@ class SystemCrud extends BaseModel return json_decode($value, true); } - - public function getRoutesIdAttr($value) + public function getRouteIdsAttr($value) { return json_decode($value, true); } diff --git a/crmeb/app/services/system/SystemCrudServices.php b/crmeb/app/services/system/SystemCrudServices.php index 6cb557123..0113a73d8 100644 --- a/crmeb/app/services/system/SystemCrudServices.php +++ b/crmeb/app/services/system/SystemCrudServices.php @@ -29,7 +29,6 @@ use crmeb\services\crud\ViewPages; use crmeb\services\crud\ViewRouter; use crmeb\services\FileService; use Phinx\Db\Adapter\AdapterFactory; -use think\exception\ValidateException; use think\facade\Db; use think\helper\Str; use think\migration\db\Table;