Explorar o código

crud相关代码增加

liaofei %!s(int64=2) %!d(string=hai) anos
pai
achega
127bf916dd
Modificáronse 47 ficheiros con 1753 adicións e 109 borrados
  1. 1 0
      .gitignore
  2. 0 3
      crmeb/config/console.php
  3. 20 0
      crmeb/crmeb/command/Crud.php
  4. 36 0
      crmeb/crmeb/command/Npm.php
  5. 3 2
      crmeb/crmeb/command/Util.php
  6. 36 0
      crmeb/crmeb/exceptions/CrudException.php
  7. 134 0
      crmeb/crmeb/services/crud/Controller.php
  8. 2 41
      crmeb/crmeb/services/crud/Dao.php
  9. 345 0
      crmeb/crmeb/services/crud/Make.php
  10. 44 0
      crmeb/crmeb/services/crud/Model.php
  11. 101 0
      crmeb/crmeb/services/crud/Route.php
  12. 87 63
      crmeb/crmeb/services/crud/Service.php
  13. 39 0
      crmeb/crmeb/services/crud/Validate.php
  14. 96 0
      crmeb/crmeb/services/crud/ViewApi.php
  15. 71 0
      crmeb/crmeb/services/crud/ViewPages.php
  16. 99 0
      crmeb/crmeb/services/crud/ViewRouter.php
  17. 51 0
      crmeb/crmeb/services/crud/stubs/controller/CrudController.stub
  18. 9 0
      crmeb/crmeb/services/crud/stubs/controller/create.stub
  19. 18 0
      crmeb/crmeb/services/crud/stubs/controller/delete.stub
  20. 10 0
      crmeb/crmeb/services/crud/stubs/controller/edit.stub
  21. 9 0
      crmeb/crmeb/services/crud/stubs/controller/index.stub
  22. 15 0
      crmeb/crmeb/services/crud/stubs/controller/save.stub
  23. 20 0
      crmeb/crmeb/services/crud/stubs/controller/update.stub
  24. 41 0
      crmeb/crmeb/services/crud/stubs/dao/CrudDao.stub
  25. 43 0
      crmeb/crmeb/services/crud/stubs/model/CrudModel.stub
  26. 1 0
      crmeb/crmeb/services/crud/stubs/route/create.stub
  27. 1 0
      crmeb/crmeb/services/crud/stubs/route/delete.stub
  28. 1 0
      crmeb/crmeb/services/crud/stubs/route/edit.stub
  29. 1 0
      crmeb/crmeb/services/crud/stubs/route/index.stub
  30. 7 0
      crmeb/crmeb/services/crud/stubs/route/route.stub
  31. 1 0
      crmeb/crmeb/services/crud/stubs/route/save.stub
  32. 1 0
      crmeb/crmeb/services/crud/stubs/route/update.stub
  33. 13 0
      crmeb/crmeb/services/crud/stubs/service/CrudListIndex.stub
  34. 10 0
      crmeb/crmeb/services/crud/stubs/service/CrudSave.stub
  35. 44 0
      crmeb/crmeb/services/crud/stubs/service/CrudService.stub
  36. 11 0
      crmeb/crmeb/services/crud/stubs/service/CrudUpdate.stub
  37. 23 0
      crmeb/crmeb/services/crud/stubs/service/GetCrudForm.stub
  38. 52 0
      crmeb/crmeb/services/crud/stubs/validate/CrudValidate.stubs
  39. 13 0
      crmeb/crmeb/services/crud/stubs/view/api/crud.stub
  40. 11 0
      crmeb/crmeb/services/crud/stubs/view/api/crudDeleteApi.stub
  41. 12 0
      crmeb/crmeb/services/crud/stubs/view/api/crudSaveApi.stub
  42. 12 0
      crmeb/crmeb/services/crud/stubs/view/api/crudUpdateApi.stub
  43. 10 0
      crmeb/crmeb/services/crud/stubs/view/api/getCrudCreateApi.stub
  44. 11 0
      crmeb/crmeb/services/crud/stubs/view/api/getCrudEditApi.stub
  45. 12 0
      crmeb/crmeb/services/crud/stubs/view/api/getCrudListApi.stub
  46. 137 0
      crmeb/crmeb/services/crud/stubs/view/pages/crud/index.stub
  47. 39 0
      crmeb/crmeb/services/crud/stubs/view/router/modules/crud.stub

+ 1 - 0
.gitignore

@@ -20,3 +20,4 @@
 /template/uni-app/node_modules/
 /template/uni-app/unpackage/
 /template/uni-app/.hbuilderx/
+crmeb/.idea/

+ 0 - 3
crmeb/config/console.php

@@ -19,9 +19,6 @@ return [
     'commands' => [
         'workerman' => \crmeb\command\Workerman::class,
         'timer' => \crmeb\command\Timer::class,
-        'make:business' => \crmeb\command\Business::class,
-        'make:dao' => \crmeb\command\Dao::class,
-        'make:service' => \crmeb\command\Service::class,
         'util' => \crmeb\command\Util::class
     ],
 ];

+ 20 - 0
crmeb/crmeb/command/Crud.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\command\crud;
+
+
+class Crud
+{
+
+}

+ 36 - 0
crmeb/crmeb/command/Npm.php

@@ -0,0 +1,36 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\command;
+
+
+use think\console\Command;
+use think\console\input\Argument;
+use think\console\input\Option;
+
+class Npm extends Command
+{
+    protected function configure()
+    {
+        $this->setName('npm')
+            ->addOption('path', 'dp', Option::VALUE_OPTIONAL, '默认路径')
+            ->addOption('build', 'bu', Option::VALUE_OPTIONAL, '打包存放路径')
+            ->addOption('zip', 'z', Option::VALUE_NONE, '打包成zip')
+            ->setDescription('NPM打包工具');
+    }
+
+    public function handle()
+    {
+
+    }
+}

+ 3 - 2
crmeb/crmeb/command/Util.php

@@ -37,7 +37,7 @@ class Util extends Command
                 if (!$url) {
                     return $output->error('缺少替换的域名');
                 }
-                $this->replaceSiteUrl($host, $url);
+                $this->replaceSiteUrl($url, $host);
                 break;
         }
 
@@ -62,9 +62,10 @@ class Util extends Command
             "UPDATE `{$prefix}article_content` SET `content` = replace(`content` ,'{$siteUrl}','{$url}')",
             "UPDATE `{$prefix}store_category` SET `pic` = replace(`pic` ,'{$siteUrl}','{$url}')",
             "UPDATE `{$prefix}system_group_data` SET `value` = replace(value ,'{$siteUrlJosn}','{$valueJosn}')",
