mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-31 23:10:45 +00:00
Merge branch 'v5.0.0dev' of https://gitee.com/ZhongBangKeJi/CRMEB into v5.0.0dev
This commit is contained in:
commit
27413c0f00
@ -78,6 +78,7 @@ class Request extends \think\Request
|
||||
$farr = [
|
||||
"/<(\\/?)(script|i?frame|style|html|body|title|link|meta|object|\\?|\\%)([^>]*?)>/isU",
|
||||
"/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
|
||||
'/phar/is',
|
||||
"/select|join|where|drop|like|modify|rename|insert|update|table|database|alter|truncate|\'|\/\*|\.\.\/|\.\/|union|into|load_file|outfile/is"
|
||||
];
|
||||
if (is_array($str)) {
|
||||
|
||||
@ -129,7 +129,7 @@ class SystemCrud extends AuthController
|
||||
return app('json')->fail('表不存在');
|
||||
}
|
||||
foreach ($field as $item) {
|
||||
$tableField[] = ['value' => $item['name'], 'comment' => $item['comment'], 'label' => $item['name']];
|
||||
$tableField[] = ['value' => $item['name'], 'all' => $item, 'comment' => $item['comment'], 'label' => $item['name']];
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,15 +156,25 @@ class SystemCrud extends AuthController
|
||||
|
||||
$routeName = 'crud/' . Str::snake($info->table_name);
|
||||
|
||||
$column = $this->services->getColumnNamesList($info->table_name);
|
||||
$key = 'id';
|
||||
foreach ($column as $value) {
|
||||
if ($value['primaryKey']) {
|
||||
$key = $value['name'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$make = $this->services->makeFile($info->table_name, $routeName, false, [
|
||||
'menuName' => $info->name,
|
||||
'key' => $key,
|
||||
'fromField' => $info->field['fromField'] ?? [],
|
||||
'columnField' => $info->field['columnField'] ?? [],
|
||||
]);
|
||||
|
||||
|
||||
$data = [];
|
||||
foreach ($make as $item) {
|
||||
$item['name'] = pathinfo($item['path'])['basename'] ?? '';
|
||||
$item['name'] = $item['path'];
|
||||
$data[] = $item;
|
||||
}
|
||||
|
||||
|
||||
@ -147,6 +147,28 @@ class SystemCrudServices extends BaseServices
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/12
|
||||
*/
|
||||
public function valueReplace(array $data)
|
||||
{
|
||||
$replace = ['phar://'];
|
||||
$newData = [];
|
||||
foreach ($data as $key => $item) {
|
||||
if (is_array($item)) {
|
||||
$item = $this->valueReplace($item);
|
||||
} else {
|
||||
$item = str_replace($replace, '', $item);
|
||||
}
|
||||
$newData[str_replace($replace, '', $key)] = $item;
|
||||
}
|
||||
return $newData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param array $data
|
||||
@ -159,8 +181,9 @@ class SystemCrudServices extends BaseServices
|
||||
{
|
||||
$tableName = $data['tableName'];
|
||||
$tableComment = $data['tableComment'];
|
||||
$tableField = $data['tableField'];
|
||||
$filePath = $data['filePath'];
|
||||
$tableField = $this->valueReplace($data['tableField']);
|
||||
$filePath = $this->valueReplace($data['filePath']);
|
||||
|
||||
|
||||
//创建数据库
|
||||
if ($tableField && !$data['isTable']) {
|
||||
@ -177,6 +200,13 @@ class SystemCrudServices extends BaseServices
|
||||
throw new ValidateException('请先创建' . $tableName . '表');
|
||||
}
|
||||
|
||||
foreach ($column as $value) {
|
||||
if ($value['primaryKey']) {
|
||||
$data['key'] = $value['name'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$routeName = 'crud/' . Str::snake($tableName);
|
||||
$uniqueAuth = $routeName . '-index-list';
|
||||
|
||||
@ -353,29 +383,34 @@ class SystemCrudServices extends BaseServices
|
||||
{
|
||||
$options['fromField'] = is_array($options['fromField']) ? $options['fromField'] : [];
|
||||
$options['columnField'] = is_array($options['columnField']) ? $options['columnField'] : [];
|
||||
//生成控制器
|
||||
$controller = app()->make(Controller::class);
|
||||
[$controllerContent, $controllerPath] = $controller->setFilePathName($filePath['controller'] ?? '')->isMake($isMake)->handle($tableName);
|
||||
//生成模型
|
||||
$model = app()->make(Model::class);
|
||||
[$modelContent, $modelPath] = $model->setFilePathName($filePath['model'] ?? '')->isMake($isMake)->handle($tableName);
|
||||
[$modelContent, $modelPath, $usePath, $nameCamel] = $model->setFilePathName($filePath['model'] ?? '')->isMake($isMake)->handle($tableName);
|
||||
//生成dao
|
||||
$dao = app()->make(Dao::class);
|
||||
[$daoContent, $daoPath] = $dao->setFilePathName($filePath['dao'] ?? '')->isMake($isMake)->handle($tableName);
|
||||
[$daoContent, $daoPath, $usePath, $nameCamel] = $dao->setFilePathName($filePath['dao'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'usePath' => $usePath . $nameCamel,
|
||||
]);
|
||||
//生成service
|
||||
$service = app()->make(Service::class);
|
||||
[$serviceContent, $servicePath, $usePath] = $service->setFilePathName($filePath['service'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'field' => $options['fromField'],
|
||||
'usePath' => $usePath,
|
||||
]);
|
||||
//生成验证器
|
||||
$validate = app()->make(Validate::class);
|
||||
[$validateContent, $validatePath] = $validate->setFilePathName($filePath['validate'] ?? '')->isMake($isMake)->handle($tableName);
|
||||
//生成控制器
|
||||
$controller = app()->make(Controller::class);
|
||||
[$controllerContent, $controllerPath] = $controller->setFilePathName($filePath['controller'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'usePath' => $usePath
|
||||
]);
|
||||
//生成路由
|
||||
$route = app()->make(Route::class);
|
||||
[$routeContent, $routePath] = $route->setFilePathName($filePath['route'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'menus' => $options['menuName'],
|
||||
'route' => $routeName
|
||||
]);
|
||||
//生成service
|
||||
$service = app()->make(Service::class);
|
||||
[$serviceContent, $servicePath] = $service->setFilePathName($filePath['service'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
'field' => $options['fromField'],
|
||||
]);
|
||||
//生成验证器
|
||||
$validate = app()->make(Validate::class);
|
||||
[$validateContent, $validatePath] = $validate->setFilePathName($filePath['validate'] ?? '')->isMake($isMake)->handle($tableName);
|
||||
//生成前台路由
|
||||
$viewRouter = app()->make(ViewRouter::class);
|
||||
[$routerContent, $routerPath] = $viewRouter->setFilePathName($filePath['router'] ?? '')->isMake($isMake)->handle($tableName, [
|
||||
|
||||
@ -94,12 +94,13 @@ class Controller extends Make
|
||||
$this->value['name'] = $className;
|
||||
$this->value['path'] = $this->getfolderPath($path);
|
||||
$this->value['content-php'] = $contentPhp;
|
||||
$this->value['use-php'] = "use " . $options['usePath'] . ";\n";
|
||||
|
||||
$contentStr = str_replace($this->var, $this->value, $contentController);
|
||||
|
||||
$filePath = $this->getFilePathName($path, $this->value['nameCamel']);
|
||||
|
||||
return [$this->makeFile($filePath, $contentStr), $this->filePathName ?: $filePath];
|
||||
return [$this->makeFile($filePath, $contentStr), $this->filePathName ?: $filePath, $this->value['path']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -236,7 +236,12 @@ abstract class Make
|
||||
|
||||
$filePath = $this->getFilePathName($path, $this->value['nameCamel']);
|
||||
|
||||
return [$this->makeFile($filePath, $contentStr), $this->filePathName ?: $filePath];
|
||||
return [
|
||||
$this->makeFile($filePath, $contentStr),
|
||||
$this->filePathName ?: $filePath,
|
||||
$this->value['path'] ?? '',
|
||||
$this->value['nameCamel']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -430,7 +435,7 @@ abstract class Make
|
||||
if (is_file($pathname)) {
|
||||
throw new CrudException($this->name . ':' . $pathname . ' already exists!');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (!is_dir(dirname($pathname))) {
|
||||
mkdir(dirname($pathname), 0755, true);
|
||||
|
||||
@ -40,6 +40,29 @@ class Model extends Make
|
||||
return 'app' . DS . 'model' . DS . 'crud';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/12
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
* @return array|mixed|void
|
||||
*/
|
||||
public function handle(string $name, array $options = [])
|
||||
{
|
||||
$this->value['key'] = $options['key'] ?? 'id';
|
||||
return parent::handle($name, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/12
|
||||
*/
|
||||
protected function getFilePathName(string $path, string $name): string
|
||||
{
|
||||
$path = ltrim(str_replace('\\', '/', $path), '/');
|
||||
|
||||
@ -92,7 +92,11 @@ class Service extends Make
|
||||
|
||||
$filePath = $this->getFilePathName($path, $this->value['nameCamel']);
|
||||
|
||||
return [$this->makeFile($filePath, $contentStr), $this->filePathName ?: $filePath];
|
||||
return [
|
||||
$this->makeFile($filePath, $contentStr),
|
||||
$this->filePathName ?: $filePath,
|
||||
$this->baseDir . '\\' . $this->value['nameCamel']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -20,7 +20,7 @@ namespace app\adminapi\controller\crud{%path%};
|
||||
|
||||
use app\adminapi\controller\AuthController;
|
||||
use think\facade\App;
|
||||
|
||||
{%use-php%}
|
||||
/**
|
||||
* Class {%nameCamel%}
|
||||
* @date {%date%}
|
||||
|
||||
@ -20,7 +20,7 @@ namespace app\dao\crub{%path%};
|
||||
|
||||
|
||||
use app\dao\BaseDao;
|
||||
|
||||
{%use-php%}
|
||||
/**
|
||||
* Class {%nameCamel%}Dao
|
||||
* @date {%date%}
|
||||
@ -36,6 +36,6 @@ class {%nameCamel%}Dao extends BaseDao
|
||||
*/
|
||||
protected function setModel(): string
|
||||
{
|
||||
return {%nameCamel%}Model::class;
|
||||
return {%nameCamel%}::class;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user