底座全局数据协调
This commit is contained in:
@@ -1,24 +1,23 @@
|
||||
import config from '@/utils/config';
|
||||
import util from 'dvcp-wui/utils/util';
|
||||
import store from "../store"
|
||||
|
||||
const Fly = require('flyio/dist/npm/wx');
|
||||
var instance = new Fly();
|
||||
var refrashToken = new Fly();
|
||||
let instance = new Fly();
|
||||
const baseURL = config.baseUrl;
|
||||
let count = 0;
|
||||
instance.config.timeout = 50000;
|
||||
instance.config.baseURL = baseURL;
|
||||
|
||||
const getToken = () => {
|
||||
if (uni.getStorageSync('token')) return uni.getStorageSync('token');
|
||||
else return '';
|
||||
if (store.state.token) return store.state.token;
|
||||
else return '';
|
||||
};
|
||||
|
||||
instance.interceptors.request.use((config) => {
|
||||
if (!config.withoutToken && getToken()) {
|
||||
config.headers['Authorization'] = getToken();
|
||||
}
|
||||
|
||||
if (!config.withoutToken) {
|
||||
config.headers['Authorization'] = getToken();
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
@@ -29,39 +28,13 @@ instance.interceptors.response.use(
|
||||
util.$toast({title: response.data.msg, duration: 3000});
|
||||
} else if (response.data.code == 2) {
|
||||
//首次静默登录异常不做任何返回
|
||||
} else if (response.data.code === 401) {
|
||||
} else if (response.data.code == 401) {
|
||||
if (count > 3) {
|
||||
return;
|
||||
}
|
||||
count = count + 1;
|
||||
this.lock();
|
||||
|
||||
count++;
|
||||
return util.$getLoginCode().then((res) => {
|
||||
return refrashToken
|
||||
.post(
|
||||
`${baseURL}/auth/wechat-con/token`,
|
||||
{
|
||||
code: res.code
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: 'Basic dmlsbGNsb3VkOnZpbGxjbG91ZA=='
|
||||
}
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
if (response.data.access_token) {
|
||||
uni.setStorageSync('token', `bearer ${response.data.access_token}`);
|
||||
response.request.headers.Authorization = `bearer ${response.data.access_token}`;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
util.$hideLoading();
|
||||
this.unlock();
|
||||
})
|
||||
.then(() => {
|
||||
return instance.request(response.request);
|
||||
});
|
||||
store.commit("getToken", {code: res.code})
|
||||
});
|
||||
} else {
|
||||
count = 0;
|
||||
|
||||
@@ -16,7 +16,7 @@ const configs = {
|
||||
dev: {
|
||||
areaId: '341021104000',
|
||||
areaName: '郑村镇',
|
||||
baseUrl: 'http://192.168.1.105:9000'
|
||||
baseUrl: 'http://192.168.1.87:9000'
|
||||
}
|
||||
}
|
||||
// 当前选中配置
|
||||
|
||||
Reference in New Issue
Block a user