mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-06 20:18:10 +08:00
style(menu): 优化菜单表单图标选择布局
为 PickerFieldComponent 增加 control_class 和 control_attrs 包裹层配置,让输入框与右侧图标能够在相对定位容器内稳定对齐,同时保留外层 label 的自定义能力。 菜单编辑表单引入专用内联样式,调整图标选择器输入框、右侧图标按钮和图标预览区域的间距与边框,提升图标选择交互的视觉一致性。 为菜单状态单选区域增加专用 class 和样式,统一选项高度、背景和单选图标尺寸,避免表单网格中状态项显示拥挤。
This commit is contained in:
parent
7e2834b6fa
commit
217b1c9ea9
@ -28,7 +28,7 @@ class PickerFieldComponent extends AbstractFormComponent
|
|||||||
|
|
||||||
public function mount(FormNode $parent): FormNode
|
public function mount(FormNode $parent): FormNode
|
||||||
{
|
{
|
||||||
$node = $parent->node('label')->class(trim(strval($this->config['class'] ?? 'relative block')));
|
$node = $parent->node('label')->class(trim(strval($this->config['class'] ?? 'block')));
|
||||||
foreach ((array)($this->config['attrs'] ?? []) as $name => $value) {
|
foreach ((array)($this->config['attrs'] ?? []) as $name => $value) {
|
||||||
$node->attr(strval($name), $value);
|
$node->attr(strval($name), $value);
|
||||||
}
|
}
|
||||||
@ -51,9 +51,14 @@ class PickerFieldComponent extends AbstractFormComponent
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$input = $node->node('input')->attrs([
|
$control = $node->div()->class(trim(strval($this->config['control_class'] ?? 'relative')));
|
||||||
|
foreach ((array)($this->config['control_attrs'] ?? []) as $name => $value) {
|
||||||
|
$control->attr(strval($name), $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$input = $control->node('input')->attrs([
|
||||||
'readonly' => null,
|
'readonly' => null,
|
||||||
'class' => trim(strval($this->config['input_class'] ?? 'layui-input')),
|
'class' => trim(strval($this->config['input_class'] ?? 'layui-input pr40')),
|
||||||
'value' => strval($this->config['value'] ?? ''),
|
'value' => strval($this->config['value'] ?? ''),
|
||||||
'title' => strval($this->config['value'] ?? ''),
|
'title' => strval($this->config['value'] ?? ''),
|
||||||
]);
|
]);
|
||||||
@ -64,7 +69,7 @@ class PickerFieldComponent extends AbstractFormComponent
|
|||||||
foreach ((array)($this->config['input_attrs'] ?? []) as $name => $value) {
|
foreach ((array)($this->config['input_attrs'] ?? []) as $name => $value) {
|
||||||
$input->attr(strval($name), $value);
|
$input->attr(strval($name), $value);
|
||||||
}
|
}
|
||||||
$icon = $node->node('span')->class(trim(strval($this->config['icon_class'] ?? 'input-right-icon layui-icon layui-icon-theme')));
|
$icon = $control->node('span')->class(trim(strval($this->config['icon_class'] ?? 'input-right-icon layui-icon layui-icon-theme')));
|
||||||
foreach ((array)($this->config['icon_attrs'] ?? []) as $name => $value) {
|
foreach ((array)($this->config['icon_attrs'] ?? []) as $name => $value) {
|
||||||
$icon->attr(strval($name), $value);
|
$icon->attr(strval($name), $value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,6 +153,7 @@ SCRIPT);
|
|||||||
$form->action(strval($context['actionUrl'] ?? ''))
|
$form->action(strval($context['actionUrl'] ?? ''))
|
||||||
->attrs(['id' => 'MenuForm', 'data-table-id' => 'MenuTable'])
|
->attrs(['id' => 'MenuForm', 'data-table-id' => 'MenuTable'])
|
||||||
->class('system-menu-form');
|
->class('system-menu-form');
|
||||||
|
$form->html('<style id="SystemMenuFormStyle">' . self::renderFormStyle() . '</style>');
|
||||||
|
|
||||||
FormModules::section($form, [
|
FormModules::section($form, [
|
||||||
'title' => '层级归属',
|
'title' => '层级归属',
|
||||||
@ -236,7 +237,7 @@ SCRIPT);
|
|||||||
|
|
||||||
$fields = $grid->div()->class('layui-col-xs12 layui-col-md6');
|
$fields = $grid->div()->class('layui-col-xs12 layui-col-md6');
|
||||||
$fields->fields(function ($fields) {
|
$fields->fields(function ($fields) {
|
||||||
$fields->text('icon', '菜单图标', 'Menu Icon', false, '可手动输入图标类名,或通过右侧图标选择器回填。', null, [
|
$status = $fields->text('icon', '菜单图标', 'Menu Icon', false, '可手动输入图标类名,或通过右侧图标选择器回填。', null, [
|
||||||
'placeholder' => '例如:layui-icon layui-icon-set-fill',
|
'placeholder' => '例如:layui-icon layui-icon-set-fill',
|
||||||
])->text('sort', '排序权重', 'Sort Order', false, '数值越大越靠前。', null, [
|
])->text('sort', '排序权重', 'Sort Order', false, '数值越大越靠前。', null, [
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
@ -244,7 +245,8 @@ SCRIPT);
|
|||||||
'placeholder' => '请输入排序权重',
|
'placeholder' => '请输入排序权重',
|
||||||
])->defaultValue(0)->radio('status', '使用状态', 'Status', '', true, [
|
])->defaultValue(0)->radio('status', '使用状态', 'Status', '', true, [
|
||||||
'required-error' => '请选择当前菜单的启用状态。',
|
'required-error' => '请选择当前菜单的启用状态。',
|
||||||
])->options([
|
]);
|
||||||
|
$status->body()->class('system-menu-status-options')->end()->options([
|
||||||
1 => '已启用',
|
1 => '已启用',
|
||||||
0 => '已禁用',
|
0 => '已禁用',
|
||||||
])->defaultValue('1');
|
])->defaultValue('1');
|
||||||
@ -255,6 +257,9 @@ SCRIPT);
|
|||||||
'title' => '图标选择器',
|
'title' => '图标选择器',
|
||||||
'subtitle' => 'Icon Picker',
|
'subtitle' => 'Icon Picker',
|
||||||
'value' => '点击打开图标选择器',
|
'value' => '点击打开图标选择器',
|
||||||
|
'class' => 'block system-menu-icon-picker',
|
||||||
|
'control_class' => 'relative',
|
||||||
|
'input_class' => 'layui-input pr40',
|
||||||
'attrs' => ['data-open-menu-icon' => null],
|
'attrs' => ['data-open-menu-icon' => null],
|
||||||
'input_attrs' => [
|
'input_attrs' => [
|
||||||
'data-open-menu-icon' => null,
|
'data-open-menu-icon' => null,
|
||||||
@ -264,7 +269,7 @@ SCRIPT);
|
|||||||
'icon_attrs' => ['data-open-menu-icon' => null],
|
'icon_attrs' => ['data-open-menu-icon' => null],
|
||||||
'help' => '选择后会自动同步到“菜单图标”字段,并实时预览当前图标样式。',
|
'help' => '选择后会自动同步到“菜单图标”字段,并实时预览当前图标样式。',
|
||||||
]);
|
]);
|
||||||
$picker->div()->class('layui-form-mid color-desc')->html(sprintf(
|
$picker->div()->class('layui-form-mid color-desc system-menu-icon-preview')->html(sprintf(
|
||||||
'<span class="inline-flex items-center"><i class="layui-icon layui-icon-set-fill font-s14 mr-8" data-menu-icon-preview></i><span data-menu-icon-preview-text>%s</span></span>',
|
'<span class="inline-flex items-center"><i class="layui-icon layui-icon-set-fill font-s14 mr-8" data-menu-icon-preview></i><span data-menu-icon-preview-text>%s</span></span>',
|
||||||
self::escape(BuilderLang::text('未设置图标'))
|
self::escape(BuilderLang::text('未设置图标'))
|
||||||
));
|
));
|
||||||
@ -345,6 +350,55 @@ SCRIPT;
|
|||||||
return strval(json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT));
|
return strval(json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function renderFormStyle(): string
|
||||||
|
{
|
||||||
|
return <<<'STYLE'
|
||||||
|
#MenuForm .system-menu-icon-picker .layui-input {
|
||||||
|
cursor: pointer;
|
||||||
|
padding-right: 44px !important;
|
||||||
|
}
|
||||||
|
#MenuForm .system-menu-icon-picker .input-right-icon {
|
||||||
|
top: 1px;
|
||||||
|
right: 1px;
|
||||||
|
width: 34px;
|
||||||
|
height: 32px;
|
||||||
|
line-height: 32px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-left: 1px solid var(--ta-border-color, #dce8e5);
|
||||||
|
border-radius: 0 3px 3px 0;
|
||||||
|
}
|
||||||
|
#MenuForm .system-menu-icon-preview {
|
||||||
|
min-height: 20px;
|
||||||
|
margin-top: 8px;
|
||||||
|
padding: 0 2px;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
#MenuForm .system-menu-icon-preview .layui-icon {
|
||||||
|
width: 18px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#MenuForm [data-field-name="status"] .system-menu-status-options {
|
||||||
|
height: auto !important;
|
||||||
|
min-height: 34px !important;
|
||||||
|
padding: 1px 0 1px 8px !important;
|
||||||
|
line-height: 32px !important;
|
||||||
|
align-items: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-color: var(--ta-border-color, #dce8e5);
|
||||||
|
background: var(--ta-surface-soft, #f7fbfb) !important;
|
||||||
|
}
|
||||||
|
#MenuForm [data-field-name="status"] .system-menu-status-options .layui-form-radio {
|
||||||
|
margin: 0 18px 0 0;
|
||||||
|
padding-right: 0;
|
||||||
|
line-height: 32px;
|
||||||
|
}
|
||||||
|
#MenuForm [data-field-name="status"] .system-menu-status-options .layui-form-radio > i {
|
||||||
|
margin-right: 5px;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
STYLE;
|
||||||
|
}
|
||||||
|
|
||||||
private static function renderFormScript(): string
|
private static function renderFormScript(): string
|
||||||
{
|
{
|
||||||
return sprintf(<<<'SCRIPT'
|
return sprintf(<<<'SCRIPT'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user