Commit 0dba7be6 authored by 李苏's avatar 李苏 💬

蒙层

parent 1c905e98
<script>
import Vue from 'vue'
import appUpdate from 'common/util/appUpdate.js'
......
import Request from '@/common/luch-request/index.js'
import {ACCESS_TOKEN} from '@/common/util/constants.js'
import {
ACCESS_TOKEN
} from '@/common/util/constants.js'
import configService from './config.service.js'
import tip from '@/common/util/tip.js';
import store from '@/store/index.js';
......@@ -8,11 +10,11 @@ let apiUrl = configService.apiUrl;
const getTokenStorage = () => {
let token = ''
try{
try {
token = uni.getStorageSync('Gtoken')
}catch(e){
} catch (e) {
//TODO handle the exception
console.log("getTokenStorage",token)
console.log("getTokenStorage", token)
}
return token
}
......@@ -20,12 +22,13 @@ const getTokenStorage = () => {
const http = new Request()
http.setConfig((config) => { /* 设置全局配置 */
config.baseUrl = apiUrl /* 根域名不同 */
config.header = {
...config.header
}
return config
http.setConfig((config) => {
/* 设置全局配置 */
config.baseUrl = apiUrl /* 根域名不同 */
config.header = {
...config.header
}
return config
})
/**
......@@ -35,78 +38,87 @@ http.setConfig((config) => { /* 设置全局配置 */
*/
// 有默认,非必写
http.validateStatus = (statusCode) => {
return statusCode === 200
return statusCode === 200
}
http.interceptor.request((config, cancel) => { /* 请求之前拦截器 */
// tip.alert(config.baseUrl)
uni.getStorageInfo({
success: function (res) {
if(uni.getStorageSync('storage_key')){
config.baseUrl=uni.getStorageSync('storage_key');
}
http.interceptor.request((config, cancel) => {
/* 请求之前拦截器 */
uni.showLoading({
title: '加载中...',
mask: true // 添加蒙层效果
});
// tip.alert(config.baseUrl)
uni.getStorageInfo({
success: function(res) {
if (uni.getStorageSync('storage_key')) {
config.baseUrl = uni.getStorageSync('storage_key');
}
}
})
config.header = {
...config.header,
'Gtoken':getTokenStorage()
}
/*
if (!token) { // 如果token不存在,调用cancel 会取消本次请求,但是该函数的catch() 仍会执行
cancel('token 不存在') // 接收一个参数,会传给catch((err) => {}) err.errMsg === 'token 不存在'
}
*/
return config
config.header = {
...config.header,
'Gtoken': getTokenStorage()
}
/*
if (!token) { // 如果token不存在,调用cancel 会取消本次请求,但是该函数的catch() 仍会执行
cancel('token 不存在') // 接收一个参数,会传给catch((err) => {}) err.errMsg === 'token 不存在'
}
*/
return config
})
// 必须使用异步函数,注意
http.interceptor.response(async (response) => { /* 请求之后拦截器 */
return response
http.interceptor.response(async (response) => {
uni.hideLoading();
/* 请求之后拦截器 */
return response
}, (response) => {
if (response) {
let data = response.data
const token = uni.getStorageSync(ACCESS_TOKEN)
console.log("------异常响应------",token)
console.log("------异常响应------",data)
switch (data.status) {
case 403:
tip.error('拒绝访问');
break
case 500:
if(!token || data.message=="Token失效,请重新登录"){
let timeout=setTimeout(tip.alert('登录已过期'), 1000);
store.dispatch('Logout').then(() => {
clearTimeout(timeout)
window.location.reload()
})
}
break
case 404:
break
case 504:
break
case 401:
if (token) {
/* store.dispatch('Logout').then(() => {
setTimeout(() => {
window.location.reload()
}, 1500)
}) */
}
break
default:
tip.error({
duration: 0,
forbidClick: true,
message: data.message
});
break
}
}
return response
uni.hideLoading();
if (response) {
let data = response.data
const token = uni.getStorageSync(ACCESS_TOKEN)
console.log("------异常响应------", token)
console.log("------异常响应------", data)
switch (data.status) {
case 403:
tip.error('拒绝访问');
break
case 500:
if (!token || data.message == "Token失效,请重新登录") {
let timeout = setTimeout(tip.alert('登录已过期'), 1000);
store.dispatch('Logout').then(() => {
clearTimeout(timeout)
window.location.reload()
})
}
break
case 404:
break
case 504:
break
case 401:
if (token) {
/* store.dispatch('Logout').then(() => {
setTimeout(() => {
window.location.reload()
}, 1500)
}) */
}
break
default:
tip.error({
duration: 0,
forbidClick: true,
message: data.message
});
break
}
}
return response
})
export {
http
}
http
}
\ No newline at end of file
......@@ -2,8 +2,8 @@
"name" : "wcs",
"appid" : "__UNI__79C58F0",
"description" : "徐工道路系统功能",
"versionName" : "1.0.4",
"versionCode" : 104,
"versionName" : "1.0.6",
"versionCode" : 106,
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
......
......@@ -5,7 +5,7 @@
<block slot="content">工位叫料</block>
</cu-custom>
<!-- 添加蒙层 -->
<orange-fullloading :loadicon='loadicon' :loadshow='loadshow' bgcolor="rgba(128, 128, 128, 0.5)" :text="loadtext"></orange-fullloading>
<!-- <orange-fullloading :loadicon='loadicon' :loadshow='loadshow' bgcolor="rgba(128, 128, 128, 0.5)" :text="loadtext"></orange-fullloading> -->
<view class="cu-bar bg-white solid-bottom">
<view class="action">
<text class="cuIcon-title text-orange "></text> 工位列表
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment