vuex模块化及axios代理重新整理

This commit is contained in:
aixianling
2022-06-10 16:14:13 +08:00
parent 7cbe10ff64
commit 1218536e64
9 changed files with 174 additions and 158 deletions

View File

@@ -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