修改crud模板名称

This commit is contained in:
liaofei 2023-04-24 18:55:56 +08:00
parent dc79fbbf9a
commit 0e7fce950c
15 changed files with 38 additions and 16 deletions

View File

@ -254,6 +254,7 @@ class SystemCrud extends AuthController
$item['default_field_type'] = $item['field_type'];
$item['default_comment'] = $item['comment'];
$item['default_default'] = $item['default'];
$item['is_table'] = !!$item['is_table'];
$item['primaryKey'] = isset($item['primaryKey']) ? (int)$item['primaryKey'] : 0;
$info['field']['tableField'][$key] = $item;
}
@ -303,6 +304,7 @@ class SystemCrud extends AuthController
if ($deleteInfo) {
array_push($info['field']['tableField'], $deleteInfo);
}
$info['field']['pid'] = (int)$info['field']['pid'];
return app('json')->success(['file' => $data, 'crudInfo' => $info]);
}

View File

@ -165,9 +165,13 @@ class SystemCrudServices extends BaseServices
'value' => 'dateTime',
'label' => '单选日期时间',
],
// [
// 'value' => 'dateTimeRange',
// 'label' => '日期时间区间选择',
// ],
[
'value' => 'dateTimeRange',
'label' => '日期时间区间选择',
'value' => 'checkbox',
'label' => '多选框',
],
[
'value' => 'radio',
@ -545,9 +549,16 @@ class SystemCrudServices extends BaseServices
$res = $this->transaction(function () use ($crudInfo, $tableInfo, $modelName, $filePath, $tableName, $routeName, $data, $dataMenu) {
$routeService = app()->make(SystemRouteServices::class);
$meunService = app()->make(SystemMenusServices::class);
//修改菜单名称
if ($crudInfo) {
app()->make(SystemMenusServices::class)->update($crudInfo->menu_id, $dataMenu);
//菜单存在的时候进行修改
if ($crudInfo->menu_id && $meunService->value(['id' => [$crudInfo->menu_id]], 'id')) {
$meunService->update($crudInfo->menu_id, $dataMenu);
$menuInfo = (object)['id' => $crudInfo->menu_id];
} else {
$menuInfo = $meunService->save($dataMenu);
}
//删除掉添加的路由权限
if ($crudInfo->routes_id) {
$routeService->deleteRoutes($crudInfo->routes_id);
@ -556,9 +567,8 @@ class SystemCrudServices extends BaseServices
if ($crudInfo->menu_ids) {
app()->make(SystemMenusServices::class)->deleteMenus($crudInfo->menu_ids);
}
$menuInfo = (object)['id' => $crudInfo->menu_id];
} else {
$menuInfo = app()->make(SystemMenusServices::class)->save($dataMenu);
$menuInfo = $meunService->save($dataMenu);
}
//写入路由权限
$cateId = app()->make(SystemRouteServices::class)->topCateId('adminapi', 'CRUD');
@ -655,6 +665,7 @@ class SystemCrudServices extends BaseServices
'table_collation' => $tableInfo['TABLE_COLLATION'] ?? '',
'field' => json_encode($data),//提交的数据
'menu_ids' => json_encode($menuIds),//生成的菜单id
'menu_id' => $menuInfo->id,//生成的菜单id
'make_path' => json_encode($makePath),
'routes_id' => json_encode($routeIds),
];
@ -667,6 +678,8 @@ class SystemCrudServices extends BaseServices
$res = $this->dao->save($crudDate);
}
// throw new ValidateException('测试中');
return $res;
});

View File

@ -124,7 +124,7 @@ class Controller extends Make
'edit' => $controllerPath . 'edit.stub',
'update' => $controllerPath . 'update.stub',
'delete' => $controllerPath . 'delete.stub',
'controller' => $controllerPath . 'CrudController.stub',
'controller' => $controllerPath . 'crudController.stub',
];
return $type ? $stubs[$type] : $stubs;

View File

