@ibiz-template/core 0.0.1-alpha.4 → 0.0.1-alpha.40

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 (114) hide show
  1. package/dist/system/index.system.js +1 -0
  2. package/out/constant/http-status-message/http-status-message.d.ts +5 -0
  3. package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
  4. package/out/constant/http-status-message/http-status-message.js +20 -0
  5. package/out/constant/index.d.ts +4 -0
  6. package/out/constant/index.d.ts.map +1 -1
  7. package/out/constant/index.js +4 -0
  8. package/out/constant/login-mode/login-mode.d.ts +23 -0
  9. package/out/constant/login-mode/login-mode.d.ts.map +1 -0
  10. package/out/constant/login-mode/login-mode.js +24 -0
  11. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
  12. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
  13. package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
  14. package/out/constant/util/util.d.ts +5 -0
  15. package/out/constant/util/util.d.ts.map +1 -0
  16. package/out/constant/util/util.js +5 -0
  17. package/out/context/index.d.ts +2 -39
  18. package/out/context/index.d.ts.map +1 -1
  19. package/out/context/index.js +34 -65
  20. package/out/environment/environment.d.ts.map +1 -1
  21. package/out/environment/environment.js +11 -1
  22. package/out/error/http-error/http-error.d.ts +18 -0
  23. package/out/error/http-error/http-error.d.ts.map +1 -0
  24. package/out/error/http-error/http-error.js +36 -0
  25. package/out/error/index.d.ts +3 -0
  26. package/out/error/index.d.ts.map +1 -0
  27. package/out/error/index.js +2 -0
  28. package/out/error/runtime-error/runtime-error.d.ts +15 -0
  29. package/out/error/runtime-error/runtime-error.d.ts.map +1 -0
  30. package/out/error/runtime-error/runtime-error.js +15 -0
  31. package/out/factory-center.d.ts +11 -0
  32. package/out/factory-center.d.ts.map +1 -0
  33. package/out/factory-center.js +10 -0
  34. package/out/ibizsys.d.ts +8 -1
  35. package/out/ibizsys.d.ts.map +1 -1
  36. package/out/ibizsys.js +8 -1
  37. package/out/index.d.ts +3 -1
  38. package/out/index.d.ts.map +1 -1
  39. package/out/index.js +3 -1
  40. package/out/install.d.ts.map +1 -1
  41. package/out/install.js +4 -2
  42. package/out/interface/click-outside/click-outside.d.ts +70 -0
  43. package/out/interface/click-outside/click-outside.d.ts.map +1 -0
  44. package/out/interface/click-outside/click-outside.js +1 -0
  45. package/out/interface/i-environment/i-environment.d.ts +76 -0
  46. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  47. package/out/interface/index.d.ts +1 -0
  48. package/out/interface/index.d.ts.map +1 -1
  49. package/out/interface/index.js +1 -1
  50. package/out/types.d.ts +20 -0
  51. package/out/types.d.ts.map +1 -1
  52. package/out/utils/click-outside/click-outside.d.ts +14 -0
  53. package/out/utils/click-outside/click-outside.d.ts.map +1 -0
  54. package/out/utils/click-outside/click-outside.js +85 -0
  55. package/out/utils/event/event.d.ts +34 -0
  56. package/out/utils/event/event.d.ts.map +1 -0
  57. package/out/utils/event/event.js +60 -0
  58. package/out/utils/index.d.ts +5 -1
  59. package/out/utils/index.d.ts.map +1 -1
  60. package/out/utils/index.js +5 -1
  61. package/out/utils/interceptor/core-interceptor.d.ts +15 -0
  62. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
  63. package/out/utils/interceptor/core-interceptor.js +30 -0
  64. package/out/utils/interceptor/index.d.ts +3 -0
  65. package/out/utils/interceptor/index.d.ts.map +1 -0
  66. package/out/utils/interceptor/index.js +2 -0
  67. package/out/utils/interceptor/interceptor.d.ts +74 -3
  68. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  69. package/out/utils/interceptor/interceptor.js +73 -22
  70. package/out/utils/logger/logger.d.ts +3 -0
  71. package/out/utils/logger/logger.d.ts.map +1 -0
  72. package/out/utils/logger/logger.js +2 -0
  73. package/out/utils/net/http-response.d.ts +4 -9
  74. package/out/utils/net/http-response.d.ts.map +1 -1
  75. package/out/utils/net/http-response.js +0 -7
  76. package/out/utils/net/net.d.ts +82 -31
  77. package/out/utils/net/net.d.ts.map +1 -1
  78. package/out/utils/net/net.js +145 -50
  79. package/out/utils/url-helper/url-helper.d.ts +51 -0
  80. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  81. package/out/utils/url-helper/url-helper.js +59 -0
  82. package/out/utils/util/util.d.ts +45 -0
  83. package/out/utils/util/util.d.ts.map +1 -1
  84. package/out/utils/util/util.js +96 -0
  85. package/package.json +18 -7
  86. package/src/constant/http-status-message/http-status-message.ts +20 -0
  87. package/src/constant/index.ts +4 -0
  88. package/src/constant/login-mode/login-mode.ts +23 -0
  89. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  90. package/src/constant/util/util.ts +5 -0
  91. package/src/context/index.ts +35 -69
  92. package/src/environment/environment.ts +11 -1
  93. package/src/error/http-error/http-error.ts +43 -0
  94. package/src/error/index.ts +2 -0
  95. package/src/error/runtime-error/runtime-error.ts +14 -0
  96. package/src/factory-center.ts +9 -0
  97. package/src/ibizsys.ts +9 -1
  98. package/src/index.ts +3 -1
  99. package/src/install.ts +4 -2
  100. package/src/interface/click-outside/click-outside.ts +71 -0
  101. package/src/interface/i-environment/i-environment.ts +86 -0
  102. package/src/interface/index.ts +1 -0
  103. package/src/types.ts +21 -0
  104. package/src/utils/click-outside/click-outside.ts +110 -0
  105. package/src/utils/event/event.ts +77 -0
  106. package/src/utils/index.ts +5 -1
  107. package/src/utils/interceptor/core-interceptor.ts +35 -0
  108. package/src/utils/interceptor/index.ts +2 -0
  109. package/src/utils/interceptor/interceptor.ts +109 -22
  110. package/src/utils/logger/logger.ts +3 -0
  111. package/src/utils/net/http-response.ts +6 -9
  112. package/src/utils/net/net.ts +175 -61
  113. package/src/utils/url-helper/url-helper.ts +62 -0
  114. package/src/utils/util/util.ts +115 -0
