Files
tk-mini-program/components/request.js

62 lines
2.5 KiB
JavaScript
Raw Normal View History

2025-06-09 19:18:38 +08:00
import addPrefixToHeaderIcon from './addPrefixToHeaderIcon.js'
2025-05-15 22:24:39 +08:00
export default function request(urldata) {
2025-05-19 18:34:04 +08:00
const { url, data, method, header, userInfo } = urldata;
2025-05-30 22:04:45 +08:00
const baseUrl = "http://120.26.251.180:8086/"+ url;
2025-06-09 19:18:38 +08:00
// const baseUrl = "http://192.168.0.218:8086/"+ url;
2025-05-15 22:24:39 +08:00
if (userInfo) {
2025-05-21 22:52:33 +08:00
return new Promise((resolve, reject) => {
uni.getStorage({
key: "userinfo",
success: (res) => {
if (res.data) {
if (res.data.nickName) {
2025-05-15 22:24:39 +08:00
uni.request({
url: baseUrl,
data: data,
method: method,
header: header,
success: function (res) {
2025-05-21 22:52:33 +08:00
console.log("请求成功1", res.data);
2025-06-09 19:18:38 +08:00
resolve(addPrefixToHeaderIcon(res.data));
// resolve(res.data);
2025-05-15 22:24:39 +08:00
},
fail: function (res) {
reject(res);
}
});
2025-05-21 22:52:33 +08:00
} else {
2025-05-22 22:05:55 +08:00
uni.setStorageSync("lastPage", getCurrentPages()[getCurrentPages().length - 1].route);
2025-05-21 22:52:33 +08:00
uni.reLaunch({ url: "/pages/UserInformation/UserInformation" })
}
2025-05-19 18:34:04 +08:00
} else {
2025-05-22 22:05:55 +08:00
uni.setStorageSync("lastPage", getCurrentPages()[getCurrentPages().length - 1].route);
2025-05-21 22:52:33 +08:00
uni.navigateTo({ url: '/pages/login/login' })
2025-05-15 22:24:39 +08:00
}
2025-05-21 22:52:33 +08:00
},
fail: function (res) {
2025-05-22 22:05:55 +08:00
uni.setStorageSync("lastPage", getCurrentPages()[getCurrentPages().length - 1].route);
uni.navigateTo({ url: '/pages/login/login' })
2025-05-21 22:52:33 +08:00
reject(res);
2025-05-15 22:24:39 +08:00
}
2025-05-21 22:52:33 +08:00
});
2025-05-19 18:34:04 +08:00
});
} else {
return new Promise((resolve, reject) => {
2025-05-15 22:24:39 +08:00
uni.request({
url: baseUrl,
data: data,
method: method,
header: header,
success: function (res) {
2025-05-21 22:52:33 +08:00
console.log("请求成功2", res);
2025-06-09 19:18:38 +08:00
// resolve(res.data);
resolve(addPrefixToHeaderIcon(res.data));
2025-05-15 22:24:39 +08:00
},
fail: function (res) {
reject(res);
}
});
});
}
}