vuex模块化及axios代理重新整理
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
import axios from 'axios'
|
||||
import store from '../store'
|
||||
import instance from './http'
|
||||
|
||||
const baseURL = process.env.NODE_ENV === "production" ? "/" :
|
||||
sessionStorage.getItem("prj") == "saas" ? "/online" : "/lan"
|
||||
let instance = axios.create({
|
||||
baseURL,
|
||||
timeout: 600000,
|
||||
withCredentials: true,
|
||||
})
|
||||
instance.interceptors.request.use(config => {
|
||||
store.commit('initWaterMarker')
|
||||
config.baseURL = "/lan"
|
||||
if (/\/node\//.test(config.url)) {
|
||||
config.baseURL = '/ns'
|
||||
} else if (/AppCountryAlbum/.test(location.pathname) || config.module == 'AppCountryAlbum') {
|
||||
config.baseURL = '/aca'
|
||||
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
|
||||
} else if (/\/project\/beta\//.test(location.pathname) || store.state.config.corpid == 'ww2a667717a70164f1' || config.module == 'wangge') {
|
||||
} else if (/\/project\/beta\//.test(location.pathname) || config.module == 'wangge') {
|
||||
config.baseURL = '/wangge'
|
||||
} else if (/\/project\/police\//.test(location.pathname) || config.module == 'hnjc') {
|
||||
config.baseURL = '/hnjc'
|
||||
@@ -23,9 +17,6 @@ instance.interceptors.request.use(config => {
|
||||
} else if (sessionStorage.getItem("prj") == "saas") {
|
||||
config.baseURL = '/online'
|
||||
}
|
||||
if (!config.withoutToken && store.state.token) {
|
||||
config.headers["Authorization"] = store.state.token
|
||||
}
|
||||
return config
|
||||
}, err => {
|
||||
console.error(err)
|
||||
@@ -45,7 +36,6 @@ instance.interceptors.response.use(res => {
|
||||
duration: 2000,
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
return res.data
|
||||
} else if (res.data.code == 401) {
|
||||
store.commit("logout");
|
||||
@@ -61,7 +51,7 @@ instance.interceptors.response.use(res => {
|
||||
}, err => {
|
||||
uni.hideLoading()
|
||||
console.error(err)
|
||||
return Promise.reject(error)
|
||||
return Promise.reject(err)
|
||||
})
|
||||
|
||||
export default instance
|
||||
|
||||
Reference in New Issue
Block a user