@ -44,6 +44,6 @@ class Dao extends Make
*/
protected function getStub(string $type = '')
{
return __DIR__ . DS . 'stubs' . DS . 'dao' . DS . 'CrudDao.stub';
return __DIR__ . DS . 'stubs' . DS . 'dao' . DS . 'crudDao.stub';
}
}

View File

@ -84,6 +84,6 @@ class Model extends Make
*/
protected function getStub(string $type = '')
{
return __DIR__ . DS . 'stubs' . DS . 'model' . DS . 'CrudModel.stub';
return __DIR__ . DS . 'stubs' . DS . 'model' . DS . 'crudModel.stub';
}
}

View File

@ -73,10 +73,13 @@ class Service extends Make
$from[] = $this->tab(2) . $this->getframeImagesPhpContent($item['field'], $item['name'], $item['required'] ?? false) . ';';
break;
default:
$from[] = $this->tab(2) . '$rule[] = FormBuilder::' . $item['type'] . '("' . $item['field'] . '","' . $item['name'] . '",$info["' . $item['field'] . '"] ?? "")' . $this->getOptionContent(in_array($item['type'], ['radio', 'select']), $item['option'] ?? []) . ';';
$valueContent = "''";
if (in_array($item['type'], ['checkbox'])) {
$valueContent = '[]';
}
$from[] = $this->tab(2) . '$rule[] = FormBuilder::' . $item['type'] . '("' . $item['field'] . '", "' . $item['name'] . '", $info["' . $item['field'] . '"] ?? ' . $valueContent . ')' . $this->getOptionContent(in_array($item['type'], ['radio', 'select']), $item['option'] ?? []) . ';';
break;
}
}
if ($from) {
$this->value['use-php'] .= "\n" . 'use crmeb\services\FormBuilder;';
@ -214,11 +217,11 @@ CONTENT;
$servicePath = __DIR__ . DS . 'stubs' . DS . 'service' . DS;
$stubs = [
'index' => $servicePath . 'CrudListIndex.stub',
'form' => $servicePath . 'GetCrudForm.stub',
'save' => $servicePath . 'CrudSave.stub',
'update' => $servicePath . 'CrudUpdate.stub',
'services' => $servicePath . 'CrudService.stub',
'index' => $servicePath . 'crudListIndex.stub',
'form' => $servicePath . 'getCrudForm.stub',
'save' => $servicePath . 'crudSave.stub',
'update' => $servicePath . 'crudUpdate.stub',
'services' => $servicePath . 'crudService.stub',
];
return $type ? $stubs[$type] : $stubs;

View File

@ -74,19 +74,23 @@ class ViewPages extends Make
$columnStr = [];
$contentVue = [];
foreach ($field as $key => $item) {
$keyName = 'key';
if (isset($item['type'])) {
switch ($item['type']) {
case 'frameImageOne':
$keyName = 'slot';
$templateContent = file_get_contents($this->getStub('image'));
$contentVue[] = str_replace(['{%field%}'], [$item['field']], $templateContent);
break;
case 'frameImages':
$keyName = 'slot';
$templateContent = file_get_contents($this->getStub('images'));
$contentVue[] = str_replace(['{%field%}'], [$item['field']], $templateContent);
break;
}
}
$columnStr[] = ($key == 0 ? $this->tab(2) : '') . "{\n" . $this->tab(3) . "title:\"{$item['name']}\"," . $this->tab(2) . "\n" . $this->tab(3) . "key:\"{$item['field']}\"\n" . $this->tab(2) . "}\n";
$columnStr[] = ($key == 0 ? $this->tab(2) : '') . "{\n" . $this->tab(3) . "title:\"{$item['name']}\"," . $this->tab(2) . "\n" . $this->tab(3) . "$keyName:\"{$item['field']}\"\n" . $this->tab(2) . "}\n";
}
$this->value['auth'] = Str::snake($name);
$this->value['componentName'] = $this->value['auth'];