@gct-paas/core 0.1.4-dev.11 → 0.1.4-dev.12

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 (130) hide show
  1. package/dist/index.esm.min.js +21679 -0
  2. package/es/constants/core.mjs +5 -4
  3. package/es/constants/default-date-type/default-date-type.mjs +73 -21
  4. package/es/constants/editor-register/editor-register.mjs +17 -5
  5. package/es/constants/expression-type/BuiltOperators.mjs +152 -147
  6. package/es/constants/expression-type/FunctionKeys.mjs +75 -79
  7. package/es/constants/expression-type/editor.mjs +10 -3
  8. package/es/constants/expression-type/function.mjs +602 -613
  9. package/es/constants/expression-type/index.mjs +111 -113
  10. package/es/constants/expression-type/modeCfg.mjs +256 -263
  11. package/es/constants/expression-type/variable.mjs +43 -39
  12. package/es/constants/form-container-type/form-container-type.mjs +17 -5
  13. package/es/constants/index.mjs +30 -10
  14. package/es/constants/page-designer/model.mjs +15 -5
  15. package/es/create-app-vue.mjs +15 -9
  16. package/es/enums/app-designer/index.d.ts +19 -0
  17. package/es/enums/app-designer/index.mjs +131 -63
  18. package/es/enums/appEnum.mjs +681 -360
  19. package/es/enums/appStateEnum.mjs +17 -10
  20. package/es/enums/authActionEnum.mjs +63 -51
  21. package/es/enums/breakpointEnum.mjs +27 -26
  22. package/es/enums/cacheEnum.mjs +22 -21
  23. package/es/enums/designEnum.mjs +110 -71
  24. package/es/enums/developer-center/integration.mjs +7 -6
  25. package/es/enums/exceptionEnum.mjs +21 -17
  26. package/es/enums/expressionEnum.d.ts +1 -1
  27. package/es/enums/expressionEnum.mjs +81 -74
  28. package/es/enums/globalEnum.mjs +59 -36
  29. package/es/enums/httpEnum.mjs +71 -61
  30. package/es/enums/index.mjs +43 -14
  31. package/es/enums/menuEnum.mjs +42 -38
  32. package/es/enums/page-designer/designer.mjs +403 -407
  33. package/es/enums/page-designer/index.mjs +4 -0
  34. package/es/enums/page-designer/panel.mjs +341 -213
  35. package/es/enums/page-designer/toolkit.mjs +13 -12
  36. package/es/enums/page-designer/widget.mjs +425 -338
  37. package/es/enums/pageEnum.mjs +14 -13
  38. package/es/enums/plugin-enum.mjs +23 -7
  39. package/es/enums/processEnum.mjs +95 -60
  40. package/es/enums/roleEnum.mjs +7 -6
  41. package/es/enums/sizeEnum.d.ts +18 -0
  42. package/es/enums/sizeEnum.mjs +28 -8
  43. package/es/global/gct/gct.mjs +84 -96
  44. package/es/global/index.mjs +1 -0
  45. package/es/hooks/index.mjs +4 -0
  46. package/es/hooks/use-app-inst/use-app-inst.mjs +11 -5
  47. package/es/hooks/use-modal/use-modal.mjs +16 -10
  48. package/es/hooks/use-sub-app-utils/use-sub-app-utils.mjs +43 -23
  49. package/es/hooks/useCopyToClipboard.mjs +50 -50
  50. package/es/index.mjs +122 -114
  51. package/es/locale/index.mjs +43 -57
  52. package/es/modules/env-manager/env-manager.const.mjs +16 -8
  53. package/es/modules/env-manager/env-manager.interface.mjs +14 -7
  54. package/es/modules/env-manager/env-manager.mjs +104 -107
  55. package/es/modules/error-handler/error-handler.const.mjs +11 -16
  56. package/es/modules/error-handler/error-strategy.mjs +199 -175
  57. package/es/modules/error-handler/index.mjs +120 -106
  58. package/es/modules/mqtt/constants/mqtt.const.mjs +21 -24
  59. package/es/modules/mqtt/enums/mqtt-status.enum.mjs +23 -9
  60. package/es/modules/mqtt/index.mjs +4 -0
  61. package/es/modules/mqtt/mqtt-client.mjs +228 -261
  62. package/es/modules/mqtt/mqtt-manager.mjs +117 -77
  63. package/es/modules/platform-config/constants/index.mjs +4 -0
  64. package/es/modules/platform-config/constants/login.const.mjs +48 -45
  65. package/es/modules/platform-config/constants/org.const.mjs +57 -52
  66. package/es/modules/platform-config/constants/theme.const.mjs +11 -4
  67. package/es/modules/platform-config/constants/watermark.const.mjs +17 -12
  68. package/es/modules/platform-config/enums/deploy.enum.mjs +13 -6
  69. package/es/modules/platform-config/enums/login.enum.mjs +29 -15
  70. package/es/modules/platform-config/enums/platform.enum.mjs +16 -13
  71. package/es/modules/platform-config/index.mjs +9 -0
  72. package/es/modules/platform-config/store.mjs +68 -79
  73. package/es/modules/platform-config/useBasicSetting.mjs +47 -35
  74. package/es/modules/platform-config/useDeploySetting.mjs +29 -21
  75. package/es/modules/platform-config/useLoginSetting.mjs +151 -173
  76. package/es/modules/platform-config/useOrgSetting.mjs +63 -62
  77. package/es/modules/platform-config/useProjectSetting.mjs +14 -6
  78. package/es/modules/platform-config/useSecuritySetting.mjs +68 -56
  79. package/es/modules/platform-config/useThemeSetting.mjs +78 -59
  80. package/es/modules/platform-config/useWatermarkSetting.mjs +37 -23
  81. package/es/modules/user-stores/index.mjs +3 -0
  82. package/es/modules/user-stores/store/permission.store.mjs +27 -36
  83. package/es/modules/user-stores/store/tenant.store.mjs +20 -22
  84. package/es/modules/user-stores/store/user.store.mjs +94 -117
  85. package/es/router/index.mjs +25 -28
  86. package/es/setup-app.mjs +23 -39
  87. package/es/state/global-pinia-state/global-pinia-state.mjs +49 -71
  88. package/es/state/index.mjs +1 -0
  89. package/es/store/global-store.mjs +50 -72
  90. package/es/store/index.mjs +25 -19
  91. package/es/types/index.d.ts +7 -0
  92. package/es/utils/axios/interceptors.mjs +21 -17
  93. package/es/utils/cache-adapter/cache-adapter.mjs +61 -56
  94. package/es/utils/design/design.mjs +18 -12
  95. package/es/utils/deviceFingerprint.mjs +74 -63
  96. package/es/utils/dictionary/dictionary.mjs +142 -145
  97. package/es/utils/file/base64Conver.mjs +35 -30
  98. package/es/utils/file/download.mjs +94 -98
  99. package/es/utils/file/parser.d.ts +3 -0
  100. package/es/utils/file/parser.mjs +29 -0
  101. package/es/utils/i18n/index.mjs +14 -3
  102. package/es/utils/index.d.ts +1 -0
  103. package/es/utils/index.mjs +31 -0
  104. package/es/utils/is-sort-filed/is-sort-filed.mjs +42 -37
  105. package/es/utils/linked-list/linked-list.mjs +115 -118
  106. package/es/utils/linked-node/linked-node.mjs +41 -31
  107. package/es/utils/lowcode/utils.mjs +13 -18
  108. package/es/utils/lowcode/validate.mjs +20 -26
  109. package/es/utils/mitt/mitt.mjs +4 -4
  110. package/es/utils/model-loader/model-loader.mjs +280 -325
  111. package/es/utils/namespace/namespace.mjs +178 -164
  112. package/es/utils/openUtil/index.mjs +2 -0
  113. package/es/utils/openUtil/modal/modal.mjs +72 -79
  114. package/es/utils/openUtil/overlay-container/overlay-container.mjs +144 -138
  115. package/es/utils/permission.mjs +33 -37
  116. package/es/utils/plugin-static-resource/plugin-static-resource.mjs +46 -42
  117. package/es/utils/style/index.mjs +94 -138
  118. package/es/utils/tools/tools.mjs +86 -54
  119. package/es/utils/treeHelper/treeHelper.mjs +205 -233
  120. package/es/utils/uploader/uploader.mjs +81 -115
  121. package/es/utils/useUUid.mjs +79 -87
  122. package/es/utils/util.mjs +55 -35
  123. package/es/utils/uuid/uuid.d.ts +1 -0
  124. package/es/utils/uuid/uuid.mjs +36 -43
  125. package/es/utils/validate.mjs +15 -19
  126. package/es/utils/value-helper/value-helper.mjs +113 -98
  127. package/package.json +12 -13
  128. package/dist/index.esm.min.mjs +0 -18322
  129. package/dist/index.min.cjs +0 -393
  130. package/dist/index.system.min.js +0 -393
