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

58 lines
2.0 KiB
JavaScript
Raw Normal View History

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;
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-05-15 22:24:39 +08:00
resolve(res.data);
},
fail: function (res) {
reject(res);
}
});
2025-05-21 22:52:33 +08:00
} else {
this.$global.lastPage = uni.page.route;
uni.reLaunch({ url: "/pages/UserInformation/UserInformation" })
}
2025-05-19 18:34:04 +08:00
} else {
this.$global.lastPage = uni.page.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) {
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-05-15 22:24:39 +08:00
resolve(res.data);
},
fail: function (res) {
reject(res);
}
});
});
}
}