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