@gct-paas/core 0.1.5-dev.1 → 0.1.5-dev.11

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 (81) hide show
  1. package/dist/index.esm.min.js +1 -1
  2. package/es/enums/app-designer/index.d.ts +11 -0
  3. package/es/enums/app-designer/index.mjs +14 -1
  4. package/es/enums/appEnum.d.ts +8 -0
  5. package/es/enums/appEnum.mjs +10 -1
  6. package/es/enums/page-designer/designer.d.ts +13 -13
  7. package/es/enums/page-designer/widget.d.ts +2 -2
  8. package/es/global/gct/gct.d.ts +108 -107
  9. package/es/hooks/index.d.ts +1 -0
  10. package/es/hooks/index.mjs +1 -0
  11. package/es/hooks/useFile.d.ts +4 -0
  12. package/es/hooks/useFile.mjs +22 -0
  13. package/es/index.mjs +15 -6
  14. package/es/interface/i-kit-plugin-module/i-kit-plugin-module.d.ts +23 -0
  15. package/es/interface/i-pinia-action/i-global-actions.d.ts +3 -0
  16. package/es/interface/i-popover-options/i-popover-options.d.ts +98 -0
  17. package/es/interface/index.d.ts +3 -2
  18. package/es/interface/index.mjs +1 -0
  19. package/es/interface/model-designer/entity.d.ts +87 -79
  20. package/es/interface/model-designer/serial.d.ts +22 -0
  21. package/es/interface/model-designer/serial.mjs +49 -0
  22. package/es/interface/open-util/i-app-full-screen-container-options/i-app-full-screen-container-options.d.ts +26 -0
  23. package/es/interface/open-util/i-overlay-controller/i-overlay-controller.d.ts +52 -0
  24. package/es/interface/open-util/i-overlay-popover-container/i-overlay-popover-container.d.ts +21 -0
  25. package/es/interface/open-util/index.d.ts +3 -1
  26. package/es/locale/index.d.ts +26 -1
  27. package/es/locale/index.mjs +51 -3
  28. package/es/locale/sys/model.d.ts +5 -0
  29. package/es/locale/sys.d.ts +5 -0
  30. package/es/modules/mqtt/enums/mqtt-status.enum.d.ts +1 -0
  31. package/es/modules/mqtt/enums/mqtt-status.enum.mjs +2 -1
  32. package/es/modules/mqtt/mqtt-manager.d.ts +1 -1
  33. package/es/modules/mqtt/mqtt-manager.mjs +2 -1
  34. package/es/modules/platform-config/store.d.ts +106 -106
  35. package/es/modules/platform-config/store.mjs +0 -1
  36. package/es/modules/platform-config/useSecuritySetting.d.ts +1 -1
  37. package/es/modules/user-stores/store/tenant.store.d.ts +6 -8
  38. package/es/modules/user-stores/store/tenant.store.mjs +12 -14
  39. package/es/modules/user-stores/store/user.store.d.ts +11 -2
  40. package/es/modules/user-stores/store/user.store.mjs +15 -4
  41. package/es/modules/user-stores/types/tenant.d.ts +7 -1
  42. package/es/router/index.mjs +2 -2
  43. package/es/setup-app.mjs +6 -2
  44. package/es/store/global-store.mjs +3 -0
  45. package/es/store/index.d.ts +1 -0
  46. package/es/store/index.mjs +1 -0
  47. package/es/store/session-store.d.ts +7 -0
  48. package/es/store/session-store.mjs +7 -0
  49. package/es/store/storage-store.d.ts +2 -0
  50. package/es/store/storage-store.mjs +3 -2
  51. package/es/types/index.d.ts +0 -1
  52. package/es/utils/data-prems/const.d.ts +26 -0
  53. package/es/utils/data-prems/const.mjs +79 -0
  54. package/es/utils/file/download.d.ts +1 -1
  55. package/es/utils/file/parser.d.ts +1 -1
  56. package/es/utils/i18n/index.mjs +3 -0
  57. package/es/utils/index.d.ts +4 -0
  58. package/es/utils/index.mjs +5 -0
  59. package/es/utils/kit-pkg-util/kit-pkg-util.d.ts +34 -13
  60. package/es/utils/kit-pkg-util/kit-pkg-util.mjs +55 -40
  61. package/es/utils/openUtil/index.d.ts +1 -0
  62. package/es/utils/openUtil/index.mjs +1 -0
  63. package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.d.ts +15 -0
  64. package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.mjs +19 -0
  65. package/es/utils/plugin-pkg-util/plugin-pkg-util.d.ts +3 -3
  66. package/es/utils/plugin-pkg-util/plugin-pkg-util.mjs +1 -1
  67. package/es/utils/script-loader/script-loader.d.ts +62 -0
  68. package/es/utils/script-loader/script-loader.mjs +92 -0
  69. package/es/utils/style/index.d.ts +8 -0
  70. package/es/utils/style/index.mjs +67 -1
  71. package/es/utils/text-measure/text-measure.d.ts +141 -0
  72. package/es/utils/text-measure/text-measure.mjs +191 -0
  73. package/es/utils/tools/tools.d.ts +1 -1
  74. package/es/utils/uploader/uploader.mjs +3 -5
  75. package/es/utils/util.d.ts +1 -0
  76. package/es/utils/util.mjs +9 -1
  77. package/es/utils/vue-component-code.d.ts +8 -0
  78. package/es/utils/vue-component-code.mjs +37 -0
  79. package/package.json +20 -20
  80. package/es/interface/i-import-style-map/i-import-style-map.d.ts +0 -15
  81. package/es/interface/i-kit-info/i-kit-info.d.ts +0 -20
