From f6c80eb1eec615c0d3f452e2d515e91185ef0f2f Mon Sep 17 00:00:00 2001 From: walkor Date: Wed, 7 Dec 2022 11:46:02 +0800 Subject: [PATCH] save --- src/plugin/admin/app/common/Util.php | 40 +++++++++++++++++ .../app/controller/AdminRuleController.php | 45 ++----------------- .../admin/app/controller/TableController.php | 12 ++--- src/plugin/admin/app/view/table/index.html | 1 - 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/plugin/admin/app/common/Util.php b/src/plugin/admin/app/common/Util.php index 29c12e1..e6bdab0 100644 --- a/src/plugin/admin/app/common/Util.php +++ b/src/plugin/admin/app/common/Util.php @@ -124,6 +124,46 @@ class Util return $var; } + /** + * 类转换为url path + * @param $controller_class + * @return false|string + */ + static function controllerToUrlPath($controller_class) + { + $key = strtolower($controller_class); + $action = ''; + if (strpos($key, '@')) { + [$key, $action] = explode( '@', $key, 2); + } + $prefix = 'plugin'; + $paths = explode('\\', $key); + if (count($paths) < 2) { + return false; + } + $base = ''; + if (strpos($key, "$prefix\\") === 0) { + if (count($paths) < 4) { + return false; + } + array_shift($paths); + $plugin = array_shift($paths); + $base = "/app/$plugin/"; + } + array_shift($paths); + foreach ($paths as $index => $path) { + if ($path === 'controller') { + unset($paths[$index]); + } + } + $suffix = 'controller'; + $code = $base . implode('/', $paths); + if (substr($code, -strlen($suffix)) === $suffix) { + $code = substr($code, 0, -strlen($suffix)); + } + return $action ? "$code/$action" : $code; + } + /** * 转换为驼峰 * @param string $value diff --git a/src/plugin/admin/app/controller/AdminRuleController.php b/src/plugin/admin/app/controller/AdminRuleController.php index 8327918..3bcb087 100644 --- a/src/plugin/admin/app/controller/AdminRuleController.php +++ b/src/plugin/admin/app/controller/AdminRuleController.php @@ -114,54 +114,15 @@ class AdminRuleController extends Crud $keys = AdminRule::whereIn('id', $rules)->pluck('key'); $permissions = []; foreach ($keys as $key) { - $key = strtolower($key); - $action = ''; - if (strpos($key, '@')) { - [$key, $action] = explode( '@', $key, 2); - } - $prefix = 'plugin'; - $paths = explode('\\', $key); - if (count($paths) < 2) { + if (!$key = Util::controllerToUrlPath($key)) { continue; } - $base = ''; - if (strpos($key, "$prefix\\") === 0) { - if (count($paths) < 4) { - continue; - } - array_shift($paths); - $plugin = array_shift($paths); - $base = "app.$plugin."; - } - if ($code = $this->formatPermissionCode($paths, $action, $base)) { - $permissions[] = $code; - } + $code = str_replace('/', '.', trim($key, '/')); + $permissions[] = $code; } return $this->json(0, 'ok', $permissions); } - /** - * @param $paths - * @param $action - * @param string $base - * @return false|string - */ - protected function formatPermissionCode($paths, $action, string $base = '') - { - array_shift($paths); - foreach ($paths as $index => $path) { - if ($path === 'controller') { - unset($paths[$index]); - } - } - $suffix = 'controller'; - $code = $base . implode('.', $paths); - if (substr($code, -strlen($suffix)) === $suffix) { - $code = substr($code, 0, -strlen($suffix)); - } - return $action ? "$code.$action" : $code; - } - /** * 根据类同步规则到数据库 * @return void diff --git a/src/plugin/admin/app/controller/TableController.php b/src/plugin/admin/app/controller/TableController.php index bd732b9..41bc754 100644 --- a/src/plugin/admin/app/controller/TableController.php +++ b/src/plugin/admin/app/controller/TableController.php @@ -699,9 +699,11 @@ EOF; * @param $controller_class_with_namespace * @return void */ - protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key) + protected function createTemplate($template_file_path, $table, $template_path, $url_path_base, $primary_key, $controller_class_with_namespace) { $this->mkdir($template_file_path . '/index.html'); + $code_base = Util::controllerToUrlPath($controller_class_with_namespace); + $code_base = str_replace('/', '.', trim($code_base, '/')); $form = LayuiForm::buildForm($table, 'search'); $html = $form->html(3); $html = $html ? << diff --git a/src/plugin/admin/app/view/table/index.html b/src/plugin/admin/app/view/table/index.html index a20ff7e..b3f29da 100644 --- a/src/plugin/admin/app/view/table/index.html +++ b/src/plugin/admin/app/view/table/index.html @@ -217,7 +217,6 @@ } }) - // 获取选择组件配置项 function getControlProps(control_args) {