package/src/install.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import { FactoryCenter } from './factory-center';
1
2
  import { IBizSys } from './ibizsys';
2
- import { Interceptor } from './utils';
3
+ import { CoreInterceptor } from './utils';
3
4
 
4
5
  /**
5
6
  * 初始化全局对象
@@ -13,5 +14,6 @@ export function install(): void {
13
14
  throw new Error('ibiz 已经存在, 无需重复安装');
14
15
  }
15
16
  window.ibiz = new IBizSys();
16
- new Interceptor();
17
+ window.___fc = new FactoryCenter();
18
+ ibiz.net.addInterceptor('CoreInterceptor', new CoreInterceptor());
17
19
  }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * 可选配置参数
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-28 16:10:48
6
+ * @export
7
+ * @interface OnClickOutsideOptions
8
+ * @extends {ConfigurableWindow}
9
+ * @template E
10
+ */
11
+ export interface OnClickOutsideOptions {
12
+ /**
13
+ * 指定使用的window,不给就用默认的window
14
+ * 一般是在iframe或测试环境中使用。
15
+ *
16
+ * @author lxm
17
+ * @date 2022-10-28 17:10:49
18
+ * @type {Window}
19
+ */
20
+ window?: Window;
21
+ /**
22
+ * 指定需要忽略的元素,用于排除某些外部的元素
23
+ *
24
+ * @author lxm
25
+ * @date 2022-10-28 17:10:50
26
+ * @type {HTMLElement[]}
27
+ */
28
+ ignore?: HTMLElement[];
29
+ /**
30
+ * 是否捕获内部元素。默认为是,内部元素不会触发回调。
31
+ * @default true
32
+ */
33
+ capture?: boolean;
34
+ }
35
+
36
+ /**
37
+ * 回调处理函数类型
38
+ */
39
+ export type OnClickOutsideHandler = (_evt: PointerEvent | MouseEvent) => void;
40
+
41
+ /**
42
+ * OnClickOutside返回对象类型
43
+ *
44
+ * @author lxm
45
+ * @date 2022-10-31 11:10:59
46
+ * @export
47
+ * @interface OnClickOutsideResult
48
+ */
49
+ export interface OnClickOutsideResult {
50
+ /**
51
+ * 停止监听,并移除相关监听事件
52
+ *
53
+ * @author lxm
54
+ * @date 2022-10-31 11:10:28
55
+ */
56
+ stop: () => void;
57
+ /**
58
+ * 暂停监听
59
+ *
60
+ * @author lxm
61
+ * @date 2022-10-31 11:10:30
62
+ */
63
+ pause: () => void;
64
+ /**
65
+ * 继续监听
66
+ *
67
+ * @author lxm
68
+ * @date 2022-10-31 11:10:32
69
+ */
70
+ proceed: () => void;
71
+ }
@@ -1,3 +1,6 @@
1
+ import { LogLevelDesc } from 'loglevel';
2
+ import { LoginMode, MenuPermissionMode } from '../../constant';
3
+
1
4
  /**
2
5
  * 配置参数
3
6
  *
@@ -16,6 +19,35 @@ export interface IEnvironment {
16
19
  */
