This commit is contained in:
walkor 2022-12-07 11:46:02 +08:00
parent af6197dfd1
commit f6c80eb1ee
4 changed files with 50 additions and 48 deletions

View File

@ -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

View File

@ -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)) {
$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

View File

@ -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 ? <<<EOF
@ -754,18 +756,18 @@ EOF
<!-- 表格顶部工具栏 -->
<script type="text/html" id="table-toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="insert">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="$code_base.insert">
<i class="layui-icon layui-icon-add-1"></i>新增
</button>
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="delete">
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="$code_base.delete">
<i class="layui-icon layui-icon-delete"></i>删除
</button>
</script>
<!-- 表格行工具栏 -->
<script type="text/html" id="table-bar">
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="update">编辑</button>
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="delete">删除</button>
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="$code_base.update">编辑</button>
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="$code_base.delete">删除</button>
</script>
<script src="/app/admin/component/layui/layui.js"></script>

View File

@ -217,7 +217,6 @@
}
})
// 获取选择组件配置项
function getControlProps(control_args)
{