Compare commits

..

No commits in common. "96f78218d65b555f3645ea0fa6fadac6b5170a71" and "d5fbedd1919f1dac67564df0854d04359c52824f" have entirely different histories.

3 changed files with 47 additions and 39 deletions

View File

@ -1,8 +1,19 @@
const baseUrl = 'https://ddbs.1024tool.vip/';
// 在登录成功后请调用 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需求加点逻辑判断处理即可
@ -22,7 +33,13 @@ 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: () => {
@ -30,6 +47,7 @@ function request(url, method = 'GET', data = {}) {
}
});
}
}
reject(res.data);
return;
}

View File

@ -34,8 +34,6 @@ Page({
weightData: [],
heightChart: null,
weightChart: null,
directChart: null,
indirectChart: null,
carList: [],
carLength: 0,
userInfo: {},
@ -147,14 +145,6 @@ Page({
this.weightChart.dispose();
this.weightChart = null;
}
if (this.directChart) {
this.directChart.dispose();
this.directChart = null;
}
if (this.indirectChart) {
this.indirectChart.dispose();
this.indirectChart = null;
}
},
// 初始化身高图表
@ -328,7 +318,6 @@ Page({
]
});
this.directChart = chart;
return chart;
});
}
@ -364,7 +353,6 @@ Page({
]
});
this.indirectChart = chart;
return chart;
});
}

View File

@ -1,4 +1,5 @@
import request from '~/api/request';
import { resetTokenInvalid } from '~/api/request';
import { aesCryptoJS } from '~/utils/util';
Page({
@ -46,6 +47,7 @@ Page({
return;
}
resetTokenInvalid()
const res = await request('doctor/login', 'post', {
password: aesCryptoJS(this.data.password),
mobile: this.data.mobile