修改jwt判断token 以及订单金额为0时前台 跳转问题

master
lemon橪 2021-06-08 18:46:25 +08:00
parent 1e53287927
commit 7cbb226416
3 changed files with 64 additions and 41 deletions

View File

@ -448,17 +448,23 @@ export default {
duration: 2000,
icon: "none",
});
// 0
if (this.orderMessage.priceDetailDTO.billPrice == 0) {
uni.redirectTo({
url: "/pages/order/myOrder?status=0",
});
} else {
// #ifdef MP-WEIXIN
//
this.pay(res.data.result.sn);
// #endif
// #ifdef MP-WEIXIN
//
this.pay(res.data.result.sn);
// #endif
// #ifndef MP-WEIXIN
this.navigateTo(
`/pages/cart/payment/payOrder?trade_sn=${res.data.result.sn}`
);
// #endif
// #ifndef MP-WEIXIN
this.navigateTo(
`/pages/cart/payment/payOrder?trade_sn=${res.data.result.sn}`
);
// #endif
}
} else {
uni.showToast({
title: "创建订单有误!请稍后重试",

View File

@ -164,7 +164,7 @@ import * as API_Trade from "@/api/trade";
export default {
data() {
return {
lightColor:this.$lightColor,
lightColor: this.$lightColor,
discountDetailsFlag: false, //
//
options: [
@ -499,16 +499,9 @@ export default {
}
uni.stopPullDownRefresh();
uni.hideLoading();
} else {
uni.showToast({
title: result.data.message,
duration: 2000,
icon: "none",
});
}
})
.catch((err) => {
uni.hideLoading();
});
} else {

View File

@ -120,6 +120,25 @@ http.interceptors.request.use(
config.params = params;
config.header.accessToken = accessToken;
console.log(accessToken);
/**
* jwt 因为安卓以及ios没有window的属性
* window.atob这个函数 base64编码的使用方法就是btoa而用于解码的使用方法是atob
* 所以使用手写 base-64 编码的字符串数据
*/
//
const atob = (str) => Buffer.from(str, "base64").toString("binary");
// 判断如果过期时间小于我的当前时间在请求上重新刷新token
if (accessToken.split(".").length <= 1) {
refresh();
} else {
if (
JSON.parse(atob(accessToken.split(".")[1])).exp <
new Date().getTime() / 1000
) {
refresh();
}
}
}
config.header = {
...config.header,
@ -132,6 +151,33 @@ http.interceptors.request.use(
}
);
async function refresh() {
// 本地储存的是过期token了重新获取
const getTokenResult = await refreshToken();
// if (getTokenResult === "success") {
// // 获取新的token成功 刷新当前页面
// let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
// let curRoute = routes[routes.length - 1].route; //获取当前页面路由
// let curParam = routes[routes.length - 1].options; //获取路由参数
// // 拼接参数
// let param = "";
// for (let key in curParam) {
// param += "&" + key + "=" + curParam[key];
// }
// // 判断当前路径
// if (curRoute.indexOf("pages/tabbar") == 1) {
// uni.switchTab({
// url: "/" + curRoute + param.replace("&", "?"),
// });
// }
// uni.redirectTo({
// url: "/" + curRoute + param.replace("&", "?"),
// });
// }
}
// 必须使用异步函数,注意
http.interceptors.response.use(
async (response) => {
@ -143,33 +189,11 @@ http.interceptors.response.use(
(token && response.statusCode === 403) ||
response.data.status === 403
) {
expireToken.includes(token) ? cleanStorage() : "";
// jwt token 过期了
expireToken.push(token); // 把过期token 储存
const currentToken = storage.getAccessToken();
if (expireToken.includes(currentToken)) {
// 本地储存的是过期token了重新获取
const getTokenResult = await refreshToken();
if (getTokenResult === "success") {
// 获取新的token成功 刷新当前页面
let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
let curRoute = routes[routes.length - 1].route; //获取当前页面路由
let curParam = routes[routes.length - 1].options; //获取路由参数
// 拼接参数
let param = "";
for (let key in curParam) {
param += "&" + key + "=" + curParam[key];
}
uni.redirectTo({
url: "/" + curRoute + param.replace("&", "?"),
});
} else {
cleanStorage();
}
} else {
cleanStorage();
refresh();
}
// 如果当前返回没登录
} else if (