fix:修复浅拷贝数组问题

This commit is contained in:
2026-06-10 12:11:55 +08:00
parent 97af0505b2
commit ea05b8ff43
5 changed files with 70 additions and 49 deletions
@@ -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 <T>(name: string, defaultValue?: T) {
return computed<string | number>({
get() {
ensurePartConfig(part.value)
return (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(configStore.config.emblems?.[part.value] as Record<string, any>)?.[name] ??
@@ -131,39 +153,27 @@ const currentInfo = function <T>(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<string, any>)[name] = val
}
ensurePartConfig(part.value)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(configStore.config.emblems[part.value] as Record<string, any>)[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,
)
}
},
})
@@ -75,7 +75,7 @@ const currentInfo = function <T>(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
+11 -5
View File
@@ -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<IConfig>({
@@ -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,
}
})
@@ -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 = () => {
<span>批量应用到同类部位</span>
<input v-model="equipBatchApply" type="checkbox" class="size-4" />
</label>
<div
v-for="part in parts"
:key="part"
class="space-y-3 rounded-md border p-2 md:p-3"
>
<div v-for="part in parts" :key="part" class="space-y-3 rounded-md border p-2 md:p-3">
<div class="grid grid-cols-[5rem_minmax(0,1fr)_auto] items-center gap-2">
<div class="font-medium">{{ part }}</div>
<div class="truncate text-muted-foreground">
@@ -1108,10 +1113,7 @@ const resetAllForge = () => {
</Card>
</div>
<div
v-if="forgeViewTab === 'config' && moduleMode === 'jade'"
class="grid grid-cols-1 gap-4"
>
<div v-if="forgeViewTab === 'config' && moduleMode === 'jade'" class="grid grid-cols-1 gap-4">
<Card class="border-border/60 bg-card/90">
<CardHeader>
<CardTitle class="flex items-center gap-2">
+5 -2
View File
@@ -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<IConfig>({
@@ -309,6 +311,7 @@ export const useConfigStore = defineStore("configStore", () => {
defaultAvatarConfig,
defaultOathConfig,
defaultEmblemConfig,
createDefaultEmblemConfig,
changeSourceLogs,
pushChangeSource,
clearChangeSource,