Commit 3b64e95d authored by 前端-许佳敏's avatar 前端-许佳敏

feat: 新增国际化http请求头

parent e1a4ef32
import { extend, ResponseError, OnionOptions, RequestOptionsInit, ResponseInterceptor, OnionMiddleware, Context, RequestMethod } from 'umi-request';
import responseCode from '@/constants/responseCode'
import { IRequestError, IRequestSuccess } from '..';
import { getIntl } from 'umi'
import { getIntl, getLocale } from 'umi'
import { message } from 'antd'
import { getCookieAuth, removeAuth } from './auth';
import { GlobalConfig } from '@/global/config';
import qs from 'qs'
import { getCookie } from './cookie';
export type CtlType = 'none' | 'message'
// 根前缀请求路径
......@@ -60,11 +61,17 @@ const errorHandler = (error: ResponseError): IRequestError => {
}
}
const requestLanguageMaps = {
'zh-CN': 'zh',
'en-US': 'en',
'ko-KR': 'ko',
}
const defaultHeaders = {
'Content-Type': 'Application/json',
'source': '1',
'environment': '1',
'site': GlobalConfig.global.siteInfo.id.toString()
'site': GlobalConfig.global.siteInfo.id.toString(),
}
/**
......@@ -84,6 +91,7 @@ baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit):
// 判断是否有权限
const { userId, memberId, token, memberRoleId } = getCookieAuth() || {}
const headers: any = {
'Accept-Language': requestLanguageMaps[getLocale() as any],
...options.headers
}
userId && (headers.userId = userId)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment