@gct-paas/core 0.1.5-test.2 → 0.1.6-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.min.js +1 -1
- package/es/enums/app-designer/index.d.ts +11 -0
- package/es/enums/app-designer/index.mjs +14 -1
- package/es/enums/appEnum.d.ts +8 -0
- package/es/enums/appEnum.mjs +10 -1
- package/es/enums/page-designer/designer.d.ts +13 -13
- package/es/index.mjs +12 -6
- package/es/interface/i-popover-options/i-popover-options.d.ts +98 -0
- package/es/interface/index.d.ts +2 -1
- package/es/interface/index.mjs +1 -0
- package/es/interface/model-designer/entity.d.ts +87 -79
- package/es/interface/model-designer/serial.d.ts +22 -0
- package/es/interface/model-designer/serial.mjs +49 -0
- package/es/interface/open-util/i-app-full-screen-container-options/i-app-full-screen-container-options.d.ts +26 -0
- package/es/interface/open-util/i-overlay-controller/i-overlay-controller.d.ts +52 -0
- package/es/interface/open-util/i-overlay-popover-container/i-overlay-popover-container.d.ts +21 -0
- package/es/interface/open-util/index.d.ts +3 -1
- package/es/locale/index.d.ts +23 -0
- package/es/locale/index.mjs +33 -0
- package/es/locale/sys/model.d.ts +5 -0
- package/es/locale/sys.d.ts +5 -0
- package/es/modules/mqtt/enums/mqtt-status.enum.d.ts +1 -0
- package/es/modules/mqtt/enums/mqtt-status.enum.mjs +2 -1
- package/es/modules/mqtt/mqtt-manager.d.ts +1 -1
- package/es/modules/mqtt/mqtt-manager.mjs +2 -1
- package/es/modules/platform-config/store.mjs +0 -1
- package/es/modules/user-stores/store/user.store.d.ts +4 -0
- package/es/router/index.mjs +1 -1
- package/es/setup-app.mjs +3 -1
- package/es/utils/data-prems/const.d.ts +26 -0
- package/es/utils/data-prems/const.mjs +79 -0
- package/es/utils/i18n/index.mjs +3 -0
- package/es/utils/index.d.ts +3 -0
- package/es/utils/index.mjs +4 -0
- package/es/utils/kit-pkg-util/kit-pkg-util.mjs +4 -0
- package/es/utils/openUtil/index.d.ts +1 -0
- package/es/utils/openUtil/index.mjs +1 -0
- package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.d.ts +15 -0
- package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.mjs +19 -0
- package/es/utils/plugin-pkg-util/plugin-pkg-util.d.ts +1 -1
- package/es/utils/plugin-pkg-util/plugin-pkg-util.mjs +1 -1
- package/es/utils/script-loader/script-loader.d.ts +62 -0
- package/es/utils/script-loader/script-loader.mjs +92 -0
- package/es/utils/style/index.d.ts +8 -0
- package/es/utils/style/index.mjs +67 -1
- package/es/utils/text-measure/text-measure.d.ts +141 -0
- package/es/utils/text-measure/text-measure.mjs +191 -0
- package/es/utils/uploader/uploader.mjs +3 -5
- package/es/utils/util.d.ts +10 -0
- package/es/utils/util.mjs +18 -1
- package/package.json +4 -3
- package/es/interface/i-import-style-map/i-import-style-map.d.ts +0 -15
|
@@ -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
|
*
|
package/es/utils/style/index.mjs
CHANGED
|
@@ -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 };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本测量工具类
|
|
3
|
+
* 使用 Canvas 测量文本宽度,支持批量测量
|
|
4
|
+
*/
|
|
5
|
+
interface TextMeasureOptions {
|
|
6
|
+
/** 字体大小,默认 14px */
|
|
7
|
+
fontSize?: string | number;
|
|
8
|
+
/** 字体族,默认 'Arial, sans-serif' */
|
|
9
|
+
fontFamily?: string;
|
|
10
|
+
/** 字体粗细,默认 'normal' */
|
|
11
|
+
fontWeight?: string | number;
|
|
12
|
+
/** 字体样式,默认 'normal' */
|
|
13
|
+
fontStyle?: string;
|
|
14
|
+
}
|
|
15
|
+
interface TextMeasureResult {
|
|
16
|
+
/** 文本内容 */
|
|
17
|
+
text: string;
|
|
18
|
+
/** 计算得到的宽度 */
|
|
19
|
+
width: number;
|
|
20
|
+
}
|
|
21
|
+
declare class TextMeasureUtil {
|
|
22
|
+
private canvas;
|
|
23
|
+
private ctx;
|
|
24
|
+
/**
|
|
25
|
+
* 获取 Canvas 上下文,懒加载创建
|
|
26
|
+
*/
|
|
27
|
+
private getContext;
|
|
28
|
+
/**
|
|
29
|
+
* 设置字体样式
|
|
30
|
+
*/
|
|
31
|
+
private setFont;
|
|
32
|
+
/**
|
|
33
|
+
* 测量单个文本的宽度
|
|
34
|
+
*
|
|
35
|
+
* @param text 要测量的文本
|
|
36
|
+
* @param options 字体选项
|
|
37
|
+
* @returns 文本宽度(像素)
|
|
38
|
+
*/
|
|
39
|
+
measureText(text: string, options?: TextMeasureOptions): number;
|
|
40
|
+
/**
|
|
41
|
+
* 批量测量多段文本的宽度
|
|
42
|
+
*
|
|
43
|
+
* @param texts 要测量的文本数组
|
|
44
|
+
* @param options 字体选项
|
|
45
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
46
|
+
*/
|
|
47
|
+
measureTexts(texts: string[], options?: TextMeasureOptions): TextMeasureResult[];
|
|
48
|
+
/**
|
|
49
|
+
* 获取文本的最大宽度
|
|
50
|
+
*
|
|
51
|
+
* @param texts 要测量的文本数组
|
|
52
|
+
* @param options 字体选项
|
|
53
|
+
* @returns 最大宽度(像素)
|
|
54
|
+
*/
|
|
55
|
+
getMaxWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
56
|
+
/**
|
|
57
|
+
* 获取文本的最小宽度
|
|
58
|
+
*
|
|
59
|
+
* @param texts 要测量的文本数组
|
|
60
|
+
* @param options 字体选项
|
|
61
|
+
* @returns 最小宽度(像素)
|
|
62
|
+
*/
|
|
63
|
+
getMinWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
64
|
+
/**
|
|
65
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
66
|
+
*
|
|
67
|
+
* @param texts 要测量的文本数组
|
|
68
|
+
* @param options 字体选项
|
|
69
|
+
* @param spacing 文本间的间距,默认 0
|
|
70
|
+
* @returns 总宽度(像素)
|
|
71
|
+
*/
|
|
72
|
+
getTotalWidth(texts: string[], options?: TextMeasureOptions, spacing?: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* 根据最大宽度截断文本,添加省略号
|
|
75
|
+
*
|
|
76
|
+
* @param text 原始文本
|
|
77
|
+
* @param maxWidth 最大宽度
|
|
78
|
+
* @param options 字体选项
|
|
79
|
+
* @param ellipsis 省略号,默认 '...'
|
|
80
|
+
* @param minChars 最少显示字符数,默认 0
|
|
81
|
+
* @returns 截断后的文本
|
|
82
|
+
*/
|
|
83
|
+
truncateText(text: string, maxWidth: number, options?: TextMeasureOptions, ellipsis?: string, minChars?: number): string;
|
|
84
|
+
/**
|
|
85
|
+
* 销毁资源
|
|
86
|
+
*/
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 测量单个文本的宽度
|
|
91
|
+
*
|
|
92
|
+
* @param text 要测量的文本
|
|
93
|
+
* @param options 字体选项
|
|
94
|
+
* @returns 文本宽度(像素)
|
|
95
|
+
*/
|
|
96
|
+
export declare function measureText(text: string, options?: TextMeasureOptions): number;
|
|
97
|
+
/**
|
|
98
|
+
* 批量测量多段文本的宽度
|
|
99
|
+
*
|
|
100
|
+
* @param texts 要测量的文本数组
|
|
101
|
+
* @param options 字体选项
|
|
102
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
103
|
+
*/
|
|
104
|
+
export declare function measureTexts(texts: string[], options?: TextMeasureOptions): TextMeasureResult[];
|
|
105
|
+
/**
|
|
106
|
+
* 获取文本的最大宽度
|
|
107
|
+
*
|
|
108
|
+
* @param texts 要测量的文本数组
|
|
109
|
+
* @param options 字体选项
|
|
110
|
+
* @returns 最大宽度(像素)
|
|
111
|
+
*/
|
|
112
|
+
export declare function getMaxTextWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
113
|
+
/**
|
|
114
|
+
* 获取文本的最小宽度
|
|
115
|
+
*
|
|
116
|
+
* @param texts 要测量的文本数组
|
|
117
|
+
* @param options 字体选项
|
|
118
|
+
* @returns 最小宽度(像素)
|
|
119
|
+
*/
|
|
120
|
+
export declare function getMinTextWidth(texts: string[], options?: TextMeasureOptions): number;
|
|
121
|
+
/**
|
|
122
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
123
|
+
*
|
|
124
|
+
* @param texts 要测量的文本数组
|
|
125
|
+
* @param options 字体选项
|
|
126
|
+
* @param spacing 文本间的间距,默认 0
|
|
127
|
+
* @returns 总宽度(像素)
|
|
128
|
+
*/
|
|
129
|
+
export declare function getTotalTextWidth(texts: string[], options?: TextMeasureOptions, spacing?: number): number;
|
|
130
|
+
/**
|
|
131
|
+
* 根据最大宽度截断文本,添加省略号
|
|
132
|
+
*
|
|
133
|
+
* @param text 原始文本
|
|
134
|
+
* @param maxWidth 最大宽度
|
|
135
|
+
* @param options 字体选项
|
|
136
|
+
* @param ellipsis 省略号,默认 '...'
|
|
137
|
+
* @param minChars 最少显示字符数,默认 0
|
|
138
|
+
* @returns 截断后的文本
|
|
139
|
+
*/
|
|
140
|
+
export declare function truncateText(text: string, maxWidth: number, options?: TextMeasureOptions, ellipsis?: string, minChars?: number): string;
|
|
141
|
+
export { TextMeasureUtil, type TextMeasureOptions, type TextMeasureResult };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
//#region src/utils/text-measure/text-measure.ts
|
|
2
|
+
var TextMeasureUtil = class {
|
|
3
|
+
canvas = null;
|
|
4
|
+
ctx = null;
|
|
5
|
+
/**
|
|
6
|
+
* 获取 Canvas 上下文,懒加载创建
|
|
7
|
+
*/
|
|
8
|
+
getContext() {
|
|
9
|
+
if (!this.canvas) {
|
|
10
|
+
this.canvas = document.createElement("canvas");
|
|
11
|
+
this.ctx = this.canvas.getContext("2d");
|
|
12
|
+
if (!this.ctx) throw new Error("无法创建 Canvas 2D 上下文");
|
|
13
|
+
}
|
|
14
|
+
return this.ctx;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 设置字体样式
|
|
18
|
+
*/
|
|
19
|
+
setFont(options = {}) {
|
|
20
|
+
const { fontSize = 14, fontFamily = "Arial, sans-serif", fontWeight = "normal", fontStyle = "normal" } = options;
|
|
21
|
+
const ctx = this.getContext();
|
|
22
|
+
ctx.font = `${fontStyle} ${fontWeight} ${typeof fontSize === "number" ? `${fontSize}px` : fontSize} ${fontFamily}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 测量单个文本的宽度
|
|
26
|
+
*
|
|
27
|
+
* @param text 要测量的文本
|
|
28
|
+
* @param options 字体选项
|
|
29
|
+
* @returns 文本宽度(像素)
|
|
30
|
+
*/
|
|
31
|
+
measureText(text, options = {}) {
|
|
32
|
+
if (!text) return 0;
|
|
33
|
+
this.setFont(options);
|
|
34
|
+
const metrics = this.getContext().measureText(text);
|
|
35
|
+
return Math.ceil(metrics.width);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 批量测量多段文本的宽度
|
|
39
|
+
*
|
|
40
|
+
* @param texts 要测量的文本数组
|
|
41
|
+
* @param options 字体选项
|
|
42
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
43
|
+
*/
|
|
44
|
+
measureTexts(texts, options = {}) {
|
|
45
|
+
if (!texts || texts.length === 0) return [];
|
|
46
|
+
this.setFont(options);
|
|
47
|
+
const ctx = this.getContext();
|
|
48
|
+
return texts.map((text) => ({
|
|
49
|
+
text,
|
|
50
|
+
width: text ? Math.ceil(ctx.measureText(text).width) : 0
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 获取文本的最大宽度
|
|
55
|
+
*
|
|
56
|
+
* @param texts 要测量的文本数组
|
|
57
|
+
* @param options 字体选项
|
|
58
|
+
* @returns 最大宽度(像素)
|
|
59
|
+
*/
|
|
60
|
+
getMaxWidth(texts, options = {}) {
|
|
61
|
+
const results = this.measureTexts(texts, options);
|
|
62
|
+
return Math.max(...results.map((result) => result.width), 0);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 获取文本的最小宽度
|
|
66
|
+
*
|
|
67
|
+
* @param texts 要测量的文本数组
|
|
68
|
+
* @param options 字体选项
|
|
69
|
+
* @returns 最小宽度(像素)
|
|
70
|
+
*/
|
|
71
|
+
getMinWidth(texts, options = {}) {
|
|
72
|
+
const results = this.measureTexts(texts, options);
|
|
73
|
+
return Math.min(...results.map((result) => result.width), 0);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
77
|
+
*
|
|
78
|
+
* @param texts 要测量的文本数组
|
|
79
|
+
* @param options 字体选项
|
|
80
|
+
* @param spacing 文本间的间距,默认 0
|
|
81
|
+
* @returns 总宽度(像素)
|
|
82
|
+
*/
|
|
83
|
+
getTotalWidth(texts, options = {}, spacing = 0) {
|
|
84
|
+
return this.measureTexts(texts, options).reduce((sum, result) => sum + result.width, 0) + Math.max(0, texts.length - 1) * spacing;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 根据最大宽度截断文本,添加省略号
|
|
88
|
+
*
|
|
89
|
+
* @param text 原始文本
|
|
90
|
+
* @param maxWidth 最大宽度
|
|
91
|
+
* @param options 字体选项
|
|
92
|
+
* @param ellipsis 省略号,默认 '...'
|
|
93
|
+
* @param minChars 最少显示字符数,默认 0
|
|
94
|
+
* @returns 截断后的文本
|
|
95
|
+
*/
|
|
96
|
+
truncateText(text, maxWidth, options = {}, ellipsis = "...", minChars = 0) {
|
|
97
|
+
if (!text) return "";
|
|
98
|
+
if (this.measureText(text, options) <= maxWidth) return text;
|
|
99
|
+
const availableWidth = maxWidth - this.measureText(ellipsis, options);
|
|
100
|
+
if (availableWidth <= 0) {
|
|
101
|
+
if (minChars > 0) return text.substring(0, minChars) + ellipsis;
|
|
102
|
+
return ellipsis;
|
|
103
|
+
}
|
|
104
|
+
let left = minChars;
|
|
105
|
+
let right = text.length;
|
|
106
|
+
let result = minChars > 0 ? text.substring(0, minChars) : "";
|
|
107
|
+
while (left <= right) {
|
|
108
|
+
const mid = Math.floor((left + right) / 2);
|
|
109
|
+
const substring = text.substring(0, mid);
|
|
110
|
+
if (this.measureText(substring, options) <= availableWidth) {
|
|
111
|
+
result = substring;
|
|
112
|
+
left = mid + 1;
|
|
113
|
+
} else right = mid - 1;
|
|
114
|
+
}
|
|
115
|
+
return result + ellipsis;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 销毁资源
|
|
119
|
+
*/
|
|
120
|
+
destroy() {
|
|
121
|
+
this.canvas = null;
|
|
122
|
+
this.ctx = null;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var textMeasureUtil = new TextMeasureUtil();
|
|
126
|
+
/**
|
|
127
|
+
* 测量单个文本的宽度
|
|
128
|
+
*
|
|
129
|
+
* @param text 要测量的文本
|
|
130
|
+
* @param options 字体选项
|
|
131
|
+
* @returns 文本宽度(像素)
|
|
132
|
+
*/
|
|
133
|
+
function measureText(text, options) {
|
|
134
|
+
return textMeasureUtil.measureText(text, options);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 批量测量多段文本的宽度
|
|
138
|
+
*
|
|
139
|
+
* @param texts 要测量的文本数组
|
|
140
|
+
* @param options 字体选项
|
|
141
|
+
* @returns 包含每段文本和对应宽度的结果数组
|
|
142
|
+
*/
|
|
143
|
+
function measureTexts(texts, options) {
|
|
144
|
+
return textMeasureUtil.measureTexts(texts, options);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 获取文本的最大宽度
|
|
148
|
+
*
|
|
149
|
+
* @param texts 要测量的文本数组
|
|
150
|
+
* @param options 字体选项
|
|
151
|
+
* @returns 最大宽度(像素)
|
|
152
|
+
*/
|
|
153
|
+
function getMaxTextWidth(texts, options) {
|
|
154
|
+
return textMeasureUtil.getMaxWidth(texts, options);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* 获取文本的最小宽度
|
|
158
|
+
*
|
|
159
|
+
* @param texts 要测量的文本数组
|
|
160
|
+
* @param options 字体选项
|
|
161
|
+
* @returns 最小宽度(像素)
|
|
162
|
+
*/
|
|
163
|
+
function getMinTextWidth(texts, options) {
|
|
164
|
+
return textMeasureUtil.getMinWidth(texts, options);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 计算文本的总宽度(用于水平排列的文本)
|
|
168
|
+
*
|
|
169
|
+
* @param texts 要测量的文本数组
|
|
170
|
+
* @param options 字体选项
|
|
171
|
+
* @param spacing 文本间的间距,默认 0
|
|
172
|
+
* @returns 总宽度(像素)
|
|
173
|
+
*/
|
|
174
|
+
function getTotalTextWidth(texts, options, spacing) {
|
|
175
|
+
return textMeasureUtil.getTotalWidth(texts, options, spacing);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 根据最大宽度截断文本,添加省略号
|
|
179
|
+
*
|
|
180
|
+
* @param text 原始文本
|
|
181
|
+
* @param maxWidth 最大宽度
|
|
182
|
+
* @param options 字体选项
|
|
183
|
+
* @param ellipsis 省略号,默认 '...'
|
|
184
|
+
* @param minChars 最少显示字符数,默认 0
|
|
185
|
+
* @returns 截断后的文本
|
|
186
|
+
*/
|
|
187
|
+
function truncateText(text, maxWidth, options, ellipsis, minChars) {
|
|
188
|
+
return textMeasureUtil.truncateText(text, maxWidth, options, ellipsis, minChars);
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
export { TextMeasureUtil, getMaxTextWidth, getMinTextWidth, getTotalTextWidth, measureText, measureTexts, truncateText };
|
|
@@ -26,9 +26,7 @@ var Uploader = class {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
static async uploadByFile(file, isApp = false, modelKey) {
|
|
29
|
-
|
|
30
|
-
formData.append("file", file, file.name);
|
|
31
|
-
return "/" + await (isApp ? appUploadapis : passUploadapis)(formData, modelKey);
|
|
29
|
+
return "/" + (await (isApp ? appUploadapis : passUploadapis)(file, modelKey)).data;
|
|
32
30
|
}
|
|
33
31
|
static toBase64(file) {
|
|
34
32
|
return new Promise((resolve, reject) => {
|
|
@@ -77,10 +75,10 @@ var Uploader = class {
|
|
|
77
75
|
}
|
|
78
76
|
};
|
|
79
77
|
async function appUploadapis(formData, modelKey) {
|
|
80
|
-
return _api.apaas.fileResource.postUpload({ ...modelKey ? { modelKey } : {} },
|
|
78
|
+
return _api.apaas.fileResource.postUpload({ ...modelKey ? { modelKey } : {} }, { file: formData });
|
|
81
79
|
}
|
|
82
80
|
async function passUploadapis(formData) {
|
|
83
|
-
return _api.apaas.file.postUploadImage({ bucket: "IMAGE" },
|
|
81
|
+
return _api.apaas.file.postUploadImage({ bucket: "IMAGE" }, { file: formData });
|
|
84
82
|
}
|
|
85
83
|
//#endregion
|
|
86
84
|
export { Uploader };
|
package/es/utils/util.d.ts
CHANGED
|
@@ -37,3 +37,13 @@ export declare function genUrl(url: string, data: IObject): string;
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
export declare function openWindow(url: string, options?: IOpenWindowOptions): Window | null;
|
|
40
|
+
/**
|
|
41
|
+
* 删除数组指定下标元素,并插入到目标下标位置
|
|
42
|
+
*
|
|
43
|
+
* @export
|
|
44
|
+
* @param {unknown[]} arr - 需要操作的原数组
|
|
45
|
+
* @param {number} deleteIndex - 要删除元素的下标
|
|
46
|
+
* @param {number} insertIndex - 元素重新插入的目标下标
|
|
47
|
+
* @return {void}
|
|
48
|
+
*/
|
|
49
|
+
export declare function deleteAndInsertArr(arr: unknown[], deleteIndex: number, insertIndex: number): void;
|
package/es/utils/util.mjs
CHANGED
|
@@ -56,5 +56,22 @@ function openWindow(url, options) {
|
|
|
56
56
|
if (optionStr) featuresStr = featuresStr ? `${featuresStr},${optionStr}` : optionStr;
|
|
57
57
|
return window.open(finalUrl, target, featuresStr);
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* 删除数组指定下标元素,并插入到目标下标位置
|
|
61
|
+
*
|
|
62
|
+
* @export
|
|
63
|
+
* @param {unknown[]} arr - 需要操作的原数组
|
|
64
|
+
* @param {number} deleteIndex - 要删除元素的下标
|
|
65
|
+
* @param {number} insertIndex - 元素重新插入的目标下标
|
|
66
|
+
* @return {void}
|
|
67
|
+
*/
|
|
68
|
+
function deleteAndInsertArr(arr, deleteIndex, insertIndex) {
|
|
69
|
+
if (deleteIndex < 0 || deleteIndex >= arr.length || insertIndex < 0 || insertIndex > arr.length) {
|
|
70
|
+
console.log("下标超出数组范围");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const deletedElement = arr.splice(deleteIndex, 1)[0];
|
|
74
|
+
arr.splice(insertIndex, 0, deletedElement);
|
|
75
|
+
}
|
|
59
76
|
//#endregion
|
|
60
|
-
export { genUrl, openWindow };
|
|
77
|
+
export { deleteAndInsertArr, genUrl, openWindow };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6-dev.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台核心包",
|
|
6
6
|
"loader": "dist/index.esm.min.js",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"author": "gct",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fingerprintjs/fingerprintjs": "^5.1.0",
|
|
35
|
-
"@
|
|
35
|
+
"@floating-ui/dom": "^1.7.6",
|
|
36
|
+
"@gct-paas/api": "^0.1.4-dev.4",
|
|
36
37
|
"@module-federation/runtime": "^2.2.3",
|
|
37
38
|
"@vueuse/core": "^14.1.0",
|
|
38
39
|
"async-validator": "^4.2.5",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"playwright": "^1.58.0"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
|
-
"@gct-paas/api": "0.1.4-
|
|
61
|
+
"@gct-paas/api": "^0.1.4-dev.4",
|
|
61
62
|
"vue": ">=3",
|
|
62
63
|
"vue-i18n": ">=11",
|
|
63
64
|
"vue-router": ">=4"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* systemjs 扩展样式模块加载声明
|
|
3
|
-
*
|
|
4
|
-
* @export
|
|
5
|
-
* @interface IStyleIMportMap
|
|
6
|
-
* @extends {System.ImportMap}
|
|
7
|
-
*/
|
|
8
|
-
export interface IStyleIMportMap extends System.ImportMap {
|
|
9
|
-
/**
|
|
10
|
-
* 样式静态资源相对或者绝对路径与 imports 里边对应,会在加载 import 脚本时,自动加载样式文件
|
|
11
|
-
*
|
|
12
|
-
* @type {(Record<string, string[] | string>)}
|
|
13
|
-
*/
|
|
14
|
-
styles?: Record<string, string[] | string>;
|
|
15
|
-
}
|