62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import store from '../store'
|
|
import instance from './http'
|
|
|
|
instance.interceptors.request.use(config => {
|
|
store.commit('initWaterMarker')
|
|
let {module} = store.state
|
|
if (/\/node\//.test(config.url)) {
|
|
config.baseURL = '/ns'
|
|
} else if (/AppCountryAlbum/.test(location.pathname) || config.module == 'AppCountryAlbum' || module == "AppCountryAlbum") {
|
|
config.baseURL = '/aca'
|
|
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
|
|
} else if (/\/project\/beta\//.test(location.pathname) || config.module == 'wangge' || module == "wangge") {
|
|
} else if (/saas/.test(location.pathname) || config.module == 'saas' || module == "saas") {
|
|
config.baseURL = '/online'
|
|
} else if (/\/project\/police\//.test(location.pathname) || config.module == 'hnjc' || module == "hnjc") {
|
|
config.baseURL = '/hnjc'
|
|
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
|
|
} else if (!/^App/.test(module) && module) {
|
|
config.baseURL = `/${module}`
|
|
if (['xaxc'].includes(module)) {
|
|
config.url = config.url.replace(/(app|auth|admin)\//, "api/")
|
|
}
|
|
} else config.baseURL = "/lan"
|
|
return config
|
|
}, err => {
|
|
console.error(err)
|
|
})
|
|
|
|
instance.interceptors.response.use(res => {
|
|
uni.hideLoading()
|
|
if (res.data) {
|
|
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
|