fix:修复浅拷贝数组问题
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user