Skip to content

Commit

Permalink
- 代码生成器-组件配置保存
Browse files Browse the repository at this point in the history
  • Loading branch information
slowlyo committed Nov 7, 2023
1 parent 8ef5829 commit f7a39d0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 13 deletions.
95 changes: 82 additions & 13 deletions src/Controllers/DevTools/CodeGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public function list()
->confirmText(__('admin.code_generators.confirm_generate_code'))
->api('/dev_tools/code_generator/generate?id=${id}')
->feedback(
amis()->Dialog()->title(' ')->bodyClassName('overflow-auto')->body(amis()->Tpl()->tpl('${result | raw}'))->onEvent([
amis()->Dialog()->title(' ')->bodyClassName('overflow-auto')->body(amis()
->Tpl()
->tpl('${result | raw}'))->onEvent([
'confirm' => [
'actions' => [
['actionType' => 'custom', 'script' => 'window.$owl.refreshRoutes()'],
Expand Down Expand Up @@ -291,8 +293,7 @@ public function form()
->value($this->getNamespace('Controllers') . '${' . $nameHandler . '}Controller'),
amis()
->TextControl('service_name', __('admin.code_generators.service_name'))
->value($this->getNamespace('Services',
1) . '${' . $nameHandler . '}Service'),
->value($this->getNamespace('Services', 1) . '${' . $nameHandler . '}Service'),
amis()
->SwitchControl('need_timestamps', 'CreatedAt & UpdatedAt')
->value(1),
Expand Down Expand Up @@ -358,10 +359,10 @@ public function columnForm()
'change' => [
'actions' => [
[
'actionType' => 'clear',
'actionType' => 'clear',
'componentId' => $key . '_property_id',
'expression' => '${!!' . $key . '_property}'
]
'expression' => '${!!' . $key . '_property}',
],
],
],
])->description(__('admin.code_generators.name_label_desc')),
Expand Down Expand Up @@ -539,9 +540,9 @@ public function generate(Request $request)
->softDelete($record->soft_delete)
->generate($record->table_name, $columns);

$message .= $successMessage('Migration', $path);
$message .= $successMessage('Migration', $path);
$migratePath = str_replace(base_path(), '', $path);
$paths[] = $path;
$paths[] = $path;
}

// Controller
Expand Down Expand Up @@ -575,9 +576,9 @@ public function generate(Request $request)

// 创建数据库表
if ($needs->contains('need_create_table')) {
if($migratePath){
if ($migratePath) {
Artisan::call('migrate', ['--path' => $migratePath]);
}else{
} else {
Artisan::call('migrate');
}
$message .= Artisan::output();
Expand Down Expand Up @@ -690,9 +691,12 @@ public function getPropertyOptions(Request $request)

$type = $request->t;

$comboName = $type . '_property';
$comboId = $comboName . '_id';

$schema = amis()
->ComboControl($type . '_property', __('admin.code_generators.property'))
->id($type . '_property_id')
->ComboControl($comboName, __('admin.code_generators.property'))
->id($comboId)
->multiple()
->visibleOn('${!!' . $type . '_type}')
->items([
Expand All @@ -707,7 +711,63 @@ public function getPropertyOptions(Request $request)
amis()->TextControl('value', __('admin.code_generators.value'))->size('md'),
]);

return $this->response()->success($schema);
$cacheAction = amis()->Flex()->justify('start')->items([
amis()->AjaxAction()->label('加载配置')->className('mr-4')->level('primary'),
amis()->DialogAction()->label('保存当前配置')->level('success')->dialog(
amis()->Dialog()->title('保存当前配置')->body(
amis()->Form()->mode('normal')->api('post:/dev_tools/code_generator/component_property')->body([
amis()->HiddenControl('key')->value($comboName),
amis()->ComboControl('value')->items([
amis()->TextControl('title')
->inline(false)
->required()
->placeholder('请输入组件配置名称')
->description('相同名称的配置将会被覆盖'),
amis()->HiddenControl('key')->value($request->c),
amis()->HiddenControl('value')->value('${' . $comboName . '}'),
]),
])
)
),
]);

$line = amis()->Divider();

return $this->response()->success([$schema, $line, $cacheAction]);
}

/**
* 保存组件配置
*
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function saveComponentProperty(Request $request)
{
$list = [];

if ($original = settings()->get($request->key)) {
foreach ($original as $item) {
$list[$item['key'] . '|' . $item['title']] = $item;
}
}

$list[$request->value['key'] . '|' . $request->value['title']] = $request->value;

$res = settings()->set($request->key, array_values($list));

return $this->autoResponse($res, __('admin.save'));
}

public function getComponentProperty(Request $request)
{

}

public function delComponentProperty(Request $request)
{

}

public function getRecord()
Expand All @@ -727,6 +787,15 @@ public function getNamespace($name, $app = null): string
$namespace->pop();
}

if ($currentModule = Admin::currentModule()) {
if (file_exists(base_path("/Modules/{$currentModule}/app")) && $app) {
$namespace->push('app');
} else {
$_http = $namespace->pop();
$namespace->push('app')->push($_http);
}
}

return $namespace->push($name)->implode('/') . '/';
}

Expand Down
18 changes: 18 additions & 0 deletions src/Services/AdminSettingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ public function arrayGet(string $key, string $path, $default = null)
return $default;
}

/**
* 清除指定设置项
*
* @param string $key
*
* @return bool
*/
public function del(string $key)
{
if ($this->query()->where('key', $key)->delete()) {
$this->clearCache($key);

return true;
}

return false;
}

/**
* 清除指定设置项的缓存
*
Expand Down
6 changes: 6 additions & 0 deletions src/Support/Cores/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ private static function baseRoutes($prefix)
$router->post('generate', [CodeGeneratorController::class, 'generate']);
$router->post('get_record', [CodeGeneratorController::class, 'getRecord']);
$router->post('get_property_options', [CodeGeneratorController::class, 'getPropertyOptions']);

$router->group(['prefix' => 'component_property'], function (Router $router) {
$router->post('/', [CodeGeneratorController::class, 'saveComponentProperty']);
$router->get('/', [CodeGeneratorController::class, 'getComponentProperty']);
$router->delete('/', [CodeGeneratorController::class, 'delComponentProperty']);
});
});

$router->resource('extensions', ExtensionController::class);
Expand Down

0 comments on commit f7a39d0

Please sign in to comment.