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 | const config: { | 1 | const config: { |
| 2 | - base_url: { | ||
| 3 | - base: string | ||
| 4 | - dev: string | ||
| 5 | - pro: string | ||
| 6 | - test: string | ||
| 7 | - } | 2 | + base_url: string |
| 8 | result_code: number | string | 3 | result_code: number | string |
| 9 | default_headers: AxiosHeaders | 4 | default_headers: AxiosHeaders |
| 10 | request_timeout: number | 5 | request_timeout: number |
| @@ -12,20 +7,7 @@ const config: { | @@ -12,20 +7,7 @@ const config: { | ||
| 12 | /** | 7 | /** |
| 13 | * api请求基础路径 | 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 +9,7 @@ import { resetRouter } from '@/router' | ||
| 9 | import { useCache } from '@/hooks/web/useCache' | 9 | import { useCache } from '@/hooks/web/useCache' |
| 10 | 10 | ||
| 11 | const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE | 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 | // 需要忽略的提示。忽略后,自动 Promise.reject('error') | 14 | // 需要忽略的提示。忽略后,自动 Promise.reject('error') |
| 17 | const ignoreMsgs = [ | 15 | const ignoreMsgs = [ |
| @@ -26,12 +24,10 @@ let requestList: any[] = [] | @@ -26,12 +24,10 @@ let requestList: any[] = [] | ||
| 26 | // 是否正在刷新中 | 24 | // 是否正在刷新中 |
| 27 | let isRefreshToken = false | 25 | let isRefreshToken = false |
| 28 | 26 | ||
| 29 | -export const PATH_URL = base_url[import.meta.env.VITE_API_BASEPATH] | ||
| 30 | - | ||
| 31 | // 创建axios实例 | 27 | // 创建axios实例 |
| 32 | const service: AxiosInstance = axios.create({ | 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 | withCredentials: false // 禁用 Cookie 等信息 | 31 | withCredentials: false // 禁用 Cookie 等信息 |
| 36 | }) | 32 | }) |
| 37 | 33 | ||
| @@ -211,7 +207,7 @@ const handleAuthorized = () => { | @@ -211,7 +207,7 @@ const handleAuthorized = () => { | ||
| 211 | wsCache.clear() | 207 | wsCache.clear() |
| 212 | removeToken() | 208 | removeToken() |
| 213 | isRelogin.show = false | 209 | isRelogin.show = false |
| 214 | - location.href = '/login' | 210 | + window.location.href = '/' |
| 215 | }) | 211 | }) |
| 216 | .catch(() => { | 212 | .catch(() => { |
| 217 | isRelogin.show = false | 213 | isRelogin.show = false |
yudao-ui-admin-vue3/src/router/index.ts
| @@ -12,12 +12,6 @@ import { useUserStoreWithOut } from '@/store/modules/user' | @@ -12,12 +12,6 @@ import { useUserStoreWithOut } from '@/store/modules/user' | ||
| 12 | import { listSimpleDictDataApi } from '@/api/system/dict/dict.data' | 12 | import { listSimpleDictDataApi } from '@/api/system/dict/dict.data' |
| 13 | import { isRelogin } from '@/config/axios' | 13 | import { isRelogin } from '@/config/axios' |
| 14 | 14 | ||
| 15 | -const permissionStore = usePermissionStoreWithOut() | ||
| 16 | - | ||
| 17 | -const dictStore = useDictStoreWithOut() | ||
| 18 | - | ||
| 19 | -const userStore = useUserStoreWithOut() | ||
| 20 | - | ||
| 21 | const { start, done } = useNProgress() | 15 | const { start, done } = useNProgress() |
| 22 | 16 | ||
| 23 | const { loadStart, loadDone } = usePageLoading() | 17 | const { loadStart, loadDone } = usePageLoading() |
| @@ -49,6 +43,9 @@ router.beforeEach(async (to, from, next) => { | @@ -49,6 +43,9 @@ router.beforeEach(async (to, from, next) => { | ||
| 49 | next({ path: '/' }) | 43 | next({ path: '/' }) |
| 50 | } else { | 44 | } else { |
| 51 | // 获取所有字典 | 45 | // 获取所有字典 |
| 46 | + const dictStore = useDictStoreWithOut() | ||
| 47 | + const userStore = useUserStoreWithOut() | ||
| 48 | + const permissionStore = usePermissionStoreWithOut() | ||
| 52 | if (!dictStore.getHasDictData) { | 49 | if (!dictStore.getHasDictData) { |
| 53 | const res = await listSimpleDictDataApi() | 50 | const res = await listSimpleDictDataApi() |
| 54 | dictStore.setDictMap(res) | 51 | dictStore.setDictMap(res) |
yudao-ui-admin-vue3/src/store/modules/user.ts
| @@ -27,6 +27,9 @@ export const useUserStore = defineStore({ | @@ -27,6 +27,9 @@ export const useUserStore = defineStore({ | ||
| 27 | nickname: '' | 27 | nickname: '' |
| 28 | } | 28 | } |
| 29 | }), | 29 | }), |
| 30 | + persist: { | ||
| 31 | + enabled: true | ||
| 32 | + }, | ||
| 30 | getters: { | 33 | getters: { |
| 31 | getPermissions(): string[] { | 34 | getPermissions(): string[] { |
| 32 | return this.permissions | 35 | return this.permissions |
yudao-ui-admin-vue3/vite.config.ts
| @@ -151,6 +151,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { | @@ -151,6 +151,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { | ||
| 151 | 'intro.js', | 151 | 'intro.js', |
| 152 | 'qrcode', | 152 | 'qrcode', |
| 153 | 'pinia', | 153 | 'pinia', |
| 154 | + 'crypto-js', | ||
| 154 | '@wangeditor/editor', | 155 | '@wangeditor/editor', |
| 155 | '@wangeditor/editor-for-vue' | 156 | '@wangeditor/editor-for-vue' |
| 156 | ] | 157 | ] |