Commit 3ca9eaf294f83411744cff341c801692f3a4e2f3
1 parent
a9c90073
fix: axios bug
Showing
5 changed files
with
13 additions
and
34 deletions
yudao-ui-admin-vue3/src/config/axios/config.ts
| 1 | 1 | const config: { |
| 2 | - base_url: { | |
| 3 | - base: string | |
| 4 | - dev: string | |
| 5 | - pro: string | |
| 6 | - test: string | |
| 7 | - } | |
| 2 | + base_url: string | |
| 8 | 3 | result_code: number | string |
| 9 | 4 | default_headers: AxiosHeaders |
| 10 | 5 | request_timeout: number |
| ... | ... | @@ -12,20 +7,7 @@ const config: { |
| 12 | 7 | /** |
| 13 | 8 | * api请求基础路径 |
| 14 | 9 | */ |
| 15 | - base_url: { | |
| 16 | - // 开发环境接口前缀 | |
| 17 | - base: '', | |
| 18 | - | |
| 19 | - // 打包开发环境接口前缀 | |
| 20 | - dev: '', | |
| 21 | - | |
| 22 | - // 打包生产环境接口前缀 | |
| 23 | - pro: '', | |
| 24 | - | |
| 25 | - // 打包测试环境接口前缀 | |
| 26 | - test: '' | |
| 27 | - }, | |
| 28 | - | |
| 10 | + base_url: import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL, | |
| 29 | 11 | /** |
| 30 | 12 | * 接口成功返回状态码 |
| 31 | 13 | */ | ... | ... |
yudao-ui-admin-vue3/src/config/axios/index.ts
| ... | ... | @@ -9,9 +9,7 @@ import { resetRouter } from '@/router' |
| 9 | 9 | import { useCache } from '@/hooks/web/useCache' |
| 10 | 10 | |
| 11 | 11 | const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE |
| 12 | -const BASE_URL = import.meta.env.VITE_BASE_URL | |
| 13 | -const BASE_API = import.meta.env.VITE_API_URL | |
| 14 | -const { result_code, base_url } = config | |
| 12 | +const { result_code, base_url, request_timeout } = config | |
| 15 | 13 | |
| 16 | 14 | // 需要忽略的提示。忽略后,自动 Promise.reject('error') |
| 17 | 15 | const ignoreMsgs = [ |
| ... | ... | @@ -26,12 +24,10 @@ let requestList: any[] = [] |
| 26 | 24 | // 是否正在刷新中 |
| 27 | 25 | let isRefreshToken = false |
| 28 | 26 | |
| 29 | -export const PATH_URL = base_url[import.meta.env.VITE_API_BASEPATH] | |
| 30 | - | |
| 31 | 27 | // 创建axios实例 |
| 32 | 28 | const service: AxiosInstance = axios.create({ |
| 33 | - baseURL: BASE_URL + BASE_API, // api 的 base_url | |
| 34 | - timeout: config.request_timeout, // 请求超时时间 | |
| 29 | + baseURL: base_url, // api 的 base_url | |
| 30 | + timeout: request_timeout, // 请求超时时间 | |
| 35 | 31 | withCredentials: false // 禁用 Cookie 等信息 |
| 36 | 32 | }) |
| 37 | 33 | |
| ... | ... | @@ -211,7 +207,7 @@ const handleAuthorized = () => { |
| 211 | 207 | wsCache.clear() |
| 212 | 208 | removeToken() |
| 213 | 209 | isRelogin.show = false |
| 214 | - location.href = '/login' | |
| 210 | + window.location.href = '/' | |
| 215 | 211 | }) |
| 216 | 212 | .catch(() => { |
| 217 | 213 | isRelogin.show = false | ... | ... |
yudao-ui-admin-vue3/src/router/index.ts
| ... | ... | @@ -12,12 +12,6 @@ import { useUserStoreWithOut } from '@/store/modules/user' |
| 12 | 12 | import { listSimpleDictDataApi } from '@/api/system/dict/dict.data' |
| 13 | 13 | import { isRelogin } from '@/config/axios' |
| 14 | 14 | |
| 15 | -const permissionStore = usePermissionStoreWithOut() | |
| 16 | - | |
| 17 | -const dictStore = useDictStoreWithOut() | |
| 18 | - | |
| 19 | -const userStore = useUserStoreWithOut() | |
| 20 | - | |
| 21 | 15 | const { start, done } = useNProgress() |
| 22 | 16 | |
| 23 | 17 | const { loadStart, loadDone } = usePageLoading() |
| ... | ... | @@ -49,6 +43,9 @@ router.beforeEach(async (to, from, next) => { |
| 49 | 43 | next({ path: '/' }) |
| 50 | 44 | } else { |
| 51 | 45 | // 获取所有字典 |
| 46 | + const dictStore = useDictStoreWithOut() | |
| 47 | + const userStore = useUserStoreWithOut() | |
| 48 | + const permissionStore = usePermissionStoreWithOut() | |
| 52 | 49 | if (!dictStore.getHasDictData) { |
| 53 | 50 | const res = await listSimpleDictDataApi() |
| 54 | 51 | dictStore.setDictMap(res) | ... | ... |
yudao-ui-admin-vue3/src/store/modules/user.ts
yudao-ui-admin-vue3/vite.config.ts