diff --git a/frontend/src/pages/Character/Forge/components/Emblems.vue b/frontend/src/pages/Character/Forge/components/Emblems.vue index 0aad4e24..29236dc5 100644 --- a/frontend/src/pages/Character/Forge/components/Emblems.vue +++ b/frontend/src/pages/Character/Forge/components/Emblems.vue @@ -112,9 +112,31 @@ const emblemItemStyle = (index: number) => { } } +const ensurePartConfig = (partName: string) => { + if (!configStore.config.emblems[partName]) { + configStore.config.emblems[partName] = configStore.createDefaultEmblemConfig() + } + const target = configStore.config.emblems[partName] + if (!Array.isArray(target.items)) { + target.items = ['', '', '', '', '', ''] + } + if (target.items.length < 6) { + target.items = [...target.items, ...Array.from({ length: 6 - target.items.length }, () => '')] + } +} + +watch( + part, + (newPart) => { + ensurePartConfig(newPart) + }, + { immediate: true }, +) + const currentInfo = function (name: string, defaultValue?: T) { return computed({ get() { + ensurePartConfig(part.value) return ( // eslint-disable-next-line @typescript-eslint/no-explicit-any (configStore.config.emblems?.[part.value] as Record)?.[name] ?? @@ -131,39 +153,27 @@ const currentInfo = function (name: string, defaultValue?: T) { // return // } - if (!configStore.config.emblems[part.value]) { - configStore.config.emblems[part.value] = { ...configStore.defaultEmblemConfig } - } - if (configStore.config.emblems[part.value]) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ;(configStore.config.emblems[part.value] as Record)[name] = val - } + ensurePartConfig(part.value) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ;(configStore.config.emblems[part.value] as Record)[name] = val if (part.value == '彩色' && name == 'lv') { // 同步其他部位的等级 const lv = val as number for (const p of ['红色', '蓝色', '黄色', '绿色']) { - if (!configStore.config.emblems[p]) { - configStore.config.emblems[p] = { ...configStore.defaultEmblemConfig } - } - if (configStore.config.emblems[p]) { - configStore.config.emblems[p]['lv'] = Math.max( - configStore.config.emblems[p]['lv'] || 0, - lv, - ) - } + ensurePartConfig(p) + configStore.config.emblems[p]['lv'] = Math.max( + configStore.config.emblems[p]['lv'] || 0, + lv, + ) } } else if (part.value != '彩色' && name == 'lv') { // 同步彩色部位的等级 const lv = val as number - if (!configStore.config.emblems['彩色']) { - configStore.config.emblems['彩色'] = { ...configStore.defaultEmblemConfig } - } - if (configStore.config.emblems['彩色']) { - configStore.config.emblems['彩色']['lv'] = Math.min( - configStore.config.emblems['彩色']['lv'] || 0, - lv, - ) - } + ensurePartConfig('彩色') + configStore.config.emblems['彩色']['lv'] = Math.min( + configStore.config.emblems['彩色']['lv'] || 0, + lv, + ) } }, }) diff --git a/frontend/src/pages/Character/Forge/components/Oaths.vue b/frontend/src/pages/Character/Forge/components/Oaths.vue index b9e4cc77..1e18bfd7 100644 --- a/frontend/src/pages/Character/Forge/components/Oaths.vue +++ b/frontend/src/pages/Character/Forge/components/Oaths.vue @@ -75,7 +75,7 @@ const currentInfo = function (name: string, defaultValue?: T) { for (const part of parts) { if (!configStore.config.oaths[part]) { - configStore.config.oaths[part] = { ...configStore.defaultOathConfig } + configStore.config.oaths[part] = configStore.createDefaultOathConfig() } if (configStore.config.oaths[part]) { // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/frontend/src/stores/config.ts b/frontend/src/stores/config.ts index ca09cf5f..0f3ad005 100644 --- a/frontend/src/stores/config.ts +++ b/frontend/src/stores/config.ts @@ -98,16 +98,20 @@ const defaultAvatarConfig = { option: '0', } -const defaultOathConfig = { +const createDefaultOathConfig = (): IConfigOath => ({ id: '', adaptation: 0, upgrade: [0, 0, 0, 0], -} +}) -const defaultEmblemConfig = { +const defaultOathConfig = createDefaultOathConfig() + +const createDefaultEmblemConfig = (): IConfigEmblem => ({ lv: 0, items: ['', '', '', '', '', ''], -} +}) + +const defaultEmblemConfig = createDefaultEmblemConfig() export const useConfigStore = defineStore('configStore', () => { const config = ref({ @@ -194,7 +198,7 @@ export const useConfigStore = defineStore('configStore', () => { // eslint-disable-next-line @typescript-eslint/no-unused-expressions config.value && !config.value?.oaths.hasOwnProperty(p) && - (config.value.oaths[p.toString()] = { ...defaultOathConfig }) + (config.value.oaths[p.toString()] = createDefaultOathConfig()) }) infoStore.options.forEach((option) => { @@ -284,6 +288,8 @@ export const useConfigStore = defineStore('configStore', () => { defaultEqusConfig, defaultAvatarConfig, defaultOathConfig, + createDefaultOathConfig, defaultEmblemConfig, + createDefaultEmblemConfig, } }) diff --git a/frontendNew/src/pages/Dcalc/Character/Forge/index.vue b/frontendNew/src/pages/Dcalc/Character/Forge/index.vue index 193a359b..93d0349d 100644 --- a/frontendNew/src/pages/Dcalc/Character/Forge/index.vue +++ b/frontendNew/src/pages/Dcalc/Character/Forge/index.vue @@ -232,7 +232,9 @@ const setOathAdaptation = (part: string, value: string) => { configStore.config.oaths[item].adaptation = Math.max(0, parsed); }); - setNotice(oathBatchApply.value ? "已批量更新全部誓约槽位适配值。" : `已更新誓约槽位 ${part} 的适配值。`); + setNotice( + oathBatchApply.value ? "已批量更新全部誓约槽位适配值。" : `已更新誓约槽位 ${part} 的适配值。`, + ); trackSource(oathBatchApply.value ? "誓约适配已批量更新" : `誓约槽位 ${part} 适配已更新`); }; @@ -348,7 +350,8 @@ const setEquipNumberField = ( const normalized = field === "precision" ? Math.max(0, Math.min(parsed, 100)) : Math.max(0, parsed); - const canBatch = equipBatchApply.value && ["reinforceType", "reinforce", "adaptation"].includes(field); + const canBatch = + equipBatchApply.value && ["reinforceType", "reinforce", "adaptation"].includes(field); const partsToApply = canBatch ? infoStore.parts.filter(canUpgradeEquip) : [part]; partsToApply.forEach((item) => { @@ -379,9 +382,15 @@ const setEquipEnchant = (part: string, value: string) => { configStore.config.equips[item].enchant = value; }); - setNotice(equipBatchApply.value && partsToApply.length > 1 ? "已批量更新装备附魔。" : `已更新 ${part} 的附魔。`); + setNotice( + equipBatchApply.value && partsToApply.length > 1 + ? "已批量更新装备附魔。" + : `已更新 ${part} 的附魔。`, + ); trackSource( - equipBatchApply.value && partsToApply.length > 1 ? "装备附魔已批量更新" : `装备 ${part} 附魔已更新`, + equipBatchApply.value && partsToApply.length > 1 + ? "装备附魔已批量更新" + : `装备 ${part} 附魔已更新`, ); }; @@ -421,7 +430,7 @@ const resetAvatarPart = () => { const ensureEmblemPart = (part: string) => { if (!configStore.config.emblems[part]) { - configStore.config.emblems[part] = { ...configStore.defaultEmblemConfig }; + configStore.config.emblems[part] = configStore.createDefaultEmblemConfig(); } return configStore.config.emblems[part]; }; @@ -463,7 +472,7 @@ const setEmblemItem = (index: number, value: string) => { }; const resetEmblemPart = () => { - configStore.config.emblems[emblemPart.value] = { ...configStore.defaultEmblemConfig }; + configStore.config.emblems[emblemPart.value] = configStore.createDefaultEmblemConfig(); setNotice(`已重置 ${emblemPart.value} 徽章配置。`); trackSource(`徽章 ${emblemPart.value} 已重置`); }; @@ -503,7 +512,7 @@ const resetAllForge = () => { configStore.config.avatar[part] = { ...configStore.defaultAvatarConfig }; }); infoStore.emblemParts.forEach((part) => { - configStore.config.emblems[part] = { ...configStore.defaultEmblemConfig }; + configStore.config.emblems[part] = configStore.createDefaultEmblemConfig(); }); jadeKeys.forEach((key) => { configStore.config.jades[key] = { id: -1, value: 0 }; @@ -688,11 +697,7 @@ const resetAllForge = () => { 批量应用到同类部位 -
+
{{ part }}
@@ -1108,10 +1113,7 @@ const resetAllForge = () => {
-
+
diff --git a/frontendNew/src/stores/config.ts b/frontendNew/src/stores/config.ts index 45ef2f4d..7b87b014 100644 --- a/frontendNew/src/stores/config.ts +++ b/frontendNew/src/stores/config.ts @@ -109,10 +109,12 @@ const defaultOathConfig = { adaptation: 0, }; -const defaultEmblemConfig = { +const createDefaultEmblemConfig = (): IConfigEmblem => ({ lv: 0, items: ["", "", "", "", "", ""], -}; +}); + +const defaultEmblemConfig = createDefaultEmblemConfig(); export const useConfigStore = defineStore("configStore", () => { const config = ref({ @@ -309,6 +311,7 @@ export const useConfigStore = defineStore("configStore", () => { defaultAvatarConfig, defaultOathConfig, defaultEmblemConfig, + createDefaultEmblemConfig, changeSourceLogs, pushChangeSource, clearChangeSource,