17
20
  namespace?: string;
18
21
 
22
+ /**
23
+ * 是否为开发模式
24
+ *
25
+ * @default false
26
+ * @author chitanda
27
+ * @date 2022-10-21 11:10:29
28
+ * @type {boolean}
29
+ */
30
+ dev: boolean;
31
+
32
+ /**
33
+ * 日志级别
34
+ *
35
+ * @author chitanda
36
+ * @date 2022-10-25 20:10:55
37
+ * @type {LogLevelDesc}
38
+ */
39
+ logLevel: LogLevelDesc;
40
+
41
+ /**
42
+ * js 静态文件 cdn 地址
43
+ *
44
+ * @default https://cdn.jsdelivr.net/
45
+ * @author chitanda
46
+ * @date 2022-10-24 11:10:14
47
+ * @type {string}
48
+ */
49
+ jsCdn: string;
50
+
19
51
  /**
20
52
  * 请求根路径
21
53
  *
@@ -25,6 +57,42 @@ export interface IEnvironment {
25
57
  */
26
58
  baseUrl: string;
27
59
 
60
+ /**
61
+ * 插件默认所在目录
62
+ *
63
+ * @author chitanda
64
+ * @date 2022-10-31 14:10:49
65
+ * @type {string}
66
+ */
67
+ pluginBaseUrl: string;
68
+
69
+ /**
70
+ * 登录模式
71
+ *
72
+ * @author lxm
73
+ * @date 2022-10-12 14:10:51
74
+ * @type {LoginMode}
75
+ */
76
+ loginMode: LoginMode;
77
+
78
+ /**
79
+ * 中央认证登录地址
80
+ *
81
+ * @author lxm
82
+ * @date 2022-10-11 12:10:21
83
+ * @type {string}
84
+ */
85
+ casLoginUrl: string;
86
+
87
+ /**
88
+ * 远程模型路径
89
+ *
90
+ * @author chitanda
91
+ * @date 2022-09-22 18:09:25
92
+ * @type {string}
93
+ */
94
+ remoteModelUrl: string;
95
+
28
96
  /**
29
97
  * 资源文件根路径
30
98
  *
@@ -60,4 +128,22 @@ export interface IEnvironment {
60
128
  * @type {string}
61
129
  */
62
130
  UploadFile: string;
