diff --git a/crmeb/crmeb/command/Dao.php b/crmeb/crmeb/command/Dao.php deleted file mode 100644 index c1f9c2998..000000000 --- a/crmeb/crmeb/command/Dao.php +++ /dev/null @@ -1,46 +0,0 @@ - -// +---------------------------------------------------------------------- -namespace crmeb\command; - -use think\console\command\Make; - -/** - * Class Business - * @package crmeb\command - */ -class Dao extends Make -{ - protected $type = "Dao"; - - protected function configure() - { - parent::configure(); - $this->setName('make:dao') - ->setDescription('Create a new service class'); - } - - protected function getStub(): string - { - return __DIR__ . DIRECTORY_SEPARATOR. 'stubs' . DIRECTORY_SEPARATOR . 'dao.stub'; - } - - protected function getNamespace(string $app): string - { - return parent::getNamespace($app) . '\\dao'; - } - - protected function getPathName(string $name): string - { - $name = str_replace('app\\', '', $name); - - return $this->app->getBasePath() . ltrim(str_replace('\\', '/', $name), '/') . 'Dao.php'; - } -} diff --git a/crmeb/crmeb/command/Service.php b/crmeb/crmeb/command/Service.php deleted file mode 100644 index a2ebe11d5..000000000 --- a/crmeb/crmeb/command/Service.php +++ /dev/null @@ -1,46 +0,0 @@ - -// +---------------------------------------------------------------------- -namespace crmeb\command; - -use think\console\command\Make; - -/** - * Class Business - * @package crmeb\command - */ -class Service extends Make -{ - protected $type = "Dao"; - - protected function configure() - { - parent::configure(); - $this->setName('make:service') - ->setDescription('Create a new service class'); - } - - protected function getStub(): string - { - return __DIR__ . DIRECTORY_SEPARATOR. 'stubs' . DIRECTORY_SEPARATOR . 'service.stub'; - } - - protected function getNamespace(string $app): string - { - return parent::getNamespace($app) . '\\services'; - } - - protected function getPathName(string $name): string - { - $name = str_replace('app\\', '', $name); - - return $this->app->getBasePath() . ltrim(str_replace('\\', '/', $name), '/') . 'Services.php'; - } -} diff --git a/crmeb/crmeb/command/stubs/dao.stub b/crmeb/crmeb/command/stubs/dao.stub deleted file mode 100644 index 75b38b17a..000000000 --- a/crmeb/crmeb/command/stubs/dao.stub +++ /dev/null @@ -1,35 +0,0 @@ - -// +---------------------------------------------------------------------- -declare (strict_types = 1); - -namespace {%namespace%}; - -use app\dao\BaseDao; -use app\model\***\{%className%}; - -/** - * - * Class {%className%}Dao - * @package {%namespace%} - */ -class {%className%}Dao extends BaseDao -{ - - /** - * 设置模型 - * @return string - */ - protected function setModel(): string - { - return {%className%}::class; - } - -} diff --git a/crmeb/crmeb/command/stubs/service.stub b/crmeb/crmeb/command/stubs/service.stub deleted file mode 100644 index 9e2f693ae..000000000 --- a/crmeb/crmeb/command/stubs/service.stub +++ /dev/null @@ -1,35 +0,0 @@ - -// +---------------------------------------------------------------------- -declare (strict_types = 1); - -namespace {%namespace%}; - -use app\services\BaseServices; -use app\dao\***\{%className%}Dao; - -/** - * - * Class {%className%}Services - * @package {%namespace%} - */ -class {%className%}Services extends BaseServices -{ - - /** - * {%className%}Services constructor. - * @param {%className%}Dao $dao - */ - public function __construct({%className%}Dao $dao) - { - $this->dao = $dao; - } - -} diff --git a/crmeb/crmeb/services/crud/Dao.php b/crmeb/crmeb/services/crud/Dao.php new file mode 100644 index 000000000..8cbf4a38b --- /dev/null +++ b/crmeb/crmeb/services/crud/Dao.php @@ -0,0 +1,77 @@ + +// +---------------------------------------------------------------------- +namespace crmeb\command\crud; + +use think\console\input\Option; + +/** + * Class Business + * @package crmeb\command + */ +class Dao extends Make +{ + /** + * 当前命令名称 + * @var string + */ + 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 + * @return string + * @author 等风来 + * @email 136327134@qq.com + * @date 2023/3/13 + */ + protected function getStub(string $type = '') + { + return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'dao' . DIRECTORY_SEPARATOR . 'CrudDao.stub'; + } +} diff --git a/crmeb/crmeb/services/crud/Service.php b/crmeb/crmeb/services/crud/Service.php new file mode 100644 index 000000000..4f7f6d622 --- /dev/null +++ b/crmeb/crmeb/services/crud/Service.php @@ -0,0 +1,120 @@ + +// +---------------------------------------------------------------------- +namespace crmeb\command\crud; + + +use think\console\input\Option; + +/** + * Class Business + * @package crmeb\command + */ +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' => '' + ]; + + /** + * 配置指令 + * @author 等风来 + * @email 136327134@qq.com + * @date 2023/3/13 + */ + protected function configure() + { + $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(); + + $name = $this->input->getArgument('name'); + $action = $this->input->getOption('a'); + $field = $this->input->getOption('k'); + $path = $this->input->getOption('f'); + + if ($action) { + $action = explode(',', $action); + } else { + $action = ['index', 'form', 'save', 'update']; + } + + $fieldData = [];; + if ($field) { + $fieldData = json_decode($field, true); + if ($fieldData === null && strstr($field, ',')) { + $fieldData = explode(',', $field); + } + } + +// $from = []; +// foreach ($fieldData as $item) { +// $from[] = ''; +// } + $axja = php_sapi_name(); + $this->writeln(compact('fieldData', 'axja')); + } + + /** + * @param string $type + * @return mixed|string|string[] + * @author 等风来 + * @email 136327134@qq.com + * @date 2023/3/13 + */ + protected function getStub(string $type = 'service') + { + $servicePath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'service' . DIRECTORY_SEPARATOR; + + $stubs = [ + 'index' => $servicePath . 'CrudListIndex.stub', + 'form' => $servicePath . 'GetCrudForm.stub', + 'save' => $servicePath . 'CrudSave.stub', + 'update' => $servicePath . 'CrudUpdate.stub', + 'service' => $servicePath . 'CrudService.stub', + ]; + + return $type ? $stubs[$type] : $stubs; + } +} diff --git a/template/admin/src/router/modules/crud/README.md b/template/admin/src/router/modules/crud/README.md new file mode 100644 index 000000000..7b8c8fa2a --- /dev/null +++ b/template/admin/src/router/modules/crud/README.md @@ -0,0 +1,6 @@ +# CRMEB ADMIN CRUD 路由存放 + + +此目录下的所有路由会被自动加载到router,无需其他配置 + +可以对此路由进行修改删除 diff --git a/template/admin/src/router/routers.js b/template/admin/src/router/routers.js index 78fc136e0..aa81576d6 100644 --- a/template/admin/src/router/routers.js +++ b/template/admin/src/router/routers.js @@ -25,6 +25,16 @@ import statistic from './modules/statistic'; import frameOut from './modules/frameOut'; import division from './modules/division'; import settings from '@/setting'; + +const modulesFiles = require.context('./modules/crud', true, /\.js$/) + +const routers = [] +// 将扫描到的路由信息加入路由数组中 +modulesFiles.keys().forEach(modulePath => { + const value = modulesFiles(modulePath) + routers.push(value.default) +}) + let routePre = settings.routePre; /** * 在主框架内显示 @@ -159,6 +169,7 @@ const frameIn = [ app, statistic, division, + ...routers ]; /**