diff --git a/.gitignore b/.gitignore index 99722bc6e..db28e6ace 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ /template/uni-app/node_modules/ /template/uni-app/unpackage/ /template/uni-app/.hbuilderx/ +crmeb/.idea/ diff --git a/crmeb/config/console.php b/crmeb/config/console.php index c4e89ddaf..a837ee506 100644 --- a/crmeb/config/console.php +++ b/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 ], ]; diff --git a/crmeb/crmeb/command/Crud.php b/crmeb/crmeb/command/Crud.php new file mode 100644 index 000000000..e323371ea --- /dev/null +++ b/crmeb/crmeb/command/Crud.php @@ -0,0 +1,20 @@ + + * +---------------------------------------------------------------------- + */ + +namespace crmeb\command\crud; + + +class Crud +{ + +} diff --git a/crmeb/crmeb/command/Npm.php b/crmeb/crmeb/command/Npm.php new file mode 100644 index 000000000..4c4b50261 --- /dev/null +++ b/crmeb/crmeb/command/Npm.php @@ -0,0 +1,36 @@ + + * +---------------------------------------------------------------------- + */ + +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() + { + + } +} diff --git a/crmeb/crmeb/command/Util.php b/crmeb/crmeb/command/Util.php index 10a84e3fc..9297033c1 100644 --- a/crmeb/crmeb/command/Util.php +++ b/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) { diff --git a/crmeb/crmeb/exceptions/CrudException.php b/crmeb/crmeb/exceptions/CrudException.php new file mode 100644 index 000000000..0ff9d2d22 --- /dev/null +++ b/crmeb/crmeb/exceptions/CrudException.php @@ -0,0 +1,36 @@ + + * +---------------------------------------------------------------------- + */ + +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); + } +} diff --git a/crmeb/crmeb/services/crud/Controller.php b/crmeb/crmeb/services/crud/Controller.php new file mode 100644 index 000000000..fcb943a64 --- /dev/null +++ b/crmeb/crmeb/services/crud/Controller.php @@ -0,0 +1,134 @@ + + * +---------------------------------------------------------------------- + */ + +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; + } +} diff --git a/crmeb/crmeb/services/crud/Dao.php b/crmeb/crmeb/services/crud/Dao.php index 8cbf4a38b..8787fb373 100644 --- a/crmeb/crmeb/services/crud/Dao.php +++ b/crmeb/crmeb/services/crud/Dao.php @@ -8,13 +8,12 @@ // +---------------------------------------------------------------------- // | Author: CRMEB Team // +---------------------------------------------------------------------- -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 diff --git a/crmeb/crmeb/services/crud/Make.php b/crmeb/crmeb/services/crud/Make.php new file mode 100644 index 000000000..9fedbcafc --- /dev/null +++ b/crmeb/crmeb/services/crud/Make.php @@ -0,0 +1,345 @@ + + * +---------------------------------------------------------------------- + */ + +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; + } +} diff --git a/crmeb/crmeb/services/crud/Model.php b/crmeb/crmeb/services/crud/Model.php new file mode 100644 index 000000000..1836c828e --- /dev/null +++ b/crmeb/crmeb/services/crud/Model.php @@ -0,0 +1,44 @@ + + * +---------------------------------------------------------------------- + */ + +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'; + } +} diff --git a/crmeb/crmeb/services/crud/Route.php b/crmeb/crmeb/services/crud/Route.php new file mode 100644 index 000000000..6e6a4172e --- /dev/null +++ b/crmeb/crmeb/services/crud/Route.php @@ -0,0 +1,101 @@ + + * +---------------------------------------------------------------------- + */ + +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; + } +} diff --git a/crmeb/crmeb/services/crud/Service.php b/crmeb/crmeb/services/crud/Service.php index 4f7f6d622..ca85efc52 100644 --- a/crmeb/crmeb/services/crud/Service.php +++ b/crmeb/crmeb/services/crud/Service.php @@ -8,94 +8,118 @@ // +---------------------------------------------------------------------- // | Author: CRMEB Team // +---------------------------------------------------------------------- -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"; + protected $name = "services"; /** - * @var string[] - */ - protected $var = [ - '{%year%}', - '{%time%}', - '{%date%}', - '{%nameCamel%}', - '{%path%}', - '{%content-php%}' - ]; - - /** - * @var string[] - */ - protected $value = [ - 'year' => '', - 'time' => '', - 'date' => '', - 'nameCamel' => '', - 'path' => '', - 'content-php' => '', - 'dao-php' => '' - ]; - - /** - * 配置指令 + * @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; diff --git a/crmeb/crmeb/services/crud/Validate.php b/crmeb/crmeb/services/crud/Validate.php new file mode 100644 index 000000000..3c2108de3 --- /dev/null +++ b/crmeb/crmeb/services/crud/Validate.php @@ -0,0 +1,39 @@ + + * +---------------------------------------------------------------------- + */ + +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'; + } +} diff --git a/crmeb/crmeb/services/crud/ViewApi.php b/crmeb/crmeb/services/crud/ViewApi.php new file mode 100644 index 000000000..69f8b8b21 --- /dev/null +++ b/crmeb/crmeb/services/crud/ViewApi.php @@ -0,0 +1,96 @@ + + * +---------------------------------------------------------------------- + */ + +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; + } + +} diff --git a/crmeb/crmeb/services/crud/ViewPages.php b/crmeb/crmeb/services/crud/ViewPages.php new file mode 100644 index 000000000..2f849de95 --- /dev/null +++ b/crmeb/crmeb/services/crud/ViewPages.php @@ -0,0 +1,71 @@ + + * +---------------------------------------------------------------------- + */ + +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'; + } +} diff --git a/crmeb/crmeb/services/crud/ViewRouter.php b/crmeb/crmeb/services/crud/ViewRouter.php new file mode 100644 index 000000000..269c42417 --- /dev/null +++ b/crmeb/crmeb/services/crud/ViewRouter.php @@ -0,0 +1,99 @@ + + * +---------------------------------------------------------------------- + */ + +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'; + } +} diff --git a/crmeb/crmeb/services/crud/stubs/controller/CrudController.stub b/crmeb/crmeb/services/crud/stubs/controller/CrudController.stub new file mode 100644 index 000000000..7da581dbf --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/controller/CrudController.stub @@ -0,0 +1,51 @@ + + * +---------------------------------------------------------------------- + */ + +/** + * @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%} + +} diff --git a/crmeb/crmeb/services/crud/stubs/controller/create.stub b/crmeb/crmeb/services/crud/stubs/controller/create.stub new file mode 100644 index 000000000..e00acbe88 --- /dev/null +++ b/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()); + } diff --git a/crmeb/crmeb/services/crud/stubs/controller/delete.stub b/crmeb/crmeb/services/crud/stubs/controller/delete.stub new file mode 100644 index 000000000..c73cb4d73 --- /dev/null +++ b/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); + } + } diff --git a/crmeb/crmeb/services/crud/stubs/controller/edit.stub b/crmeb/crmeb/services/crud/stubs/controller/edit.stub new file mode 100644 index 000000000..6e01c891f --- /dev/null +++ b/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)); + } diff --git a/crmeb/crmeb/services/crud/stubs/controller/index.stub b/crmeb/crmeb/services/crud/stubs/controller/index.stub new file mode 100644 index 000000000..7b982c2c3 --- /dev/null +++ b/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()); + } diff --git a/crmeb/crmeb/services/crud/stubs/controller/save.stub b/crmeb/crmeb/services/crud/stubs/controller/save.stub new file mode 100644 index 000000000..4e5b4b2b2 --- /dev/null +++ b/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); + } diff --git a/crmeb/crmeb/services/crud/stubs/controller/update.stub b/crmeb/crmeb/services/crud/stubs/controller/update.stub new file mode 100644 index 000000000..eec2f9e64 --- /dev/null +++ b/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); + } diff --git a/crmeb/crmeb/services/crud/stubs/dao/CrudDao.stub b/crmeb/crmeb/services/crud/stubs/dao/CrudDao.stub new file mode 100644 index 000000000..e1968469e --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/dao/CrudDao.stub @@ -0,0 +1,41 @@ + + * +---------------------------------------------------------------------- + */ + +/** + * @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; + } +} diff --git a/crmeb/crmeb/services/crud/stubs/model/CrudModel.stub b/crmeb/crmeb/services/crud/stubs/model/CrudModel.stub new file mode 100644 index 000000000..e7947bf36 --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/model/CrudModel.stub @@ -0,0 +1,43 @@ + + * +---------------------------------------------------------------------- + */ + +/** + * @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%}'; + +} diff --git a/crmeb/crmeb/services/crud/stubs/route/create.stub b/crmeb/crmeb/services/crud/stubs/route/create.stub new file mode 100644 index 000000000..a0e1084b5 --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/route/create.stub @@ -0,0 +1 @@ +Route::get('{%route%}/create', 'v1.{%route%}{%controller%}/create')->name('{%menus%}获取创建表单接口'); diff --git a/crmeb/crmeb/services/crud/stubs/route/delete.stub b/crmeb/crmeb/services/crud/stubs/route/delete.stub new file mode 100644 index 000000000..b22369941 --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/route/delete.stub @@ -0,0 +1 @@ +Route::delete('{%route%}/:id', 'v1.{%route%}{%controller%}/delete')->name('{%menus%}删除数据接口'); diff --git a/crmeb/crmeb/services/crud/stubs/route/edit.stub b/crmeb/crmeb/services/crud/stubs/route/edit.stub new file mode 100644 index 000000000..5414ae95a --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/route/edit.stub @@ -0,0 +1 @@ +Route::get('{%route%}/:id/edit', 'v1.{%route%}{%controller%}/edit')->name('{%menus%}获取修改表单接口'); diff --git a/crmeb/crmeb/services/crud/stubs/route/index.stub b/crmeb/crmeb/services/crud/stubs/route/index.stub new file mode 100644 index 000000000..176636872 --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/route/index.stub @@ -0,0 +1 @@ +Route::get('{%route%}', 'v1.{%route%}{%controller%}/index')->name('{%menus%}列表接口'); diff --git a/crmeb/crmeb/services/crud/stubs/route/route.stub b/crmeb/crmeb/services/crud/stubs/route/route.stub new file mode 100644 index 000000000..564b2a74d --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/route/route.stub @@ -0,0 +1,7 @@ +name('{%menus%}保存数据接口'); diff --git a/crmeb/crmeb/services/crud/stubs/route/update.stub b/crmeb/crmeb/services/crud/stubs/route/update.stub new file mode 100644 index 000000000..09eabe379 --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/route/update.stub @@ -0,0 +1 @@ +Route::put('{%route%}/:id', 'v1.{%route%}{%controller%}/update')->name('{%menus%}修改数据接口'); diff --git a/crmeb/crmeb/services/crud/stubs/service/CrudListIndex.stub b/crmeb/crmeb/services/crud/stubs/service/CrudListIndex.stub new file mode 100644 index 000000000..ac9b31586 --- /dev/null +++ b/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()]; + } diff --git a/crmeb/crmeb/services/crud/stubs/service/CrudSave.stub b/crmeb/crmeb/services/crud/stubs/service/CrudSave.stub new file mode 100644 index 000000000..d741f0c73 --- /dev/null +++ b/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); + } diff --git a/crmeb/crmeb/services/crud/stubs/service/CrudService.stub b/crmeb/crmeb/services/crud/stubs/service/CrudService.stub new file mode 100644 index 000000000..fc929e8d9 --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/service/CrudService.stub @@ -0,0 +1,44 @@ + + * +---------------------------------------------------------------------- + */ + +/** + * @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%} + +} diff --git a/crmeb/crmeb/services/crud/stubs/service/CrudUpdate.stub b/crmeb/crmeb/services/crud/stubs/service/CrudUpdate.stub new file mode 100644 index 000000000..3e7484ae9 --- /dev/null +++ b/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); + } diff --git a/crmeb/crmeb/services/crud/stubs/service/GetCrudForm.stub b/crmeb/crmeb/services/crud/stubs/service/GetCrudForm.stub new file mode 100644 index 000000000..3cf4f1ca2 --- /dev/null +++ b/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'); + } diff --git a/crmeb/crmeb/services/crud/stubs/validate/CrudValidate.stubs b/crmeb/crmeb/services/crud/stubs/validate/CrudValidate.stubs new file mode 100644 index 000000000..7df4bd47d --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/validate/CrudValidate.stubs @@ -0,0 +1,52 @@ + + * +---------------------------------------------------------------------- + */ + +/** + * @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 = [ + + ]; +} diff --git a/crmeb/crmeb/services/crud/stubs/view/api/crud.stub b/crmeb/crmeb/services/crud/stubs/view/api/crud.stub new file mode 100644 index 000000000..28c426f4d --- /dev/null +++ b/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 +// +---------------------------------------------------------------------- + +import request from '@/libs/request'; + +{%content-js%} diff --git a/crmeb/crmeb/services/crud/stubs/view/api/crudDeleteApi.stub b/crmeb/crmeb/services/crud/stubs/view/api/crudDeleteApi.stub new file mode 100644 index 000000000..0f1231138 --- /dev/null +++ b/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' + }); +} diff --git a/crmeb/crmeb/services/crud/stubs/view/api/crudSaveApi.stub b/crmeb/crmeb/services/crud/stubs/view/api/crudSaveApi.stub new file mode 100644 index 000000000..f5b350bd2 --- /dev/null +++ b/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 + }); +} diff --git a/crmeb/crmeb/services/crud/stubs/view/api/crudUpdateApi.stub b/crmeb/crmeb/services/crud/stubs/view/api/crudUpdateApi.stub new file mode 100644 index 000000000..188691119 --- /dev/null +++ b/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 + }); +} diff --git a/crmeb/crmeb/services/crud/stubs/view/api/getCrudCreateApi.stub b/crmeb/crmeb/services/crud/stubs/view/api/getCrudCreateApi.stub new file mode 100644 index 000000000..bc26f7d35 --- /dev/null +++ b/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', + }); +} diff --git a/crmeb/crmeb/services/crud/stubs/view/api/getCrudEditApi.stub b/crmeb/crmeb/services/crud/stubs/view/api/getCrudEditApi.stub new file mode 100644 index 000000000..b15c66e8c --- /dev/null +++ b/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' + }); +} diff --git a/crmeb/crmeb/services/crud/stubs/view/api/getCrudListApi.stub b/crmeb/crmeb/services/crud/stubs/view/api/getCrudListApi.stub new file mode 100644 index 000000000..33583ed2c --- /dev/null +++ b/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, + }); +} diff --git a/crmeb/crmeb/services/crud/stubs/view/pages/crud/index.stub b/crmeb/crmeb/services/crud/stubs/view/pages/crud/index.stub new file mode 100644 index 000000000..df1224d76 --- /dev/null +++ b/crmeb/crmeb/services/crud/stubs/view/pages/crud/index.stub @@ -0,0 +1,137 @@ + + + + + diff --git a/crmeb/crmeb/services/crud/stubs/view/router/modules/crud.stub b/crmeb/crmeb/services/crud/stubs/view/router/modules/crud.stub new file mode 100644 index 000000000..3982b7de2 --- /dev/null +++ b/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 +// +--------------------------------------------------------------------- + +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'), + }, + ], +}