@@ -1,108 +1,105 @@
1
- import { EnvironmentType } from './env-manager.interface.mjs';
2
- import { HOST_REG, APP_RUN_PATH_REG, APP_PROD_PATH_REG, APP_PREVIEW_PATH_REG, DEV_SINGLE_PATH_REG, TEST_SINGLE_PATH_REG, IP_REG } from './env-manager.const.mjs';
3
-
4
- class EnvironmentManager {
5
- /** 测试环境标识 */
6
- _testEnv = false;
7
- /** 测试环境租户数据 */
8
- _testTenantData = {};
9
- /** 平台地址 */
10
- _platformOrigin;
11
- /** 域名访问模式标识 */
12
- _isHostMode = false;
13
- constructor() {
14
- this._platformOrigin = (location.origin) || "";
15
- this._isHostMode = HOST_REG.test(this._platformOrigin);
16
- }
17
- /**
18
- * 是否为应用前端运行时
19
- */
20
- get isAppRun() {
21
- return APP_RUN_PATH_REG.test(location.pathname);
22
- }
23
- /**
24
- * 是否为应用前端运行时生产环境包含测试环境
25
- */
26
- get isAppProd() {
27
- return APP_PROD_PATH_REG.test(location.pathname);
28
- }
29
- /**
30
- * 是否为应用前端运行时预览环境
31
- */
32
- get isAppPreview() {
33
- return APP_PREVIEW_PATH_REG.test(location.pathname);
34
- }
35
- /**
36
- * 是否为dev环境单应用
37
- */
38
- get isDevSingleEnv() {
39
- return DEV_SINGLE_PATH_REG.test(location.pathname);
40
- }
41
- /**
42
- * 是否为测试环境
43
- */
44
- get isTestEnv() {
45
- return TEST_SINGLE_PATH_REG.test(location.pathname) || this._testEnv;
46
- }
47
- /**
48
- * 平台地址
49
- */
50
- get platformOrigin() {
51
- return this._platformOrigin;
52
- }
53
- /**
54
- * 是否为域名访问模式
55
- */
56
- get isHostMode() {
57
- return this._isHostMode;
58
- }
59
- /**
60
- * 测试环境租户数据
61
- */
62
- get testTenantData() {
63
- return this._testTenantData;
64
- }
65
- /**
66
- * 检测是否为测试环境
67
- */
68
- async checkIsTestEnv() {
69
- let matches = null;
70
- if (this._isHostMode) {
71
- matches = this._platformOrigin.match(HOST_REG);
72
- this._testEnv = !!(matches && matches[1]);
73
- if (this._testEnv) {
74
- const data = await _api.platform.tenant.getInfoByPortOrDomain({
75
- domain: matches[1]
76
- });
77
- Object.assign(this._testTenantData, data);
78
- }
79
- } else {
80
- matches = this._platformOrigin.match(IP_REG);
81
- const port = matches && matches[2];
82
- if (port) {
83
- const data = await _api.platform.tenant.getInfoByPortOrDomain({
84
- port
85
- });
86
- if (data) {
87
- Object.assign(this._testTenantData, data);
88
- this._testEnv = data.testEnvPort === port;
89
- }
90
- }
91
- }
92
- }
93
- /**
94
- * 获取当前环境类型
95
- * @returns 环境类型
96
- */
97
- getEnv() {
98
- if (this.isTestEnv) {
99
- return EnvironmentType.TEST;
100
- } else if (this.isAppProd) {
101
- return EnvironmentType.PROD;
102
- } else {
103
- return EnvironmentType.DEV;
104
- }
105
- }
106
- }
107
-
1
+ import { EnvironmentType } from "./env-manager.interface.mjs";
2
+ import { APP_PREVIEW_PATH_REG, APP_PROD_PATH_REG, APP_RUN_PATH_REG, DEV_SINGLE_PATH_REG, HOST_REG, IP_REG, TEST_SINGLE_PATH_REG } from "./env-manager.const.mjs";
3
+ //#region src/modules/env-manager/env-manager.ts
4
+ /**
5
+ * 环境管理器
6
+ *
7
+ * @description 负责检测和管理应用运行环境,包括测试环境检测、租户信息获取等功能
8
+ */
9
+ var EnvironmentManager = class {
10
+ /** 测试环境标识 */
11
+ _testEnv = false;
12
+ /** 测试环境租户数据 */
13
+ _testTenantData = {};
14
+ /** 平台地址 */
15
+ _platformOrigin;
16
+ /** 域名访问模式标识 */
17
+ _isHostMode = false;
18
+ constructor() {
19
+ this._platformOrigin = location.origin || "";
20
+ this._isHostMode = HOST_REG.test(this._platformOrigin);
21
+ }
22
+ /**
23
+ * 是否为应用前端运行时
24
+ */
25
+ get isAppRun() {
26
+ return APP_RUN_PATH_REG.test(location.pathname);
27
+ }
28
+ /**
29
+ * 是否为应用前端运行时生产环境包含测试环境
30
+ */
31
+ get isAppProd() {
32
+ return APP_PROD_PATH_REG.test(location.pathname);
33
+ }
34
+ /**
35
+ * 是否为应用前端运行时预览环境
36
+ */
37
+ get isAppPreview() {
38
+ return APP_PREVIEW_PATH_REG.test(location.pathname);
39
+ }
40
+ /**
41
+ * 是否为dev环境单应用
42
+ */
43
+ get isDevSingleEnv() {
44
+ return DEV_SINGLE_PATH_REG.test(location.pathname);
45
+ }
46
+ /**
47
+ * 是否为测试环境
48
+ */
49
+ get isTestEnv() {
50
+ return TEST_SINGLE_PATH_REG.test(location.pathname) || this._testEnv;
51
+ }
52
+ /**
53
+ * 平台地址
54
+ */
55
+ get platformOrigin() {
56
+ return this._platformOrigin;
57
+ }
58
+ /**
59
+ * 是否为域名访问模式
60
+ */
61
+ get isHostMode() {
62
+ return this._isHostMode;
63
+ }
64
+ /**
65
+ * 测试环境租户数据
66
+ */
67
+ get testTenantData() {
68
+ return this._testTenantData;
69
+ }
70
+ /**
71
+ * 检测是否为测试环境
72
+ */
73
+ async checkIsTestEnv() {
74
+ let matches = null;
75
+ if (this._isHostMode) {
76
+ matches = this._platformOrigin.match(HOST_REG);
77
+ this._testEnv = !!(matches && matches[1]);
78
+ if (this._testEnv) {
79
+ const data = await _api.platform.tenant.getInfoByPortOrDomain({ domain: matches[1] });
80
+ Object.assign(this._testTenantData, data);
81
+ }
82
+ } else {
83
+ matches = this._platformOrigin.match(IP_REG);
84
+ const port = matches && matches[2];
85
+ if (port) {
86
+ const data = await _api.platform.tenant.getInfoByPortOrDomain({ port });
87
+ if (data) {
88
+ Object.assign(this._testTenantData, data);
89
+ this._testEnv = data.testEnvPort === port;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ /**
95
+ * 获取当前环境类型
96
+ * @returns 环境类型
97
+ */
98
+ getEnv() {
99
+ if (this.isTestEnv) return EnvironmentType.TEST;
100
+ else if (this.isAppProd) return EnvironmentType.PROD;
101
+ else return EnvironmentType.DEV;
102
+ }
103
+ };
104
+ //#endregion
108
105
  export { EnvironmentManager };
@@ -1,18 +1,13 @@
1
- const HTTP_STATUS_CODE = {
2
- /** 未授权 */
3
- UNAUTHORIZED: 401,
4
- /** 禁止访问 */
5
- FORBIDDEN: 403,
6
- /** 资源未找到 */
7
- NOT_FOUND: 404,
8
- /** 内部服务器错误 */
9
- INTERNAL_SERVER_ERROR: 500,
10
- /** 网关错误 */
11
- BAD_GATEWAY: 502,
12
- /** 服务不可用 */
13
- SERVICE_UNAVAILABLE: 503,
14
- /** 网关超时 */
15
- GATEWAY_TIMEOUT: 504
1
+ //#region src/modules/error-handler/error-handler.const.ts
2
+ /** HTTP 状态码常量 */
3
+ var HTTP_STATUS_CODE = {
4
+ UNAUTHORIZED: 401,
5
+ FORBIDDEN: 403,
6
+ NOT_FOUND: 404,
7
+ INTERNAL_SERVER_ERROR: 500,
8
+ BAD_GATEWAY: 502,
9
+ SERVICE_UNAVAILABLE: 503,
10
+ GATEWAY_TIMEOUT: 504
16
11
  };
17
-
12
+ //#endregion
18
13
  export { HTTP_STATUS_CODE };
@@ -1,175 +1,199 @@
1
- import { HTTP_STATUS_CODE } from './error-handler.const.mjs';
2
- import { ErrorTypeEnum } from '../../enums/exceptionEnum.mjs';
3
-
4
- class JavaScriptErrorStrategy {
5
- /**
6
- * 处理 JavaScript 错误
7
- *
8
- * @param {IErrorInfo} errorInfo 错误信息
9
- */
10
- handle(errorInfo) {
11
- console.error(errorInfo);
12
- }
13
- }
14
- class VueErrorStrategy {
15
- /**
16
- * 处理 Vue 组件错误
17
- *
18
- * @param {IErrorInfo} errorInfo 错误信息
19
- */
20
- handle(errorInfo) {
21
- console.error(errorInfo);
22
- }
23
- }
24
- class PromiseErrorStrategy {
25
- /**
26
- * 处理 Promise 错误
27
- *
28
- * @param {IErrorInfo} errorInfo 错误信息
29
- */
30
- handle(errorInfo) {
31
- if (errorInfo.type === ErrorTypeEnum.AJAX) {
32
- const httpStrategy = new HttpErrorStrategy();
33
- httpStrategy.handle(errorInfo);
34
- return;
35
- }
36
- console.error(errorInfo);
37
- }
38
- }
39
- class HttpErrorStrategy {
40
- /**
41
- * 处理 HTTP 错误
42
- *
43
- * @param {IErrorInfo} errorInfo 错误信息
44
- */
45
- handle(errorInfo) {
46
- const status = this._extractStatusCode(errorInfo.message);
47
- if (status) {
48
- switch (status) {
49
- case HTTP_STATUS_CODE.UNAUTHORIZED:
50
- this._handleUnauthorized();
51
- break;
52
- case HTTP_STATUS_CODE.FORBIDDEN:
53
- this._handleForbidden();
54
- break;
55
- case HTTP_STATUS_CODE.NOT_FOUND:
56
- this._handleNotFound();
57
- break;
58
- case HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR:
59
- case HTTP_STATUS_CODE.BAD_GATEWAY:
60
- case HTTP_STATUS_CODE.SERVICE_UNAVAILABLE:
61
- case HTTP_STATUS_CODE.GATEWAY_TIMEOUT:
62
- this._handleServerError(status);
63
- break;
64
- default:
65
- this._handleGenericHttpError(errorInfo);
66
- break;
67
- }
68
- } else {
69
- this._handleGenericHttpError(errorInfo);
70
- }
71
- }
72
- /**
73
- * 从错误消息中提取 HTTP 状态码
74
- *
75
- * @private
76
- * @param {string} message 错误消息
77
- * @return {number | null} HTTP 状态码,如果没有找到则返回 null
78
- */
79
- _extractStatusCode(message) {
80
- const statusMatch = message.match(
81
- /HTTP\s+(\d{3})|Business\s+Error\s+\[(\d+)\]/
82
- );
83
- if (statusMatch) {
84
- return parseInt(
85
- statusMatch[1] || statusMatch[2],
86
- 10
87
- );
88
- }
89
- return null;
90
- }
91
- /**
92
- * 处理通用 HTTP 错误
93
- *
94
- * @private
95
- * @param {IErrorInfo} errorInfo 错误信息
96
- */
97
- _handleGenericHttpError(errorInfo) {
98
- if (errorInfo.message.includes("Business Error")) {
99
- console.debug("Handling business error:", errorInfo.message);
100
- } else if (errorInfo.message.includes("Network")) {
101
- console.debug("Handling network error:", errorInfo.message);
102
- } else {
103
- console.debug("Handling HTTP error:", errorInfo.message);
104
- }
105
- }
106
- /**
107
- * 处理未授权错误
108
- *
109
- * @private
110
- */
111
- _handleUnauthorized() {
112
- console.warn("Unauthorized access, redirecting to login...");
113
- }
114
- /**
115
- * 处理禁止访问错误
116
- *
117
- * @private
118
- */
119
- _handleForbidden() {
120
- console.warn("Access forbidden");
121
- }
122
- /**
123
- * 处理资源未找到错误
124
- *
125
- * @private
126
- */
127
- _handleNotFound() {
128
- console.warn("Resource not found");
129
- }
130
- /**
131
- * 处理服务器错误
132
- *
133
- * @private
134
- * @param {number} [status] HTTP 状态码
135
- */
136
- _handleServerError(status) {
137
- console.warn(`Server error: ${status}`);
138
- }
139
- }
140
- class ErrorStrategyFactory {
141
- static _strategies = /* @__PURE__ */ new Map();
142
- /**
143
- * 初始化策略工厂
144
- *
145
- * @static
146
- */
147
- static init() {
148
- this.registerStrategy(ErrorTypeEnum.SCRIPT, new JavaScriptErrorStrategy());
149
- this.registerStrategy(ErrorTypeEnum.VUE, new VueErrorStrategy());
150
- this.registerStrategy(ErrorTypeEnum.PROMISE, new PromiseErrorStrategy());
151
- this.registerStrategy(ErrorTypeEnum.AJAX, new HttpErrorStrategy());
152
- }
153
- /**
154
- * 获取错误处理策略
155
- *
156
- * @static
157
- * @param {ErrorTypeEnum} type 错误类型
158
- * @return {IErrorHandlerStrategy | undefined} 错误处理策略
159
- */
160
- static getStrategy(type) {
161
- return this._strategies.get(type);
162
- }
163
- /**
164
- * 注册自定义错误处理策略
165
- *
166
- * @static
167
- * @param {ErrorTypeEnum} type 错误类型
168
- * @param {IErrorHandlerStrategy} strategy 错误处理策略
169
- */
170
- static registerStrategy(type, strategy) {
171
- this._strategies.set(type, strategy);
172
- }
173
- }
174
-
175
- export { ErrorStrategyFactory, HttpErrorStrategy, JavaScriptErrorStrategy, PromiseErrorStrategy, VueErrorStrategy };
1
+ import { ErrorTypeEnum } from "../../enums/exceptionEnum.mjs";
2
+ import { HTTP_STATUS_CODE } from "./error-handler.const.mjs";
3
+ //#region src/modules/error-handler/error-strategy.ts
4
+ /**
5
+ * JavaScript 错误处理策略
6
+ * 负责处理 JavaScript 运行时错误
7
+ *
8
+ * @export
9
+ * @class JavaScriptErrorStrategy
10
+ * @implements {IErrorHandlerStrategy}
11
+ */
12
+ var JavaScriptErrorStrategy = class {
13
+ /**
14
+ * 处理 JavaScript 错误
15
+ *
16
+ * @param {IErrorInfo} errorInfo 错误信息
17
+ */
18
+ handle(errorInfo) {
19
+ console.error(errorInfo);
20
+ }
21
+ };
22
+ /**
23
+ * Vue 组件错误处理策略
24
+ * 负责处理 Vue 组件相关错误
25
+ *
26
+ * @export
27
+ * @class VueErrorStrategy
28
+ * @implements {IErrorHandlerStrategy}
29
+ */
30
+ var VueErrorStrategy = class {
31
+ /**
32
+ * 处理 Vue 组件错误
33
+ *
34
+ * @param {IErrorInfo} errorInfo 错误信息
35
+ */
36
+ handle(errorInfo) {
37
+ console.error(errorInfo);
38
+ }
39
+ };
40
+ /**
41
+ * Promise 错误处理策略
42
+ * 负责处理未捕获的 Promise 异常,包括 HTTP 请求错误
43
+ *
44
+ * @export
45
+ * @class PromiseErrorStrategy
46
+ * @implements {IErrorHandlerStrategy}
47
+ */
48
+ var PromiseErrorStrategy = class {
49
+ /**
50
+ * 处理 Promise 错误
51
+ *
52
+ * @param {IErrorInfo} errorInfo 错误信息
53
+ */
54
+ handle(errorInfo) {
55
+ if (errorInfo.type === ErrorTypeEnum.AJAX) {
56
+ new HttpErrorStrategy().handle(errorInfo);
57
+ return;
58
+ }
59
+ console.error(errorInfo);
60
+ }
61
+ };
62
+ /**
63
+ * HTTP 错误处理策略
64
+ * 负责处理 HTTP 请求相关错误,包括网络错误和业务错误
65
+ *
66
+ * @export
67
+ * @class HttpErrorStrategy
68
+ * @implements {IErrorHandlerStrategy}
69
+ */
70
+ var HttpErrorStrategy = class {
71
+ /**
72
+ * 处理 HTTP 错误
73
+ *
74
+ * @param {IErrorInfo} errorInfo 错误信息
75
+ */
76
+ handle(errorInfo) {
77
+ const status = this._extractStatusCode(errorInfo.message);
78
+ if (status) switch (status) {
79
+ case HTTP_STATUS_CODE.UNAUTHORIZED:
80
+ this._handleUnauthorized();
81
+ break;
82
+ case HTTP_STATUS_CODE.FORBIDDEN:
83
+ this._handleForbidden();
84
+ break;
85
+ case HTTP_STATUS_CODE.NOT_FOUND:
86
+ this._handleNotFound();
87
+ break;
88
+ case HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR:
89
+ case HTTP_STATUS_CODE.BAD_GATEWAY:
90
+ case HTTP_STATUS_CODE.SERVICE_UNAVAILABLE:
91
+ case HTTP_STATUS_CODE.GATEWAY_TIMEOUT:
92
+ this._handleServerError(status);
93
+ break;
94
+ default:
95
+ this._handleGenericHttpError(errorInfo);
96
+ break;
97
+ }
98
+ else this._handleGenericHttpError(errorInfo);
99
+ }
100
+ /**
101
+ * 从错误消息中提取 HTTP 状态码
102
+ *
103
+ * @private
104
+ * @param {string} message 错误消息
105
+ * @return {number | null} HTTP 状态码,如果没有找到则返回 null
106
+ */
107
+ _extractStatusCode(message) {
108
+ const statusMatch = message.match(/HTTP\s+(\d{3})|Business\s+Error\s+\[(\d+)\]/);
109
+ if (statusMatch) return parseInt(statusMatch[1] || statusMatch[2], 10);
110
+ return null;
111
+ }
112
+ /**
113
+ * 处理通用 HTTP 错误
114
+ *
115
+ * @private
116
+ * @param {IErrorInfo} errorInfo 错误信息
117
+ */
118
+ _handleGenericHttpError(errorInfo) {
119
+ if (errorInfo.message.includes("Business Error")) console.debug("Handling business error:", errorInfo.message);
120
+ else if (errorInfo.message.includes("Network")) console.debug("Handling network error:", errorInfo.message);
121
+ else console.debug("Handling HTTP error:", errorInfo.message);
122
+ }
123
+ /**
124
+ * 处理未授权错误
125
+ *
126
+ * @private
127
+ */
128
+ _handleUnauthorized() {
129
+ console.warn("Unauthorized access, redirecting to login...");
130
+ }
131
+ /**
132
+ * 处理禁止访问错误
133
+ *
134
+ * @private
135
+ */
136
+ _handleForbidden() {
137
+ console.warn("Access forbidden");
138
+ }
139
+ /**
140
+ * 处理资源未找到错误
141
+ *
142
+ * @private
143
+ */
144
+ _handleNotFound() {
145
+ console.warn("Resource not found");
146
+ }
147
+ /**
148
+ * 处理服务器错误
149
+ *
150
+ * @private
151
+ * @param {number} [status] HTTP 状态码
152
+ */
153
+ _handleServerError(status) {
154
+ console.warn(`Server error: ${status}`);
155
+ }
156
+ };
157
+ /**
158
+ * 错误处理策略工厂
159
+ * 负责根据错误类型创建对应的处理策略
160
+ *
161
+ * @export
162
+ * @class ErrorStrategyFactory
163
+ */
164
+ var ErrorStrategyFactory = class {
165
+ static _strategies = /* @__PURE__ */ new Map();
166
+ /**
167
+ * 初始化策略工厂
168
+ *
169
+ * @static
170
+ */
171
+ static init() {
172
+ this.registerStrategy(ErrorTypeEnum.SCRIPT, new JavaScriptErrorStrategy());
173
+ this.registerStrategy(ErrorTypeEnum.VUE, new VueErrorStrategy());
174
+ this.registerStrategy(ErrorTypeEnum.PROMISE, new PromiseErrorStrategy());
175
+ this.registerStrategy(ErrorTypeEnum.AJAX, new HttpErrorStrategy());
176
+ }
177
+ /**
178
+ * 获取错误处理策略
179
+ *
180
+ * @static
181
+ * @param {ErrorTypeEnum} type 错误类型
182
+ * @return {IErrorHandlerStrategy | undefined} 错误处理策略
183
+ */
184
+ static getStrategy(type) {
185
+ return this._strategies.get(type);
186
+ }
187
+ /**
188
+ * 注册自定义错误处理策略
189
+ *
190
+ * @static
191
+ * @param {ErrorTypeEnum} type 错误类型
192
+ * @param {IErrorHandlerStrategy} strategy 错误处理策略
193
+ */
194
+ static registerStrategy(type, strategy) {
195
+ this._strategies.set(type, strategy);
196
+ }
197
+ };
198
+ //#endregion
199
+ export { ErrorStrategyFactory };