Przeglądaj źródła

Merge branch 'v5.0.0dev' of https://gitee.com/ZhongBangKeJi/CRMEB into v5.0.0dev

From-wh 2 lat temu
rodzic
commit
f1ae59d215

+ 12 - 4
crmeb/app/services/system/SystemCrudServices.php

@@ -320,7 +320,7 @@ class SystemCrudServices extends BaseServices
                 [
                 [
                     'path' => $routeName,
                     'path' => $routeName,
                     'method' => 'POST',
                     'method' => 'POST',
-                    'name' => $modelName . '保存数据接口',
+                    'name' => $modelName . '保存接口',
                     'app_name' => 'adminapi',
                     'app_name' => 'adminapi',
                     'cate_id' => $cateId,
                     'cate_id' => $cateId,
                     'unique_auth' => '',
                     'unique_auth' => '',
@@ -338,7 +338,7 @@ class SystemCrudServices extends BaseServices
                 [
                 [
                     'path' => $routeName . '/<id>',
                     'path' => $routeName . '/<id>',
                     'method' => 'PUT',
                     'method' => 'PUT',
-                    'name' => $modelName . '修改数据接口',
+                    'name' => $modelName . '修改接口',
                     'app_name' => 'adminapi',
                     'app_name' => 'adminapi',
                     'cate_id' => $cateId,
                     'cate_id' => $cateId,
                     'unique_auth' => '',
                     'unique_auth' => '',
@@ -347,13 +347,19 @@ class SystemCrudServices extends BaseServices
                 [
                 [
                     'path' => $routeName . '/<id>',
                     'path' => $routeName . '/<id>',
                     'method' => 'DELETE',
                     'method' => 'DELETE',
-                    'name' => $modelName . '删除数据接口',
+                    'name' => $modelName . '删除接口',
                     'app_name' => 'adminapi',
                     'app_name' => 'adminapi',
                     'cate_id' => $cateId,
                     'cate_id' => $cateId,
                     'unique_auth' => '',
                     'unique_auth' => '',
                     'add_time' => date('Y-m-d H:i:s')
                     'add_time' => date('Y-m-d H:i:s')
                 ],
                 ],
             ];
             ];
+            $routeService = app()->make(SystemRouteServices::class);
+            foreach ($ruleData as $key => $item) {
+                if ($routeService->count(['method' => $item['method'], 'path' => $item['path']])) {
+                    unset($ruleData[$key]);
+                }
+            }
             app()->make(SystemRouteServices::class)->saveAll($ruleData);
             app()->make(SystemRouteServices::class)->saveAll($ruleData);
             //记录权限加入菜单表
             //记录权限加入菜单表
             $menuData = [];
             $menuData = [];
@@ -538,7 +544,9 @@ class SystemCrudServices extends BaseServices
         ]);
         ]);
         //生成验证器
         //生成验证器
         $validate = app()->make(Validate::class);
         $validate = app()->make(Validate::class);
