|
@@ -1,3 +1,4 @@
|
|
|
+import { objToUrl } from '@/libs/tools.js';
|
|
|
const baseUrl = getApp().globalData.baseUrl
|
|
|
//带Token请求
|
|
|
const request = (opts, hasToken) => {
|
|
@@ -38,15 +39,17 @@ const request = (opts, hasToken) => {
|
|
|
if(ret.status == '200'){
|
|
|
resolve(ret)
|
|
|
}else{
|
|
|
- if(ret.status == 1001 && loginTimeOut == 'NO'){ // 未登录或登录过期
|
|
|
+ if(ret.status == 401 && loginTimeOut == 'NO'){ // 未登录或登录过期
|
|
|
uni.showToast({
|
|
|
icon:'none',
|
|
|
title: ret.message,
|
|
|
duration: 5000
|
|
|
})
|
|
|
- uni.reLaunch({
|
|
|
- url: '/pages/login/login'
|
|
|
- })
|
|
|
+ setTimeout(function() {
|
|
|
+ const currentRoute = getRoutePath();
|
|
|
+ const url = `/pages/login/login?lanuch=${currentRoute.lanuch}&path=` + encodeURIComponent(currentRoute.url);
|
|
|
+ uni.reLaunch({ url });
|
|
|
+ }, 1000);
|
|
|
uni.setStorageSync('loginTimeOut', 'YES');
|
|
|
}
|
|
|
// 503
|
|
@@ -69,6 +72,28 @@ const request = (opts, hasToken) => {
|
|
|
})
|
|
|
return promise
|
|
|
}
|
|
|
+function getRoutePath() {
|
|
|
+ // eslint-disable-next-line no-undef
|
|
|
+ const pages = getCurrentPages(); // 获取加载的页面
|
|
|
+
|
|
|
+ const currentPage = pages[pages.length - 1]; // 获取当前页面的对象
|
|
|
+
|
|
|
+ let url = currentPage.route; // 当前页面url
|
|
|
+
|
|
|
+ const options = objToUrl(currentPage.options); // 如果要获取url中所带的参数可以查看options
|
|
|
+
|
|
|
+ const lanuch = [
|
|
|
+ 'pages/index/index'
|
|
|
+ ].includes(url);
|
|
|
+ url = '/' + url;
|
|
|
+ if (options.length) {
|
|
|
+ url += '?' + options;
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ url,
|
|
|
+ lanuch
|
|
|
+ };
|
|
|
+}
|
|
|
|
|
|
export default {
|
|
|
baseUrl,
|