|
|
@@ -4,16 +4,27 @@ import { config } from './config'
|
|
|
|
|
|
const { default_headers } = config
|
|
|
|
|
|
+const DEFAULT_LANG = 'zh-CN'
|
|
|
+
|
|
|
+const getRequestLang = () => {
|
|
|
+ try {
|
|
|
+ const langStore = JSON.parse(localStorage.getItem('lang') || '{}')
|
|
|
+ const lang = typeof langStore === 'string' ? langStore : langStore?.v
|
|
|
+
|
|
|
+ return typeof lang === 'string' && lang ? lang.replace(/"/g, '') : DEFAULT_LANG
|
|
|
+ } catch {
|
|
|
+ return DEFAULT_LANG
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const request = (option: any) => {
|
|
|
const { headersType, headers, ...otherOption } = option
|
|
|
|
|
|
- const langStore = JSON.parse(localStorage.getItem('lang') || '{}')
|
|
|
-
|
|
|
return service({
|
|
|
...otherOption,
|
|
|
headers: {
|
|
|
'Content-Type': headersType || default_headers,
|
|
|
- Lang: langStore.v.replace(/"/g, ''),
|
|
|
+ Lang: getRequestLang(),
|
|
|
...headers
|
|
|
}
|
|
|
})
|