@jetlinks-web/core 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/axios.ts +10 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetlinks-web/core",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "module": "index.ts",
@@ -16,9 +16,9 @@
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
18
  "axios": "^1.7.4",
19
- "@jetlinks-web/types": "^1.0.2",
20
19
  "@jetlinks-web/constants": "^1.0.7",
21
- "@jetlinks-web/utils": "^1.2.5"
20
+ "@jetlinks-web/utils": "^1.2.5",
21
+ "@jetlinks-web/types": "^1.0.2"
22
22
  },
23
23
  "publishConfig": {
24
24
  "registry": "https://registry.npmjs.org/",
package/src/axios.ts CHANGED
@@ -18,6 +18,10 @@ interface Options {
18
18
  codeKey?: string
19
19
  timeout?: number
20
20
  handleRequest?: () => void
21
+ /**
22
+ * 用以获取localstorage中的lang
23
+ */
24
+ langKey?: string
21
25
  /**
22
26
  * response处理函数
23
27
  * @param response AxiosResponse实例
@@ -44,6 +48,7 @@ let _options: Options = {
44
48
  handleRequest: undefined,
45
49
  handleResponse: undefined,
46
50
  handleError: undefined,
51
+ langKey: 'lang',
47
52
  requestOptions: (config) => ({}),
48
53
  tokenExpiration: () => {},
49
54
  }
@@ -52,6 +57,7 @@ const controller = new AbortController();
52
57
 
53
58
  const handleRequest = (config: InternalAxiosRequestConfig) => {
54
59
  const token = getToken()
60
+ const lang = localStorage.getItem(_options.langKey)
55
61
 
56
62
  // 没有token,并且该接口需要token校验
57
63
  if (!token && !_options.filter_url?.some((url) => config.url?.includes(url))) {
@@ -64,6 +70,10 @@ const handleRequest = (config: InternalAxiosRequestConfig) => {
64
70
  config.headers[TOKEN_KEY] = token
65
71
  }
66
72
 
73
+ if (lang) {
74
+ config.headers[_options.langKey] = lang
75
+ }
76
+
67
77
  if (_options.requestOptions && isFunction(_options.requestOptions)) {
68
78
  const extraOptions = _options.requestOptions(config)
69
79
  if (extraOptions && isObject(extraOptions)) {