fix: axios bug
parent
a9c9007337
commit
3ca9eaf294
|
@ -1,10 +1,5 @@
|
||||||
const config: {
|
const config: {
|
||||||
base_url: {
|
base_url: string
|
||||||
base: string
|
|
||||||
dev: string
|
|
||||||
pro: string
|
|
||||||
test: string
|
|
||||||
}
|
|
||||||
result_code: number | string
|
result_code: number | string
|
||||||
default_headers: AxiosHeaders
|
default_headers: AxiosHeaders
|
||||||
request_timeout: number
|
request_timeout: number
|
||||||
|
@ -12,20 +7,7 @@ const config: {
|
||||||
/**
|
/**
|
||||||
* api请求基础路径
|
* api请求基础路径
|
||||||
*/
|
*/
|
||||||
base_url: {
|
base_url: import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL,
|
||||||
// 开发环境接口前缀
|
|
||||||
base: '',
|
|
||||||
|
|
||||||
// 打包开发环境接口前缀
|
|
||||||
dev: '',
|
|
||||||
|
|
||||||
// 打包生产环境接口前缀
|
|
||||||
pro: '',
|
|
||||||
|
|
||||||
// 打包测试环境接口前缀
|
|
||||||
test: ''
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口成功返回状态码
|
* 接口成功返回状态码
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,9 +9,7 @@ import { resetRouter } from '@/router'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useCache } from '@/hooks/web/useCache'
|
||||||
|
|
||||||
const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
|
const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
|
||||||
const BASE_URL = import.meta.env.VITE_BASE_URL
|
const { result_code, base_url, request_timeout } = config
|
||||||
const BASE_API = import.meta.env.VITE_API_URL
|
|
||||||
const { result_code, base_url } = config
|
|
||||||
|
|
||||||
// 需要忽略的提示。忽略后,自动 Promise.reject('error')
|
// 需要忽略的提示。忽略后,自动 Promise.reject('error')
|
||||||
const ignoreMsgs = [
|
const ignoreMsgs = [
|
||||||
|
@ -26,12 +24,10 @@ let requestList: any[] = []
|
||||||
// 是否正在刷新中
|
// 是否正在刷新中
|
||||||
let isRefreshToken = false
|
let isRefreshToken = false
|
||||||
|
|
||||||
export const PATH_URL = base_url[import.meta.env.VITE_API_BASEPATH]
|
|
||||||
|
|
||||||
// 创建axios实例
|
// 创建axios实例
|
||||||
const service: AxiosInstance = axios.create({
|
const service: AxiosInstance = axios.create({
|
||||||
baseURL: BASE_URL + BASE_API, // api 的 base_url
|
baseURL: base_url, // api 的 base_url
|
||||||
timeout: config.request_timeout, // 请求超时时间
|
timeout: request_timeout, // 请求超时时间
|
||||||
withCredentials: false // 禁用 Cookie 等信息
|
withCredentials: false // 禁用 Cookie 等信息
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -211,7 +207,7 @@ const handleAuthorized = () => {
|
||||||
wsCache.clear()
|
wsCache.clear()
|
||||||
removeToken()
|
removeToken()
|
||||||
isRelogin.show = false
|
isRelogin.show = false
|
||||||
location.href = '/login'
|
window.location.href = '/'
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
isRelogin.show = false
|
isRelogin.show = false
|
||||||
|
|
|
@ -12,12 +12,6 @@ import { useUserStoreWithOut } from '@/store/modules/user'
|
||||||
import { listSimpleDictDataApi } from '@/api/system/dict/dict.data'
|
import { listSimpleDictDataApi } from '@/api/system/dict/dict.data'
|
||||||
import { isRelogin } from '@/config/axios'
|
import { isRelogin } from '@/config/axios'
|
||||||
|
|
||||||
const permissionStore = usePermissionStoreWithOut()
|
|
||||||
|
|
||||||
const dictStore = useDictStoreWithOut()
|
|
||||||
|
|
||||||
const userStore = useUserStoreWithOut()
|
|
||||||
|
|
||||||
const { start, done } = useNProgress()
|
const { start, done } = useNProgress()
|
||||||
|
|
||||||
const { loadStart, loadDone } = usePageLoading()
|
const { loadStart, loadDone } = usePageLoading()
|
||||||
|
@ -49,6 +43,9 @@ router.beforeEach(async (to, from, next) => {
|
||||||
next({ path: '/' })
|
next({ path: '/' })
|
||||||
} else {
|
} else {
|
||||||
// 获取所有字典
|
// 获取所有字典
|
||||||
|
const dictStore = useDictStoreWithOut()
|
||||||
|
const userStore = useUserStoreWithOut()
|
||||||
|
const permissionStore = usePermissionStoreWithOut()
|
||||||
if (!dictStore.getHasDictData) {
|
if (!dictStore.getHasDictData) {
|
||||||
const res = await listSimpleDictDataApi()
|
const res = await listSimpleDictDataApi()
|
||||||
dictStore.setDictMap(res)
|
dictStore.setDictMap(res)
|
||||||
|
|
|
@ -27,6 +27,9 @@ export const useUserStore = defineStore({
|
||||||
nickname: ''
|
nickname: ''
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
persist: {
|
||||||
|
enabled: true
|
||||||
|
},
|
||||||
getters: {
|
getters: {
|
||||||
getPermissions(): string[] {
|
getPermissions(): string[] {
|
||||||
return this.permissions
|
return this.permissions
|
||||||
|
|
|
@ -151,6 +151,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||||||
'intro.js',
|
'intro.js',
|
||||||
'qrcode',
|
'qrcode',
|
||||||
'pinia',
|
'pinia',
|
||||||
|
'crypto-js',
|
||||||
'@wangeditor/editor',
|
'@wangeditor/editor',
|
||||||
'@wangeditor/editor-for-vue'
|
'@wangeditor/editor-for-vue'
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue