mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-31 23:10:45 +00:00
修改crud路由加载
This commit is contained in:
parent
0129d6222d
commit
e705eff467
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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';
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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';
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
77
crmeb/crmeb/services/crud/Dao.php
Normal file
77
crmeb/crmeb/services/crud/Dao.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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';
|
||||
}
|
||||
}
|
||||
120
crmeb/crmeb/services/crud/Service.php
Normal file
120
crmeb/crmeb/services/crud/Service.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
}
|
||||
6
template/admin/src/router/modules/crud/README.md
Normal file
6
template/admin/src/router/modules/crud/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# CRMEB ADMIN CRUD 路由存放
|
||||
|
||||
|
||||
此目录下的所有路由会被自动加载到router,无需其他配置
|
||||
|
||||
可以对此路由进行修改删除
|
||||
@ -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
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user