dssff
This commit is contained in:
parent
20b415ffc4
commit
3bcd80be76
@ -1,19 +1,8 @@
|
||||
// 在登录成功后请调用 resetTokenInvalid() 重置 isTokenInvalid 标志
|
||||
let isTokenInvalid = false;
|
||||
|
||||
const baseUrl = 'https://ddbs.1024tool.vip/';
|
||||
let isNavigatingToLogin = false;
|
||||
|
||||
// 重置 token 失效标志(登录成功后调用)
|
||||
export function resetTokenInvalid() {
|
||||
isTokenInvalid = false;
|
||||
}
|
||||
|
||||
function request(url, method = 'GET', data = {}) {
|
||||
// 如果 token 已失效,直接中断请求
|
||||
if (isTokenInvalid) {
|
||||
return Promise.reject({ code: 10103, message: '登录已失效,请重新登录' });
|
||||
}
|
||||
|
||||
const header = {
|
||||
'content-type': 'application/json',
|
||||
// 有其他content-type需求加点逻辑判断处理即可
|
||||
@ -33,13 +22,7 @@ function request(url, method = 'GET', data = {}) {
|
||||
success(res) {
|
||||
if (res.data.code) {
|
||||
if (res.data.code == 10103) {
|
||||
isTokenInvalid = true;
|
||||
wx.removeStorageSync('access_token');
|
||||
if (!isNavigatingToLogin) {
|
||||
const pages = getCurrentPages();
|
||||
const currentRoute = pages[pages.length - 1]?.route;
|
||||
if (currentRoute !== 'pages/login/login') {
|
||||
isNavigatingToLogin = true;
|
||||
wx.navigateTo({
|
||||
url: '/pages/login/login',
|
||||
complete: () => {
|
||||
@ -47,7 +30,6 @@ function request(url, method = 'GET', data = {}) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
reject(res.data);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import request from '~/api/request';
|
||||
import { resetTokenInvalid } from '~/api/request';
|
||||
import { aesCryptoJS } from '~/utils/util';
|
||||
|
||||
Page({
|
||||
@ -47,7 +46,6 @@ Page({
|
||||
return;
|
||||
}
|
||||
|
||||
resetTokenInvalid()
|
||||
const res = await request('doctor/login', 'post', {
|
||||
password: aesCryptoJS(this.data.password),
|
||||
mobile: this.data.mobile
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user