-        $validate->setFilePathName($filePath['validate'] ?? '')->setbasePath($basePath)->handle($tableName);
+        $validate->setFilePathName($filePath['validate'] ?? '')->setbasePath($basePath)->handle($tableName, [
+            'field' => $options['fromField'],
+        ]);
         //生成控制器
         //生成控制器
         $controller = app()->make(Controller::class);
         $controller = app()->make(Controller::class);
         $controller->setFilePathName($filePath['controller'] ?? '')->setbasePath($basePath)->handle($tableName, [
         $controller->setFilePathName($filePath['controller'] ?? '')->setbasePath($basePath)->handle($tableName, [

+ 7 - 1
crmeb/app/services/system/SystemRouteServices.php

@@ -204,7 +204,13 @@ class SystemRouteServices extends BaseServices
                 $cateId = $commmonId;
                 $cateId = $commmonId;
             } else {
             } else {
                 if (!isset($item['option']['cate_name'])) {
                 if (!isset($item['option']['cate_name'])) {
-                    $cateId = $id;
+                    if (strstr($item['rule'], '<MISS>') === false) {
+                        $rule = explode('/', $item['rule']);
+                        $cateId = $this->topCateId($app, $rule[0]);
+                    } else {
+                        //miss路由不写入
+                        continue;
+                    }
                 } else {
                 } else {
                     $cateId = $this->topCateId($app, $item['option']['cate_name']);
                     $cateId = $this->topCateId($app, $item['option']['cate_name']);
                 }
                 }

+ 2 - 0
crmeb/crmeb/services/crud/Service.php

@@ -148,6 +148,7 @@ class Service extends Make
      */
      */
     protected function getframeImageOnePhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-add', string $width = '950px', string $height = '505px')
     protected function getframeImageOnePhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-add', string $width = '950px', string $height = '505px')
     {
     {
+        $name = addslashes($name);
         $requiredText = $required ? '->required()' : '';
         $requiredText = $required ? '->required()' : '';
         $content = <<<CONTENT
         $content = <<<CONTENT
 \$rule[] = FormBuilder::frameImage('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field']), \$info['$field'] ?? '')->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
 \$rule[] = FormBuilder::frameImage('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field']), \$info['$field'] ?? '')->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
@@ -170,6 +171,7 @@ CONTENT;
      */
      */
     protected function getframeImagesPhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-images', int $maxLength = 10, string $width = '950px', string $height = '505px')
     protected function getframeImagesPhpContent(string $field, string $name, bool $required = false, string $icon = 'ios-images', int $maxLength = 10, string $width = '950px', string $height = '505px')
     {
     {
+        $name = addslashes($name);
         $requiredText = $required ? '->required()' : '';
         $requiredText = $required ? '->required()' : '';
         $content = <<<CONTENT
         $content = <<<CONTENT
 \$rule[] = FormBuilder::frameImages('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field', 'type' => 'many', 'maxLength' => $maxLength]), \$info['$field'] ?? [])->maxLength($maxLength)->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText
 \$rule[] = FormBuilder::frameImages('$field', '$name', url(config('app.admin_prefix', 'admin') . '/widget.images/index', ['fodder' => '$field', 'type' => 'many', 'maxLength' => $maxLength]), \$info['$field'] ?? [])->maxLength($maxLength)->icon('$icon')->width('$width')->height('$height')->modal(['footer-hide' => true])$requiredText

+ 37 - 0
crmeb/crmeb/services/crud/Validate.php

@@ -38,6 +38,43 @@ class Validate extends Make
         return 'app' . DS . 'adminapi' . DS . 'validate' . DS . 'crud';
         return 'app' . DS . 'adminapi' . DS . 'validate' . DS . 'crud';
     }
     }
 
 
+    /**
+     * @param string $name
+     * @param array $options
+     * @return Validate
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/23
+     */
+    public function handle(string $name, array $options = [])
+    {
+        [$rule, $message] = $this->getRuleContent($options['field']);
+        $this->value['rule-php'] = $rule;
+        $this->value['message-php'] = $message;
+        return parent::handle($name, $options); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * @param array $field
+     * @return array
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/23
+     */
+    protected function getRuleContent(array $field)
+    {
+        $content = [];
+        $message = [];
+        foreach ($field as $item) {
+            $item['name'] = addslashes($item['name']);
+            if ($item['required']) {
+                $content[] = $this->tab(2) . '\'' . $item['field'] . '\'=>\'require\'';
+                $message[] = $this->tab(2) . '\'' . $item['field'] . '.require\'=>\'' . $item['name'] . '必须填写\'';
+            }
+        }
+        return [implode("\n", $content), implode("\n", $message)];
+    }
+
     /**
     /**
      * 模板文件配置
      * 模板文件配置
      * @param string $type
      * @param string $type

+ 1 - 1
crmeb/crmeb/services/crud/stubs/route/delete.stub

@@ -1 +1 @@
-Route::delete('{%route%}/:id', 'crud.{%routePath%}{%controller%}/delete')->option(['real_name' => '{%menus%}删除数据接口']);
+Route::delete('{%route%}/:id', 'crud.{%routePath%}{%controller%}/delete')->option(['real_name' => '{%menus%}删除接口']);

+ 1 - 1
crmeb/crmeb/services/crud/stubs/route/save.stub

@@ -1 +1 @@
-Route::post('{%route%}', 'crud.{%routePath%}{%controller%}/save')->option(['real_name' => '{%menus%}保存数据接口']);
+Route::post('{%route%}', 'crud.{%routePath%}{%controller%}/save')->option(['real_name' => '{%menus%}保存接口']);

+ 1 - 1
crmeb/crmeb/services/crud/stubs/route/update.stub

@@ -1 +1 @@
-Route::put('{%route%}/:id', 'crud.{%routePath%}{%controller%}/update')->option(['real_name' => '{%menus%}修改数据接口']);
+Route::put('{%route%}/:id', 'crud.{%routePath%}{%controller%}/update')->option(['real_name' => '{%menus%}修改接口']);

+ 2 - 2
crmeb/crmeb/services/crud/stubs/validate/crudValidate.stub

@@ -33,14 +33,14 @@ class {%nameCamel%}Validate extends Validate
      * @var array
      * @var array
      */
      */
     protected $rule = [
     protected $rule = [
-
+{%rule-php%}
     ];
     ];
 
 
     /**
     /**
      * @var array
      * @var array
      */
      */
     protected $message = [
     protected $message = [
-
+{%message-php%}
     ];
     ];
 
 
     /**
     /**