feat(EasyComponent): 优化选项管理器支持深度查找和缓存清理

- 引入 deepFindObjArr 工具函数用于深度查找对象数组
- 改进 Promise 处理逻辑,失败时设置为空数组而非删除缓存
- 新增 asyncGetOptionsItemByBaseCode 方法支持深度选项查找
- 重构 asyncGetOptionsLabelByBaseCode 依赖新的查找方法
- 添加 removeOptionsCache 方法用于清理选项缓存

fix(request): 调整响应拦截器条件判断逻辑

- 修改错误处理条件,当 useResponseData 配置为 true 时也跳过拦截处理
This commit is contained in:
chenxf 2026-01-06 14:17:55 +08:00
parent 50d8d1e992
commit 883fbdc4c9
2 changed files with 34 additions and 15 deletions

View File

@ -1,3 +1,4 @@
import { deepFindObjArr } from './object-helper'
import { ComponentConfig } from './globalConfig' import { ComponentConfig } from './globalConfig'
import { createPathObject } from './utils' import { createPathObject } from './utils'
@ -14,16 +15,18 @@ export function getOptionsByBaseCode(baseCode) {
return OptionsMap[baseCode] return OptionsMap[baseCode]
} }
if (OptionsMap[baseCode] instanceof Promise) { if (OptionsMap[baseCode] instanceof Promise) {
OptionsMap[baseCode].then((data) => { OptionsMap[baseCode]
if (Array.isArray(data)) { .then((data) => {
OptionsMap[baseCode] = data if (Array.isArray(data)) {
} else { OptionsMap[baseCode] = data
throw new Error('BaseOptionsLoader必须返回Array或Promise<Array>') } else {
} throw new Error('BaseOptionsLoader必须返回Array或Promise<Array>')
}).catch((e) => { }
console.error(e) })
delete OptionsMap[baseCode] .catch((e) => {
}) console.error(e)
OptionsMap[baseCode] = []
})
return [] return []
} }
throw new Error('BaseOptionsLoader必须返回Array或Promise<Array>') throw new Error('BaseOptionsLoader必须返回Array或Promise<Array>')
@ -39,10 +42,26 @@ export async function asyncGetOptionsByBaseCode(baseCode) {
return OptionsMap[baseCode] return OptionsMap[baseCode]
} }
export async function asyncGetOptionsLabelByBaseCode(baseCode, value) { export async function asyncGetOptionsItemByBaseCode(baseCode, value, deepOption) {
return asyncGetOptionsByBaseCode(baseCode).then((arr) => { return asyncGetOptionsByBaseCode(baseCode).then((arr) => {
return (arr.find((item) => { if (deepOption) {
return item.value === value return deepFindObjArr(arr, (item) => {
}) || {}).label return item.value === value
}, typeof deepOption === 'object' ? deepOption : undefined)
} else {
return (
arr.find((item) => {
return item.value === value
}) || {}
)
}
}) })
} }
export async function asyncGetOptionsLabelByBaseCode(baseCode, value, deepOption) {
return (await asyncGetOptionsItemByBaseCode(baseCode, value, deepOption))?.label
}
export function removeOptionsCache(baseCode) {
delete OptionsMap[baseCode]
}

View File

@ -78,7 +78,7 @@ service.interceptors.response.use(
location.reload() location.reload()
}) })
} else { } else {
if (error.config.throwError) { // 不被拦截处理 if (error.config.throwError || error.config.useResponseData) { // 不被拦截处理
throw error.response throw error.response
} else { } else {
Message({ Message({