From 6fd86eda13253ab71fd5cd93714d6b66904a2d98 Mon Sep 17 00:00:00 2001 From: Oscar Date: Mon, 8 Dec 2025 17:28:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(sidebar):=20=E8=A1=A5=E5=85=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BE=A7=E8=BE=B9=E6=A0=8F=E9=A1=B9=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E4=BE=A7=E8=BE=B9=E6=A0=8F=E4=BD=8D=E8=BF=BD=E5=8A=A0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/shared/SidebarCustomizer.vue | 57 ++++++++++++------- dashboard/src/utils/sidebarCustomization.js | 41 +++++++------ 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/dashboard/src/components/shared/SidebarCustomizer.vue b/dashboard/src/components/shared/SidebarCustomizer.vue index 625320d0d..6fc160858 100644 --- a/dashboard/src/components/shared/SidebarCustomizer.vue +++ b/dashboard/src/components/shared/SidebarCustomizer.vue @@ -133,32 +133,49 @@ const draggedItem = ref(null); function initializeItems() { const customization = getSidebarCustomization(); - + const all = new Map(); + const defaultMain = []; + const defaultMore = []; + + sidebarItems.forEach(item => { + if (item.children) { + item.children.forEach(child => { + all.set(child.title, child); + defaultMore.push(child.title); + }); + } else { + all.set(item.title, item); + defaultMain.push(item.title); + } + }); + if (customization) { - // Load from customization - const allItemsMap = new Map(); - - sidebarItems.forEach(item => { - if (item.children) { - item.children.forEach(child => { - allItemsMap.set(child.title, child); - }); - } else { - allItemsMap.set(item.title, item); + const used = new Set([...(customization.mainItems || []), ...(customization.moreItems || [])]); + + mainItems.value = (customization.mainItems || []) + .map(title => all.get(title)) + .filter(Boolean); + // 追加新增默认主区项 + defaultMain.forEach(title => { + if (!used.has(title)) { + const item = all.get(title); + if (item) mainItems.value.push(item); + } + }); + + moreItems.value = (customization.moreItems || []) + .map(title => all.get(title)) + .filter(Boolean); + // 追加新增默认更多区项 + defaultMore.forEach(title => { + if (!used.has(title)) { + const item = all.get(title); + if (item) moreItems.value.push(item); } }); - - mainItems.value = customization.mainItems - .map(title => allItemsMap.get(title)) - .filter(item => item); - - moreItems.value = customization.moreItems - .map(title => allItemsMap.get(title)) - .filter(item => item); } else { // Load default structure mainItems.value = sidebarItems.filter(item => !item.children); - const moreGroup = sidebarItems.find(item => item.title === 'core.navigation.groups.more'); moreItems.value = moreGroup ? [...moreGroup.children] : []; } diff --git a/dashboard/src/utils/sidebarCustomization.js b/dashboard/src/utils/sidebarCustomization.js index 75cc5896f..6c7ad02a5 100644 --- a/dashboard/src/utils/sidebarCustomization.js +++ b/dashboard/src/utils/sidebarCustomization.js @@ -51,46 +51,43 @@ export function applySidebarCustomization(defaultItems) { return defaultItems; } - const { mainItems, moreItems } = customization; + const { mainItems = [], moreItems = [] } = customization; - // Create a map of all items by title for quick lookup - // Deep clone items to avoid mutating originals - const allItemsMap = new Map(); + const all = new Map(); + const defaultMain = []; + const defaultMore = []; defaultItems.forEach(item => { if (item.children) { - // If it's the "More" group, add children to map item.children.forEach(child => { - allItemsMap.set(child.title, { ...child }); + all.set(child.title, { ...child }); + defaultMore.push(child.title); }); } else { - allItemsMap.set(item.title, { ...item }); + all.set(item.title, { ...item }); + defaultMain.push(item.title); } }); const customizedItems = []; + const used = new Set([...mainItems, ...moreItems]); - // Add main items in custom order - mainItems.forEach(title => { - const item = allItemsMap.get(title); - if (item) { - customizedItems.push(item); - } - }); + // 按用户顺序还原主区 + mainItems.forEach(title => all.get(title) && customizedItems.push(all.get(title))); + // 追加新增的默认主区项 + defaultMain.forEach(title => !used.has(title) && customizedItems.push(all.get(title))); - // If there are items in moreItems, create the "More Features" group - if (moreItems && moreItems.length > 0) { + // 更多区:用户配置 + 新增默认 + const mergedMore = [...moreItems]; + defaultMore.forEach(title => { if (!used.has(title)) mergedMore.push(title); }); + + if (mergedMore.length > 0) { const moreGroup = { title: 'core.navigation.groups.more', icon: 'mdi-dots-horizontal', children: [] }; - moreItems.forEach(title => { - const item = allItemsMap.get(title); - if (item) { - moreGroup.children.push(item); - } - }); + mergedMore.forEach(title => all.get(title) && moreGroup.children.push(all.get(title))); customizedItems.push(moreGroup); }