131
+
132
+ /**
133
+ * 是否启用权限校验(默认true)
134
+ *
135
+ * @author lxm
136
+ * @date 2022-10-12 18:10:25
137
+ * @type {boolean}
138
+ */
139
+ enablePermission: boolean;
140
+
141
+ /**
142
+ * 菜单权限校验模式(默认MIXIN)
143
+ *
144
+ * @author lxm
145
+ * @date 2022-10-12 18:10:27
146
+ * @type {MenuPermissionMode}
147
+ */
148
+ menuPermissionMode: MenuPermissionMode;
63
149
  }
@@ -1,2 +1,3 @@
1
1
  export { IEnvironment } from './i-environment/i-environment';
2
2
  export { OrgData } from './org-data/org-data';
3
+ export * from './click-outside/click-outside';
package/src/types.ts CHANGED
@@ -1,11 +1,21 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { FactoryCenter } from './factory-center';
2
3
  import { IBizSys } from './ibizsys';
3
4
 
4
5
  declare global {
5
6
  const ibiz: IBizSys;
7
+ const ___fc: FactoryCenter;
6
8
 
7
9
  interface Window {
8
10
  ibiz: IBizSys;
11
+ /**
12
+ * 全局工厂中心
13
+ *
14
+ * @author lxm
15
+ * @date 2022-10-17 15:10:43
16
+ * @type {FactoryCenter}
17
+ */
18
+ ___fc: FactoryCenter;
9
19
  }
10
20
 
11
21
  /**
@@ -40,4 +50,15 @@ declare global {
40
50
  interface IData {
41
51
  [key: string | symbol]: any;
42
52
  }
53
+
54
+ /**
55
+ * 任意对象结构
56
+ *
57
+ * @author chitanda
58
+ * @date 2022-09-21 15:09:30
59
+ * @interface IObject
60
+ */
61
+ interface IObject {
62
+ [key: string | symbol]: any;
63
+ }
43
64
  }
