接口前缀调整

This commit is contained in:
qsh
2024-05-23 18:07:49 +08:00
parent 33be215c0a
commit 8adaf72682
18 changed files with 124 additions and 84 deletions

View File

@@ -7,7 +7,7 @@ const config: {
/**
* api请求基础路径
*/
base_url: import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL,
base_url: 'http://localhost' + import.meta.env.VITE_API_BASEPATH,
/**
* 接口成功返回状态码
*/

View File

@@ -9,7 +9,14 @@ import axios, {
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
import qs from 'qs'
import { config } from '@/config/axios/config'
import { getAccessToken, getRefreshToken, getTenantId, removeToken, setToken } from '@/utils/auth'
import {
getAccessToken,
getRefreshToken,
getTenantId,
getAppId,
removeToken,
setToken
} from '@/utils/auth'
import errorCode from './errorCode'
import { resetRouter } from '@/router'
@@ -58,6 +65,13 @@ service.interceptors.request.use(
if (tenantId) {
;(config as Recordable).headers['tenant-id'] = tenantId
}
// 设置实例
const appId = getAppId()
if (appId) {
;(config as Recordable).headers['instance-id'] = appId
}
const params = config.params || {}
const data = config.data || false
if (
@@ -225,12 +239,15 @@ const handleAuthorized = () => {
type: 'warning'
}).then(() => {
const { wsCache } = useCache()
const tenantId = wsCache.get('TENANT_ID')
const appId = wsCache.get('App_ID')
resetRouter() // 重置静态路由表
wsCache.clear()
removeToken()
isRelogin.show = false
// 干掉token后再走一次路由让它过router.beforeEach的校验
window.location.href = window.location.href
// window.location.href = window.location.href
window.location.href = `/login?tenantId=${tenantId}&appId=${appId}`
})
}
return Promise.reject(t('sys.api.timeoutMessage'))