Files
dvcp_v2_wxcp_app/src/common/axios.js
aixianling 33baad65de BUG 30108
2022-06-10 17:46:34 +08:00

58 lines
1.7 KiB
JavaScript

import store from '../store'
import instance from './http'
instance.interceptors.request.use(config => {
store.commit('initWaterMarker')
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) || config.module == 'wangge' || store.state.config.corpid == 'ww2a667717a70164f1') {
config.baseURL = '/wangge'
} else if (/\/project\/police\//.test(location.pathname) || config.module == 'hnjc') {
config.baseURL = '/hnjc'
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
} else if (sessionStorage.getItem("prj") == "saas") {
config.baseURL = '/online'
} else config.baseURL = "/lan"
return config
}, err => {
console.error(err)
})
instance.interceptors.response.use(res => {
if (res.data) {
uni.hideLoading()
if (res.data.access_token) {
return res.data
}
if (res.data.code == 0) {
return res.data
} else if (res.data.code === 1) {
uni.showToast({
title: res.data.msg,
duration: 2000,
icon: 'none'
})
return res.data
} else if (res.data.code == 401) {
store.commit("logout");
uni.showToast({title: "请登录用户!", icon: "none"})
} else {
console.error(res.data.msg || "请求失败!")
return Promise.reject(res.data.msg)
}
} else {
console.error("服务器异常,请联系管理员!")
return res.data
}
}, err => {
uni.hideLoading()
console.error(err)
return Promise.reject(err)
})
export default instance