配置后台接口中英文对照

This commit is contained in:
2026-03-17 16:31:31 +08:00
parent 683bd5d97a
commit eb8123c7b3
7 changed files with 295 additions and 30 deletions

View File

@@ -16,11 +16,19 @@
import axios, { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
import { useUserStore } from '@/store/modules/user'
import i18n from '@/locales'
import { ApiStatus } from './status'
import { HttpError, handleError, showError, showSuccess } from './error'
import { $t } from '@/locales'
import { BaseResponse } from '@/types'
/** 当前语言zh/en供请求头 lang 使用,无 header 时后端按后台语言回包 */
function getRequestLang(): string {
const locale = i18n.global.locale as string | { value: string }
const lang = typeof locale === 'string' ? locale : (locale && 'value' in locale ? locale.value : 'zh')
return lang === 'en' ? 'en' : 'zh'
}
/** 请求配置常量(超时时间 30s */
const REQUEST_TIMEOUT = 30000
const LOGOUT_DELAY = 500
@@ -66,6 +74,7 @@ axiosInstance.interceptors.request.use(
(request: InternalAxiosRequestConfig) => {
const { accessToken } = useUserStore()
if (accessToken) request.headers.set('Authorization', `Bearer ` + accessToken)
request.headers.set('lang', getRequestLang())
if (request.data && !(request.data instanceof FormData) && !request.headers['Content-Type']) {
request.headers.set('Content-Type', 'application/json')