@ibiz-template/core 0.7.41-alpha.12 → 0.7.41-alpha.138

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 (200) hide show
  1. package/dist/index.esm.js +94 -23
  2. package/dist/index.system.min.js +1 -1
  3. package/out/environment/environment.d.ts.map +1 -1
  4. package/out/environment/environment.js +10 -0
  5. package/out/error/http-error/http-error-factory.d.ts +1 -1
  6. package/out/error/http-error/http-error-factory.d.ts.map +1 -1
  7. package/out/error/http-error/http-error-factory.js +11 -1
  8. package/out/error/http-error/http-error.d.ts +2 -2
  9. package/out/error/http-error/http-error.d.ts.map +1 -1
  10. package/out/interface/api/chat-message/i-api-chat-message.d.ts +63 -0
  11. package/out/interface/api/chat-message/i-api-chat-message.d.ts.map +1 -0
  12. package/out/interface/api/chat-message/i-api-chat-message.js +1 -0
  13. package/out/interface/api/chat-message/index.d.ts +2 -0
  14. package/out/interface/api/chat-message/index.d.ts.map +1 -0
  15. package/out/interface/api/chat-message/index.js +1 -0
  16. package/out/interface/api/environment/i-devtool-config.d.ts +29 -1
  17. package/out/interface/api/environment/i-devtool-config.d.ts.map +1 -1
  18. package/out/interface/api/environment/i-environment.d.ts +146 -1
  19. package/out/interface/api/environment/i-environment.d.ts.map +1 -1
  20. package/out/interface/api/ibizsys/i-app-data.d.ts +57 -0
  21. package/out/interface/api/ibizsys/i-app-data.d.ts.map +1 -0
  22. package/out/interface/api/ibizsys/i-app-data.js +1 -0
  23. package/out/interface/api/ibizsys/i-org-data.d.ts +1 -1
  24. package/out/interface/api/ibizsys/index.d.ts +1 -0
  25. package/out/interface/api/ibizsys/index.d.ts.map +1 -1
  26. package/out/interface/api/index.d.ts +1 -0
  27. package/out/interface/api/index.d.ts.map +1 -1
  28. package/out/interface/api/index.js +1 -0
  29. package/out/interface/api/utils/i-api-i18n.d.ts +9 -9
  30. package/out/interface/api/utils/index.d.ts +1 -0
  31. package/out/interface/api/utils/index.d.ts.map +1 -1
  32. package/out/interface/api/utils/message-center/base/i-message-base.d.ts +3 -3
  33. package/out/interface/api/utils/message-center/command/add-in-changed/i-command-add-in-changed.d.ts +1 -1
  34. package/out/interface/api/utils/message-center/command/async-action/i-command-async-action.d.ts +1 -1
  35. package/out/interface/api/utils/message-center/command/i-message-command.d.ts +1 -1
  36. package/out/interface/api/utils/message-center/command/internal-message/i-command-internal-message.d.ts +1 -1
  37. package/out/interface/api/utils/message-center/command/mark-open-data/i-command-mark-open-data.d.ts +1 -1
  38. package/out/interface/api/utils/message-center/common/i-message-center-event.d.ts +5 -0
  39. package/out/interface/api/utils/message-center/common/i-message-center-event.d.ts.map +1 -1
  40. package/out/interface/api/utils/message-center/common/i-portal-message.d.ts +3 -3
  41. package/out/interface/api/utils/message-center/console/i-message-console.d.ts +1 -1
  42. package/out/interface/api/utils/message-center/error/i-message-error.d.ts +1 -1
  43. package/out/interface/api/utils/message-center/i-message-center.d.ts +2 -2
  44. package/out/interface/api/utils/net/i-api-http-error.d.ts +39 -0
  45. package/out/interface/api/utils/net/i-api-http-error.d.ts.map +1 -0
  46. package/out/interface/api/utils/net/i-api-http-error.js +1 -0
  47. package/out/interface/api/utils/net/i-api-net.d.ts +1 -1
  48. package/out/interface/i-chat-message/i-chat-message.d.ts +2 -49
  49. package/out/interface/i-chat-message/i-chat-message.d.ts.map +1 -1
  50. package/out/utils/download-file/download-file.d.ts.map +1 -1
  51. package/out/utils/download-file/download-file.js +5 -1
  52. package/out/utils/interceptor/core-interceptor.js +2 -1
  53. package/out/utils/net/http-response.d.ts +2 -1
  54. package/out/utils/net/http-response.d.ts.map +1 -1
  55. package/out/utils/net/http-response.js +5 -1
  56. package/out/utils/net/net.d.ts +1 -1
  57. package/out/utils/net/net.d.ts.map +1 -1
  58. package/out/utils/net/net.js +16 -6
  59. package/out/utils/recursive/find-recursive-child.d.ts +20 -0
  60. package/out/utils/recursive/find-recursive-child.d.ts.map +1 -1
  61. package/out/utils/recursive/find-recursive-child.js +69 -7
  62. package/out/utils/string-util/string-util.d.ts.map +1 -1
  63. package/out/utils/string-util/string-util.js +2 -4
  64. package/package.json +5 -4
  65. package/src/command/command-register.ts +121 -0
  66. package/src/command/command.ts +78 -0
  67. package/src/command/index.ts +8 -0
  68. package/src/command/utils/index.ts +2 -0
  69. package/src/command/utils/linked-list.ts +136 -0
  70. package/src/command/utils/util.ts +103 -0
  71. package/src/constant/core/core.ts +54 -0
  72. package/src/constant/emoji/emoji.ts +2929 -0
  73. package/src/constant/http-status-message/http-status-message.ts +18 -0
  74. package/src/constant/index.ts +4 -0
  75. package/src/constant/util/util.ts +3 -0
  76. package/src/context/index.ts +231 -0
  77. package/src/environment/environment.ts +67 -0
  78. package/src/error/http-error/entity-error.ts +29 -0
  79. package/src/error/http-error/http-error-factory.ts +33 -0
  80. package/src/error/http-error/http-error.ts +52 -0
  81. package/src/error/index.ts +7 -0
  82. package/src/error/model-error/model-error.ts +27 -0
  83. package/src/error/notice-error/notice-error.ts +16 -0
  84. package/src/error/runtime-error/runtime-error.ts +13 -0
  85. package/src/error/runtime-model-error/runtime-model-error.ts +27 -0
  86. package/src/ibizsys.ts +82 -0
  87. package/src/index.ts +14 -0
  88. package/src/install.ts +12 -0
  89. package/src/interface/api/chat-message/i-api-chat-message.ts +71 -0
  90. package/src/interface/api/chat-message/index.ts +1 -0
  91. package/src/interface/api/constant/index.ts +2 -0
  92. package/src/interface/api/constant/login-mode/login-mode.ts +25 -0
  93. package/src/interface/api/constant/menu-permission-mode/menu-permission-mode.ts +20 -0
  94. package/src/interface/api/environment/i-devtool-config.ts +76 -0
  95. package/src/interface/api/environment/i-environment.ts +532 -0
  96. package/src/interface/api/environment/index.ts +2 -0
  97. package/src/interface/api/global-param/i-api-context.ts +37 -0
  98. package/src/interface/api/global-param/i-global-param.ts +27 -0
  99. package/src/interface/api/global-param/index.ts +2 -0
  100. package/src/interface/api/ibizsys/i-api-ibizsys.ts +54 -0
  101. package/src/interface/api/ibizsys/i-app-data.ts +64 -0
  102. package/src/interface/api/ibizsys/i-org-data.ts +31 -0
  103. package/src/interface/api/ibizsys/index.ts +3 -0
  104. package/src/interface/api/index.ts +6 -0
  105. package/src/interface/api/utils/i-api-i18n.ts +56 -0
  106. package/src/interface/api/utils/index.ts +5 -0
  107. package/src/interface/api/utils/message-center/base/i-message-all.ts +8 -0
  108. package/src/interface/api/utils/message-center/base/i-message-base.ts +29 -0
  109. package/src/interface/api/utils/message-center/base/index.ts +2 -0
  110. package/src/interface/api/utils/message-center/command/add-in-changed/i-add-in-changed.ts +25 -0
  111. package/src/interface/api/utils/message-center/command/add-in-changed/i-command-add-in-changed.ts +16 -0
  112. package/src/interface/api/utils/message-center/command/async-action/i-command-async-action.ts +17 -0
  113. package/src/interface/api/utils/message-center/command/change/i-command-change.ts +8 -0
  114. package/src/interface/api/utils/message-center/command/create/i-command-create.ts +18 -0
  115. package/src/interface/api/utils/message-center/command/i-command-base.ts +23 -0
  116. package/src/interface/api/utils/message-center/command/i-message-command.ts +94 -0
  117. package/src/interface/api/utils/message-center/command/index.ts +20 -0
  118. package/src/interface/api/utils/message-center/command/internal-message/i-command-internal-message.ts +17 -0
  119. package/src/interface/api/utils/message-center/command/internal-message/i-internal-message.ts +132 -0
  120. package/src/interface/api/utils/message-center/command/mark-open-data/i-command-mark-open-data.ts +17 -0
  121. package/src/interface/api/utils/message-center/command/mark-open-data/i-mark-open-data.ts +47 -0
  122. package/src/interface/api/utils/message-center/command/remove/i-command-remove.ts +18 -0
  123. package/src/interface/api/utils/message-center/command/update/i-command-update.ts +18 -0
  124. package/src/interface/api/utils/message-center/common/i-app-data-entity.ts +16 -0
  125. package/src/interface/api/utils/message-center/common/i-message-center-event.ts +15 -0
  126. package/src/interface/api/utils/message-center/common/i-msg-meta-data.ts +13 -0
  127. package/src/interface/api/utils/message-center/common/i-portal-async-action.ts +144 -0
  128. package/src/interface/api/utils/message-center/common/i-portal-message.ts +84 -0
  129. package/src/interface/api/utils/message-center/common/index.ts +5 -0
  130. package/src/interface/api/utils/message-center/console/i-message-console.ts +17 -0
  131. package/src/interface/api/utils/message-center/error/i-message-error.ts +17 -0
  132. package/src/interface/api/utils/message-center/i-message-center.ts +53 -0
  133. package/src/interface/api/utils/message-center/index.ts +6 -0
  134. package/src/interface/api/utils/net/i-api-http-error.ts +43 -0
  135. package/src/interface/api/utils/net/i-api-net.ts +93 -0
  136. package/src/interface/api/utils/net/i-http-response.ts +67 -0
  137. package/src/interface/click-outside/click-outside.ts +51 -0
  138. package/src/interface/command/command/i-command-option.ts +47 -0
  139. package/src/interface/command/command/i-command.ts +68 -0
  140. package/src/interface/command/disposable/i-disposable.ts +12 -0
  141. package/src/interface/command/i-command-controller.ts +50 -0
  142. package/src/interface/command/index.ts +11 -0
  143. package/src/interface/context/index.ts +42 -0
  144. package/src/interface/error/index.ts +13 -0
  145. package/src/interface/i-chat-message/i-chat-message.ts +16 -0
  146. package/src/interface/ibizsys/i-ibizsys.ts +33 -0
  147. package/src/interface/ibizsys/index.ts +1 -0
  148. package/src/interface/index.ts +11 -0
  149. package/src/interface/utils/i-18n.ts +22 -0
  150. package/src/interface/utils/index.ts +1 -0
  151. package/src/locale/en/index.ts +30 -0
  152. package/src/locale/index.ts +2 -0
  153. package/src/locale/zh-CN/index.ts +28 -0
  154. package/src/params/params.ts +131 -0
  155. package/src/types.ts +26 -0
  156. package/src/utils/bit-mask/bit-mask.ts +87 -0
  157. package/src/utils/click-outside/click-outside.ts +108 -0
  158. package/src/utils/clone/clone.ts +38 -0
  159. package/src/utils/color/color.ts +84 -0
  160. package/src/utils/cookie-util/cookie-util.ts +192 -0
  161. package/src/utils/data-type/data-types.ts +93 -0
  162. package/src/utils/download-file/download-file.ts +110 -0
  163. package/src/utils/event/event.ts +69 -0
  164. package/src/utils/history-list/history-item.ts +41 -0
  165. package/src/utils/history-list/history-list.ts +137 -0
  166. package/src/utils/index.ts +24 -0
  167. package/src/utils/interceptor/core-interceptor.ts +127 -0
  168. package/src/utils/interceptor/index.ts +2 -0
  169. package/src/utils/interceptor/interceptor.ts +122 -0
  170. package/src/utils/logger/logger.ts +34 -0
  171. package/src/utils/message-center/base/message-all.ts +10 -0
  172. package/src/utils/message-center/base/message-base.ts +73 -0
  173. package/src/utils/message-center/command/add-in-changed/command-add-in-changed.ts +23 -0
  174. package/src/utils/message-center/command/async-action/command-async-action.ts +23 -0
  175. package/src/utils/message-center/command/change/command-change.ts +11 -0
  176. package/src/utils/message-center/command/command-base/command-base.ts +35 -0
  177. package/src/utils/message-center/command/create/command-create.ts +25 -0
  178. package/src/utils/message-center/command/internal-message/command-internal-message.ts +26 -0
  179. package/src/utils/message-center/command/mark-open-data/command-mark-open-data.ts +23 -0
  180. package/src/utils/message-center/command/message-command.ts +162 -0
  181. package/src/utils/message-center/command/remove/command-remove.ts +25 -0
  182. package/src/utils/message-center/command/update/command-update.ts +25 -0
  183. package/src/utils/message-center/console/message-console.ts +27 -0
  184. package/src/utils/message-center/error/message-error.ts +27 -0
  185. package/src/utils/message-center/index.ts +1 -0
  186. package/src/utils/message-center/message-center.ts +77 -0
  187. package/src/utils/namespace/namespace.ts +217 -0
  188. package/src/utils/net/http-response.ts +60 -0
  189. package/src/utils/net/net.ts +463 -0
  190. package/src/utils/recursive/find-recursive-child.ts +238 -0
  191. package/src/utils/string-util/string-util.ts +76 -0
  192. package/src/utils/style/remote-style.ts +17 -0
  193. package/src/utils/sync/await-timeout.ts +29 -0
  194. package/src/utils/sync/count-latch.ts +79 -0
  195. package/src/utils/sync/index.ts +2 -0
  196. package/src/utils/types/types.ts +24 -0
  197. package/src/utils/upload/select-file.ts +93 -0
  198. package/src/utils/upload/upload-file.ts +194 -0
  199. package/src/utils/url-helper/url-helper.ts +52 -0
  200. package/src/utils/util/util.ts +580 -0
