Skip to content

Commit

Permalink
feat: 调整组件选择组件
Browse files Browse the repository at this point in the history
  • Loading branch information
slowlyo committed Jun 4, 2024
1 parent 1ae4ab4 commit a789dc4
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 130 deletions.
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
'scope' => 'Scope',
'list_component' => 'List Component',
'list_component_desc' => 'List Component, Default Is TableColumn',
'filter_component' => 'Table Filter',
'filter_component_desc' => 'Filter Component, Default Is TableColumn',
'form_component' => 'Form Component',
'form_component_desc' => 'Form Component, Default Is TextControl',
'detail_component' => 'Detail Component',
Expand Down
2 changes: 2 additions & 0 deletions lang/zh_CN/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
'scope' => '作用域',
'list_component' => '列表组件',
'list_component_desc' => '列表组件, 默认为 TableColumn',
'filter_component' => '列表筛选',
'filter_component_desc' => '列表组件, 默认为 TableColumn',
'form_component' => '表单组件',
'form_component_desc' => '表单组件, 默认为 TextControl',
'detail_component' => '详情组件',
Expand Down
265 changes: 140 additions & 125 deletions src/Controllers/DevTools/CodeGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,123 +673,25 @@ public function cachedColumns()
]);
}

/**
* 字段表单
*
* @return \Slowlyo\OwlAdmin\Renderers\Card
*/
public function columnForm()
public function componentSelect($key, $label = '')
{
// 设置组件的 Tab
$componentSchema = function ($title, $tips, $key) {
$comboName = $key . '_property';
$comboId = $comboName . '_id';

return amis()->Tab()->title($title)->body([
amis()->Alert()->level('info')->showIcon()->body($tips),

amis()->Flex()->justify('end')->items([
amis()->DrawerAction()
->className('mr-3')
->label(admin_trans('admin.code_generators.load_config'))
->level('primary')
->drawer(
amis()->Drawer()
->title(admin_trans('admin.code_generators.load_config'))
->bodyClassName('p-0')
->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=${' . $key . '_type}')
->body(
amis()->CRUDTable()
->className('border-none')
->loadDataOnce()
->source('${component_property_list}')
->columns([
amis()
->TableColumn('label', admin_trans('admin.admin_role.name'))
->searchable(),

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

// 删除
amis()->AjaxAction()
->label(admin_trans('admin.delete'))
->level('danger')
->confirmText(admin_trans('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(admin_trans('admin.code_generators.save_current_config'))
->level('success')
->dialog(
amis()->Dialog()->title(admin_trans('admin.code_generators.save_current_config'))->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('label')
->inline(false)
->required()
->placeholder(admin_trans('admin.code_generators.input_config_name'))
->description(admin_trans('admin.code_generators.same_name_tips')),
amis()->HiddenControl('key')->value('${' . $key . '_type}'),
amis()->HiddenControl('value')->value('${' . $comboName . '}'),
]),
])
)
),
]),

amis()->Divider(),

amis()->Service()
->className('px-20')
->initFetchOn('${!!' . $key . '_type}')
->api('post:/dev_tools/code_generator/get_property_options?c=${' . $key . '_type}&t=' . $key)
->body([
$comboName = $key . '_property';
$comboId = $comboName . '_id';

return amis()->ComboControl($key, $label)->items([
amis()->Service()
->className('px-20')
->initFetchOn('${!!' . $key . '_type}')
->api('post:/dev_tools/code_generator/get_property_options?c=${' . $key . '_type}&t=' . $key)
->body([
amis('group')->body([
amis()->SelectControl($key . '_type', admin_trans('admin.admin_menu.type'))
->searchable()
->id($key)
->clearable()
->size('lg')
->source('${component_options}')
->set('columnRatio', 8)
->onEvent([
'change' => [
'actions' => [
Expand All @@ -801,21 +703,134 @@ public function columnForm()
],
],
])->description(admin_trans('admin.code_generators.name_label_desc')),

amis()->ComboControl($comboName, admin_trans('admin.code_generators.property'))
->id($comboId)
->multiple()
->strictMode(false)
->items([
amis()->TextControl('name', admin_trans('admin.code_generators.property_name'))
->required()
->set('unique', true)
->size('md')
->clearable()
->source('${component_property_options}'),
amis()->TextControl('value', admin_trans('admin.code_generators.value'))->size('md'),
]),
amis('group')->body([
amis()->DrawerAction()
->label(admin_trans('admin.code_generators.load_config'))
->level('primary')
->set('columnRatio', 4)
->drawer(
amis()->Drawer()
->title(admin_trans('admin.code_generators.load_config'))
->bodyClassName('p-0')
->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=${' . $key . '_type}')
->body(
amis()->CRUDTable()
->className('border-none')
->loadDataOnce()
->source('${component_property_list}')
->columns([
amis()
->TableColumn('label', admin_trans('admin.admin_role.name'))
->searchable(),

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

// 删除
amis()->AjaxAction()
->label(admin_trans('admin.delete'))
->level('danger')
->confirmText(admin_trans('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(admin_trans('admin.code_generators.save_current_config'))
->level('success')
->set('columnRatio', 8)
->dialog(
amis()
->Dialog()
->title(admin_trans('admin.code_generators.save_current_config'))
->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('label')
->inline(false)
->required()
->placeholder(admin_trans('admin.code_generators.input_config_name'))
->description(admin_trans('admin.code_generators.same_name_tips')),
amis()->HiddenControl('key')->value('${' . $key . '_type}'),
amis()->HiddenControl('value')->value('${' . $comboName . '}'),
]),
])
)
),
])->set('columnRatio', 4),
]),

amis()->ComboControl($comboName, admin_trans('admin.code_generators.property'))
->id($comboId)
->multiple()
->strictMode(false)
->items([
amis()->TextControl('name', admin_trans('admin.code_generators.property_name'))
->required()
->set('unique', true)
->size('md')
->clearable()
->source('${component_property_options}'),
amis()->TextControl('value', admin_trans('admin.code_generators.value'))->size('md'),
]),
]),
]);
}

/**
* 字段表单
*
* @return \Slowlyo\OwlAdmin\Renderers\Card
*/
public function columnForm()
{
// 设置组件的 Tab
$componentSchema = function ($title, $tips, $key) {
return amis()->Tab()->title($title)->body([
amis()->Alert()->level('info')->showIcon()->body($tips),
amis()->Divider(),
$this->componentSelect($key)->mode('normal'),
]);
};

Expand Down
Loading

0 comments on commit a789dc4

Please sign in to comment.