-            "UPDATE `{$prefix}eb_diy` SET `value` = replace(value ,'{$siteUrlJosn}','{$valueJosn}')",
+            "UPDATE `{$prefix}diy` SET `value` = replace(value ,'{$siteUrlJosn}','{$valueJosn}')",
             "UPDATE `{$prefix}store_product_description` SET `description`= replace(description,'{$siteUrl}','{$url}')"
         ];
+
         return Db::transaction(function () use ($sql) {
             try {
                 foreach ($sql as $item) {

+ 36 - 0
crmeb/crmeb/exceptions/CrudException.php

@@ -0,0 +1,36 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\exceptions;
+
+
+class CrudException extends \RuntimeException
+{
+    public function __construct($message = "", $replace = [], $code = 0, \Throwable $previous = null)
+    {
+        if (is_array($message)) {
+            $errInfo = $message;
+            $message = $errInfo[1] ?? '未知错误';
+            if ($code === 0) {
+                $code = $errInfo[0] ?? 400;
+            }
+        }
+
+        if (is_numeric($message)) {
+            $code = $message;
+            $message = getLang($message, $replace);
+        }
+
+        parent::__construct($message, $code, $previous);
+    }
+}

+ 134 - 0
crmeb/crmeb/services/crud/Controller.php

@@ -0,0 +1,134 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+
+use think\helper\Str;
+
+/**
+ * 创建Controller
+ * Class Controller
+ * @author 等风来
+ * @email 136327134@qq.com
+ * @date 2023/3/13
+ * @package crmeb\servives\crud
+ */
+class Controller extends Make
+{
+
+    /**
+     * @var string
+     */
+    protected $name = 'controller';
+
+    /**
+     * @return mixed|void
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    public function handle(string $name, string $path, array $options = [])
+    {
+        $contentPhp = '';
+        $var = ["{%date%}"];
+        $fieldPhp = [$this->value['date']];
+
+        $action = $options['action'] ?? [];
+        $field = $options['field'] ?? [];
+
+        if (!$action) {
+            $action = ['index', 'create', 'save', 'edit', 'update', 'delete'];
+        }
+
+        if ($field) {
+            $fieldStr = '';
+            foreach ($field as $k) {
+                $fieldStr .= "['$k',''],\n";
+            }
+            $fieldPhp[] = $fieldStr;
+        }
+
+        $res = false;
+        foreach ($action as $item) {
+            if (in_array($item, ['save', 'update'])) {
+                $res = true;
+            }
+            [$class, $stub] = $this->getStubContent($name, $item);
+            $contentPhp .= $stub . "\r\n";
+        }
+
+        if ($res) {
+            $var[] = '{%field-php%}';
+        }
+
+        if ($var && $fieldPhp) {
+            $contentPhp = str_replace($var, $fieldPhp, $contentPhp);
+        }
+
+        [$className, $contentController] = $this->getStubContent($name, 'controller');
+
+        $this->value['nameCamel'] = Str::studly($name);
+        $this->value['name'] = $className;
+        $this->value['path'] = $this->getfolderPath($path);
+        $this->value['content-php'] = $contentPhp;
+
+        $contentStr = str_replace($this->var, $this->value, $contentController);
+
+        $filePath = $this->getFilePathName($path, $this->value['nameCamel']);
+
+        return $this->makeFile($filePath, $contentStr);
+    }
+
+    /**
+     * 返回模板路径
+     * @param string $type
+     * @return mixed|string|string[]
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getStub(string $type = '')
+    {
+        $controllerPath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR;
+
+        $stubs = [
+            'index' => $controllerPath . 'index.stub',
+            'create' => $controllerPath . 'create.stub',
+            'save' => $controllerPath . 'save.stub',
+            'edit' => $controllerPath . 'edit.stub',
+            'update' => $controllerPath . 'update.stub',
+            'delete' => $controllerPath . 'delete.stub',
+            'controller' => $controllerPath . 'CrudController.stub',
+        ];
+
+        return $type ? $stubs[$type] : $stubs;
+    }
+
+    /**
+     * @param string $path
+     * @param string $name
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getFilePathName(string $path, string $name): string
+    {
+        $path = str_replace(['app\\', 'app/'], '', $path);
+
+        $path = ltrim(str_replace('\\', '/', $path), '/');
+
+        return $this->app->getBasePath() . $path . DIRECTORY_SEPARATOR . $name . '.' . $this->fileMime;
+    }
+}

+ 2 - 41
crmeb/crmeb/services/crud/Dao.php

@@ -8,13 +8,12 @@
 // +----------------------------------------------------------------------
 // | Author: CRMEB Team <admin@crmeb.com>
 // +----------------------------------------------------------------------
-namespace crmeb\command\crud;
+namespace crmeb\services\crud;
 
-use think\console\input\Option;
 
 /**
  * Class Business
- * @package crmeb\command
+ * @package crmeb\services
  */
 class Dao extends Make
 {
@@ -24,44 +23,6 @@ class Dao extends Make
      */
     protected $name = "dao";
 
-    /**
-     * 变量名称
-     * @var string[]
-     */
-    protected $var = [
-        '{%year%}',
-        '{%time%}',
-        '{%path%}',
-        '{%name%}',
-        '{%nameCamel%}',
-        '{%date%}',
-    ];
-
-    /**
-     * @var null[]
-     */
-    protected $value = [
-        'year' => '',
-        'time' => '',
-        'path' => '',
-        'name' => '',
-        'nameCamel' => '',
-        'date' => '',
-    ];
-
-    /**
-     * 命令行配置
-     * @author 等风来
-     * @email 136327134@qq.com
-     * @date 2023/3/13
-     */
-    protected function configure()
-    {
-        $this->preConfigure();
-        $this->addOption('f', null, Option::VALUE_REQUIRED, 'dao层文件存放');
-        $this->setDescription('CRUD创建dao层代码');
-    }
-
     /**
      * 模板文件
      * @param string $type

+ 345 - 0
crmeb/crmeb/services/crud/Make.php

@@ -0,0 +1,345 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+use crmeb\exceptions\CrudException;
+use think\App;
+use think\helper\Str;
+
+/**
+ * 创建crud基类
+ * Class Make
+ * @author 等风来
+ * @email 136327134@qq.com
+ * @date 2023/3/13
+ * @package crmeb\services\crud
+ */
+abstract class Make
+{
+
+    /**
+     * 命令名称
+     * @var string
+     */
+    protected $name = '';
+
+    /**
+     * 文件类型
+     * @var string
+     */
+    protected $fileMime = 'php';
+
+    /**
+     * 变量名称
+     * @var array
+     */
+    protected $var = [];
+
+    /**
+     * 内容
+     * @var array
+     */
+    protected $value = [];
+
+    /**
+     * @var bool
+     */
+    protected $isMake = true;
+
+    /**
+     * 后台前端模板根路径
+     * @var string
+     */
+    protected $adminTemplatePath;
+
+    /**
+     * @var string
+     */
+    protected $basePath;
+
+    /**
+     * @var
+     */
+    protected $app;
+
+
+    /**
+     * Make constructor.
+     * @param App $app
+     */
+    public function __construct(App $app)
+    {
+        $this->app = $app;
+        $this->adminTemplatePath = dirname($this->app->getRootPath()) . DS . 'template' . DS . 'admin' . DS . 'src' . DS;
+        $this->basePath = $this->app->getRootPath();
+        $this->authDrawVar();
+        $this->drawValueKeys();
+        $this->setDefaultValue();
+    }
+
+    /**
+     * @param int $num
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/29
+     */
+    public function tab(int $num = 1): string
+    {
+        return str_pad('', 4 * $num);
+    }
+
+    /**
+     * 是否成功文件
+     * @param bool $isMake
+     * @return $this
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/3
+     */
+    public function isMake(bool $isMake = true)
+    {
+        $this->isMake = $isMake;
+        return $this;
+    }
+
+    /**
+     * 执行
+     * @return mixed|void
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    public function handle(string $name, string $path, array $options = [])
+    {
+
+        [$nameData, $content] = $this->getStubContent($name);
+
+        $this->value['name'] = $nameData;
+        if (isset($this->value['nameCamel'])) {
+            $this->value['nameCamel'] = Str::studly($name);
+        }
+        if (isset($this->value['path'])) {
+            $this->value['path'] = $this->getfolderPath($path);
+        }
+
+        $contentStr = str_replace($this->var, $this->value, $content);
+
+        $filePath = $this->getFilePathName($path, $this->value['nameCamel']);
+
+        return $this->makeFile($filePath, $contentStr);
+    }
+
+    /**
+     * 模板文件配置
+     * @param string $type
+     * @return mixed
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    abstract protected function getStub(string $type = '');
+
+    /**
+     * 自动
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/29
+     */
+    protected function authDrawVar()
+    {
+        $content = file_get_contents($this->getStub());
+        $pattern = '/\{\%+[a-zA-Z0-9_-]+\%\}/';
+        preg_match_all($pattern, $content, $var);
+        $varData = $var[0] ?? [];
+        $varData = array_unique($varData);
+        if ($varData) {
+            $this->var = $varData;
+        }
+    }
+
+    /**
+     * 提取value key
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/29
+     */
+    protected function drawValueKeys()
+    {
+        foreach ($this->var as $value) {
+            $this->value[str_replace(['{%', '%}'], '', $value)] = '';
+        }
+    }
+
+    /**
+     * 设置默认值
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function setDefaultValue()
+    {
+        if (isset($this->value['year'])) {
+            $this->value['year'] = date('Y');
+        }
+        if (isset($this->value['time'])) {
+            $this->value['time'] = date('Y/m/d H:i:s');
+        }
+        if (isset($this->value['date'])) {
+            $this->value['date'] = date('Y/m/d');
+        }
+    }
+
+    /**
+     * @param string $name
+     * @return array
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getStubContent(string $name, string $type = '')
+    {
+        $stub = file_get_contents($this->getStub($type));
+
+        $namespace = trim(implode('\\', array_slice(explode('\\', $name), 0, -1)), '\\');
+
+        $class = str_replace($namespace . '\\', '', $name);
+
+        return [$class, $stub];
+    }
+
+    /**
+     * 获取文件路径
+     * @param string $path
+     * @param string $name
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getFilePathName(string $path, string $name): string
+    {
+        $path = str_replace(['app\\', 'app/'], '', $path);
+
+        $path = ltrim(str_replace('\\', '/', $path), '/');
+
+        return $this->basePath . $path . DIRECTORY_SEPARATOR . $name . ucwords($this->name) . '.' . $this->fileMime;
+    }
+
+    /**
+     * @param string $path
+     * @return mixed|string|null
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getfolderPath(string $path)
+    {
+        $path = ltrim(str_replace('\\', '/', $path), '/');
+        $pathArr = explode('/', $path);
+        $count = count($pathArr);
+        $res = $pathArr[$count - 1] ?? null;
+        if ($pathArr && $res && $res == $this->name) {
+            return '';
+        } else {
+            return '\\' . $res;
+        }
+    }
+
+    /**
+     * 获取文件路径
+     * @param string $name
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getPathName(string $name): string
+    {
+        $name = str_replace('app\\', '', $name);
+
+        return $this->app->getBasePath() . ltrim(str_replace('\\', '/', $name), '/') . '.php';
+    }
+
+    /**
+     * 获取类名
+     * @param string $name
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getClassName(string $name): string
+    {
+        if (strpos($name, '\\') !== false) {
+            return $name;
+        }
+
+        if (strpos($name, '@')) {
+            [$app, $name] = explode('@', $name);
+        } else {
+            $app = '';
+        }
+
+        if (strpos($name, '/') !== false) {
+            $name = str_replace('/', '\\', $name);
+        }
+
+        return $this->getNamespace($app) . '\\' . $name;
+    }
+
+    /**
+     * 获取命名空间名
+     * @param string $app
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getNamespace(string $app): string
+    {
+        return 'app' . ($app ? '\\' . $app : '');
+    }
+
+    /**
+     * 执行创建文件
+     * @return false
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function makeFile(string $pathname, string $content)
+    {
+
+        if (is_file($pathname)) {
+            throw new CrudException($this->name . ':' . $pathname . ' already exists!');
+        }
+
+        if (!is_dir(dirname($pathname))) {
+            mkdir(dirname($pathname), 0755, true);
+        }
+
+        $content = str_replace('', '', $content);
+
+        if ($this->isMake) {
+            try {
+                file_put_contents($pathname, $content);
+            } catch (\Throwable $e) {
+                throw new CrudException('CRUD生成文件报错,无法写入:' . $pathname);
+            }
+        }
+
+        return $content;
+    }
+}

+ 44 - 0
crmeb/crmeb/services/crud/Model.php

@@ -0,0 +1,44 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+
+/**
+ * Class Model
+ * @author 等风来
+ * @email 136327134@qq.com
+ * @date 2023/3/13
+ * @package crmeb\command\crud
+ */
+class Model extends Make
+{
+    /**
+     * 当前命令名称
+     * @var string
+     */
+    protected $name = "model";
+
+    /**
+     * 模板文件
+     * @param string $type
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/13
+     */
+    protected function getStub(string $type = '')
+    {
+        return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'CrudModel.stub';
+    }
+}

+ 101 - 0
crmeb/crmeb/services/crud/Route.php

@@ -0,0 +1,101 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+
+use crmeb\exceptions\CrudException;
+
+class Route extends Make
+{
+    /**
+     * @var string
+     */
+    protected $name = 'route';
+
+    /**
+     * @param string $name
+     * @param string $path
+     * @param array $options
+     * @return mixed|void
+     */
+    public function handle(string $name, string $path, array $options = [])
+    {
+        $action = $options['action'] ?? [];
+        $route = $options['route'] ?? '';
+        $controller = $options['controller'] ?? '';
+        $menus = $options['menus'] ?? '';
+        if (!$route) {
+            throw new CrudException('缺少路由名称');
+        }
+        if (!$action) {
+            $action = ['index', 'create', 'save', 'edit', 'update', 'delete'];
+        }
+
+        $var = [
+            '{%route%}',
+            '{%controller%}',
+            '{%menus%}',
+        ];
+
+        $value = [
+            $route,
+            $controller ? '.' . $controller : '',
+            $menus
+        ];
+
+        $routeContent = "";
+        foreach ($action as $item) {
+            $routeContent .= $this->getStub($item) . "\r\n";
+        }
+
+        if ($var && $value) {
+            $routeContent = str_replace($var, $value, $routeContent);
+        }
+
+        $content = $this->getStub();
+
+        $this->value['content-php'] = $routeContent;
+
+        $contentStr = str_replace($this->var, $this->value, $content);
+
+        $filePath = $this->getFilePathName($path, $this->value['nameCamel']);
+
+        return $this->makeFile($filePath, $contentStr);
+    }
+
+    /**
+     * 设置模板
+     * @param string $type
+     * @return mixed|string|string[]
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/14
+     */
+    protected function getStub(string $type = 'route')
+    {
+        $routePath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'route' . DIRECTORY_SEPARATOR;
+
+        $stubs = [
+            'index' => $routePath . 'index.stub',
+            'create' => $routePath . 'create.stub',
+            'save' => $routePath . 'save.stub',
+            'edit' => $routePath . 'edit.stub',
+            'update' => $routePath . 'update.stub',
+            'delete' => $routePath . 'delete.stub',
+            'route' => $routePath . 'route.stub',
+        ];
+
+        return $type ? $stubs[$type] : $stubs;
+    }
+}

+ 87 - 63
crmeb/crmeb/services/crud/Service.php

@@ -8,94 +8,118 @@
 // +----------------------------------------------------------------------
 // | Author: CRMEB Team <admin@crmeb.com>
 // +----------------------------------------------------------------------
-namespace crmeb\command\crud;
+namespace crmeb\services\crud;
 
-
-use think\console\input\Option;
+use think\helper\Str;
 
 /**
  * Class Business
- * @package crmeb\command
+ * @package crmeb\services
  */
 class Service extends Make
 {
     /**
      * @var string
      */
-    protected $name = "service";
-
-    /**
-     * @var string[]
-     */
-    protected $var = [
-        '{%year%}',
-        '{%time%}',
-        '{%date%}',
-        '{%nameCamel%}',
-        '{%path%}',
-        '{%content-php%}'
-    ];
-
-    /**
-     * @var string[]
-     */
-    protected $value = [
-        'year' => '',
-        'time' => '',
-        'date' => '',
-        'nameCamel' => '',
-        'path' => '',
-        'content-php' => '',
-        'dao-php' => ''
-    ];
+    protected $name = "services";
 
     /**
-     * 配置指令
+     * @param string $name
+     * @param string $path
+     * @param array $options
+     * @return mixed|void
      * @author 等风来
      * @email 136327134@qq.com
-     * @date 2023/3/13
+     * @date 2023/3/23
      */
-    protected function configure()
+    public function handle(string $name, string $path, array $options = [])
     {
-        $this->preConfigure();
-        $this->addOption('a', null, Option::VALUE_OPTIONAL, '需要的生成的方法,可选参数:index、form、save、update;多个生成用英文逗号隔开');
-        $this->addOption('f', null, Option::VALUE_REQUIRED, 'service层文件存放');
-        $this->addOption('k', null, Option::VALUE_OPTIONAL, '需要的生成获取的数据字段;多个生成用英文逗号隔开');
-        $this->addOption('d', null, Option::VALUE_OPTIONAL, '关联dao层');
-        $this->setDescription('CRUD创建service层代码');
-    }
 
-    public function handle()
-    {
-        $this->setDefaultValue();
+        $this->value['use-php'] = $this->getDaoClassName($name, $path);
 
-        $name = $this->input->getArgument('name');
-        $action = $this->input->getOption('a');
-        $field = $this->input->getOption('k');
-        $path = $this->input->getOption('f');
+        $action = $options['action'] ?? [];
+        $field = $options['field'] ?? [];
 
-        if ($action) {
-            $action = explode(',', $action);
-        } else {
+        if (!$action) {
             $action = ['index', 'form', 'save', 'update'];
         }
 
-        $fieldData = [];;
-        if ($field) {
-            $fieldData = json_decode($field, true);
-            if ($fieldData === null && strstr($field, ',')) {
-                $fieldData = explode(',', $field);
+        $contentAction = '';
+        foreach ($action as $item) {
+            [$class, $stub] = $this->getStubContent($name, $item);
+            $contentAction .= $stub . "\n";
+        }
+
+        //生成form表单
+        if (in_array('save', $action) || in_array('update', $action)) {
+            $var = ['{%date%}', '{%route%}', '{%form-php%}', '{%menus%}'];
+            $value = [$this->value['date'], Str::snake($options['route'] ?? $name)];
+            $from = [];
+            foreach ($field as $item) {
+                $from[] = $this->tab(2) . '$rule[] = FormBuilder::' . $item['type'] . '("' . $item['field'] . '","' . $item['name'] . '",$info["' . $item['field'] . '"] ?? "")' . $this->getOptionContent($item['option'] ?? []) . (!empty($item['required']) ? '->required()' : '') . ';';
+            }
+            if ($from) {
+                $this->value['use-php'] .= "\n" . 'use crmeb\services\FormBuilder;';
+                $value[] = implode("\n", $from);
+            }
+            $value[] = $options['menus'] ?? $name;
+
+            if ($value && $var) {
+                $contentAction = str_replace($var, $value, $contentAction);
             }
         }
 
-//        $from = [];
-//        foreach ($fieldData as $item) {
-//            $from[] = '';
-//        }
-        $axja = php_sapi_name();
-        $this->writeln(compact('fieldData', 'axja'));
+        //生成service
+        [$className, $content] = $this->getStubContent($name, $this->name);
+
+        $this->value['nameCamel'] = Str::studly($name);
+        $this->value['name'] = $className;
+        $this->value['path'] = $this->getfolderPath($path);
+        $this->value['content-php'] = $contentAction;
+
+        $contentStr = str_replace($this->var, $this->value, $content);
+
+        $filePath = $this->getFilePathName($path, $this->value['nameCamel']);
+
+        return $this->makeFile($filePath, $contentStr);
     }
 
+    /**
+     * @param array $option
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/23
+     */
+    protected function getOptionContent(array $option = [])
+    {
+        $php = '';
+        if ($option) {
+            $res = var_export($option, true);
+
+            $strOption = str_replace(['array', '(', ')'], ['', '[', ']'], $res);
+            $php = '->options(' . $strOption . ')';
+        }
+
+        return $php;
+    }
+
+    /**
+     * @param string $name
+     * @param string $path
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/3/23
+     */
+    protected function getDaoClassName(string $name, string $path)
+    {
+        $path = str_replace(['app\\services', 'app/services'], '', $path);
+        $path = ltrim(str_replace('\\', '/', $path), '/');
+        return 'use app\dao\\' . ($path ? $path . '\\' : '') . Str::studly($name) . 'Dao;';
+    }
+
+
     /**
      * @param string $type
      * @return mixed|string|string[]
@@ -103,7 +127,7 @@ class Service extends Make
      * @email 136327134@qq.com
      * @date 2023/3/13
      */
-    protected function getStub(string $type = 'service')
+    protected function getStub(string $type = 'services')
     {
         $servicePath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'service' . DIRECTORY_SEPARATOR;
 
@@ -112,7 +136,7 @@ class Service extends Make
             'form' => $servicePath . 'GetCrudForm.stub',
             'save' => $servicePath . 'CrudSave.stub',
             'update' => $servicePath . 'CrudUpdate.stub',
-            'service' => $servicePath . 'CrudService.stub',
+            'services' => $servicePath . 'CrudService.stub',
         ];
 
         return $type ? $stubs[$type] : $stubs;

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

@@ -0,0 +1,39 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+/**
+ * Class Validate
+ * @author 等风来
+ * @email 136327134@qq.com
+ * @date 2023/3/29
+ * @package crmeb\services\crud
+ */
+class Validate extends Make
+{
+    /**
+     * @var string
+     */
+    protected $name = 'validate';
+
+    /**
+     * 模板文件配置
+     * @param string $type
+     * @return mixed
+     */
+    protected function getStub(string $type = '')
+    {
+        return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'validate' . DIRECTORY_SEPARATOR . 'CrudValidate.stub';
+    }
+}

+ 96 - 0
crmeb/crmeb/services/crud/ViewApi.php

@@ -0,0 +1,96 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+use crmeb\exceptions\CrudException;
+use think\helper\Str;
+
+/**
+ * Class ViewApi
+ * @author 等风来
+ * @email 136327134@qq.com
+ * @date 2023/4/1
+ * @package crmeb\services\crud
+ */
+class ViewApi extends Make
+{
+
+    /**
+     * @var string
+     */
+    protected $name = 'api';
+
+    public function handle(string $name, string $path, array $options = [])
+    {
+
+        $action = $options['action'] ?? [];
+        if (!$action) {
+            $action = ['index', 'create', 'save', 'edit', 'update'];
+        }
+        $route = $options['route'] ?? '';
+        if (!$route) {
+            throw new CrudException('缺少路由名称');
+        }
+
+        $contentJs = '';
+
+        foreach ($action as $item) {
+            $contentJs .= file_get_contents($this->getStub($item)) . "\n";
+        }
+
+        if ($contentJs) {
+            $var = ['{%name%}', '{%route%}', '{%nameCamel%}'];
+            $value = [$name, $route, Str::studly($name)];
+            $contentJs = str_replace($var, $value, $contentJs);
+        }
+
+        $this->value['content-js'] = $contentJs;
+
+        //生成api
+        [$className, $content] = $this->getStubContent($name, $this->name);
+
+        $contentStr = str_replace($this->var, $this->value, $content);
+
+        $this->basePath = $this->adminTemplatePath;
+        $this->fileMime = 'js';
+        $filePath = $this->getFilePathName($path, $this->value['nameCamel']);
+
+        $content = $this->makeFile($filePath, $contentStr);
+
+        return [$content, $filePath];
+
+    }
+
+    /**
+     * 模板文件配置
+     * @param string $type
+     * @return mixed
+     */
+    protected function getStub(string $type = 'api')
+    {
+        $servicePath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR;
+
+        $stubs = [
+            'index' => $servicePath . 'getCrudListApi.stub',
+            'create' => $servicePath . 'CrudUpdate.stub',
+            'save' => $servicePath . 'CrudSave.stub',
+            'edit' => $servicePath . 'GetCrudForm.stub',
+            'update' => $servicePath . 'CrudUpdate.stub',
+            'api' => $servicePath . 'CrudService.stub',
+        ];
+
+        return $type ? $stubs[$type] : $stubs;
+    }
+
+}

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

@@ -0,0 +1,71 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+use think\helper\Str;
+
+/**
+ * Class ViewPages
+ * @author 等风来
+ * @email 136327134@qq.com
+ * @date 2023/4/1
+ * @package crmeb\services\crud
+ */
+class ViewPages extends Make
+{
+
+    /**
+     * @var string
+     */
+    protected $name = 'pages';
+
+    /**
+     * @param string $name
+     * @param string $path
+     * @param array $options
+     * @return false|mixed|void
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/3
+     */
+    public function handle(string $name, string $path, array $options = [])
+    {
+        $field = $options['field'] ?? [];
+
+        $columnStr = [];
+        foreach ($field as $item) {
+            $columnStr[] = "{\n\"title:\"{$item['name']},\n\"key:\"{$item['field']}\n}";
+        }
+        $this->value['auth'] = Str::snake($name);
+        $this->value['content-vue'] = "\n" . implode(',', $columnStr);
+        $this->value['pathApiJs'] = $options['pathApiJs'] ?? '';
+        $this->basePath = $this->adminTemplatePath;
+        $this->fileMime = 'vue';
+        return parent::handle($name, $path, $options); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * @param string $type
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/1
+     */
+    protected function getStub(string $type = '')
+    {
+        return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'view' .
+            DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . 'crud' .
+            DIRECTORY_SEPARATOR . 'index.stub';
+    }
+}

+ 99 - 0
crmeb/crmeb/services/crud/ViewRouter.php

@@ -0,0 +1,99 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+namespace crmeb\services\crud;
+
+use crmeb\exceptions\CrudException;
+use think\helper\Str;
+
+/**
+ * Class ViewRouter
+ * @author 等风来
+ * @email 136327134@qq.com
+ * @date 2023/4/1
+ * @package crmeb\services\crud
+ */
+class ViewRouter extends Make
+{
+    /**
+     * @var string
+     */
+    protected $name = 'router';
+
+
+    public function handle(string $name, string $path, array $options = [])
+    {
+        $this->basePath = $this->adminTemplatePath;
+        $this->fileMime = 'js';
+
+        [$nameData, $content] = $this->getStubContent($name);
+
+        $menus = $options['menus'] ?? $name;
+        $route = $options['route'] ?? Str::snake($name);
+        $pagePath = $options['$pagePath'] ?? Str::camel($name);
+        if (!$route) {
+            throw new CrudException('缺少路由名称');
+        }
+        $this->value['menus'] = $menus;
+        $this->value['name'] = $nameData;
+        $this->value['route'] = $route;
+        $this->value['pagePath'] = $pagePath;
+        if (isset($this->value['path'])) {
+            $this->value['path'] = $this->getfolderPath($path);
+        }
+
+        $contentStr = str_replace($this->var, $this->value, $content);
+
+        $filePath = $this->getFilePathName($path, Str::camel($name));
+
+        $makeContent = $this->makeFile($filePath, $contentStr);
+
+        dump($filePath);
+        $pathInfo = pathinfo($filePath);
+        dump($pathInfo);
+        $router = '';
+
+        return $makeContent;
+    }
+
+    /**
+     * @param string $path
+     * @param string $name
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/3
+     */
+    protected function getFilePathName(string $path, string $name): string
+    {
+        $path = str_replace(['app\\', 'app/'], '', $path);
+
+        $path = ltrim(str_replace('\\', '/', $path), '/');
+
+        return $this->basePath . $path . DIRECTORY_SEPARATOR . $name . '.' . $this->fileMime;
+    }
+
+    /**
+     * @param string $type
+     * @return string
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/4/1
+     */
+    protected function getStub(string $type = '')
+    {
+        return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'view' .
+            DIRECTORY_SEPARATOR . 'router' . DIRECTORY_SEPARATOR . 'modules' .
+            DIRECTORY_SEPARATOR . 'crud.stub';
+    }
+}

+ 51 - 0
crmeb/crmeb/services/crud/stubs/controller/CrudController.stub

@@ -0,0 +1,51 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~{%year%} https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+/**
+ * @author crud自动生成代码
+ * @date {%time%}
+ */
+
+namespace app\adminapi\controller\v1{%path%};
+
+use app\adminapi\controller\AuthController;
+use think\facade\App;
+
+/**
+ * Class {%nameCamel%}
+ * @date {%date%}
+ * @package app\adminapi\controller\v1{%path%}
+ */
+class {%nameCamel%} extends AuthController
+{
+
+    /**
+     * @var {%nameCamel%}Service
+     */
+    protected $service;
+
+    /**
+     * {%nameCamel%}Controller constructor.
+     * @param App $app
+     * @param {%nameCamel%}Service $service
+     */
+    public function __construct(App $app, {%nameCamel%}Service $service)
+    {
+        parent::__construct($app);
+        $this->service = $service;
+    }
+
+
+    {%content-php%}
+
+}

+ 9 - 0
crmeb/crmeb/services/crud/stubs/controller/create.stub

@@ -0,0 +1,9 @@
+    /**
+     * 创建
+     * @return \think\Response
+     * @date {%date%}
+     */
+    public function create()
+    {
+        return app('json')->success($this->service->getCrudForm());
+    }

+ 18 - 0
crmeb/crmeb/services/crud/stubs/controller/delete.stub

@@ -0,0 +1,18 @@
+    /**
+     * 删除
+     * @param $id
+     * @return \think\Response
+     * @date {%date%}
+     */
+    public function delete($id)
+    {
+        if (!$id) {
+            return app('json')->fail(100100);
+        }
+
+        if ($this->service->delete($id)) {
+            return app('json')->success(100002);
+        } else {
+            return app('json')->success(100008);
+        }
+    }

+ 10 - 0
crmeb/crmeb/services/crud/stubs/controller/edit.stub

@@ -0,0 +1,10 @@
+    /**
+     * 编辑获取数据
+     * @param $id
+     * @return \think\Response
+     * @date {%date%}
+     */
+    public function edit($id)
+    {
+        return app('json')->success($this->service->getCrudForm($id));
+    }

+ 9 - 0
crmeb/crmeb/services/crud/stubs/controller/index.stub

@@ -0,0 +1,9 @@
+    /**
+     * 列表
+     * @date {%date%}
+     * @return \think\Response
+     */
+    public function index()
+    {
+        return app('json')->success($this->service->getCrudListIndex());
+    }

+ 15 - 0
crmeb/crmeb/services/crud/stubs/controller/save.stub

@@ -0,0 +1,15 @@
+    /**
+     * 保存
+     * @return \think\Response
+     * @date {%date%}
+     */
+    public function save()
+    {
+        $data = $this->request->postMore([
+            {%field-php%}
+        ]);
+
+        $this->service->crudSave($data);
+
+        return app('json')->success(100021);
+    }

+ 20 - 0
crmeb/crmeb/services/crud/stubs/controller/update.stub

@@ -0,0 +1,20 @@
+    /**
+     * 修改
+     * @param $id
+     * @return \think\Response
+     * @date {%date%}
+     */
+    public function update($id)
+    {
+        if (!$id) {
+            return app('json')->fail(100100);
+        }
+
+        $data = $this->request->postMore([
+            {%field-php%}
+        ]);
+
+        $this->service->crudUpdate((int)$id, $data);
+
+        return app('json')->success(100001);
+    }

+ 41 - 0
crmeb/crmeb/services/crud/stubs/dao/CrudDao.stub

@@ -0,0 +1,41 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~{%year%} https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+/**
+ * @author crud自动生成代码
+ * @date {%time%}
+ */
+
+namespace app\dao{%path%};
+
+
+use app\dao\BaseDao;
+
+/**
+ * Class {%nameCamel%}Dao
+ * @date {%date%}
+ * @package app\dao{%path%}
+ */
+class {%nameCamel%}Dao extends BaseDao
+{
+
+    /**
+     * 设置模型
+     * @return string
+     * @date {%date%}
+     */
+    protected function setModel(): string
+    {
+        return {%nameCamel%}Model::class;
+    }
+}

+ 43 - 0
crmeb/crmeb/services/crud/stubs/model/CrudModel.stub

@@ -0,0 +1,43 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~{%year%} https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+/**
+ * @author crud自动生成代码
+ * @date {%time%}
+ */
+
+namespace app\model{%path%};
+
+
+use crmeb\basic\BaseModel;
+
+/**
+ * Class {%nameCamel%}
+ * @date {%date%}
+ * @package app\model{%path%}
+ */
+class {%nameCamel%} extends BaseModel
+{
+
+    /**
+     * 表名
+     * @var string
+     */
+    protected $name = '{%name%}';
+
+    /**
+     * @var string
+     */
+    protected $key = '{%key%}';
+
+}

+ 1 - 0
crmeb/crmeb/services/crud/stubs/route/create.stub

@@ -0,0 +1 @@
+Route::get('{%route%}/create', 'v1.{%route%}{%controller%}/create')->name('{%menus%}获取创建表单接口');

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

@@ -0,0 +1 @@
+Route::delete('{%route%}/:id', 'v1.{%route%}{%controller%}/delete')->name('{%menus%}删除数据接口');

+ 1 - 0
crmeb/crmeb/services/crud/stubs/route/edit.stub

@@ -0,0 +1 @@
+Route::get('{%route%}/:id/edit', 'v1.{%route%}{%controller%}/edit')->name('{%menus%}获取修改表单接口');

+ 1 - 0
crmeb/crmeb/services/crud/stubs/route/index.stub

@@ -0,0 +1 @@
+Route::get('{%route%}', 'v1.{%route%}{%controller%}/index')->name('{%menus%}列表接口');

+ 7 - 0
crmeb/crmeb/services/crud/stubs/route/route.stub

@@ -0,0 +1,7 @@
+<?php
+
+
+use think\facade\Route;
+
+{%content-php%}
+

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

@@ -0,0 +1 @@
+Route::post('{%route%}', 'v1.{%route%}{%controller%}/save')->name('{%menus%}保存数据接口');

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

@@ -0,0 +1 @@
+Route::put('{%route%}/:id', 'v1.{%route%}{%controller%}/update')->name('{%menus%}修改数据接口');

+ 13 - 0
crmeb/crmeb/services/crud/stubs/service/CrudListIndex.stub

@@ -0,0 +1,13 @@
+    /**
+     * 主页数据接口
+     * @param array $where
+     * @return array
+     * @date {%date%}
+     */
+    public function getCrudListIndex(array $where = [])
+    {
+        [$page, $limit] = $this->getPageValue();
+        $model = $this->dao->selectModel($where, '*', $page, $limit);
+
+        return ['count' => $model->count(), 'list' => $model->select()->toArray()];
+    }

+ 10 - 0
crmeb/crmeb/services/crud/stubs/service/CrudSave.stub

@@ -0,0 +1,10 @@
+    /**
+     * 新增
+     * @date {%date%}
+     * @param array $data
+     * @return mixed
+     */
+    public function crudSave(array $data)
+    {
+        return $this->dao->save($data);
+    }

+ 44 - 0
crmeb/crmeb/services/crud/stubs/service/CrudService.stub

@@ -0,0 +1,44 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~{%year%} https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+/**
+ * @author crud自动生成代码
+ * @date {%time%}
+ */
+
+namespace app\services{%path%};
+
+use app\services\BaseServices;
+use think\exception\ValidateException;
+{%use-php%}
+
+/**
+ * Class CrudService
+ * @date {%date%}
+ * @package app\services{%path%}
+ */
+class {%nameCamel%}Service extends BaseServices
+{
+
+    /**
+     * {%nameCamel%}Service constructor.
+     * @param {%nameCamel%}Dao $dao
+     */
+    public function __construct({%nameCamel%}Dao $dao)
+    {
+        $this->dao = $dao;
+    }
+
+    {%content-php%}
+
+}

+ 11 - 0
crmeb/crmeb/services/crud/stubs/service/CrudUpdate.stub

@@ -0,0 +1,11 @@
+    /**
+     * 修改
+     * @date {%date%}
+     * @param int $id
+     * @param array $data
+     * @return \crmeb\basic\BaseModel
+     */
+    public function crudUpdate(int $id, array $data)
+    {
+        return $this->dao->update($id, $data);
+    }

+ 23 - 0
crmeb/crmeb/services/crud/stubs/service/GetCrudForm.stub

@@ -0,0 +1,23 @@
+    /**
+     * 编辑和获取表单
+     * @date {%date%}
+     * @param int $id
+     * @return array
+     */
+    public function getCrudForm(int $id = 0)
+    {
+        $url = '/{%route%}';
+        $info = [];
+        if ($id) {
+            $info = $this->dao->get($id);
+            if (!$info) {
+                throw new ValidateException(100026);
+            }
+            $url .= '/' . $id;
+        }
+        $rule = [];
+
+{%form-php%}
+
+        return create_form('{%menus%}', $rule, $url, $id ? 'PUT' : 'POST');
+    }

+ 52 - 0
crmeb/crmeb/services/crud/stubs/validate/CrudValidate.stubs

@@ -0,0 +1,52 @@
+<?php
+/**
+ *  +----------------------------------------------------------------------
+ *  | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+ *  +----------------------------------------------------------------------
+ *  | Copyright (c) 2016~{%year%} https://www.crmeb.com All rights reserved.
+ *  +----------------------------------------------------------------------
+ *  | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+ *  +----------------------------------------------------------------------
+ *  | Author: CRMEB Team <admin@crmeb.com>
+ *  +----------------------------------------------------------------------
+ */
+
+/**
+ * @author crud自动生成代码
+ * @date {%time%}
+ */
+
+namespace app\adminapi\validate{%path%};
+
+
+use think\Validate;
+
+/**
+ * Class CrudValidate
+ * @date {%date%}
+ * @package app\adminapi\validate{%path%}
+ */
+class {%nameCamel%}Validate extends Validate
+{
+
+    /**
+     * @var array
+     */
+    protected $rule = [
+
+    ];
+
+    /**
+     * @var array
+     */
+    protected $message = [
+
+    ];
+
+    /**
+     * @var array
+     */
+    protected $scene = [
+
+    ];
+}

+ 13 - 0
crmeb/crmeb/services/crud/stubs/view/api/crud.stub

@@ -0,0 +1,13 @@
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~{%year%} https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+import request from '@/libs/request';
+
+{%content-js%}

+ 11 - 0
crmeb/crmeb/services/crud/stubs/view/api/crudDeleteApi.stub

@@ -0,0 +1,11 @@
+/**
+ * 删除数据
+ * @param id
+ * @return {*}
+ */
+export function {%name%}DeleteApi(id) {
+    return request({
+        url: `{%route%}/${id}`,
+        method: 'delete'
+    });
+}

+ 12 - 0
crmeb/crmeb/services/crud/stubs/view/api/crudSaveApi.stub

@@ -0,0 +1,12 @@
+/**
+ * 添加数据
+ * @param data
+ * @return {*}
+ */
+export function {%name%}SaveApi(data) {
+    return request({
+        url: '{%route%}',
+        method: 'post',
+        data
+    });
+}

+ 12 - 0
crmeb/crmeb/services/crud/stubs/view/api/crudUpdateApi.stub

@@ -0,0 +1,12 @@
+/**
+ * 修改数据
+ * @param id
+ * @return {*}
+ */
+export function {%name%}UpdateApi(id, data) {
+    return request({
+        url: `{%route%}/${id}`,
+        method: 'put',
+        data
+    });
+}

+ 10 - 0
crmeb/crmeb/services/crud/stubs/view/api/getCrudCreateApi.stub

@@ -0,0 +1,10 @@
+/**
+ * 获取添加表单数据
+ * @return {*}
+ */
+export function get{%nameCamel%}CreateApi() {
+    return request({
+        url: '{%route%}/create',
+        method: 'get',
+    });
+}

+ 11 - 0
crmeb/crmeb/services/crud/stubs/view/api/getCrudEditApi.stub

@@ -0,0 +1,11 @@
+/**
+ * 获取编辑表单数据
+ * @param id
+ * @return {*}
+ */
+export function get{%nameCamel%}EditApi(id) {
+    return request({
+        url: `{%route%}/${id}`,
+        method: 'get'
+    });
+}

+ 12 - 0
crmeb/crmeb/services/crud/stubs/view/api/getCrudListApi.stub

@@ -0,0 +1,12 @@
+/**
+ * 获取列表数据
+ * @param params
+ * @return {*}
+ */
+export function get{%nameCamel%}ListApi(params) {
+    return request({
+        url: '{%route%}',
+        method: 'get',
+        params,
+    });
+}

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

@@ -0,0 +1,137 @@
+<template>
+  <div>
+    <Card :bordered="false" dis-hover class="ivu-mt">
+      <Row type="flex">
+        <Col v-bind="grid">
+          <Button v-auth="['{%auth%}']" type="primary" icon="md-add" @click="add">添加{%menus%}</Button>
+        </Col>
+      </Row>
+      <Table
+          :columns="columns"
+          :data="dataList"
+          ref="table"
+          class="mt25"
+          :loading="loading"
+          highlight-row
+          no-userFrom-text="暂无数据"
+          no-filtered-userFrom-text="暂无筛选结果"
+      >
+        <template slot-scope="{ row, index }" slot="icons">
+          <div class="tabBox_img" v-viewer>
+            <img v-lazy="row.icon" />
+          </div>
+        </template>
+        <template slot-scope="{ row, index }" slot="action">
+          <a @click="edit(row.id)">修改</a>
+          <Divider type="vertical" />
+          <a @click="del(row, '删除{%menus%}', index)">删除</a>
+        </template>
+      </Table>
+      <div class="acea-row row-right page">
+        <Page :total="total" show-elevator show-total @on-change="pageChange" :page-size="from.limit" />
+      </div>
+    </Card>
+  </div>
+</template>
+
+<script>
+import { mapState } from 'vuex';
+import { {%name%}SaveApi, {%name%}DeleteApi, {%name%}UpdateApi, get{%nameCamel%}CreateApi, get{%nameCamel%}EditApi, get{%nameCamel%}ListApi} from '@/api/{%pathApiJs%}';
+export default {
+  name: 'user_group',
+  data() {
+    return {
+      grid: {
+        xl: 7,
+        lg: 7,
+        md: 12,
+        sm: 24,
+        xs: 24,
+      },
+      loading: false,
+      columns: [
+        {
+          title: 'ID',
+          key: 'id',
+          width: 80,
+        },{%content-vue%}
+        {
+          title: '操作',
+          slot: 'action',
+          fixed: 'right',
+          minWidth: 120,
+        },
+      ],
+      from: {
+        page: 1,
+        limit: 15,
+      },
+      dataList: [],
+      total: 0,
+    };
+  },
+  computed: {
+    ...mapState('media', ['isMobile']),
+    labelWidth() {
+      return this.isMobile ? undefined : 75;
+    },
+    labelPosition() {
+      return this.isMobile ? 'top' : 'left';
+    },
+  },
+  created() {
+    this.getList();
+  },
+  methods: {
+    // 添加
+    add() {
+      this.$modalForm(get{%nameCamel%}CreateApi()).then(() => this.getList());
+    },
+    //列表
+    getList() {
+      this.loading = true;
+      get{%nameCamel%}ListApi(this.from)
+          .then(async (res) => {
+            let data = res.data;
+            this.dataList = data.list;
+            this.total = data.count;
+            this.loading = false;
+          })
+          .catch((res) => {
+            this.loading = false;
+            this.$Message.error(res.msg);
+          });
+    },
+    //分页
+    pageChange(index) {
+      this.from.page = index;
+      this.getList();
+    },
+    // 修改
+    edit(id) {
+      this.$modalForm(get{%nameCamel%}EditApi(id)).then(() => this.getList());
+    },
+    // 删除
+    del(row, tit, num) {
+      let delfromData = {
+        title: tit,
+        num: num,
+        url: `{%route%}/${row.id}`,
+        method: 'DELETE',
+        ids: '',
+      };
+      this.$modalSure(delfromData)
+          .then((res) => {
+            this.$Message.success(res.msg);
+            this.groupLists.splice(num, 1);
+            this.getList();
+          })
+          .catch((res) => {
+            this.$Message.error(res.msg);
+          });
+    },
+  },
+};
+</script>
+
+<style scoped lang="stylus"></style>

+ 39 - 0
crmeb/crmeb/services/crud/stubs/view/router/modules/crud.stub

@@ -0,0 +1,39 @@
+// +---------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +---------------------------------------------------------------------
+// | Copyright (c) 2016~{%year%} https://www.crmeb.com All rights reserved.
+// +---------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +---------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +---------------------------------------------------------------------
+
+import BasicLayout from '@/components/main';
+import setting from '@/setting'
+
+let routePre = setting.routePre
+
+const meta = {
+    auth: true,
+}
+
+const pre = '{%name%}_'
+
+export default {
+    path: `${routePre}/{%route%}`,
+    name: '{%name%}',
+    header: '{%nameHeader%}',
+    meta,
+    component: BasicLayout,
+    children: [
+        {
+            path: 'list',
+            name: `${pre}list`,
+            meta: {
+                auth: ['{%name%}-list-index'],
+                title: '{%menus%}',
+            },
+            component: () => import('@/pages/{%pagePath%}/index'),
+        },
+    ],
+}