优化页面
This commit is contained in:
28
components/addPrefixToHeaderIcon.js
Normal file
28
components/addPrefixToHeaderIcon.js
Normal file
@@ -0,0 +1,28 @@
|
||||
function addPrefixToHeaderIcon(data) {
|
||||
// 处理数组:递归处理每个元素
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach(item => addPrefixToHeaderIcon(item));
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理对象:递归处理每个属性
|
||||
if (typeof data === 'object' && data !== null) {
|
||||
for (const key in data) {
|
||||
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/" + (
|
||||
typeof value === 'string' ? value
|
||||
: value != null ? String(value)
|
||||
: ""
|
||||
);
|
||||
} else if (typeof data[key] === 'object' && data[key] !== null) {
|
||||
// 递归处理嵌套对象或数组
|
||||
addPrefixToHeaderIcon(data[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export default addPrefixToHeaderIcon;
|
||||
@@ -1,7 +1,8 @@
|
||||
import addPrefixToHeaderIcon from './addPrefixToHeaderIcon.js'
|
||||
export default function request(urldata) {
|
||||
const { url, data, method, header, userInfo } = urldata;
|
||||
const baseUrl = "http://120.26.251.180:8086/"+ url;
|
||||
// const baseUrl = "http://192.168.1.218:8086/"+ url;
|
||||
// const baseUrl = "http://192.168.0.218:8086/"+ url;
|
||||
if (userInfo) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getStorage({
|
||||
@@ -16,7 +17,8 @@ export default function request(urldata) {
|
||||
header: header,
|
||||
success: function (res) {
|
||||
console.log("请求成功1", res.data);
|
||||
resolve(res.data);
|
||||
resolve(addPrefixToHeaderIcon(res.data));
|
||||
// resolve(res.data);
|
||||
},
|
||||
fail: function (res) {
|
||||
reject(res);
|
||||
@@ -47,7 +49,8 @@ export default function request(urldata) {
|
||||
header: header,
|
||||
success: function (res) {
|
||||
console.log("请求成功2", res);
|
||||
resolve(res.data);
|
||||
// resolve(res.data);
|
||||
resolve(addPrefixToHeaderIcon(res.data));
|
||||
},
|
||||
fail: function (res) {
|
||||
reject(res);
|
||||
|
||||
Reference in New Issue
Block a user