diff --git a/yudao-ui-admin-vue3/src/config/axios/index.ts b/yudao-ui-admin-vue3/src/config/axios/index.ts
index 69ce0df80..e7d1cebce 100644
--- a/yudao-ui-admin-vue3/src/config/axios/index.ts
+++ b/yudao-ui-admin-vue3/src/config/axios/index.ts
@@ -4,6 +4,8 @@ import qs from 'qs'
import { config } from '@/config/axios/config'
import { getAccessToken, getRefreshToken, getTenantId } from '@/utils/auth'
import errorCode from './errorCode'
+import { useI18n } from '@/hooks/web/useI18n'
+const { t } = useI18n()
const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
const BASE_URL = import.meta.env.VITE_BASE_URL
@@ -18,8 +20,11 @@ const ignoreMsgs = [
// 是否显示重新登录
export const isRelogin = { show: false }
// Axios 无感知刷新令牌,参考 https://www.dashingdog.cn/article/11 与 https://segmentfault.com/a/1190000020210980 实现
+// 请求队列
+// const requestList = []
// 是否正在刷新中
let isRefreshToken = false
+
export const PATH_URL = base_url[import.meta.env.VITE_API_BASEPATH]
// 创建axios实例
@@ -95,13 +100,17 @@ service.interceptors.response.use(
if (!getRefreshToken()) {
return handleAuthorized()
}
+ // 2. 进行刷新访问令牌
+ // TODO: 引入refreshToken会循环依赖报错
}
} else if (code === 500) {
- ElMessage.error(msg)
+ ElMessage.error(t('sys.api.errMsg500'))
return Promise.reject(new Error(msg))
} else if (code === 901) {
ElMessage.error(
- '
演示模式,无法进行写操作
' +
+ '' +
+ t('sys.api.errMsg901') +
+ '
' +
'
' +
'参考 https://doc.iocoder.cn/ 教程
' +
'
' +
@@ -126,11 +135,11 @@ service.interceptors.response.use(
console.log('err' + error) // for debug
let { message } = error
if (message === 'Network Error') {
- message = '后端接口连接异常'
+ message = t('sys.api.errorMessage')
} else if (message.includes('timeout')) {
- message = '系统接口请求超时'
+ message = t('sys.api.apiTimeoutMessage')
} else if (message.includes('Request failed with status code')) {
- message = '系统接口' + message.substr(message.length - 3) + '异常'
+ message = t('sys.api.apiRequestFailed') + message.substr(message.length - 3)
}
ElMessage.error(message)
return Promise.reject(error)
@@ -139,9 +148,9 @@ service.interceptors.response.use(
function handleAuthorized() {
if (!isRelogin.show) {
isRelogin.show = true
- ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
- confirmButtonText: '重新登录',
- cancelButtonText: '取消',
+ ElMessageBox.confirm(t('sys.api.timeoutMessage'), t('common.confirmTitle'), {
+ confirmButtonText: t('login.relogin'),
+ cancelButtonText: t('common.cancel'),
type: 'warning'
})
.then(() => {
@@ -151,6 +160,6 @@ function handleAuthorized() {
isRelogin.show = false
})
}
- return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
+ return Promise.reject(t('sys.api.timeoutMessage'))
}
export { service }
diff --git a/yudao-ui-admin-vue3/src/router/modules/error.ts b/yudao-ui-admin-vue3/src/router/modules/error.ts
deleted file mode 100644
index 30bd0497b..000000000
--- a/yudao-ui-admin-vue3/src/router/modules/error.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { Layout } from '@/utils/routerHelper'
-import { useI18n } from '@/hooks/web/useI18n'
-const { t } = useI18n()
-
-const errorRouter = [
- {
- path: '/error',
- component: Layout,
- redirect: '/error/404',
- name: 'Error',
- meta: {
- title: t('router.errorPage'),
- icon: 'ci:error',
- alwaysShow: true
- },
- children: [
- {
- path: '404-demo',
- component: () => import('@/views/Error/404.vue'),
- name: '404Demo',
- meta: {
- title: '404'
- }
- },
- {
- path: '403-demo',
- component: () => import('@/views/Error/403.vue'),
- name: '403Demo',
- meta: {
- title: '403'
- }
- },
- {
- path: '500-demo',
- component: () => import('@/views/Error/500.vue'),
- name: '500Demo',
- meta: {
- title: '500'
- }
- }
- ]
- }
-]
-
-export default errorRouter