From 769c970e084df03d6d6e5587b3397942294d0b4b Mon Sep 17 00:00:00 2001 From: PanFu Date: Wed, 20 May 2026 17:24:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=89=E4=B8=AA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9A=E5=81=8F=E5=A5=BD=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E4=BF=AE=E6=94=B9=E5=90=8E=E9=87=8D=E5=90=AF=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E7=94=9F=E6=95=88=EF=BC=9B=E9=94=81=E5=B1=8F=E5=BC=B9?= =?UTF-8?q?=E5=87=BA=E6=A1=86=E7=9A=84=E6=8C=89=E9=92=AE=E6=96=87=E5=AD=97?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=9B=E5=8F=B3=E4=B8=8A=E8=A7=92=E5=81=8F?= =?UTF-8?q?=E5=A5=BD=E8=AE=BE=E7=BD=AE=E6=8C=89=E9=92=AE=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BC=98=E5=8C=96=EF=BC=9B=20(#7930)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修正偏好设置加载缓存的偏好设置并与初始配置合并的顺序 * fix: 修正锁屏弹出框的按钮文字 * fix: 偏好设置按钮排序优化(取第三个占位的数字,若是第三个占位不是数字,则自动分配排序索引) * fix: 修正偏好设置加载缓存的偏好设置并与初始配置合并的顺序 - 代码QC问题修改 --------- Co-authored-by: PanFu --- packages/@core/preferences/src/preferences.ts | 6 +- .../layouts/src/basic/header/header.vue | 84 +++++++++++++------ packages/locales/src/langs/en-US/ui.json | 2 +- packages/locales/src/langs/zh-CN/ui.json | 2 +- 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/packages/@core/preferences/src/preferences.ts b/packages/@core/preferences/src/preferences.ts index 799f3c1fd..8e4cf4b5b 100644 --- a/packages/@core/preferences/src/preferences.ts +++ b/packages/@core/preferences/src/preferences.ts @@ -124,19 +124,19 @@ class PreferenceManager { // 使用命名空间初始化存储管理器 this.cache = new StorageManager({ prefix: namespace }); - // 合并初始偏好设置 + // 合并初始偏好设置:前面的对象优先,后面的对象仅补齐缺失字段 this.initialPreferences = merge({}, overrides, defaultPreferences); this.customPreferencesExtension = extension ?? null; this.initialCustomPreferences = this.resolveCustomPreferencesDefaults( this.customPreferencesExtension, ); - // 加载缓存的偏好设置并与初始配置合并 + // 加载缓存的偏好设置,并仅用缓存补齐初始化配置中未显式设置的字段 const cachedPreferences = (await this.loadFromCache()) || {}; const mergedPreference = merge( {}, + this.initialPreferences, // 初始化配置优先,缓存仅补齐缺失字段 cachedPreferences, - this.initialPreferences, ); // 更新偏好设置 diff --git a/packages/effects/layouts/src/basic/header/header.vue b/packages/effects/layouts/src/basic/header/header.vue index b8332822d..1bc8d7f73 100644 --- a/packages/effects/layouts/src/basic/header/header.vue +++ b/packages/effects/layouts/src/basic/header/header.vue @@ -33,52 +33,61 @@ withDefaults(defineProps(), { const emit = defineEmits<{ clearPreferencesAndLogout: [] }>(); -const REFERENCE_VALUE = 50; +const REFERENCE_VALUE = 100; const accessStore = useAccessStore(); const { globalSearchShortcutKey, preferencesButtonPosition } = usePreferences(); const slots = useSlots(); const { refresh } = useRefresh(); +/** + * 插槽列表类型 + */ +type SlotItem = { index: number; name: string }; + const rightSlots = computed(() => { - const list = [{ index: REFERENCE_VALUE + 100, name: 'user-dropdown' }]; + const list: Array = []; + // 全局搜索 if (preferences.widget.globalSearch) { list.push({ index: REFERENCE_VALUE, name: 'global-search', }); } - + // 偏好设置快捷功能 if (preferencesButtonPosition.value.header) { list.push({ index: REFERENCE_VALUE + 10, name: 'preferences', }); + // 将偏好设置中的子功能分组到同一个按钮位置控制逻辑下 + if (preferences.widget.themeToggle) { + list.push({ + index: REFERENCE_VALUE + 20, + name: 'theme-toggle', + }); + } + if (preferences.widget.languageToggle) { + list.push({ + index: REFERENCE_VALUE + 30, + name: 'language-toggle', + }); + } + if (preferences.widget.timezone) { + list.push({ + index: REFERENCE_VALUE + 40, + name: 'timezone', + }); + } } - if (preferences.widget.themeToggle) { - list.push({ - index: REFERENCE_VALUE + 20, - name: 'theme-toggle', - }); - } - if (preferences.widget.languageToggle) { - list.push({ - index: REFERENCE_VALUE + 30, - name: 'language-toggle', - }); - } - if (preferences.widget.timezone) { - list.push({ - index: REFERENCE_VALUE + 40, - name: 'timezone', - }); - } + // 全屏 if (preferences.widget.fullscreen) { list.push({ index: REFERENCE_VALUE + 50, name: 'fullscreen', }); } + // 消息通知 if (preferences.widget.notification) { list.push({ index: REFERENCE_VALUE + 60, @@ -87,17 +96,24 @@ const rightSlots = computed(() => { } Object.keys(slots).forEach((key) => { - const name = key.split('-'); + // 适配插槽名称,例如第一个插槽名:header-right-1 if (key.startsWith('header-right')) { - list.push({ index: Number(name[2]), name: key }); + // 取第三个占位的数字,若是第三个占位不是数字,则自动分配排序索引 + const slotIndex = Number(key.split('-')[2]); + const index = Number.isNaN(slotIndex) ? nextIndex(list) : slotIndex; + list.push({ index, name: key }); } }); + // 最后追加用户下拉框,若是索引值超过1000时则固定在1000(适配用户按钮不在最后的场景) + const userDropdownIndex = Math.min(1000, nextIndex(list)); + list.push({ index: userDropdownIndex, name: 'user-dropdown' }); + // 按照索引排序,保证插槽顺序 return list.toSorted((a, b) => a.index - b.index); }); const leftSlots = computed(() => { - const list: Array<{ index: number; name: string }> = []; - + const list: Array = []; + // 刷新 if (preferences.widget.refresh) { list.push({ index: 0, @@ -106,14 +122,28 @@ const leftSlots = computed(() => { } Object.keys(slots).forEach((key) => { - const name = key.split('-'); + // 适配插槽名称,例如第一个插槽名:header-left-1 if (key.startsWith('header-left')) { - list.push({ index: Number(name[2]), name: key }); + // 取第三个占位的数字,若是第三个占位不是数字,则自动分配排序索引 + const slotIndex = Number(key.split('-')[2]); + const index = Number.isNaN(slotIndex) ? nextIndex(list) : slotIndex; + list.push({ index, name: key }); } }); + // 按照索引排序,保证插槽顺序 return list.toSorted((a, b) => a.index - b.index); }); +/** + * 获取列表下一个索引值(用于排序) + * @param list 列表 + */ +function nextIndex(list: Array) { + const index = + list.length > 0 ? Math.max(...list.map((item) => item.index)) : 0; + return index + 1; +} + function clearPreferencesAndLogout() { emit('clearPreferencesAndLogout'); } diff --git a/packages/locales/src/langs/en-US/ui.json b/packages/locales/src/langs/en-US/ui.json index 25ef7a78d..b57778d42 100644 --- a/packages/locales/src/langs/en-US/ui.json +++ b/packages/locales/src/langs/en-US/ui.json @@ -149,7 +149,7 @@ }, "lockScreen": { "title": "Lock Screen", - "screenButton": "Locking", + "screenButton": "Unlock", "password": "Password", "placeholder": "Please enter password", "unlock": "Click to unlock", diff --git a/packages/locales/src/langs/zh-CN/ui.json b/packages/locales/src/langs/zh-CN/ui.json index cf718b941..9abce19fb 100644 --- a/packages/locales/src/langs/zh-CN/ui.json +++ b/packages/locales/src/langs/zh-CN/ui.json @@ -149,7 +149,7 @@ }, "lockScreen": { "title": "锁定屏幕", - "screenButton": "锁定", + "screenButton": "解锁", "password": "密码", "placeholder": "请输入锁屏密码", "unlock": "点击解锁",