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 f7a39d0 commit da581a3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
80 changes: 76 additions & 4 deletions src/Controllers/DevTools/CodeGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,55 @@ public function getPropertyOptions(Request $request)
]);

$cacheAction = amis()->Flex()->justify('start')->items([
amis()->AjaxAction()->label('加载配置')->className('mr-4')->level('primary'),
amis()->DialogAction()->className('mr-3')->label('加载配置')->level('primary')->dialog(
amis()->Dialog()
->title("加载{$request->c}配置")
->actions([])
->id('load_config_dialog')
->closeOnOutside()
->body(
amis()->Service()
->name('component_property_list_service')
->api('post:/dev_tools/code_generator/component_property/list?key=' . $comboName . '&c=' . $request->c)
->body(
amis()->Table()->source('${component_property_list}')->columns([
amis()->TableColumn('label'),

amis()->Operation()->buttons([
amis()->VanillaAction()->label('填充')->level('primary')->onEvent([
'click' => [
'actions' => [
[
'actionType' => 'setValue',
'componentId' => $comboId,
'args' => ['value' => '${value}',],
],
[
'actionType' => 'closeDialog',
'componentId' => 'load_config_dialog',
],
],
],
]),

amis()->AjaxAction()
->label('删除')
->level('danger')
->confirmText(__('admin.confirm_delete'))
->reload('component_property_list_service')
->api('post:/dev_tools/code_generator/component_property/del?name=' . $comboName),
])->set('width', 150),
])
)
)
),

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')
amis()->TextControl('label')
->inline(false)
->required()
->placeholder('请输入组件配置名称')
Expand Down Expand Up @@ -749,25 +791,55 @@ public function saveComponentProperty(Request $request)

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

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

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

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

/**
* 获取组件配置
*
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function getComponentProperty(Request $request)
{
$component_property_list = collect(settings()->get($request->key))->where('key', $request->c)->values();

return $this->response()->success(compact('component_property_list'));
}

/**
* 删除组件配置
*
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
*/
public function delComponentProperty(Request $request)
{
$list = settings()->get($request->name);

if (blank($list)) {
return $this->autoResponse(false);
}

foreach ($list as $key => $item) {
if ($item['label'] == $request->label && $item['key'] == $request->key) {
unset($list[$key]);
}
}

settings()->set($request->name, array_values($list));

return $this->autoResponse(true);
}

public function getRecord()
Expand Down
4 changes: 2 additions & 2 deletions src/Support/Cores/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ private static function baseRoutes($prefix)

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

Expand Down

0 comments on commit da581a3

Please sign in to comment.