@@ -0,0 +1,137 @@
1
+ import { clone } from 'ramda';
2
+ import { HistoryItem } from './history-item';
3
+
4
+ /**
5
+ * @description 数据对象历史记录,只支持纯对象形式的数据。并未支持数组
6
+ * @export
7
+ * @class HistoryList
8
+ * @template E
9
+ */
10
+ export class HistoryList<E = IData> {
11
+ /**
12
+ * @description 当前步骤的历史记录
13
+ * @private
14
+ * @type {HistoryItem<E>}
15
+ * @memberof HistoryList
16
+ */
17
+ private _cur: HistoryItem<E>;
18
+
19
+ /**
20
+ * @description 当前的数据
21
+ * @readonly
22
+ * @type {E}
23
+ * @memberof HistoryList
24
+ */
25
+ get data(): E {
26
+ return this._cur.data;
27
+ }
28
+
29
+ /**
30
+ * Creates an instance of HistoryList.
31
+ * @param {E} data
32
+ * @memberof HistoryList
33
+ */
34
+ constructor(data: E) {
35
+ this._cur = new HistoryItem<E>(data);
36
+ }
37
+
38
+ /**
39
+ * @description 先创建一次历史记录,再赋值
40
+ * @param {IData} data
41
+ * @memberof HistoryList
42
+ */
43
+ assign(data: IData): void {
44
+ if (data) {
45
+ this.save();
46
+ Object.assign(this._cur.data!, data);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * @description 创建一次历史记录
52
+ * @memberof HistoryList
53
+ */
54
+ save(): void {
55
+ const oldCur = this._cur;
56
+ // 克隆当前数据对象
57
+ const data = clone(oldCur.data);
58
+ // 新的历史对象
59
+ const history = new HistoryItem<E>(data);
60
+ // 设置新历史的上一次历史为当前历史
61
+ history._prev = oldCur;
62
+ // 将下一步的前一步置空,断开引用
63
+ oldCur._next._prev = HistoryItem.Undefined;
64
+ // 清空下一步的所有引用
65
+ this._clear(oldCur._next);
66
+ // 设置当前历史的下一次历史为新历史,如果有旧的前进步骤就干掉了
67
+ oldCur._next = history;
68
+ // 设置新历史为新历史对象
69
+ this._cur = history;
70
+ }
71
+
72
+ /**
73
+ * @description 上一步
74
+ * @returns {*} {boolean}
75
+ * @memberof HistoryList
76
+ */
77
+ prev(): boolean {
78
+ if (this._cur._prev && this._cur._prev !== HistoryItem.Undefined) {
79
+ this._cur = this._cur._prev;
80
+ return true;
81
+ }
82
+ return false;
83
+ }
84
+
85
+ /**
86
+ * @description 下一步
87
+ * @returns {*} {boolean}
88
+ * @memberof HistoryList
89
+ */
90
+ next(): boolean {
91
+ if (this._cur._next && this._cur._next !== HistoryItem.Undefined) {
92
+ this._cur = this._cur._next;
93
+ return true;
94
+ }
95
+ return false;
96
+ }
97
+
98
+ /**
99
+ * @description 清空引用,避免内存泄漏
100
+ * @protected
101
+ * @param {HistoryItem<E>} h
102
+ * @memberof HistoryList
103
+ */
104
+ protected _clear(h: HistoryItem<E>): void {
105
+ if (h._prev && h._prev !== HistoryItem.Undefined) {
106
+ h._prev._next = HistoryItem.Undefined;
107
+ this._clear(h._prev);
108
+ h._prev = HistoryItem.Undefined;
109
+ }
110
+ if (h._next && h._next !== HistoryItem.Undefined) {
111
+ h._next._prev = HistoryItem.Undefined;
112
+ this._clear(h._next);
113
+ h._next = HistoryItem.Undefined;
114
+ }
115
+ h.data = {} as E;
116
+ }
117
+
118
+ /**
119
+ * @description 禁止克隆,直接返回当前实例
120
+ * @protected
121
+ * @returns {*} {HistoryList<E>}
122
+ * @memberof HistoryList
123
+ */
124
+ protected clone(): HistoryList<E> {
125
+ const history = new HistoryList<E>({} as E);
126
+ history._cur = clone(this._cur);
127
+ return this;
128
+ }
129
+
130
+ /**
131
+ * @description 销毁
132
+ * @memberof HistoryList
133
+ */
134
+ destroy(): void {
135
+ this._clear(this._cur);
136
+ }
137
+ }
@@ -0,0 +1,24 @@
1
+ export * from './interceptor';
2
+ export { MessageCenter } from './message-center';
3
+ export { Namespace } from './namespace/namespace';
4
+ export { HttpResponse } from './net/http-response';
5
+ export { Net } from './net/net';
6
+ export { StringUtil } from './string-util/string-util';
7
+ export * from './util/util';
8
+ export * from './types/types';
9
+ export * from './url-helper/url-helper';
10
+ export * from './event/event';
11
+ export { HistoryItem } from './history-list/history-item';
12
+ export { HistoryList } from './history-list/history-list';
13
+ export * from './click-outside/click-outside';
14
+ export * from './color/color';
15
+ export * from './download-file/download-file';
16
+ export * from './upload/select-file';
17
+ export * from './upload/upload-file';
18
+ export * from './sync';
19
+ export * from './style/remote-style';
20
+ export * from './recursive/find-recursive-child';
21
+ export { DataTypes } from './data-type/data-types';
22
+ export * from './clone/clone';
23
+ export { BitMask } from './bit-mask/bit-mask';
24
+ export * from './cookie-util/cookie-util';
@@ -0,0 +1,127 @@
1
+ import { InternalAxiosRequestConfig } from 'axios';
2
+ import { getToken } from '../util/util';
3
+ import { Interceptor } from './interceptor';
4
+ import { getAppCookie } from '../cookie-util/cookie-util';
5
+ import { CoreConst } from '../../constant';
6
+
7
+ /**
8
+ * @description 核心包拦截器
9
+ * @export
10
+ * @class CoreInterceptor
11
+ * @extends {Interceptor}
12
+ */
13
+ export class CoreInterceptor extends Interceptor {
14
+ /**
15
+ * @description 请求之前处理
16
+ * @protected
17
+ * @param {InternalAxiosRequestConfig} config
18
+ * @returns {*} {Promise<InternalAxiosRequestConfig>}
19
+ * @memberof CoreInterceptor
20
+ */
21
+ protected async onBeforeRequest(
22
+ config: InternalAxiosRequestConfig,
23
+ ): Promise<InternalAxiosRequestConfig> {
24
+ config = await super.onBeforeRequest(config);
25
+
26
+ const { headers } = config;
27
+
28
+ // Set the access token.
29
+ const token = getToken();
30
+ if (token) {
31
+ headers.set(
32
+ `${ibiz.env.tokenHeader}Authorization`,
33
+ `${ibiz.env.tokenPrefix}Bearer ${token}`,
34
+ );
35
+ }
36
+
37
+ // Set the system ID.
38
+ let systemId = ibiz.env.dcSystem;
39
+ const { orgData } = ibiz;
40
+ if (orgData) {
41
+ if (orgData.systemid) {
42
+ systemId = orgData.systemid;
43
+ }
44
+ if (orgData.orgid) {
45
+ headers.set('srforgid', orgData.orgid);
46
+ }
47
+ }
48
+ headers.set('srfsystemid', systemId);
49
+
50
+ return config;
51
+ }
52
+
53
+ /**
54
+ * @description 响应失败之后处理
55
+ * @protected
56
+ * @param {Error} error
57
+ * @returns {*} {Promise<never>}
58
+ * @memberof CoreInterceptor
59
+ */
60
+ protected async onResponseError(error: Error): Promise<never> {
61
+ const { config, response } = error as IData;
62
+ if (
63
+ this.instance &&
64
+ response?.status === 401 &&
65
+ config &&
66
+ !config._retry &&
67
+ config.url &&
68
+ // 排除获取系统信息、应用数据、刷新 token 预定义接口
69
+ (config.url.indexOf('/uaa/getbydcsystem/') === -1 ||
70
+ config.url.indexOf('/appdata') !== -1 ||
71
+ config.url.indexOf('/uaa/refresh_token/') !== -1)
72
+ ) {
73
+ try {
74
+ // 标记为已重试
75
+ config._retry = true;
76
+ // 刷新 token(匿名登录通过登录换算token,非匿名登录通过refreshToken换算新的token)
77
+ if (ibiz.env.enableAnonymous) {
78
+ const authInfo = (ibiz as IData).auth.getAuthInfo();
79
+ const refreshToken = getAppCookie(CoreConst.REFRESH_TOKEN);
80
+ // 匿名登录、匿名登录无refreshToken情况通过登录换算token
81
+ if (authInfo.isAnonymous || !refreshToken) {
82
+ const tempOrgData = ibiz.orgData;
83
+ await (ibiz as IData).auth.anonymousLogin();
84
+ ibiz.orgData = tempOrgData;
85
+ } else {
86
+ await (ibiz as IData).auth.refreshToken();
87
+ }
88
+ } else {
89
+ await (ibiz as IData).auth.refreshToken();
90
+ }
91
+ // 重新加载应用数据
92
+ const res = await ibiz.net.get(
93
+ '/appdata',
94
+ (ibiz as IData).appUtil?.getAppContext(),
95
+ );
96
+ if (res && res.ok) {
97
+ ibiz.appData = res.data;
98
+ }
99
+ // 重新发起原始请求
100
+ const { headers } = config;
101
+ const token = getToken();
102
+ if (token) {
103
+ headers.set(
104
+ `${ibiz.env.tokenHeader}Authorization`,
105
+ `${ibiz.env.tokenPrefix}Bearer ${token}`,
106
+ );
107
+ }
108
+ let systemId = ibiz.env.dcSystem;
109
+ const { orgData } = ibiz;
110
+ if (orgData) {
111
+ if (orgData.systemid) {
112
+ systemId = orgData.systemid;
113
+ }
114
+ if (orgData.orgid) {
115
+ headers.set('srforgid', orgData.orgid);
116
+ }
117
+ }
118
+ headers.set('srfsystemid', systemId);
119
+ return this.instance(config);
120
+ } catch (err) {
121
+ return Promise.reject(error);
122
+ }
123
+ }
124
+ // 处理响应错误
125
+ return Promise.reject(error);
126
+ }
127
+ }
@@ -0,0 +1,2 @@
1
+ export * from './core-interceptor';
2
+ export * from './interceptor';
@@ -0,0 +1,122 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import {
3
+ AxiosInstance,
4
+ InternalAxiosRequestConfig,
5
+ AxiosResponse,
6
+ } from 'axios';
7
+
8
+ /**
9
+ * @description 拦截器基类
10
+ * @export
11
+ * @class Interceptor
12
+ */
13
+ export class Interceptor {
14
+ /**
15
+ * @description 请求拦截器绑定标识
16
+ * @private
17
+ * @type {number}
18
+ * @memberof Interceptor
19
+ */
20
+ private requestTag?: number;
21
+
22
+ /**
23
+ * @description 响应拦截器绑定标识
24
+ * @private
25
+ * @type {number}
26
+ * @memberof Interceptor
27
+ */
28
+ private responseTag?: number;
29
+
30
+ /**
31
+ * @description axios实例
32
+ * @protected
33
+ * @type {(AxiosInstance | undefined)}
34
+ * @memberof Interceptor
35
+ */
36
+ protected instance: AxiosInstance | undefined;
37
+
38
+ /**
39
+ * @description 请求之前处理
40
+ * @protected
41
+ * @param {InternalAxiosRequestConfig} config
42
+ * @returns {*} {Promise<InternalAxiosRequestConfig>}
43
+ * @memberof Interceptor
44
+ */
45
+ protected async onBeforeRequest(
46
+ config: InternalAxiosRequestConfig,
47
+ ): Promise<InternalAxiosRequestConfig> {
48
+ return config;
49
+ }
50
+
51
+ /**
52
+ * @description 请求失败之后处理
53
+ * @protected
54
+ * @param {Error} error
55
+ * @returns {*} {Promise<never>}
56
+ * @memberof Interceptor
57
+ */
58
+ protected onRequestError(error: Error): Promise<never> {
59
+ // 处理请求错误
60
+ return Promise.reject(error);
61
+ }
62
+
63
+ /**
64
+ * @description 响应成功之后处理
65
+ * @protected
66
+ * @param {AxiosResponse} config
67
+ * @returns {*} {Promise<AxiosResponse>}
68
+ * @memberof Interceptor
69
+ */
70
+ protected async onResponseSuccess(
71
+ config: AxiosResponse,
72
+ ): Promise<AxiosResponse> {
73
+ return config;
74
+ }
75
+
76
+ /**
77
+ * @description 响应失败之后处理
78
+ * @protected
79
+ * @param {Error} error
80
+ * @returns {*} {Promise<never>}
81
+ * @memberof Interceptor
82
+ */
83
+ protected onResponseError(error: Error): Promise<never> {
84
+ // 处理响应错误
85
+ return Promise.reject(error);
86
+ }
87
+
88
+ /**
89
+ * @description 使用拦截器
90
+ * @param {AxiosInstance} instance
91
+ * @memberof Interceptor
92
+ */
93
+ use(instance: AxiosInstance): void {
94
+ this.instance = instance;
95
+ this.onBeforeRequest = this.onBeforeRequest.bind(this);
96
+ this.onRequestError = this.onRequestError.bind(this);
97
+ this.onResponseSuccess = this.onResponseSuccess.bind(this);
98
+ this.onResponseError = this.onResponseError.bind(this);
99
+ this.requestTag = instance.interceptors.request.use(
100
+ this.onBeforeRequest,
101
+ this.onRequestError,
102
+ );
103
+ this.responseTag = instance.interceptors.response.use(
104
+ this.onResponseSuccess,
105
+ this.onResponseError,
106
+ );
107
+ }
108
+
109
+ /**
110
+ * @description 移出拦截器
111
+ * @param {AxiosInstance} instance
112
+ * @memberof Interceptor
113
+ */
114
+ eject(instance: AxiosInstance): void {
115
+ if (this.requestTag) {
116
+ instance.interceptors.request.eject(this.requestTag);
117
+ }
118
+ if (this.responseTag) {
119
+ instance.interceptors.response.eject(this.responseTag);
120
+ }
121
+ }
122
+ }
@@ -0,0 +1,34 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
3
+ import Logger from 'loglevel';
4
+ import prefix from 'loglevel-plugin-prefix';
5
+
6
+ // 重写 methodFactory
7
+ const originalFactory = Logger.methodFactory;
8
+ const NOOP = (message: string) => {};
9
+ Logger.methodFactory = (methodName, logLevel, loggerName) => {
10
+ const rawMethod = originalFactory(methodName, logLevel, loggerName);
11
+ if (window.Environment?.environmentTag === 'production') {
12
+ if (
13
+ methodName === 'error' ||
14
+ methodName === 'warn' ||
15
+ methodName === 'debug'
16
+ ) {
17
+ return NOOP;
18
+ }
19
+ }
20
+ if (window.Environment?.environmentTag === 'test') {
21
+ if (methodName === 'error' || methodName === 'warn') {
22
+ return NOOP;
23
+ }
24
+ }
25
+ return rawMethod;
26
+ };
27
+
28
+ const logger = Logger.noConflict();
29
+
30
+ prefix.reg(logger);
31
+
32
+ prefix.apply(logger);
33
+
34
+ export { logger };
@@ -0,0 +1,10 @@
1
+ import { IMessageAll } from '../../../interface';
2
+ import { MessageBase } from './message-base';
3
+
4
+ /**
5
+ * @description 所有消息控制器
6
+ * @export
7
+ * @class MessageAll
8
+ * @extends {MessageBase}
9
+ */
10
+ export class MessageAll extends MessageBase implements IMessageAll {}
@@ -0,0 +1,73 @@
1
+ import { QXEvent } from 'qx-util';
2
+ import {
3
+ IMessageBase,
4
+ IMessageCenterEvent,
5
+ IPortalMessage,
6
+ } from '../../../interface';
7
+
8
+ /**
9
+ * @description 消息基类控制器,各个类型消息继承此类
10
+ * @export
11
+ * @abstract
12
+ * @class MessageBase
13
+ * @implements {IMessageBase}
14
+ */
15
+ export abstract class MessageBase implements IMessageBase {
16
+ /**
17
+ * @description 事件对象
18
+ * @protected
19
+ * @type {QXEvent<IMessageCenterEvent>}
20
+ * @memberof MessageBase
21
+ */
22
+ protected evt: QXEvent<IMessageCenterEvent> = new QXEvent(1000);
23
+
24
+ /**
25
+ * Creates an instance of MessageBase.
26
+ * @param {MessageBase} [parent]
27
+ * @memberof MessageBase
28
+ */
29
+ constructor(protected parent?: MessageBase) {}
30
+
31
+ /**
32
+ * @description 推送标准结构消息
33
+ * @param {IPortalMessage} msg
34
+ * @memberof MessageBase
35
+ */
36
+ next(msg: IPortalMessage): void {
37
+ this.evt.emit('all', msg);
38
+ if (this.parent) {
39
+ this.nextParent(msg);
40
+ }
41
+ }
42
+
43
+ /**
44
+ * @description 向父级推送消息(私有方法)
45
+ * @protected
46
+ * @param {IPortalMessage} msg
47
+ * @memberof MessageBase
48
+ */
49
+ protected nextParent(msg: IPortalMessage): void {
50
+ if (this.parent) {
51
+ this.parent.evt.emit('all', msg);
52
+ this.parent.nextParent(msg);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * @description 订阅消息
58
+ * @param {(msg: IPortalMessage) => void} cb
59
+ * @memberof MessageBase
60
+ */
61
+ on(cb: (msg: IPortalMessage) => void): void {
62
+ this.evt.on('all', cb);
63
+ }
64
+
65
+ /**
66
+ * @description 取消订阅消息
67
+ * @param {(msg: IPortalMessage) => void} cb
68
+ * @memberof MessageBase
69
+ */
70
+ off(cb: (msg: IPortalMessage) => void): void {
71
+ this.evt.off('all', cb);
72
+ }
73
+ }
@@ -0,0 +1,23 @@
1
+ import { IAddInChanged, ICommandAddInChanged } from '../../../../interface';
2
+ import { CommandBase } from '../command-base/command-base';
3
+
4
+ /**
5
+ * @description 添加变更指令消息控制器
6
+ * @export
7
+ * @class CommandAddInChanged
8
+ * @extends {CommandBase}
9
+ * @implements {ICommandAddInChanged}
10
+ */
11
+ export class CommandAddInChanged
12
+ extends CommandBase
13
+ implements ICommandAddInChanged
14
+ {
15
+ /**
16
+ * @description 发送消息
17
+ * @param {IAddInChanged} data
18
+ * @memberof CommandAddInChanged
19
+ */
20
+ send(data: IAddInChanged): void {
21
+ this.sendCommand(data, 'ADDINCHANGED');
22
+ }
23
+ }
@@ -0,0 +1,23 @@
1
+ import { ICommandAsyncAction, IPortalAsyncAction } from '../../../../interface';
2
+ import { CommandBase } from '../command-base/command-base';
3
+
4
+ /**
5
+ * @description 异步作业指令消息控制器
6
+ * @export
7
+ * @class CommandAsyncAction
8
+ * @extends {CommandBase}
9
+ * @implements {ICommandAsyncAction}
10
+ */
11
+ export class CommandAsyncAction
12
+ extends CommandBase
13
+ implements ICommandAsyncAction
14
+ {
15
+ /**
16
+ * @description 发送消息
17
+ * @param {IPortalAsyncAction} data
18
+ * @memberof CommandAsyncAction
19
+ */
20
+ send(data: IPortalAsyncAction): void {
21
+ this.sendCommand(data, 'ASYNCACTION');
22
+ }
23
+ }
@@ -0,0 +1,11 @@
1
+ import { ICommandChange } from '../../../../interface';
2
+ import { CommandBase } from '../command-base/command-base';
3
+
4
+ /**
5
+ * @description 数据变更指令消息控制器
6
+ * @export
7
+ * @class CommandChange
8
+ * @extends {CommandBase}
9
+ * @implements {ICommandChange}
10
+ */
11
+ export class CommandChange extends CommandBase implements ICommandChange {}
@@ -0,0 +1,35 @@
1
+ import { createUUID } from 'qx-util';
2
+ import { ICommandBase, IPortalMessage } from '../../../../interface';
3
+ import { MessageBase } from '../../base/message-base';
4
+
5
+ /**
6
+ * @description 指令消息基类控制器
7
+ * @export
8
+ * @class CommandBase
9
+ * @extends {MessageBase}
10
+ * @implements {ICommandBase}
11
+ */
12
+ export class CommandBase extends MessageBase implements ICommandBase {
13
+ /**
14
+ * @description 发送指令消息
15
+ * @param {IData} data
16
+ * @param {IPortalMessage['subtype']} subtype
17
+ * @param {string} [triggerKey]
18
+ * @memberof CommandBase
19
+ */
20
+ sendCommand(
21
+ data: IData,
22
+ subtype: IPortalMessage['subtype'],
23
+ triggerKey?: string,
24
+ ): void {
25
+ const msg: IPortalMessage = {
26
+ messageid: createUUID(),
27
+ messagename: 'command',
28
+ type: 'COMMAND',
29
+ subtype,
30
+ triggerKey,
31
+ data,
32
+ };
33
+ this.next(msg);
34
+ }
35
+ }
@@ -0,0 +1,25 @@
1
+ import {
2
+ IAppDataEntity,
3
+ ICommandCreate,
4
+ IMsgMetaData,
5
+ } from '../../../../interface';
6
+ import { CommandBase } from '../command-base/command-base';
7
+
8
+ /**
9
+ * @description 创建指令消息控制器
10
+ * @export
11
+ * @class CommandCreate
12
+ * @extends {CommandBase}
13
+ * @implements {ICommandCreate}
14
+ */
15
+ export class CommandCreate extends CommandBase implements ICommandCreate {
16
+ /**
17
+ * @description 发送消息
18
+ * @param {IAppDataEntity} data
19
+ * @param {IMsgMetaData} [meta]
20
+ * @memberof CommandCreate
21
+ */
22
+ send(data: IAppDataEntity, meta?: IMsgMetaData): void {
23
+ this.sendCommand(data, 'OBJECTCREATED', meta?.triggerKey);
24
+ }
25
+ }
@@ -0,0 +1,26 @@
1
+ import {
2
+ ICommandInternalMessage,
3
+ IInternalMessage,
4
+ } from '../../../../interface';
5
+ import { CommandBase } from '../command-base/command-base';
6
+
7
+ /**
8
+ * @description 站内信指令消息控制器
9
+ * @export
10
+ * @class CommandInternalMessage
11
+ * @extends {CommandBase}
12
+ * @implements {ICommandInternalMessage}
13
+ */
14
+ export class CommandInternalMessage
15
+ extends CommandBase
16
+ implements ICommandInternalMessage
17
+ {
18
+ /**
19
+ * @description 发送消息
20
+ * @param {IInternalMessage} data
21
+ * @memberof CommandInternalMessage
22
+ */
23
+ send(data: IInternalMessage): void {
24
+ this.sendCommand(data, 'INTERNALMESSAGE');
25
+ }
26
+ }