sds
This commit is contained in:
parent
a74c9750e6
commit
6f348e7c19
@ -1,6 +1,19 @@
|
|||||||
|
// 在登录成功后请调用 resetTokenInvalid() 重置 isTokenInvalid 标志
|
||||||
|
let isTokenInvalid = false;
|
||||||
|
|
||||||
const baseUrl = 'https://ddbs.1024tool.vip/';
|
const baseUrl = 'https://ddbs.1024tool.vip/';
|
||||||
let isNavigatingToLogin = false;
|
let isNavigatingToLogin = false;
|
||||||
|
|
||||||
|
// 重置 token 失效标志(登录成功后调用)
|
||||||
|
export function resetTokenInvalid() {
|
||||||
|
isTokenInvalid = false;
|
||||||
|
}
|
||||||
|
|
||||||
function request(url, method = 'GET', data = {}) {
|
function request(url, method = 'GET', data = {}) {
|
||||||
|
// 如果 token 已失效,直接中断请求
|
||||||
|
if (isTokenInvalid) {
|
||||||
|
return Promise.reject({ code: 10103, message: '登录已失效,请重新登录' });
|
||||||
|
}
|
||||||
const header = {
|
const header = {
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
// 有其他content-type需求加点逻辑判断处理即可
|
// 有其他content-type需求加点逻辑判断处理即可
|
||||||
@ -20,6 +33,7 @@ function request(url, method = 'GET', data = {}) {
|
|||||||
success(res) {
|
success(res) {
|
||||||
if (res.data.code) {
|
if (res.data.code) {
|
||||||
if (res.data.code == 10103) {
|
if (res.data.code == 10103) {
|
||||||
|
isTokenInvalid = true;
|
||||||
wx.removeStorageSync('access_token');
|
wx.removeStorageSync('access_token');
|
||||||
if (!isNavigatingToLogin) {
|
if (!isNavigatingToLogin) {
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
@ -35,6 +49,7 @@ function request(url, method = 'GET', data = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reject(res.data);
|
reject(res.data);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: res.data.message,
|
title: res.data.message,
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import request from '~/api/request';
|
import request from '~/api/request';
|
||||||
|
|
||||||
|
import { resetTokenInvalid } from '~/api/request';
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
phoneNumber: '',
|
phoneNumber: '',
|
||||||
@ -32,10 +34,12 @@ Page({
|
|||||||
// console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
|
// console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
|
||||||
// console.log(e.detail.errno) // 错误码(失败时返回)
|
// console.log(e.detail.errno) // 错误码(失败时返回)
|
||||||
if (e.detail.code) {
|
if (e.detail.code) {
|
||||||
|
resetTokenInvalid()
|
||||||
const res = await request('patient/quick_login', 'post', {
|
const res = await request('patient/quick_login', 'post', {
|
||||||
code: e.detail.code
|
code: e.detail.code
|
||||||
})
|
})
|
||||||
await wx.setStorageSync('access_token', res.token);
|
await wx.setStorageSync('access_token', res.token);
|
||||||
|
|
||||||
if (res.is_personal_information_complete) {
|
if (res.is_personal_information_complete) {
|
||||||
wx.navigateBack();
|
wx.navigateBack();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import request from '~/api/request';
|
import request from '~/api/request';
|
||||||
|
import {resetTokenInvalid } from '~/api/request';
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
code: '',
|
code: '',
|
||||||
@ -108,6 +108,7 @@ Page({
|
|||||||
// });
|
// });
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
resetTokenInvalid()
|
||||||
|
|
||||||
const res = await request('patient/code_login', 'post', {
|
const res = await request('patient/code_login', 'post', {
|
||||||
code: this.data.code,
|
code: this.data.code,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user