整合小程序库
This commit is contained in:
@@ -1,52 +1,26 @@
|
||||
import config from '@/utils/config';
|
||||
import setting from './config';
|
||||
import util from 'dvcp-wui/utils/util';
|
||||
import store from "../store"
|
||||
|
||||
const Fly = require('flyio/dist/npm/wx');
|
||||
let instance = new Fly();
|
||||
const baseURL = config.baseUrl;
|
||||
let count = 0;
|
||||
instance.config.timeout = 50000;
|
||||
instance.config.baseURL = baseURL;
|
||||
|
||||
const getToken = () => {
|
||||
if (store.state.token) return store.state.token;
|
||||
else return '';
|
||||
};
|
||||
import instance from "dvcp-wui/utils/http";
|
||||
|
||||
instance.interceptors.request.use((config) => {
|
||||
if (!config.withoutToken) {
|
||||
config.headers['Authorization'] = getToken();
|
||||
}
|
||||
config.baseURL = config.baseURL || setting.baseUrl
|
||||
return config;
|
||||
});
|
||||
|
||||
instance.interceptors.response.use(
|
||||
function (response) {
|
||||
util.$hideLoading();
|
||||
if (response.data.code === 1) {
|
||||
util.$toast({title: response.data.msg, duration: 3000});
|
||||
} else if (response.data.code == 2) {
|
||||
//首次静默登录异常不做任何返回
|
||||
} else if (response.data.code == 401) {
|
||||
if (count > 3) {
|
||||
return;
|
||||
}
|
||||
count++;
|
||||
return util.$getLoginCode().then((res) => {
|
||||
store.commit("getToken", {code: res.code})
|
||||
});
|
||||
} else {
|
||||
count = 0;
|
||||
return response.data;
|
||||
}
|
||||
},
|
||||
function (err) {
|
||||
console.log(err);
|
||||
}
|
||||
);
|
||||
instance.interceptors.response.use(response => {
|
||||
util.$hideLoading();
|
||||
if (response.data.code === 1) {
|
||||
util.$toast({title: response.data.msg, duration: 3000});
|
||||
} else if (response.data.code == 2) {
|
||||
//首次静默登录异常不做任何返回
|
||||
} else if (response.data.code == 401) {
|
||||
return store.commit('logout')
|
||||
} else {
|
||||
return response.data;
|
||||
}
|
||||
}, err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
export default {
|
||||
instance,
|
||||
baseURL
|
||||
};
|
||||
export default instance
|
||||
|
||||
Reference in New Issue
Block a user