fix(admin): 内容下拉去格式后缀,侧边栏开关右置并即时保存
- 内容页/条目弹窗的分组下拉只显示名称,去掉格式后缀与缩进,统一对齐 - 侧边栏开关移到右侧;拨动即保存到 settings.sidebar.tree_hidden - 移除侧边栏页的保存/撤销按钮 - Playwright 验证:选项无括号且对齐、开关在右、无保存按钮、设置即时落库
This commit is contained in:
@@ -136,6 +136,22 @@ export function AdminNext() {
|
||||
toast.success('已保存')
|
||||
}
|
||||
|
||||
/** 侧边栏开关即时保存(不再单独点保存按钮) */
|
||||
const saveSidebar = async (sidebar: SiteSettings['sidebar']) => {
|
||||
if (document === null || draft === null) return
|
||||
setSaving(true)
|
||||
const result = await saveSettings(document.version, { ...draft, sidebar })
|
||||
setSaving(false)
|
||||
if (!result.ok) {
|
||||
toast.error(result.error)
|
||||
void load()
|
||||
return
|
||||
}
|
||||
setDocument(result.document)
|
||||
setDraft(clone(result.document.settings))
|
||||
toast.success('侧边栏已保存')
|
||||
}
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (pending === null) return
|
||||
setDeleting(true)
|
||||
@@ -234,9 +250,13 @@ export function AdminNext() {
|
||||
<SidebarPanel
|
||||
groups={groups}
|
||||
value={draft.sidebar}
|
||||
onChange={(sidebar) => setDraft({ ...draft, sidebar })}
|
||||
onSave={save}
|
||||
saving={saving}
|
||||
onToggle={(key, visible) => {
|
||||
const hidden = new Set(draft.sidebar.tree_hidden)
|
||||
if (visible) hidden.delete(key)
|
||||
else hidden.add(key)
|
||||
void saveSidebar({ ...draft.sidebar, tree_hidden: [...hidden] })
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -265,7 +285,7 @@ export function AdminNext() {
|
||||
|
||||
{tab === 'system' && <SystemPanel />}
|
||||
|
||||
{(tab === 'header' || tab === 'profile' || tab === 'sidebar') && (
|
||||
{(tab === 'header' || tab === 'profile') && (
|
||||
<Space gap="sm" justify="end" className="admin-actions">
|
||||
<Button
|
||||
variant="secondary"
|
||||
@@ -833,7 +853,7 @@ function ContentPanel({ groups, onReload }: { groups: GroupNode[]; onReload: ()
|
||||
<Select
|
||||
options={options.map((option) => ({
|
||||
value: option.key,
|
||||
label: `${' '.repeat(option.depth)}${option.title}(${FORMAT_LABEL[option.format]})`,
|
||||
label: option.title,
|
||||
}))}
|
||||
value={group?.key ?? ''}
|
||||
onChange={setGroupKey}
|
||||
@@ -1084,7 +1104,7 @@ function EntryDialog({
|
||||
<Select
|
||||
options={options.map((option) => ({
|
||||
value: option.key,
|
||||
label: `${' '.repeat(option.depth)}${option.title}`,
|
||||
label: option.title,
|
||||
}))}
|
||||
value={groupKey}
|
||||
onChange={setGroupKey}
|
||||
@@ -1169,38 +1189,27 @@ function EntryDialog({
|
||||
function SidebarPanel({
|
||||
groups,
|
||||
value,
|
||||
onChange,
|
||||
onSave,
|
||||
onToggle,
|
||||
saving,
|
||||
}: {
|
||||
groups: GroupNode[]
|
||||
value: SiteSettings['sidebar']
|
||||
onChange: (sidebar: SiteSettings['sidebar']) => void
|
||||
onSave: () => void
|
||||
onToggle: (key: string, visible: boolean) => void
|
||||
saving: boolean
|
||||
}) {
|
||||
const hidden = new Set(value.tree_hidden)
|
||||
|
||||
const toggle = (key: string, visible: boolean) => {
|
||||
const next = new Set(hidden)
|
||||
if (visible) next.delete(key)
|
||||
else next.add(key)
|
||||
onChange({ ...value, tree_hidden: [...next] })
|
||||
}
|
||||
|
||||
function render(nodes: GroupNode[], depth: number) {
|
||||
return nodes.map((node) => (
|
||||
<div key={node.key} style={{ marginLeft: depth * 22 }}>
|
||||
<div className="admin-item-row admin-nav-row">
|
||||
<div className="sidebar-toggle-row">
|
||||
<Text className="admin-item-title">{node.title}</Text>
|
||||
<Switch
|
||||
checked={!hidden.has(node.key)}
|
||||
onChange={(visible) => toggle(node.key, visible)}
|
||||
onChange={(visible) => onToggle(node.key, visible)}
|
||||
label={`侧栏显示 ${node.title}`}
|
||||
disabled={saving}
|
||||
/>
|
||||
<Text className="admin-item-title">{node.title}</Text>
|
||||
<Text size="sm" tone="muted">
|
||||
{node.format}
|
||||
</Text>
|
||||
</div>
|
||||
{render(node.children, depth + 1)}
|
||||
</div>
|
||||
@@ -1210,14 +1219,9 @@ function SidebarPanel({
|
||||
return (
|
||||
<Space direction="column" gap="md" align="stretch" className="admin-form">
|
||||
<Text size="sm" tone="muted">
|
||||
勾选要在侧边栏显示的分组;子分组可以单独勾选,父分组不勾选也不影响子项。
|
||||
勾选要在侧边栏显示的分组;子分组可以单独勾选,父分组不勾选也不影响子项。开关修改后立即保存。
|
||||
</Text>
|
||||
{render(groups, 0)}
|
||||
<Space gap="sm" justify="end">
|
||||
<Button loading={saving} icon={<Icon name="check_line" />} onClick={onSave}>
|
||||
保存侧边栏
|
||||
</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user