Files
dvcp_v2_wxcp_app/src/common/axios.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-11-15 10:29:05 +08:00
import store from '../store'
import instance from './http'
2021-11-15 10:29:05 +08:00
instance.interceptors.request.use(config => {
store.commit('initWaterMarker')
config.baseURL = "/lan"
2022-05-31 10:31:01 +08:00
if (/\/node\//.test(config.url)) {
config.baseURL = '/ns'
} else if (/AppCountryAlbum/.test(location.pathname) || config.module == 'AppCountryAlbum') {
2022-05-30 15:38:40 +08:00
config.baseURL = '/aca'
2022-05-18 14:16:04 +08:00
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
} else if (/\/project\/beta\//.test(location.pathname) || config.module == 'wangge') {
2022-05-30 15:31:51 +08:00
config.baseURL = '/wangge'
2022-06-08 10:48:17 +08:00
} else if (/\/project\/police\//.test(location.pathname) || config.module == 'hnjc') {
2022-05-30 15:31:51 +08:00
config.baseURL = '/hnjc'
2022-05-30 15:38:40 +08:00
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
2022-05-30 18:46:49 +08:00
} else if (sessionStorage.getItem("prj") == "saas") {
config.baseURL = '/online'
2022-05-18 18:06:39 +08:00
}
2021-11-15 10:29:05 +08:00
return config
}, err => {
console.error(err)
})
instance.interceptors.response.use(res => {
if (res.data) {
2022-05-30 11:02:56 +08:00
uni.hideLoading()
2022-05-30 14:12:46 +08:00
if (res.data.access_token) {
return res.data
}
2022-05-30 11:02:56 +08:00
if (res.data.code == 0) {
return res.data
} else if (res.data.code === 1) {
uni.showToast({
title: res.data.msg,
duration: 2000,
icon: 'none'
})
2021-11-15 10:29:05 +08:00
return res.data
2022-05-30 11:02:56 +08:00
} else if (res.data.code == 401) {
store.commit("logout");
2022-05-31 10:31:01 +08:00
uni.showToast({title: "请登录用户!", icon: "none"})
2022-05-30 11:02:56 +08:00
} else {
console.error(res.data.msg || "请求失败!")
return Promise.reject(res.data.msg)
2021-11-15 10:29:05 +08:00
}
} else {
console.error("服务器异常,请联系管理员!")
2022-05-30 14:12:46 +08:00
return res.data
2021-11-15 10:29:05 +08:00
}
}, err => {
2022-01-20 11:22:22 +08:00
uni.hideLoading()
2021-11-15 10:29:05 +08:00
console.error(err)
return Promise.reject(err)
2021-11-15 10:29:05 +08:00
})
export default instance