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

蒙层

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