给token区分环境
This commit is contained in:
17
src/apis.js
17
src/apis.js
@@ -24,7 +24,9 @@ try {
|
||||
}
|
||||
|
||||
function request(method, url, data = {}) {
|
||||
const token = uni.getStorageSync("token");
|
||||
const token = uni.getStorageSync(
|
||||
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
|
||||
);
|
||||
const header = {};
|
||||
if (token) header.Authorization = `Bearer ${token || ""}`;
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -40,7 +42,9 @@ function request(method, url, data = {}) {
|
||||
if (code === 0) resolve(data);
|
||||
else if (message) {
|
||||
if (message.indexOf("登录身份已失效") !== -1) {
|
||||
uni.removeStorageSync("token");
|
||||
uni.removeStorageSync(
|
||||
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`
|
||||
);
|
||||
}
|
||||
if (message === "ROOM_FULL") {
|
||||
resolve({ full: true });
|
||||
@@ -71,17 +75,17 @@ function request(method, url, data = {}) {
|
||||
return;
|
||||
}
|
||||
if (message === "ROOM_EMPTY") {
|
||||
uni.showToast({
|
||||
return uni.showToast({
|
||||
title: "房间已过期",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
reject("");
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
@@ -166,7 +170,10 @@ export const loginAPI = async (nickName, avatarData, code) => {
|
||||
avatarData,
|
||||
code,
|
||||
});
|
||||
uni.setStorageSync("token", result.token);
|
||||
uni.setStorageSync(
|
||||
`${uni.getAccountInfoSync().miniProgram.envVersion}_token`,
|
||||
result.token
|
||||
);
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user