@@ -0,0 +1,79 @@
1
+ //#region src/utils/data-prems/const.ts
2
+ /**
3
+ * 分类的模块类型
4
+ */
5
+ var CategoryModuleEnum = /* @__PURE__ */ function(CategoryModuleEnum) {
6
+ /** 在线表单 */
7
+ CategoryModuleEnum["ONLINE_FORM"] = "online_form_module";
8
+ /** eDHR */
9
+ CategoryModuleEnum["EDHR"] = "edhr_module";
10
+ /** 单据项目 */
11
+ CategoryModuleEnum["CHECK_LIST"] = "check_list_module";
12
+ /** 检验模板 */
13
+ CategoryModuleEnum["INSPECTION"] = "inspection_module";
14
+ /** 放行模板 */
15
+ CategoryModuleEnum["RELEASE"] = "release_module";
16
+ return CategoryModuleEnum;
17
+ }({});
18
+ var moduleConfig = {
19
+ [CategoryModuleEnum.ONLINE_FORM]: {
20
+ modelKey: "em_form_category",
21
+ bsKeyList: {
22
+ list: "biz_tree",
23
+ tmpls: "biz_get_form_tmpls"
24
+ }
25
+ },
26
+ [CategoryModuleEnum.EDHR]: {
27
+ modelKey: "em_edhr_category",
28
+ bsKeyList: {
29
+ list: "biz_tree",
30
+ tmpls: "biz_get_edhr_tmpls",
31
+ querylist: "biz_list_edhr_tmpls"
32
+ }
33
+ },
34
+ [CategoryModuleEnum.INSPECTION]: {
35
+ modelKey: "em_inspection_category",
36
+ bsKeyList: {
37
+ list: "biz_tree",
38
+ tmpls: "biz_get_edhr_tmpls",
39
+ querylist: "biz_list_edhr_tmpls"
40
+ }
41
+ },
42
+ [CategoryModuleEnum.RELEASE]: {
43
+ modelKey: "em_product_release_category",
44
+ bsKeyList: {
45
+ list: "biz_tree",
46
+ tmpls: "biz_get_edhr_tmpls",
47
+ querylist: "biz_list_edhr_tmpls"
48
+ }
49
+ }
50
+ };
51
+ var getInterfaceApi = {
52
+ getCategoryList: ({ moduleType }) => {
53
+ if (moduleType === CategoryModuleEnum.CHECK_LIST) return _api.apaas.formRelate.getCategory({ moduleType });
54
+ const { modelKey, bsKeyList } = moduleConfig[moduleType] || {};
55
+ return _api.apaas.modelComprehensive.postBizServiceModelCategoryModelKeyBsKey({
56
+ modelCategory: "entity",
57
+ modelKey,
58
+ bsKey: bsKeyList.list
59
+ }, {}, {});
60
+ },
61
+ getTmplsList: (params, config) => {
62
+ if (params.moduleType === CategoryModuleEnum.CHECK_LIST) throw new Error("该模块不支持模板列表接口");
63
+ const { isQuery, ...otherParams } = params || {};
64
+ const { moduleType } = otherParams || {};
65
+ const { modelKey, bsKeyList } = moduleConfig[moduleType] || {};
66
+ const operatingState = Object.hasOwnProperty.call(otherParams, "operatingState") ? otherParams.operatingState : true;
67
+ const bsKey = isQuery ? bsKeyList?.querylist || bsKeyList?.tmpls : bsKeyList?.tmpls;
68
+ return _api.apaas.modelComprehensive.getBizServiceModelCategoryModelKeyBsKey({
69
+ modelCategory: "entity",
70
+ modelKey,
71
+ bsKey: bsKey || ""
72
+ }, {
73
+ ...otherParams,
74
+ operatingState
75
+ }, config);
76
+ }
77
+ };
78
+ //#endregion
79
+ export { CategoryModuleEnum, getInterfaceApi };
@@ -15,8 +15,8 @@ export declare function downloadByOnlineUrl(url: string, filename: string, mime?
15
15
  */
16
16
  export declare function downloadByBase64(buf: string, filename: string, mime?: string, bom?: BlobPart): void;
17
17
  export declare function uploaderFiles({ multiple, accept }?: {
18
- multiple?: boolean | undefined;
19
18
  accept?: string | undefined;
19
+ multiple?: boolean | undefined;
20
20
  }): Promise<File[]>;
21
21
  /**
22
22
  * Download according to the background interface file stream
@@ -1,3 +1,3 @@
1
1
  import { UploadTypeEnum } from '../../enums';
2
2
  export declare const sizeParser: (size: number) => string;
3
- export declare const typeParser: (fileName: string) => "attachment" | "img" | UploadTypeEnum.JPG | UploadTypeEnum.JPEG | UploadTypeEnum.PNG | UploadTypeEnum.BMP | UploadTypeEnum.DOCX | UploadTypeEnum.XLSX | UploadTypeEnum.DOC | UploadTypeEnum.MP4 | UploadTypeEnum.AVI | UploadTypeEnum.PPT | UploadTypeEnum.GIF | "MP4" | "PDF" | "ssl";
3
+ export declare const typeParser: (fileName: string) => "MP4" | "PDF" | "attachment" | "img" | "ssl" | UploadTypeEnum.JPG | UploadTypeEnum.JPEG | UploadTypeEnum.PNG | UploadTypeEnum.BMP | UploadTypeEnum.DOCX | UploadTypeEnum.XLSX | UploadTypeEnum.DOC | UploadTypeEnum.MP4 | UploadTypeEnum.AVI | UploadTypeEnum.PPT | UploadTypeEnum.GIF;
@@ -10,6 +10,9 @@
10
10
  * @returns {*} {string}
11
11
  */
12
12
  var t = (...args) => {
13
+ if (!args || args.length === 0) return "";
14
+ const key = args[0];
15
+ if (!key || typeof key !== "string" || key.trim() === "") return "";
13
16
  return _gct.i18n.global.t(...args);
14
17
  };
15
18
  //#endregion
@@ -29,4 +29,8 @@ export * from './file/download';
29
29
  export * from './file/base64Conver';
30
30
  export * from './file/parser';
31
31
  export * from './design/design';
32
+ export * from './text-measure/text-measure';
33
+ export { scriptLoader, type IScriptOptions, } from './script-loader/script-loader';
32
34
  export { permission } from './permission';
35
+ export { getVueComponentByCode } from './vue-component-code';
36
+ export * from './data-prems/const';
@@ -11,6 +11,7 @@ import "./model-loader/model-loader.mjs";
11
11
  import "./namespace/namespace.mjs";
12
12
  import "./openUtil/modal/modal.mjs";
13
13
  import "./openUtil/overlay-container/overlay-container.mjs";
14
+ import "./openUtil/overlay-popover-container/overlay-popover-container.mjs";
14
15
  import "./openUtil/index.mjs";
15
16
  import "./kit-pkg-util/kit-pkg-util.mjs";
16
17
  import "./plugin-pkg-util/plugin-pkg-util.mjs";
@@ -31,4 +32,8 @@ import "./file/base64Conver.mjs";
31
32
  import "./file/download.mjs";
32
33
  import "./file/parser.mjs";
33
34
  import "./design/design.mjs";
35
+ import "./text-measure/text-measure.mjs";
36
+ import "./script-loader/script-loader.mjs";
34
37
  import "./permission.mjs";
38
+ import "./vue-component-code.mjs";
39
+ import "./data-prems/const.mjs";
@@ -1,6 +1,5 @@
1
1
  import { PluginModeEnum } from '../../enums';
2
- import { IKitInfo } from '../../interface';
3
- import { App } from 'vue';
2
+ import { IPluginKitModule } from '../../interface';
4
3
  /**
5
4
  * 用于加载套件包的工具类
6
5
  *
@@ -8,25 +7,47 @@ import { App } from 'vue';
8
7
  * @class KitPkgUtil
9
8
  */
10
9
  export declare class KitPkgUtil {
11
- protected static readonly KIT_PKG_BASE_PATH = "/kits";
12
- protected static cache: Map<string, IKitInfo>;
10
+ protected static readonly KIT_PKG_BASE_PATH = "/plugin-kit";
13
11
  protected static joinPaths(...paths: string[]): string;
14
12
  /**
15
- * 加载套件包配置
13
+ * 加载套件包,返回套件包入口实例
16
14
  *
17
15
  * @static
18
16
  * @param {string} kit
19
- * @return {*} {(Promise<IKitInfo | undefined>)}
17
+ * @param {PluginModeEnum} mode
18
+ * @return {*} {(Promise<IPluginKitModule | null>)}
20
19
  */
21
- static loadKitPkgInfo(kit: string): Promise<IKitInfo | undefined>;
20
+ static loadKit(kit: string, mode: PluginModeEnum): Promise<IPluginKitModule | null>;
22
21
  /**
23
- * 加载套件包内的插件
22
+ * 加载设计模式套件包
24
23
  *
25
24
  * @static
26
- * @param {App} app
27
- * @param {(string | string[])} kit
28
- * @param {PluginModeEnum} mode
29
- * @return {*} {Promise<void>}
25
+ * @param {string} kit
26
+ * @return {*} {(Promise<IPluginKitModule | null>)}
27
+ */
28
+ static loadDesign(kit: string): Promise<IPluginKitModule | null>;
29
+ /**
30
+ * 加载移动端绘制模式套件包
31
+ *
32
+ * @static
33
+ * @param {string} kit
34
+ * @return {*} {(Promise<IPluginKitModule | null>)}
35
+ */
36
+ static loadMobile(kit: string): Promise<IPluginKitModule | null>;
37
+ /**
38
+ * 加载平板端绘制模式套件包
39
+ *
40
+ * @static
41
+ * @param {string} kit
42
+ * @return {*} {(Promise<IPluginKitModule | null>)}
43
+ */
44
+ static loadPad(kit: string): Promise<IPluginKitModule | null>;
45
+ /**
46
+ * 加载网页端绘制模式套件包
47
+ *
48
+ * @static
49
+ * @param {string} kit
50
+ * @return {*} {(Promise<IPluginKitModule | null>)}
30
51
  */
31
- static loadKits(app: App, kit: string | string[], mode: PluginModeEnum): Promise<void>;
52
+ static loadWeb(kit: string): Promise<IPluginKitModule | null>;
32
53
  }
@@ -1,3 +1,5 @@
1
+ import { PluginModeEnum } from "../../enums/plugin-enum.mjs";
2
+ import "../../enums/index.mjs";
1
3
  //#region src/utils/kit-pkg-util/kit-pkg-util.ts
2
4
  /**
3
5
  * 用于加载套件包的工具类
@@ -6,8 +8,7 @@
6
8
  * @class KitPkgUtil
7
9
  */
8
10
  var KitPkgUtil = class {
9
- static KIT_PKG_BASE_PATH = "/kits";
10
- static cache = /* @__PURE__ */ new Map();
11
+ static KIT_PKG_BASE_PATH = "/plugin-kit";
11
12
  static joinPaths(...paths) {
12
13
  return paths.filter((p) => p && p.length > 0).map((p, index) => {
13
14
  let normalized = p;
@@ -17,56 +18,70 @@ var KitPkgUtil = class {
17
18
  }).join("/");
18
19
  }
19
20
  /**
20
- * 加载套件包配置
21
+ * 加载套件包,返回套件包入口实例
21
22
  *
22
23
  * @static
23
24
  * @param {string} kit
24
- * @return {*} {(Promise<IKitInfo | undefined>)}
25
+ * @param {PluginModeEnum} mode
26
+ * @return {*} {(Promise<IPluginKitModule | null>)}
25
27
  */
26
- static async loadKitPkgInfo(kit) {
27
- if (this.cache.has(kit)) return this.cache.get(kit);
28
+ static async loadKit(kit, mode) {
29
+ if (!kit) {
30
+ console.error("Kit name is required to load a kit package");
31
+ return null;
32
+ }
33
+ const loaderUrl = this.joinPaths(this.KIT_PKG_BASE_PATH, kit, mode, "loader.esm.min.js");
28
34
  try {
29
- const url = this.joinPaths(this.KIT_PKG_BASE_PATH, kit.toUpperCase(), "kit-info.json");
30
- const response = await fetch(url);
31
- if (!response.ok) throw new Error(`Failed to load kit package from ${url}`);
32
- const config = await response.json();
33
- this.cache.set(kit, config);
34
- return config;
35
+ const module = await import(
36
+ /* @vite-ignore */
37
+ loaderUrl
38
+ );
39
+ if (module) return module;
40
+ else console.warn(`Kit ${kit} does not export a default function`);
35
41
  } catch (error) {
36
- console.error(`Error loading kit package ${kit}:`, error);
42
+ console.error(`Error loading kit ${kit} from ${loaderUrl}:`, error);
37
43
  }
44
+ return null;
38
45
  }
39
46
  /**
40
- * 加载套件包内的插件
47
+ * 加载设计模式套件包
41
48
  *
42
49
  * @static
43
- * @param {App} app
44
- * @param {(string | string[])} kit
45
- * @param {PluginModeEnum} mode
46
- * @return {*} {Promise<void>}
50
+ * @param {string} kit
51
+ * @return {*} {(Promise<IPluginKitModule | null>)}
47
52
  */
48
- static async loadKits(app, kit, mode) {
49
- const kits = Array.isArray(kit) ? kit : [kit];
50
- for (const k of kits) {
51
- if (this.cache.has(k)) {
52
- console.warn(`Kit package ${k} is already loaded, skipping.`);
53
- return;
54
- }
55
- const config = await this.loadKitPkgInfo(k);
56
- if (config) {
57
- const loaderUrl = this.joinPaths(this.KIT_PKG_BASE_PATH, config.kit.toUpperCase(), mode, `loader.esm.min.js?version=${config.version || "0.0.0"}`);
58
- try {
59
- const module = await import(
60
- /* @vite-ignore */
61
- loaderUrl
62
- );
63
- if (module && module.default) app.use(module.default);
64
- else console.warn(`Kit ${config.kit} does not export a default function`);
65
- } catch (error) {
66
- console.error(`Error loading kit ${config.kit} from ${loaderUrl}:`, error);
67
- }
68
- }
69
- }
53
+ static loadDesign(kit) {
54
+ return this.loadKit(kit, PluginModeEnum.DESIGN);
55
+ }
56
+ /**
57
+ * 加载移动端绘制模式套件包
58
+ *
59
+ * @static
60
+ * @param {string} kit
61
+ * @return {*} {(Promise<IPluginKitModule | null>)}
62
+ */
63
+ static loadMobile(kit) {
64
+ return this.loadKit(kit, PluginModeEnum.MOBILE);
65
+ }
66
+ /**
67
+ * 加载平板端绘制模式套件包
68
+ *
69
+ * @static
70
+ * @param {string} kit
71
+ * @return {*} {(Promise<IPluginKitModule | null>)}
72
+ */
73
+ static loadPad(kit) {
74
+ return this.loadKit(kit, PluginModeEnum.PAD);
75
+ }
76
+ /**
77
+ * 加载网页端绘制模式套件包
78
+ *
79
+ * @static
80
+ * @param {string} kit
81
+ * @return {*} {(Promise<IPluginKitModule | null>)}
82
+ */
83
+ static loadWeb(kit) {
84
+ return this.loadKit(kit, PluginModeEnum.WEB);
70
85
  }
71
86
  };
72
87
  //#endregion
@@ -1,2 +1,3 @@
1
1
  export { Modal } from './modal/modal';
2
2
  export { OverlayContainer } from './overlay-container/overlay-container';
3
+ export { OverlayPopoverContainer } from './overlay-popover-container/overlay-popover-container';
@@ -1,2 +1,3 @@
1
1
  import "./modal/modal.mjs";
2
2
  import "./overlay-container/overlay-container.mjs";
3
+ import "./overlay-popover-container/overlay-popover-container.mjs";
@@ -0,0 +1,15 @@
1
+ import { IOverlayPopoverContainer, IPopoverOptions } from '../../../interface';
2
+ import { OverlayContainer } from '../overlay-container/overlay-container';
3
+ /**
4
+ * 飘窗组件呈现容器
5
+ *
6
+ * @author zhanghanrui
7
+ * @date 2024-04-08 09:04:42
8
+ * @export
9
+ * @class OverlayPopoverContainer
10
+ * @extends {OverlayContainer<IPopoverOptions>}
11
+ * @implements {IOverlayPopoverContainer}
12
+ */
13
+ export declare class OverlayPopoverContainer extends OverlayContainer<IPopoverOptions> implements IOverlayPopoverContainer {
14
+ present(): Promise<void>;
15
+ }
@@ -0,0 +1,19 @@
1
+ import { OverlayContainer } from "../overlay-container/overlay-container.mjs";
2
+ //#region src/utils/openUtil/overlay-popover-container/overlay-popover-container.ts
3
+ /**
4
+ * 飘窗组件呈现容器
5
+ *
6
+ * @author zhanghanrui
7
+ * @date 2024-04-08 09:04:42
8
+ * @export
9
+ * @class OverlayPopoverContainer
10
+ * @extends {OverlayContainer<IPopoverOptions>}
11
+ * @implements {IOverlayPopoverContainer}
12
+ */
13
+ var OverlayPopoverContainer = class extends OverlayContainer {
14
+ present(target) {
15
+ return this.modal.present(target);
16
+ }
17
+ };
18
+ //#endregion
19
+ export { OverlayPopoverContainer };
@@ -1,6 +1,6 @@
1
1
  import { PluginModeEnum, Platform } from '../../enums';
2
2
  import { PluginTenant } from '@gct-paas/api/platform';
3
- export type IModuleMap = Record<string, System.Module>;
3
+ export type IModuleMap = Record<string, IObject>;
4
4
  export type LoadPluginResult = [PluginTenant[], IModuleMap];
5
5
  /**
6
6
  * 插件包处理工具类
@@ -28,7 +28,7 @@ export declare class PluginPgkUtil {
28
28
  *
29
29
  * @static
30
30
  */
31
- static readonly module: Map<string, System.Module>;
31
+ static readonly module: Map<string, IObject>;
32
32
  protected static joinPaths(...paths: string[]): string;
33
33
  /**
34
34
  * 加载插件包配置
@@ -47,7 +47,7 @@ export declare class PluginPgkUtil {
47
47
  * @protected
48
48
  * @static
49
49
  * @param {IStyleIMportMap[]} plugins
50
- * @returns {*} {Promise<System.Module[]>}
50
+ * @returns {*} {Promise<IObject[]>}
51
51
  */
52
52
  protected static loadPlugins(mode: PluginModeEnum, configs?: PluginTenant['plugins']): Promise<IModuleMap>;
53
53
  /**
@@ -60,7 +60,7 @@ var PluginPgkUtil = class {
60
60
  * @protected
61
61
  * @static
62
62
  * @param {IStyleIMportMap[]} plugins
63
- * @returns {*} {Promise<System.Module[]>}
63
+ * @returns {*} {Promise<IObject[]>}
64
64
  */
65
65
  static async loadPlugins(mode, configs = []) {
66
66
  const moduleMap = {};
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Script 动态加载工具类
3
+ *
4
+ * 从 CDN 动态加载 JS 脚本文件,具备以下特性:
5
+ * - 已成功加载的路径永久缓存,避免重复插入 script 标签
6
+ * - 同一时刻对同一路径的多次调用共享同一个 Promise(请求去重)
7
+ * - 加载失败不写入缓存,允许下次重试
8
+ * - 加载前检查 DOM 中是否已存在相同 src 的 script 标签
9
+ * - 支持配置 async、defer、crossOrigin、type 等脚本属性
10
+ *
11
+ * @author chitanda
12
+ * @date 2026-04-17
13
+ */
14
+ /** Script 加载选项 */
15
+ export interface IScriptOptions {
16
+ /** 是否异步加载,默认 true */
17
+ async?: boolean;
18
+ /** 是否延迟加载 */
19
+ defer?: boolean;
20
+ /** 跨域属性 */
21
+ crossOrigin?: 'anonymous' | 'use-credentials';
22
+ /** 脚本 MIME 类型,默认 'text/javascript' */
23
+ type?: string;
24
+ }
25
+ /**
26
+ * Script 动态加载工具类
27
+ *
28
+ * @class ScriptLoader
29
+ */
30
+ declare class ScriptLoader {
31
+ /** 已成功加载的脚本 URL 集合(永久缓存) */
32
+ private _loadedSet;
33
+ /** 正在加载中的脚本 URL 对应的 Promise(用于请求去重) */
34
+ private _pendingMap;
35
+ /**
36
+ * 动态加载单个 JS 脚本文件
37
+ *
38
+ * 同一 URL 只会加载一次,首次调用时的 options 生效。
39
+ *
40
+ * @param {string} url 脚本文件的完整 URL
41
+ * @param {IScriptOptions} [options] 脚本加载选项
42
+ * @returns {Promise<void>} 加载完成后 resolve;加载失败则 reject
43
+ */
44
+ load(url: string, options?: IScriptOptions): Promise<void>;
45
+ /**
46
+ * 加载 ExcelJS 库
47
+ *
48
+ * @return {*} {Promise<IObject>}
49
+ */
50
+ loadExcelsJs(): Promise<IObject>;
51
+ /**
52
+ * 并发加载多个 JS 脚本文件
53
+ *
54
+ * @param {string[]} urls 脚本文件 URL 列表
55
+ * @param {IScriptOptions} [options] 脚本加载选项,对所有 URL 生效
56
+ * @returns {Promise<void>} 所有文件均加载完成后 resolve;任一失败则 reject
57
+ */
58
+ loadBatch(urls: string[], options?: IScriptOptions): Promise<void>;
59
+ }
60
+ /** Script 动态加载工具单例 */
61
+ export declare const scriptLoader: ScriptLoader;
62
+ export {};
@@ -0,0 +1,92 @@
1
+ //#region src/utils/script-loader/script-loader.ts
2
+ /**
3
+ * Script 动态加载工具类
4
+ *
5
+ * @class ScriptLoader
6
+ */
7
+ var ScriptLoader = class {
8
+ /** 已成功加载的脚本 URL 集合(永久缓存) */
9
+ _loadedSet = /* @__PURE__ */ new Set();
10
+ /** 正在加载中的脚本 URL 对应的 Promise(用于请求去重) */
11
+ _pendingMap = /* @__PURE__ */ new Map();
12
+ /**
13
+ * 动态加载单个 JS 脚本文件
14
+ *
15
+ * 同一 URL 只会加载一次,首次调用时的 options 生效。
16
+ *
17
+ * @param {string} url 脚本文件的完整 URL
18
+ * @param {IScriptOptions} [options] 脚本加载选项
19
+ * @returns {Promise<void>} 加载完成后 resolve;加载失败则 reject
20
+ */
21
+ load(url, options) {
22
+ if (this._loadedSet.has(url)) return Promise.resolve();
23
+ if (this._pendingMap.has(url)) return this._pendingMap.get(url);
24
+ if (typeof document !== "undefined") {
25
+ const escaped = CSS.escape ? CSS.escape(url) : url;
26
+ if (document.querySelector(`script[src="${escaped}"]`)) {
27
+ this._loadedSet.add(url);
28
+ return Promise.resolve();
29
+ }
30
+ }
31
+ const promise = new Promise((resolve, reject) => {
32
+ if (typeof document === "undefined") {
33
+ reject(/* @__PURE__ */ new Error(`[ScriptLoader] 当前环境不支持 DOM,无法加载脚本: ${url}`));
34
+ return;
35
+ }
36
+ const script = document.createElement("script");
37
+ script.src = url;
38
+ script.type = options?.type ?? "text/javascript";
39
+ script.async = options?.async ?? true;
40
+ if (options?.defer !== void 0) script.defer = options.defer;
41
+ if (options?.crossOrigin !== void 0) script.crossOrigin = options.crossOrigin;
42
+ /** 加载成功回调 */
43
+ const onLoad = () => {
44
+ cleanup();
45
+ this._loadedSet.add(url);
46
+ this._pendingMap.delete(url);
47
+ resolve();
48
+ };
49
+ /** 加载失败回调 */
50
+ const onError = () => {
51
+ cleanup();
52
+ this._pendingMap.delete(url);
53
+ const err = /* @__PURE__ */ new Error(`[ScriptLoader] 脚本文件加载失败: ${url}`);
54
+ console.error(err.message);
55
+ reject(err);
56
+ };
57
+ /** 移除事件监听,防止内存泄漏 */
58
+ const cleanup = () => {
59
+ script.removeEventListener("load", onLoad);
60
+ script.removeEventListener("error", onError);
61
+ };
62
+ script.addEventListener("load", onLoad);
63
+ script.addEventListener("error", onError);
64
+ document.head.appendChild(script);
65
+ });
66
+ this._pendingMap.set(url, promise);
67
+ return promise;
68
+ }
69
+ /**
70
+ * 加载 ExcelJS 库
71
+ *
72
+ * @return {*} {Promise<IObject>}
73
+ */
74
+ async loadExcelsJs() {
75
+ await this.load("/extras/exceljs/4.4.0/exceljs.min.js");
76
+ return window.ExcelJS;
77
+ }
78
+ /**
79
+ * 并发加载多个 JS 脚本文件
80
+ *
81
+ * @param {string[]} urls 脚本文件 URL 列表
82
+ * @param {IScriptOptions} [options] 脚本加载选项,对所有 URL 生效
83
+ * @returns {Promise<void>} 所有文件均加载完成后 resolve;任一失败则 reject
84
+ */
85
+ async loadBatch(urls, options) {
86
+ await Promise.all(urls.map((url) => this.load(url, options)));
87
+ }
88
+ };
89
+ /** Script 动态加载工具单例 */
90
+ var scriptLoader = new ScriptLoader();
91
+ //#endregion
92
+ export { scriptLoader };
@@ -6,6 +6,14 @@
6
6
  * @returns
7
7
  */
8
8
  export declare const calcStyle: (data: IData, ignoringStyle?: string[]) => IObject;
9
+ /**
10
+ * 计算配置样式 补充px
11
+ *
12
+ * @param data
13
+ * @param ignoringStyle 忽略计算的样式
14
+ * @returns
15
+ */
16
+ export declare const calcStylePX: (data: IData, ignoringStyle?: string[]) => IObject;
9
17
  /**
10
18
  * 计算字体样式
11
19
  *
@@ -71,6 +71,72 @@ var calcStyle = (data, ignoringStyle = []) => {
71
71
  return style;
72
72
  };
73
73
  /**
74
+ * 计算配置样式 补充px
75
+ *
76
+ * @param data
77
+ * @param ignoringStyle 忽略计算的样式
78
+ * @returns
79
+ */
80
+ var calcStylePX = (data, ignoringStyle = []) => {
81
+ if (!data) return {};
82
+ const style = {};
83
+ if (data.paddingTop && data.paddingTop != "0" && !ignoringStyle.includes("paddingTop")) style["padding-top"] = `${data.paddingTop}px`;
84
+ if (data.paddingRight && data.paddingRight != "0" && !ignoringStyle.includes("paddingRight")) style["padding-right"] = `${data.paddingRight}px`;
85
+ if (data.paddingBottom && data.paddingBottom != "0" && !ignoringStyle.includes("paddingBottom")) style["padding-bottom"] = `${data.paddingBottom}px`;
86
+ if (data.paddingLeft && data.paddingLeft != "0" && !ignoringStyle.includes("paddingLeft")) style["padding-left"] = `${data.paddingLeft}px`;
87
+ if (data.marginTop && data.marginTop != "0" && !ignoringStyle.includes("marginTop")) style["margin-top"] = `${data.marginTop}px`;
88
+ if (data.marginRight && data.marginRight != "0" && !ignoringStyle.includes("marginRight")) style["margin-right"] = `${data.marginRight}px`;
89
+ if (data.marginBottom && data.marginBottom != "0" && !ignoringStyle.includes("marginBottom")) style["margin-bottom"] = `${data.marginBottom}px`;
90
+ if (data.marginLeft && data.marginLeft != "0" && !ignoringStyle.includes("marginLeft")) style["margin-left"] = `${data.marginLeft}px`;
91
+ if (data.backgroundColor && !ignoringStyle.includes("backgroundColor")) style["background-color"] = data.backgroundColor;
92
+ if (data.width != null && data.width != "" && !ignoringStyle.includes("width")) style.width = `${data.width}px`;
93
+ if (data.height != null && data.height != "" && !ignoringStyle.includes("height")) {
94
+ style.height = `${data.height}px`;
95
+ style.overflowX = "hidden";
96
+ style.overflowY = "auto";
97
+ }
98
+ const position = data.position;
99
+ if (position && !ignoringStyle.includes("zIndex")) {
100
+ style.position = position;
101
+ style["z-index"] = 1;
102
+ }
103
+ if (data.top && !ignoringStyle.includes("top")) style.top = `${data.top}px`;
104
+ if (data.right && !ignoringStyle.includes("right")) style.right = `${data.right}px`;
105
+ if (data.bottom && !ignoringStyle.includes("bottom")) style.bottom = `${data.bottom}px`;
106
+ if (data.left && !ignoringStyle.includes("left")) style.left = `${data.left}px`;
107
+ if (data.borderBottomLeftRadius && !ignoringStyle.includes("borderBottomLeftRadius")) style["border-top-left-radius"] = `${data.borderBottomLeftRadius}px`;
108
+ if (data.borderTopRightRadius && !ignoringStyle.includes("borderTopRightRadius")) style["border-top-right-radius"] = `${data.borderTopRightRadius}px`;
109
+ if (data.borderBottomLeftRadius && !ignoringStyle.includes("borderBottomLeftRadius")) style["border-bottom-left-radius"] = `${data.borderBottomLeftRadius}px`;
110
+ if (data.borderBottomRightRadius && !ignoringStyle.includes("borderBottomRightRadius")) style["border-bottom-right-radius"] = `${data.borderBottomRightRadius}px`;
111
+ {
112
+ const top = data.borderTop;
113
+ if (top) {
114
+ if (top.borderColor && !ignoringStyle.includes("borderTopColor")) style["border-top-color"] = top.borderColor;
115
+ if (top.borderWidth && !ignoringStyle.includes("borderTopWidth")) style["border-top-width"] = `${top.borderWidth}px`;
116
+ if (top.borderStyle && !ignoringStyle.includes("borderTopStyle")) style["border-top-style"] = top.borderStyle;
117
+ }
118
+ const right = data.borderRight;
119
+ if (right) {
120
+ if (right.borderColor && !ignoringStyle.includes("borderRightColor")) style["border-right-color"] = right.borderColor;
121
+ if (right.borderWidth && !ignoringStyle.includes("borderRightWidth")) style["border-right-width"] = `${right.borderWidth}px`;
122
+ if (right.borderStyle && !ignoringStyle.includes("borderRightStyle")) style["border-right-style"] = right.borderStyle;
123
+ }
124
+ const bottom = data.borderBottom;
125
+ if (bottom) {
126
+ if (bottom.borderColor && !ignoringStyle.includes("borderBottomColor")) style["border-bottom-color"] = bottom.borderColor;
127
+ if (bottom.borderWidth && !ignoringStyle.includes("borderBottomWidth")) style["border-bottom-width"] = `${bottom.borderWidth}px`;
128
+ if (bottom.borderStyle && !ignoringStyle.includes("borderBottomStyle")) style["border-bottom-style"] = bottom.borderStyle;
129
+ }
130
+ const left = data.borderLeft;
131
+ if (left) {
132
+ if (left.borderColor && !ignoringStyle.includes("borderLeftColor")) style["border-left-color"] = left.borderColor;
133
+ if (left.borderWidth && !ignoringStyle.includes("borderLeftWidth")) style["border-left-width"] = `${left.borderWidth}px`;
134
+ if (left.borderStyle && !ignoringStyle.includes("borderLeftStyle")) style["border-left-style"] = left.borderStyle;
135
+ }
136
+ }
137
+ return style;
138
+ };
139
+ /**
74
140
  * 计算字体样式
75
141
  *
76
142
  * @param data
@@ -94,4 +160,4 @@ var calcFontStyle = (data, ignoringStyle = []) => {
94
160
  return style;
95
161
  };
96
162
  //#endregion
97
- export { calcFontStyle, calcStyle };
163
+ export { calcFontStyle, calcStyle, calcStylePX };