@jetlinks-web/core 1.0.6 → 1.0.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetlinks-web/core",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "module": "index.ts",
@@ -17,8 +17,8 @@
17
17
  "axios": "^1.4.0",
18
18
  "rxjs": "^7.8.1",
19
19
  "@jetlinks-web/constants": "^1.0.1",
20
- "@jetlinks-web/router": "^1.0.7",
21
20
  "@jetlinks-web/types": "^1.0.1",
21
+ "@jetlinks-web/router": "^1.0.7",
22
22
  "@jetlinks-web/utils": "^1.0.5"
23
23
  },
24
24
  "devDependencies": {
@@ -1,6 +1,5 @@
1
1
  import { TOKEN_KEY, BASE_API } from '@jetlinks-web/constants'
2
2
  import { getToken } from '@jetlinks-web/utils'
3
- import { jumpLogin } from '@jetlinks-web/router'
4
3
  import axios from 'axios'
5
4
  import type {
6
5
  AxiosRequestConfig,
@@ -21,6 +20,8 @@ export interface ContextOptions {
21
20
  ) => InternalAxiosRequestConfig
22
21
  handleResponse?: (response: AxiosResponse) => AxiosResponse
23
22
  errorHandler?: (error: AxiosError) => void
23
+
24
+ loginInvalid?: () => void
24
25
  }
25
26
 
26
27
  export interface CreateAxiosOptions extends AxiosRequestConfig, ContextOptions {}
@@ -48,13 +49,17 @@ export class Axios {
48
49
  )
49
50
  }
50
51
 
52
+ jumpLogin() {
53
+ this.options.loginInvalid?.()
54
+ }
55
+
51
56
  request(config: InternalAxiosRequestConfig) {
52
57
  const token = getToken()
53
58
  const filterUrl = this.options.filterUrl // 不需要token校验接口
54
59
  // 没有token,并且该接口需要token校验
55
60
  if (!token && !filterUrl?.some((url) => config.url?.includes(url))) {
56
61
  // 跳转登录页
57
- jumpLogin()
62
+ this.jumpLogin()
58
63
  return config
59
64
  }
60
65
 
@@ -108,7 +113,7 @@ export class Axios {
108
113
  break;
109
114
  case 401:
110
115
  this.showNotification('用户未登录', status)
111
- jumpLogin()
116
+ this.jumpLogin()
112
117
  break;
113
118
  default:
114
119
  break;
@@ -1,7 +1,5 @@
1
1
  import { Axios } from "./axios";
2
2
  import type { CreateAxiosOptions } from "./axios";
3
- import { merge } from 'lodash-es'
4
- import { context } from './context'
5
3
  export { initRequest } from './context'
6
4
 
7
5
  export const createAxios = (options?: Partial<CreateAxiosOptions>) => {