@@ -0,0 +1,110 @@
1
+ import { RuntimeError } from '../../error';
2
+ import {
3
+ OnClickOutsideHandler,
4
+ OnClickOutsideOptions,
5
+ OnClickOutsideResult,
6
+ } from '../../interface';
7
+ import { eventPath, isEventInside, listenJSEvent } from '../event/event';
8
+
9
+ const defaultWindow = typeof window !== 'undefined' ? window : undefined;
10
+
11
+ /**
12
+ * 监听目标元素之外的点击事件回调
13
+ *
14
+ * @author lxm
15
+ * @date 2022-10-28 18:10:25
16
+ * @export
17
+ * @param {HTMLElement} target 目标元素
18
+ * @param {OnClickOutsideHandler} handler 触发的时间回调
19
+ * @param {OnClickOutsideOptions} [options={}] 额外配置参数
20
+ * @returns {*} {OnClickOutsideResult}
21
+ */
22
+ export function onClickOutside(
23
+ target: HTMLElement,
24
+ handler: OnClickOutsideHandler,
25
+ options: OnClickOutsideOptions = {},
26
+ ): OnClickOutsideResult {
27
+ const { window = defaultWindow, ignore = [], capture = true } = options;
28
+
29
+ if (!target) throw new RuntimeError('target元素不存在');
30
+ if (!window) throw new RuntimeError('找不到window');
31
+
32
+ /** 是否需要监听,为false时handler不会执行 */
33
+ let shouldListen = true;
34
+
35
+ /**
36
+ * 判断event的触发是否是在元素的外部(排除了ignore元素)
37
+ * @param event 事件对象
38
+ * @returns
39
+ */
40
+ const isOutside = (event: MouseEvent) => {
41
+ // 有一个判断是在内部,则不算外部,返回false
42
+ return ![target, ...ignore].some(el => {
43
+ return isEventInside(event, el);
44
+ });
45
+ };
46
+
47
+ /** 暂停,所有监听的回调都不执行,用于增强某些ignore无法实现的场景 */
48
+ let isPaused = false;
49
+ const pause = () => {
50
+ isPaused = true;
51
+ };
52
+ const proceed = () => {
53
+ isPaused = false;
54
+ };
55
+
56
+ /** pointerup延时触发标识 */
57
+ let fallback: number;
58
+
59
+ /**
60
+ * 事件监听处理回调
61
+ * @param event 事件对象
62
+ * @returns
63
+ */
64
+ const listener = (event: MouseEvent) => {
65
+ if (isPaused) return;
66
+ window.clearTimeout(fallback);
67
+
68
+ // 当需要监听并且最终触发在外部时才需要执行回调
69
+ if (!(shouldListen && isOutside(event))) return;
70
+
71
+ handler(event);
72
+ };
73
+
74
+ // 鼠标左键单击先后触发pointerdown,pointerup,click
75
+ // 鼠标右键单击先后触发pointerdown,pointerup
76
+ const cleanups = [
77
+ listenJSEvent(window, 'click', listener, { passive: true, capture }),
78
+ listenJSEvent(
79
+ window,
80
+ 'pointerdown',
81
+ e => {
82
+ if (isPaused) return;
83
+ // 当pointerdown是在内部触发则不需要后续监听
84
+ shouldListen = isOutside(e);
85
+ },
86
+ { passive: true },
87
+ ),
88
+ listenJSEvent(
89
+ window,
90
+ 'pointerup',
91
+ e => {
92
+ if (isPaused) return;
93
+ // 鼠标左键触发才执行
94
+ if (e.button === 0) {
95
+ // 锁死结果避免延时执行时变更
96
+ const path = eventPath(e);
97
+ e.composedPath = () => path;
98
+ fallback = window.setTimeout(() => listener(e), 50);
99
+ }
100
+ },
101
+ { passive: true },
102
+ ),
103
+ ].filter(Boolean);
104
+
105
+ /**
106
+ * 停止事件监听,移除监听
107
+ */
108
+ const stop = () => cleanups.forEach(fn => fn());
109
+ return { stop, pause, proceed };
110
+ }
@@ -0,0 +1,77 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import { NOOP } from '../../constant';
4
+
5
+ /**
6
+ * 计算event的composedPath返回事件路径(兼容了IE)
7
+ *
8
+ * @author lxm
9
+ * @date 2022-10-28 17:10:14
10
+ * @param {MouseEvent} event
11
+ * @returns {*}
12
+ */
13
+ export function eventPath(event: MouseEvent): (EventTarget | null)[] {
14
+ const path = ((event.composedPath && event.composedPath()) ||
15
+ (event as any).path) as HTMLElement[] | undefined;
16
+
17
+ if (path != null) return path;
18
+
19
+ // 浏览器没有提供的,自己递归计算
20
+ function getParents(
21
+ node: HTMLElement,
22
+ memo: HTMLElement[] = [],
23
+ ): HTMLElement[] {
24
+ const parentNode = node.parentNode as HTMLElement | null;
25
+
26
+ return parentNode
27
+ ? getParents(parentNode, memo.concat([parentNode]))
28
+ : memo;
29
+ }
30
+
31
+ return [event.target].concat(getParents(event.target as HTMLElement));
32
+ }
33
+
34
+ /**
35
+ * 监听JS原生事件,返回cleanup回调,调用后删除该监听
36
+ *
37
+ * @author lxm
38
+ * @date 2022-10-28 18:10:36
39
+ * @export
40
+ * @param {EventTarget} target 监听对象
41
+ * @param {string} eventName 监听事件名称
42
+ * @param {(..._args: any[]) => any} listener 监听回调
43
+ * @param {AddEventListenerOptions} options 额外参数
44
+ * @returns {*} {() => void}
45
+ */
46
+ export function listenJSEvent(
47
+ target: EventTarget,
48
+ eventName: string,
49
+ listener: (..._args: any[]) => any,
50
+ options: AddEventListenerOptions = {},
51
+ ): () => void {
52
+ target.addEventListener(eventName, listener, options);
53
+
54
+ let cleanup = () => {
55
+ target.removeEventListener(eventName, listener, options);
56
+ // cleanup方法只能调用一次
57
+ cleanup = NOOP;
58
+ };
59
+
60
+ return () => {
61
+ cleanup();
62
+ };
63
+ }
64
+
65
+ /**
66
+ * event是否是在目标元素内部触发的
67
+ *
68
+ * @author lxm
69
+ * @date 2022-10-31 11:10:49
70
+ * @export
71
+ * @param {MouseEvent} event 原生事件
72
+ * @param {HTMLElement} el 目标元素
73
+ * @returns {*} {boolean}
74
+ */
75
+ export function isEventInside(event: MouseEvent, el: HTMLElement): boolean {
76
+ return el && (event.target === el || eventPath(event).includes(el));
77
+ }
@@ -1,6 +1,10 @@
1
- export { Interceptor } from './interceptor/interceptor';
1
+ export * from './interceptor';
2
+ export { Logger } from './logger/logger';
2
3
  export { Namespace } from './namespace/namespace';
