ソースを参照

修改生成默认模板

liaofei 2 年 前
コミット
f413c45952

+ 2 - 0
crmeb/app/services/system/SystemCrudServices.php

@@ -531,6 +531,7 @@ class SystemCrudServices extends BaseServices
         $service = app()->make(Service::class);
         $service->setFilePathName($filePath['service'] ?? '')->setbasePath($basePath)->handle($tableName, [
             'field' => $options['fromField'],
+            'key' => $options['key'],
             'usePath' => $dao->getUsePath(),
             'modelName' => $options['modelName'] ?? '',
         ]);
@@ -566,6 +567,7 @@ class SystemCrudServices extends BaseServices
         $viewPages->setFilePathName($filePath['pages'] ?? '')->setbasePath($basePath)->handle($tableName, [
             'field' => $options['columnField'],
             'route' => $routeName,
+            'key' => $options['key'],
             'pathApiJs' => '@/' . str_replace('\\', '/', str_replace([Make::adminTemplatePath(), '.js'], '', $viewApi->getPath())),
         ]);
 

+ 4 - 7
crmeb/crmeb/services/crud/Service.php

@@ -49,12 +49,9 @@ class Service extends Make
         $this->value['use-php'] = $this->getDaoClassName($name, $path);
         $this->value['modelName'] = $options['modelName'] ?? $name;
 
-        $action = $options['action'] ?? [];
-        $field = $options['field'] ?? [];
 
-        if (!$action) {
-            $action = ['index', 'form', 'save', 'update'];
-        }
+        $field = $options['field'] ?? [];
+        $action = ['index', 'form', 'save', 'update'];
 
         $contentAction = '';
         foreach ($action as $item) {
@@ -64,8 +61,8 @@ class Service extends Make
 
         //生成form表单
         if (in_array('save', $action) || in_array('update', $action)) {
-            $var = ['{%date%}', '{%route%}', '{%form-php%}', '{%modelName%}'];
-            $value = [$this->value['date'], Str::snake($options['route'] ?? $name)];
+            $var = ['{%key%}', '{%date%}', '{%route%}', '{%form-php%}', '{%modelName%}'];
+            $value = [$options['key'] ?? 'id', $this->value['date'], Str::snake($options['route'] ?? $name)];
             $from = [];
             foreach ($field as $item) {
                 switch ($item['type']) {

+ 1 - 0
crmeb/crmeb/services/crud/ViewPages.php

@@ -90,6 +90,7 @@ class ViewPages extends Make
         }
         $this->value['auth'] = Str::snake($name);
         $this->value['componentName'] = $this->value['auth'];
+        $this->value['key'] = $options['key'] ?? 'id';
         $this->value['route'] = $route;
         $this->value['content-vue'] = $columnStr ? "\n" . implode($this->tab(2) . ',', $columnStr) . $this->tab(2) . ',' : '';
         $this->value['pathApiJs'] = $options['pathApiJs'] ?? '';

+ 1 - 1
crmeb/crmeb/services/crud/stubs/service/CrudListIndex.stub

@@ -7,7 +7,7 @@
     public function getCrudListIndex(array $where = [])
     {
         [$page, $limit] = $this->getPageValue();
-        $model = $this->dao->selectModel($where, '*', $page, $limit);
+        $model = $this->dao->selectModel($where, '*', $page ?: 1, $limit ?: 10, '{%key%} desc');
 
         return ['count' => $model->count(), 'list' => $model->select()->toArray()];
     }

+ 1 - 1
crmeb/crmeb/services/crud/stubs/view/pages/crud/index.stub

@@ -48,7 +48,7 @@ export default {
       columns: [
         {
           title: 'ID',
-          key: 'id',
+          key: '{%key%}',
           width: 80,
         },{%content-vue%}
         {