@jetlinks-web/core 1.0.6 → 1.0.8

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.8",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "module": "index.ts",
@@ -18,8 +18,8 @@
18
18
  "rxjs": "^7.8.1",
19
19
  "@jetlinks-web/constants": "^1.0.1",
20
20
  "@jetlinks-web/router": "^1.0.7",
21
- "@jetlinks-web/types": "^1.0.1",
22
- "@jetlinks-web/utils": "^1.0.5"
21
+ "@jetlinks-web/utils": "^1.0.5",
22
+ "@jetlinks-web/types": "^1.0.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/lodash-es": "^4.17.7",
@@ -1,6 +1,5 @@
1
1
  import { TOKEN_KEY, BASE_API } from '@jetlinks-web/constants'
2
- import { getToken } from '@jetlinks-web/utils'
3
- import { jumpLogin } from '@jetlinks-web/router'
2
+ import { getToken, cleanToken } from '@jetlinks-web/utils'
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,18 @@ export class Axios {
48
49
  )
49
50
  }
50
51
 
52
+ jumpLogin() {
53
+ cleanToken()
54
+ this.options.loginInvalid?.()
55
+ }
56
+
51
57
  request(config: InternalAxiosRequestConfig) {
52
58
  const token = getToken()
53
59
  const filterUrl = this.options.filterUrl // 不需要token校验接口
54
60
  // 没有token,并且该接口需要token校验
55
61
  if (!token && !filterUrl?.some((url) => config.url?.includes(url))) {
56
62
  // 跳转登录页
57
- jumpLogin()
63
+ this.jumpLogin()
58
64
  return config
59
65
  }
60
66
 
@@ -108,7 +114,7 @@ export class Axios {
108
114
  break;
109
115
  case 401:
110
116
  this.showNotification('用户未登录', status)
111
- jumpLogin()
117
+ this.jumpLogin()
112
118
  break;
113
119
  default:
114
120
  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>) => {