优化代码

This commit is contained in:
pengxiaolong
2025-08-29 13:31:08 +08:00
parent d294f62469
commit aa74346232
24 changed files with 1002 additions and 518 deletions

View File

@@ -47,7 +47,9 @@ axios.interceptors.response.use((response) => {
return Promise.reject(error)
})
// 处理headerIcon的前缀
import { translateCountryName } from './countryUtil';
// 处理headerIcon的前缀和country的翻译
function addPrefixToHeaderIcon(data) {
// 处理数组:递归处理每个元素
if (Array.isArray(data)) {
@@ -58,7 +60,7 @@ function addPrefixToHeaderIcon(data) {
// 处理对象:递归处理每个属性
if (typeof data === 'object' && data !== null) {
for (const key in data) {
if (key === 'headerIcon' ||key === 'anchorIcon' && data.hasOwnProperty(key)) {
if (key === 'headerIcon' || key === 'anchorIcon' && data.hasOwnProperty(key)) {
// 在headerIcon值前添加前缀处理各种类型anchorIconA anchorIconB anchorIcon
const value = data[key];
data[key] = "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/headerIcon/" + (
@@ -66,6 +68,12 @@ function addPrefixToHeaderIcon(data) {
: value != null ? String(value)
: ""
);
} else if (key === 'country' && data.hasOwnProperty(key)) {
// 翻译country值
const value = data[key];
if (typeof value === 'string') {
data[key] = translateCountryName(value);
}
} else if (typeof data[key] === 'object' && data[key] !== null) {
// 递归处理嵌套对象或数组
addPrefixToHeaderIcon(data[key]);