3
4
  export { IHttpResponse, HttpResponse } from './net/http-response';
4
5
  export { Net } from './net/net';
5
6
  export { plural, pluralLower } from './plural/plural';
6
7
  export * from './util/util';
8
+ export * from './url-helper/url-helper';
9
+ export * from './event/event';
10
+ export * from './click-outside/click-outside';
@@ -0,0 +1,35 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { getToken } from '../util/util';
3
+ import { Interceptor } from './interceptor';
4
+
5
+ /**
6
+ * 核心包拦截器
7
+ *
8
+ * @author lxm
9
+ * @date 2022-10-27 17:10:48
10
+ * @export
11
+ * @class CoreInterceptor
12
+ * @extends {Interceptor}
13
+ */
14
+ export class CoreInterceptor extends Interceptor {
15
+ protected async onBeforeRequest(
16
+ config: AxiosRequestConfig,
17
+ ): Promise<AxiosRequestConfig> {
18
+ await super.onBeforeRequest(config);
19
+
20
+ if (!config.headers) {
21
+ config.headers = {};
22
+ }
23
+ config.headers.Authorization = `Bearer ${getToken()}`;
24
+ const { orgData } = ibiz;
25
+ if (orgData) {
26
+ if (orgData.systemid) {
27
+ config.headers.srfsystemid = orgData.systemid;
28
+ }
29
+ if (orgData.orgid) {
30
+ config.headers.srforgid = orgData.orgid;
31
+ }
32
+ }
33
+ return config;
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from './core-interceptor';
2
+ export * from './interceptor';
@@ -1,8 +1,8 @@
1
- import axios from 'axios';
2
- import { getToken } from '../util/util';
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
3
3
 
4
4
  /**
5
- * 默认请求拦截器
5
+ * 拦截器基类
6
6
  *
7
7
  * @author chitanda
8
8
  * @date 2022-07-20 18:07:11
@@ -10,26 +10,113 @@ import { getToken } from '../util/util';
10
10
  * @class Interceptor
11
11
  */
12
12
  export class Interceptor {
13
- constructor() {
14
- this.init();
13
+ /**
14
+ * 请求拦截器绑定标识
15
+ *
16
+ * @author lxm
17
+ * @date 2022-10-27 17:10:20
18
+ * @private
19
+ * @type {number}
20
+ */
21
+ private requestTag?: number;
22
+
23
+ /**
24
+ * 响应拦截器绑定标识
25
+ *
26
+ * @author lxm
27
+ * @date 2022-10-27 17:10:19
28
+ * @private
29
+ * @type {number}
30
+ */
31
+ private responseTag?: number;
32
+
33
+ /**
34
+ * 请求之前处理
35
+ *
36
+ * @author lxm
37
+ * @date 2022-10-27 17:10:41
38
+ * @protected
39
+ * @param {AxiosRequestConfig} config
40
+ * @returns {*} {Promise<AxiosRequestConfig>}
41
+ */
42
+ protected async onBeforeRequest(
43
+ config: AxiosRequestConfig,
44
+ ): Promise<AxiosRequestConfig> {
45
+ return config;
46
+ }
47
+
48
+ /**
49
+ * 请求失败之后处理
50
+ *
51
+ * @author lxm
52
+ * @date 2022-10-27 17:10:40
53
+ * @protected
54
+ * @param {*} error
55
+ */
56
+ protected onRequestError(error: any) {
57
+ // 处理请求错误
58
+ return Promise.reject(error);
59
+ }
60
+
61
+ /**
62
+ * 响应成功之后处理
63
+ *
64
+ * @author lxm
65
+ * @date 2022-10-27 17:10:38
66
+ * @protected
67
+ * @param {AxiosResponse} config
68
+ * @returns {*} {Promise<AxiosRequestConfig>}
69
+ */
70
+ protected async onResponseSuccess(
71
+ config: AxiosResponse,
72
+ ): Promise<AxiosResponse> {
73
+ return config;
74
+ }
75
+
76
+ /**
77
+ * 响应失败之后处理
78
+ *
79
+ * @author lxm
80
+ * @date 2022-10-27 17:10:37
81
+ * @protected
82
+ * @param {*} _error
83
+ */
84
+ protected onResponseError(error: any) {
85
+ // 处理响应错误
86
+ return Promise.reject(error);
87
+ }
88
+
89
+ /**
90
+ * 使用拦截器
91
+ *
92
+ * @author lxm
93
+ * @date 2022-10-27 17:10:28
94
+ * @param {AxiosInstance} instance
95
+ */
96
+ use(instance: AxiosInstance): void {
97
+ this.requestTag = instance.interceptors.request.use(
98
+ this.onBeforeRequest,
99
+ this.onRequestError,
100
+ );
101
+ this.responseTag = instance.interceptors.response.use(
102
+ this.onResponseSuccess,
103
+ this.onResponseError,
104
+ );
15
105
  }
16
106
 
17
- protected init(): void {
18
- axios.interceptors.request.use(config => {
19
- if (!config.headers) {
20
- config.headers = {};
21
- }
22
- config.headers.Authorization = `Bearer ${getToken()}`;
23
- const { orgData } = ibiz;
24
- if (orgData) {
25
- if (orgData.systemid) {
26
- config.headers.srfsystemid = orgData.systemid;
27
- }
28
- if (orgData.orgid) {
29
- config.headers.srforgid = orgData.orgid;
30
- }
31
- }
32
- return config;
33
- });
107
+ /**
108
+ * 移出拦截器
109
+ *
110
+ * @author lxm
111
+ * @date 2022-10-27 17:10:27
112
+ * @param {AxiosInstance} instance
113
+ */
114
+ eject(instance: AxiosInstance) {
115
+ if (this.requestTag) {
116
+ instance.interceptors.request.eject(this.requestTag);
117
+ }
118
+ if (this.responseTag) {
119
+ instance.interceptors.response.eject(this.responseTag);
120
+ }
34
121
  }
35
122
  }
@@ -0,0 +1,3 @@
1
+ import * as Logger from 'loglevel';
2
+
3
+ export { Logger };
@@ -28,7 +28,7 @@ export interface IHttpResponse<T = IData> extends AxiosResponse {
28
28
  * @date 2022-08-18 15:08:44
29
29
  * @type {boolean}
30
30
  */
31
- local?: boolean;
31
+ local: boolean;
32
32
 
33
33
  data: T;
34
34
 
@@ -75,14 +75,11 @@ export class HttpResponse<T = IData> implements IHttpResponse<T> {
75
75
 
76
76
  statusText: string;
77
77
 
78
- /**
79
- * header 本地仿造时值为空
80
- *
81
- * @author chitanda
82
- * @date 2022-08-18 15:08:46
83
- * @type {AxiosResponseHeaders}
84
- */
85
- headers: AxiosResponseHeaders = {};
78
+ headers:
79
+ | AxiosResponseHeaders
80
+ | Partial<
81
+ Record<string, string> & { 'set-cookie'?: string[] | undefined }
82
+ > = {};
86
83
 
87
84
  /**
88
85
  * AxiosResponse 本地仿造时值为空