修改前端去除后端模块名
This commit is contained in:
@@ -12,14 +12,30 @@ const loadingInstance: LoadingInstance = {
|
||||
target: null,
|
||||
count: 0
|
||||
}
|
||||
|
||||
const VITE_FLAG = import.meta.env.VITE_NAME == 'removeMode'
|
||||
// console.log('🚀 ~ import.meta.env.VITE_NAME:', import.meta.env.VITE_NAME)
|
||||
/**
|
||||
* 根据运行环境获取基础请求URL
|
||||
*/
|
||||
export const getUrl = (): string => {
|
||||
return '/api'
|
||||
}
|
||||
|
||||
function removeBeforeSecondSlash(str: string) {
|
||||
// 找到第一个斜杠的位置
|
||||
const firstSlashIndex = str.indexOf('/')
|
||||
if (firstSlashIndex === -1) {
|
||||
// 如果没有斜杠,返回原字符串
|
||||
return str
|
||||
}
|
||||
// 从第一个斜杠之后开始找第二个斜杠
|
||||
const secondSlashIndex = str.indexOf('/', firstSlashIndex + 1)
|
||||
if (secondSlashIndex === -1) {
|
||||
// 如果只有一个斜杠,返回原字符串
|
||||
return str
|
||||
}
|
||||
// 返回第二个斜杠及之后的内容
|
||||
return str.substring(secondSlashIndex)
|
||||
}
|
||||
/**
|
||||
* 创建`Axios`
|
||||
* 默认开启`reductDataFormat(简洁响应)`,返回类型为`ApiPromise`
|
||||
@@ -54,11 +70,12 @@ function createAxios<Data = any, T = ApiPromise<Data>>(
|
||||
|
||||
// 请求拦截
|
||||
Axios.interceptors.request.use(
|
||||
config => {
|
||||
// if(config.url?.substring(0, 13)=='/advance-boot'){
|
||||
// config.url=config.url?.slice(13)
|
||||
// config.baseURL='/hzj'
|
||||
// }
|
||||
async (config: any) => {
|
||||
//嵌入去除所有请求头
|
||||
if (VITE_FLAG) {
|
||||
config.url = await removeBeforeSecondSlash(config.url)
|
||||
}
|
||||
|
||||
// 取消重复请求
|
||||
|
||||
if (
|
||||
@@ -148,7 +165,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(
|
||||
})
|
||||
})
|
||||
}
|
||||
} else if (response.data.code == 'A0024'||response.data.code == 'null') {
|
||||
} else if (response.data.code == 'A0024' || response.data.code == 'null') {
|
||||
// // 登录失效
|
||||
ElNotification({
|
||||
type: 'error',
|
||||
|
||||
Reference in New Issue
Block a user