浏览代码

新增一键CRUD类名冲突检测
新增一键CRUD自动传递请求参数
新增一键菜单之支持ThinkPHP5标准命名规则
新增Table.api.formatter.toggle自定义URL
新增Table.api.formatter.search自定义搜索字段
修复关联模型不同命名空间之间的BUG
优化时间字段修改器的判断

Karson 6 年之前
父节点
当前提交
eccf03e43f

文件差异内容过多而无法显示
+ 29 - 15
application/admin/command/Crud.php


+ 1 - 1
application/admin/command/Crud/stubs/javascript.stub

@@ -5,7 +5,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             // 初始化表格参数配置
             Table.api.init({
                 extend: {
-                    index_url: '{%controllerUrl%}/index',
+                    index_url: '{%controllerUrl%}/index' + location.search,
                     add_url: '{%controllerUrl%}/add',
                     edit_url: '{%controllerUrl%}/edit',
                     del_url: '{%controllerUrl%}/del',

+ 1 - 1
application/admin/command/Crud/stubs/mixins/modelrelationmethod.stub

@@ -1,5 +1,5 @@
 
     public function {%relationMethod%}()
     {
-        return $this->{%relationMode%}('{%relationName%}', '{%relationForeignKey%}', '{%relationPrimaryKey%}', [], 'LEFT')->setEagerlyType(0);
+        return $this->{%relationMode%}('{%relationClassName%}', '{%relationForeignKey%}', '{%relationPrimaryKey%}', [], 'LEFT')->setEagerlyType(0);
     }

+ 1 - 1
application/admin/command/Crud/stubs/mixins/radio.stub

@@ -1,6 +1,6 @@
 
     public function {%methodName%}($value, $data)
-    {        
+    {
         $value = $value ? $value : (isset($data['{%field%}']) ? $data['{%field%}'] : '');
         $list = $this->{%listMethodName%}();
         return isset($list[$value]) ? $list[$value] : '';

+ 1 - 1
application/admin/command/Crud/stubs/mixins/select.stub

@@ -1,6 +1,6 @@
 
     public function {%methodName%}($value, $data)
-    {        
+    {
         $value = $value ? $value : (isset($data['{%field%}']) ? $data['{%field%}'] : '');
         $list = $this->{%listMethodName%}();
         return isset($list[$value]) ? $list[$value] : '';

+ 33 - 8
application/admin/command/Menu.php

@@ -12,6 +12,7 @@ use think\console\Input;
 use think\console\input\Option;
 use think\console\Output;
 use think\Exception;
+use think\Loader;
 
 class Menu extends Command
 {
@@ -52,6 +53,18 @@ class Menu extends Command
             $ids = [];
             $list = $this->model->where(function ($query) use ($controller, $equal) {
                 foreach ($controller as $index => $item) {
+                    if (stripos($item, '_') !== false) {
+                        $item = Loader::parseName($item, 1);
+                    }
+                    if (stripos($item, '/') !== false) {
+                        $controllerArr = explode('/', $item);
+                        end($controllerArr);
+                        $key = key($controllerArr);
+                        $controllerArr[$key] = Loader::parseName($controllerArr[$key]);
+                    } else {
+                        $controllerArr = [Loader::parseName($item)];
+                    }
+                    $item = str_replace('_', '\_', implode('/', $controllerArr));
                     if ($equal) {
                         $query->whereOr('name', 'eq', $item);
                     } else {
@@ -82,10 +95,17 @@ class Menu extends Command
 
         if (!in_array('all-controller', $controller)) {
             foreach ($controller as $index => $item) {
-                $controllerArr = explode('/', $item);
-                end($controllerArr);
-                $key = key($controllerArr);
-                $controllerArr[$key] = ucfirst($controllerArr[$key]);
+                if (stripos($item, '_') !== false) {
+                    $item = Loader::parseName($item, 1);
+                }
+                if (stripos($item, '/') !== false) {
+                    $controllerArr = explode('/', $item);
+                    end($controllerArr);
+                    $key = key($controllerArr);
+                    $controllerArr[$key] = ucfirst($controllerArr[$key]);
+                } else {
+                    $controllerArr = [ucfirst($item)];
+                }
                 $adminPath = dirname(__DIR__) . DS . 'controller' . DS . implode(DS, $controllerArr) . '.php';
                 if (!is_file($adminPath)) {
                     $output->error("controller not found");
@@ -159,10 +179,15 @@ class Menu extends Command
     protected function importRule($controller)
     {
         $controller = str_replace('\\', '/', $controller);
-        $controllerArr = explode('/', $controller);
-        end($controllerArr);
-        $key = key($controllerArr);
-        $controllerArr[$key] = ucfirst($controllerArr[$key]);
+        if (stripos($controller, '/') !== false) {
+            $controllerArr = explode('/', $controller);
+            end($controllerArr);
+            $key = key($controllerArr);
+            $controllerArr[$key] = ucfirst($controllerArr[$key]);
+        } else {
+            $key = 0;
+            $controllerArr = [ucfirst($controller)];
+        }
         $classSuffix = Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : '';
         $className = "\\app\\admin\\controller\\" . implode("\\", $controllerArr) . $classSuffix;
 

+ 8 - 2
public/assets/js/require-table.js

@@ -479,14 +479,20 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
                     var color = typeof this.color !== 'undefined' ? this.color : 'success';
                     var yes = typeof this.yes !== 'undefined' ? this.yes : 1;
                     var no = typeof this.no !== 'undefined' ? this.no : 0;
+                    var url = typeof this.url !== 'undefined' ? this.url : '';
                     return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Click to toggle') + "' class='btn-change' data-id='"
-                        + row.id + "' data-params='" + this.field + "=" + (value == yes ? no : yes) + "'><i class='fa fa-toggle-on " + (value == yes ? 'text-' + color : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>";
+                        + row.id + "' " + (url ? "data-url='" + url + "'" : "") + " data-params='" + this.field + "=" + (value == yes ? no : yes) + "'><i class='fa fa-toggle-on " + (value == yes ? 'text-' + color : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>";
                 },
                 url: function (value, row, index) {
                     return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
                 },
                 search: function (value, row, index) {
-                    return '<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', value) + '" data-field="' + this.field + '" data-value="' + value + '">' + value + '</a>';
+                    var field = this.field;
+                    if (typeof this.customField !== 'undefined' && typeof row[this.customField] !== 'undefined') {
+                        value = row[this.customField];
+                        field = this.customField;
+                    }
+                    return '<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', value) + '" data-field="' + field + '" data-value="' + value + '">' + value + '</a>';
                 },
                 addtabs: function (value, row, index) {
                     var url = Table.api.replaceurl(this.url, row, this.table);