@gct-paas/schema 0.1.4-dev.9 → 0.1.5-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 -0
- package/es/constants/design.d.ts +26 -0
- package/es/constants/design.mjs +30 -0
- package/es/constants/index.d.ts +24 -1
- package/es/constants/index.mjs +410 -18
- package/es/index.d.ts +1 -1
- package/es/index.mjs +13 -19
- package/es/interface/design/i-design-container-node.d.ts +13 -0
- package/es/interface/design/i-design-data.d.ts +44 -0
- package/es/interface/design/i-design-editor-data.d.ts +20 -0
- package/es/interface/design/i-design-editor-node.d.ts +15 -0
- package/es/interface/design/i-design-node-data.d.ts +19 -0
- package/es/interface/design/i-design-node.d.ts +80 -0
- package/es/interface/design/i-design-page-node-data.d.ts +15 -0
- package/es/interface/design/i-design-tree-item.d.ts +26 -0
- package/es/interface/design/i-drag-data-item.d.ts +46 -0
- package/es/interface/design/index.d.ts +9 -0
- package/es/interface/designer.d.ts +1 -1
- package/es/interface/index.d.ts +2 -0
- package/es/interface/modal/i-modal-body.d.ts +1 -1
- package/es/interface/relationship-diagram-config/i-relationship-diagram-node.d.ts +82 -0
- package/es/interface/relationship-diagram-config/i-rule-config.d.ts +135 -0
- package/es/interface/relationship-diagram-config/index.d.ts +2 -0
- package/es/interface/schema/widget-props/i-card-list-props.d.ts +79 -0
- package/es/interface/schema/widget-props/i-form-container-props.d.ts +19 -5
- package/es/interface/schema/widget-props/i-form-input-props.d.ts +1 -1
- package/es/interface/schema/widget-props/i-search-widget-props.d.ts +6 -0
- package/es/interface/schema/widget-props/i-table-props.d.ts +6 -6
- package/es/interface/schema/widget-props/index.d.ts +1 -0
- package/es/interface/schema/widget-types.d.ts +36 -7
- package/es/interface/widget/i-common.d.ts +2 -1
- package/es/interface/widget/i-editors.d.ts +3 -2
- package/es/interface/widget/i-props.d.ts +13 -32
- package/es/interface/widget/i-schemas.d.ts +2 -0
- package/es/interface/widget/i-styles.d.ts +1 -0
- package/es/interface/widget/index.d.ts +3 -1
- package/es/utils/field-editor-override-registry/field-editor-override-registry.d.ts +36 -0
- package/es/utils/field-editor-override-registry/field-editor-override-registry.mjs +29 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.mjs +6 -0
- package/es/utils/schema/index.d.ts +4 -1
- package/es/utils/schema/index.mjs +75 -39
- package/es/utils/schema/search.d.ts +9 -0
- package/es/utils/schema/search.mjs +146 -0
- package/es/utils/schema/utils.d.ts +21 -0
- package/es/utils/schema/utils.mjs +182 -0
- package/es/utils/schema-style/index.mjs +203 -127
- package/es/utils/widget-info/widget-info.mjs +132 -57
- package/package.json +12 -13
- package/dist/index.esm.min.mjs +0 -898
- package/dist/index.min.cjs +0 -1
- package/dist/index.system.min.js +0 -1
- package/es/schema/common-config/base-button-config.d.ts +0 -3
- package/es/schema/common-config/base-button-config.mjs +0 -84
- package/es/schema/common-config/button-editor-config.d.ts +0 -4
- package/es/schema/common-config/button-editor-config.mjs +0 -206
- package/es/schema/common-config/button-props-func.d.ts +0 -5
- package/es/schema/common-config/button-props-func.mjs +0 -11
- package/es/schema/common-config/common-field-editor-config.d.ts +0 -10
- package/es/schema/common-config/common-field-editor-config.mjs +0 -61
- package/es/schema/common-config/common-style.d.ts +0 -3
- package/es/schema/common-config/common-style.mjs +0 -85
- package/es/schema/common-config/display-editor-config.d.ts +0 -3
- package/es/schema/common-config/display-editor-config.mjs +0 -89
- package/es/schema/common-config/permission-editor-config.d.ts +0 -2
- package/es/schema/common-config/permission-editor-config.mjs +0 -23
- package/es/schema/index.d.ts +0 -9
- package/es/schema/modal/modal-body.d.ts +0 -2
- package/es/schema/modal/modal-body.mjs +0 -9
- package/es/schema/modal/modal-footer.d.ts +0 -2
- package/es/schema/modal/modal-footer.mjs +0 -9
- package/es/schema/modal/modal.d.ts +0 -8
- package/es/schema/modal/modal.mjs +0 -182
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { EntityFormulaReturnTypeEnum, FIELD_TYPE, MaterialEnum, ReturnTypeEnum } from "@gct-paas/core";
|
|
2
|
+
//#region src/utils/schema/utils.ts
|
|
3
|
+
/** 树转一维数组 */
|
|
4
|
+
function flatten(array = [], path = "", inSubTable = false) {
|
|
5
|
+
return [].concat(...array.map((item) => {
|
|
6
|
+
const key = item.materialType === MaterialEnum.MaterialSubTableModalField ? `modalfield_${item.id}` : item.id;
|
|
7
|
+
item.path = `${path}|${/^modalBody_/.test(item.id) ? "undefined" : key}`;
|
|
8
|
+
item.inSubTable = inSubTable || !!(/^modal_/.test(item.id) && item.props?.isSubTableModal);
|
|
9
|
+
const children = [...item.children || []];
|
|
10
|
+
if (item.type === "workflow-nodes" && item.props) {
|
|
11
|
+
/**工作流节点特殊逻辑处理 */
|
|
12
|
+
if (item.props.specModalInfo) children.push(item.props.specModalInfo);
|
|
13
|
+
if (item.props.workflowModalInfo) children.push(item.props.workflowModalInfo);
|
|
14
|
+
}
|
|
15
|
+
return [].concat({
|
|
16
|
+
id: item.id,
|
|
17
|
+
key,
|
|
18
|
+
name: item.name,
|
|
19
|
+
customName: item.alias,
|
|
20
|
+
path: item.path,
|
|
21
|
+
type: item.type,
|
|
22
|
+
inSubTable: item.inSubTable
|
|
23
|
+
}, flatten(children, item.path, item.inSubTable ?? false));
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 字段填充映射处理
|
|
28
|
+
*/
|
|
29
|
+
var transformMappingField = (fieldType) => {
|
|
30
|
+
return {
|
|
31
|
+
[FIELD_TYPE.TEXT]: { filterArr: [FIELD_TYPE.TEXT] },
|
|
32
|
+
[FIELD_TYPE.LONG_TEXT]: { filterArr: [FIELD_TYPE.TEXT, FIELD_TYPE.LONG_TEXT] },
|
|
33
|
+
[FIELD_TYPE.INTEGER]: { filterArr: [FIELD_TYPE.INTEGER] },
|
|
34
|
+
[FIELD_TYPE.LONG]: { filterArr: [FIELD_TYPE.INTEGER, FIELD_TYPE.LONG] },
|
|
35
|
+
[FIELD_TYPE.DOUBLE]: { filterArr: [FIELD_TYPE.DOUBLE, FIELD_TYPE.DECIMAL] },
|
|
36
|
+
[FIELD_TYPE.DECIMAL]: { filterArr: [FIELD_TYPE.DECIMAL] },
|
|
37
|
+
[FIELD_TYPE.BOOLEAN]: { filterArr: [FIELD_TYPE.BOOLEAN] },
|
|
38
|
+
[FIELD_TYPE.DATE]: { filterArr: [FIELD_TYPE.DATE] },
|
|
39
|
+
[FIELD_TYPE.TIME]: { filterArr: [FIELD_TYPE.TIME] },
|
|
40
|
+
[FIELD_TYPE.DATE_TIME]: { filterArr: [FIELD_TYPE.DATE_TIME] },
|
|
41
|
+
[FIELD_TYPE.IMAGE]: { filterArr: [FIELD_TYPE.IMAGE] },
|
|
42
|
+
[FIELD_TYPE.ATTACHMENT]: { filterArr: [FIELD_TYPE.ATTACHMENT] },
|
|
43
|
+
[FIELD_TYPE.MASTERSLAVE]: {
|
|
44
|
+
filterArr: [FIELD_TYPE.MASTERSLAVE],
|
|
45
|
+
equal: true
|
|
46
|
+
},
|
|
47
|
+
[FIELD_TYPE.USER]: { filterArr: [FIELD_TYPE.USER] },
|
|
48
|
+
[FIELD_TYPE.USER_MULTI]: { filterArr: [FIELD_TYPE.USER, FIELD_TYPE.USER_MULTI] },
|
|
49
|
+
[FIELD_TYPE.ORG]: { filterArr: [FIELD_TYPE.ORG] },
|
|
50
|
+
[FIELD_TYPE.ORG_MULTI]: { filterArr: [FIELD_TYPE.ORG, FIELD_TYPE.ORG_MULTI] },
|
|
51
|
+
[FIELD_TYPE.ENUM]: {
|
|
52
|
+
filterArr: [FIELD_TYPE.ENUM],
|
|
53
|
+
equal: true
|
|
54
|
+
},
|
|
55
|
+
[FIELD_TYPE.ENUM_MULTI]: {
|
|
56
|
+
filterArr: [FIELD_TYPE.ENUM, FIELD_TYPE.ENUM_MULTI],
|
|
57
|
+
equal: true
|
|
58
|
+
},
|
|
59
|
+
[FIELD_TYPE.REF]: {
|
|
60
|
+
filterArr: [FIELD_TYPE.REF],
|
|
61
|
+
equal: true
|
|
62
|
+
},
|
|
63
|
+
[FIELD_TYPE.REF_MULTI]: {
|
|
64
|
+
filterArr: [FIELD_TYPE.REF, FIELD_TYPE.REF_MULTI],
|
|
65
|
+
equal: true
|
|
66
|
+
},
|
|
67
|
+
[FIELD_TYPE.RDO_REF]: {
|
|
68
|
+
filterArr: [FIELD_TYPE.RDO_REF],
|
|
69
|
+
equal: true
|
|
70
|
+
},
|
|
71
|
+
[FIELD_TYPE.LABEL_TEMPLATE_REF]: { filterArr: [FIELD_TYPE.LABEL_TEMPLATE_REF] },
|
|
72
|
+
[FIELD_TYPE.DOCUMENT_TEMPLATE]: { filterArr: [FIELD_TYPE.DOCUMENT_TEMPLATE] },
|
|
73
|
+
[FIELD_TYPE.SERIALRULE]: { filterArr: [FIELD_TYPE.SERIALRULE] },
|
|
74
|
+
[FIELD_TYPE.PRINTER]: { filterArr: [FIELD_TYPE.PRINTER] },
|
|
75
|
+
[FIELD_TYPE.MESSAGE_TMPL]: { filterArr: [FIELD_TYPE.MESSAGE_TMPL] },
|
|
76
|
+
[FIELD_TYPE.RANGE_USER]: { filterArr: [FIELD_TYPE.RANGE_USER] },
|
|
77
|
+
[FIELD_TYPE.SIGNATURE]: { filterArr: [FIELD_TYPE.SIGNATURE] },
|
|
78
|
+
[FIELD_TYPE.ONLINE_FORM_TEMPLATE]: { filterArr: [FIELD_TYPE.ONLINE_FORM_TEMPLATE] },
|
|
79
|
+
[FIELD_TYPE.E_DHR_TEMPLATE]: { filterArr: [FIELD_TYPE.E_DHR_TEMPLATE] },
|
|
80
|
+
[FIELD_TYPE.ESOP]: { filterArr: [FIELD_TYPE.ESOP] }
|
|
81
|
+
}[fieldType];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* 转换原始的returnType为字段类型
|
|
85
|
+
*/
|
|
86
|
+
var convertMappingType = (type) => {
|
|
87
|
+
return [
|
|
88
|
+
{
|
|
89
|
+
old: ReturnTypeEnum.String,
|
|
90
|
+
new: EntityFormulaReturnTypeEnum.LongText
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
old: ReturnTypeEnum.Number,
|
|
94
|
+
new: EntityFormulaReturnTypeEnum.Double
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
old: ReturnTypeEnum.Boolean,
|
|
98
|
+
new: EntityFormulaReturnTypeEnum.Boolean
|
|
99
|
+
}
|
|
100
|
+
].find((i) => i.old == type)?.new ?? type;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 自动填充映射处理
|
|
104
|
+
*/
|
|
105
|
+
var transformMappingField4Auto = (fieldType) => {
|
|
106
|
+
return {
|
|
107
|
+
[FIELD_TYPE.TEXT]: { filterArr: [FIELD_TYPE.TEXT, FIELD_TYPE.LONG_TEXT] },
|
|
108
|
+
[FIELD_TYPE.LONG_TEXT]: { filterArr: [FIELD_TYPE.LONG_TEXT] },
|
|
109
|
+
[FIELD_TYPE.INTEGER]: { filterArr: [
|
|
110
|
+
FIELD_TYPE.INTEGER,
|
|
111
|
+
FIELD_TYPE.LONG,
|
|
112
|
+
FIELD_TYPE.DOUBLE,
|
|
113
|
+
FIELD_TYPE.TEXT,
|
|
114
|
+
FIELD_TYPE.LONG_TEXT
|
|
115
|
+
] },
|
|
116
|
+
[FIELD_TYPE.LONG]: { filterArr: [
|
|
117
|
+
FIELD_TYPE.LONG,
|
|
118
|
+
FIELD_TYPE.TEXT,
|
|
119
|
+
FIELD_TYPE.LONG_TEXT,
|
|
120
|
+
FIELD_TYPE.DOUBLE
|
|
121
|
+
] },
|
|
122
|
+
[FIELD_TYPE.DOUBLE]: { filterArr: [
|
|
123
|
+
FIELD_TYPE.DOUBLE,
|
|
124
|
+
FIELD_TYPE.TEXT,
|
|
125
|
+
FIELD_TYPE.LONG_TEXT
|
|
126
|
+
] },
|
|
127
|
+
[FIELD_TYPE.DECIMAL]: { filterArr: [
|
|
128
|
+
FIELD_TYPE.DECIMAL,
|
|
129
|
+
FIELD_TYPE.TEXT,
|
|
130
|
+
FIELD_TYPE.LONG_TEXT
|
|
131
|
+
] },
|
|
132
|
+
[FIELD_TYPE.DATE]: { filterArr: [FIELD_TYPE.DATE] },
|
|
133
|
+
[FIELD_TYPE.TIME]: { filterArr: [FIELD_TYPE.TIME] },
|
|
134
|
+
[FIELD_TYPE.DATE_TIME]: { filterArr: [
|
|
135
|
+
FIELD_TYPE.DATE_TIME,
|
|
136
|
+
FIELD_TYPE.DATE,
|
|
137
|
+
FIELD_TYPE.TIME
|
|
138
|
+
] },
|
|
139
|
+
[FIELD_TYPE.IMAGE]: { filterArr: [FIELD_TYPE.IMAGE] },
|
|
140
|
+
[FIELD_TYPE.ATTACHMENT]: { filterArr: [FIELD_TYPE.ATTACHMENT] },
|
|
141
|
+
[FIELD_TYPE.MASTERSLAVE]: {
|
|
142
|
+
filterArr: [FIELD_TYPE.MASTERSLAVE],
|
|
143
|
+
equal: true
|
|
144
|
+
},
|
|
145
|
+
[FIELD_TYPE.USER]: { filterArr: [FIELD_TYPE.USER, FIELD_TYPE.USER_MULTI] },
|
|
146
|
+
[FIELD_TYPE.USER_MULTI]: { filterArr: [FIELD_TYPE.USER_MULTI] },
|
|
147
|
+
[FIELD_TYPE.ORG]: { filterArr: [FIELD_TYPE.ORG, FIELD_TYPE.ORG_MULTI] },
|
|
148
|
+
[FIELD_TYPE.ORG_MULTI]: { filterArr: [FIELD_TYPE.ORG_MULTI] },
|
|
149
|
+
[FIELD_TYPE.ENUM]: {
|
|
150
|
+
filterArr: [FIELD_TYPE.ENUM, FIELD_TYPE.ENUM_MULTI],
|
|
151
|
+
equal: true
|
|
152
|
+
},
|
|
153
|
+
[FIELD_TYPE.ENUM_MULTI]: {
|
|
154
|
+
filterArr: [FIELD_TYPE.ENUM_MULTI],
|
|
155
|
+
equal: true
|
|
156
|
+
},
|
|
157
|
+
[FIELD_TYPE.REF]: {
|
|
158
|
+
filterArr: [FIELD_TYPE.REF, FIELD_TYPE.REF_MULTI],
|
|
159
|
+
equal: true
|
|
160
|
+
},
|
|
161
|
+
[FIELD_TYPE.REF_MULTI]: {
|
|
162
|
+
filterArr: [FIELD_TYPE.REF_MULTI],
|
|
163
|
+
equal: true
|
|
164
|
+
},
|
|
165
|
+
[FIELD_TYPE.RDO_REF]: {
|
|
166
|
+
filterArr: [FIELD_TYPE.RDO_REF],
|
|
167
|
+
equal: true
|
|
168
|
+
},
|
|
169
|
+
[FIELD_TYPE.ESOP]: { filterArr: [FIELD_TYPE.ESOP] },
|
|
170
|
+
[FIELD_TYPE.TRANSACTION]: { filterArr: [FIELD_TYPE.TRANSACTION] },
|
|
171
|
+
[FIELD_TYPE.LABEL_TEMPLATE_REF]: { filterArr: [FIELD_TYPE.LABEL_TEMPLATE_REF] },
|
|
172
|
+
[FIELD_TYPE.DOCUMENT_TEMPLATE]: { filterArr: [FIELD_TYPE.DOCUMENT_TEMPLATE] },
|
|
173
|
+
[FIELD_TYPE.SERIALRULE]: { filterArr: [FIELD_TYPE.SERIALRULE] },
|
|
174
|
+
[FIELD_TYPE.PRINTER]: { filterArr: [FIELD_TYPE.PRINTER] },
|
|
175
|
+
[FIELD_TYPE.MESSAGE_TMPL]: { filterArr: [FIELD_TYPE.MESSAGE_TMPL] },
|
|
176
|
+
[FIELD_TYPE.RANGE_USER]: { filterArr: [FIELD_TYPE.RANGE_USER] },
|
|
177
|
+
[FIELD_TYPE.ONLINE_FORM_TEMPLATE]: { filterArr: [FIELD_TYPE.ONLINE_FORM_TEMPLATE] },
|
|
178
|
+
[FIELD_TYPE.E_DHR_TEMPLATE]: { filterArr: [FIELD_TYPE.E_DHR_TEMPLATE] }
|
|
179
|
+
}[fieldType];
|
|
180
|
+
};
|
|
181
|
+
//#endregion
|
|
182
|
+
export { convertMappingType, flatten, transformMappingField, transformMappingField4Auto };
|
|
@@ -1,155 +1,231 @@
|
|
|
1
|
-
import { isEmpty,
|
|
2
|
-
|
|
1
|
+
import { isEmpty, isNil, pick } from "lodash-es";
|
|
2
|
+
//#region src/utils/schema-style/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* 样式计算工具类
|
|
5
|
+
* 提供样式单位转换、属性映射、样式属性处理等公共方法
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 将像素值转换为对应单位
|
|
9
|
+
* 在移动环境下转换为 vw,其他环境保持 px
|
|
10
|
+
*
|
|
11
|
+
* @param pxValue - 像素值
|
|
12
|
+
* @returns 转换后的单位值字符串
|
|
13
|
+
*/
|
|
3
14
|
function pxToVw(pxValue) {
|
|
4
|
-
|
|
15
|
+
return pxValue + "px";
|
|
5
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* 添加 px 单位到样式值
|
|
19
|
+
*
|
|
20
|
+
* @param value - 样式值
|
|
21
|
+
* @returns 带 px 单位和 !important 的样式字符串
|
|
22
|
+
*/
|
|
6
23
|
function addPxUnit(value) {
|
|
7
|
-
|
|
24
|
+
return isEmpty(value) ? "" : `${value}px !important`;
|
|
8
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* 添加 !important 标志到样式值(不添加单位)
|
|
28
|
+
*
|
|
29
|
+
* @param value - 样式值
|
|
30
|
+
* @returns 带 !important 的样式字符串
|
|
31
|
+
*/
|
|
9
32
|
function addImportant(value) {
|
|
10
|
-
|
|
33
|
+
return isEmpty(value) ? "" : `${value} !important`;
|
|
11
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* 格式化边框样式对象
|
|
37
|
+
*
|
|
38
|
+
* @param border - 边框配置对象,包含 borderWidth、borderStyle、borderColor
|
|
39
|
+
* @returns 格式化后的边框样式字符串
|
|
40
|
+
*/
|
|
12
41
|
function formatBorder(border) {
|
|
13
|
-
|
|
14
|
-
|
|
42
|
+
if (!border || isEmpty(border.borderWidth)) return "";
|
|
43
|
+
return `${border.borderWidth}px ${border.borderStyle || "solid"} ${border.borderColor || "transparent"} !important`;
|
|
15
44
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
45
|
+
/**
|
|
46
|
+
* 字体样式处理默认配置
|
|
47
|
+
*/
|
|
48
|
+
var DEFAULT_FONT_CONFIG = {
|
|
49
|
+
fontAttrs: [
|
|
50
|
+
"fontWeight",
|
|
51
|
+
"fontSize",
|
|
52
|
+
"color",
|
|
53
|
+
"textDecorationLine",
|
|
54
|
+
"textAlign"
|
|
55
|
+
],
|
|
56
|
+
mapAttrs: {
|
|
57
|
+
bold: {
|
|
58
|
+
attr: "fontWeight",
|
|
59
|
+
callback: (value) => {
|
|
60
|
+
return value ? 700 : 400;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
italic: {
|
|
64
|
+
attr: "fontStyle",
|
|
65
|
+
callback: (value) => {
|
|
66
|
+
return value ? "italic" : "normal";
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
textDecoration: { attr: "textDecorationLine" },
|
|
70
|
+
fontSize: {
|
|
71
|
+
attr: "fontSize",
|
|
72
|
+
callback: (value) => {
|
|
73
|
+
return value ? pxToVw(value) : "";
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
align: { attr: "textAlign" }
|
|
77
|
+
}
|
|
50
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* 从字体配置对象中提取并转换字体样式
|
|
81
|
+
*
|
|
82
|
+
* @param font - 字体配置对象
|
|
83
|
+
* @param config - 字体样式处理配置(可选,使用默认配置)
|
|
84
|
+
* @returns 转换后的样式对象
|
|
85
|
+
*/
|
|
51
86
|
function extractFontStyle(font, config = DEFAULT_FONT_CONFIG) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
87
|
+
if (!font) return {};
|
|
88
|
+
const result = {};
|
|
89
|
+
Object.assign(result, pick(font, config.fontAttrs));
|
|
90
|
+
if (typeof config.mapAttrs === "object") Object.keys(config.mapAttrs).forEach((k) => {
|
|
91
|
+
const { attr, callback } = config.mapAttrs[k];
|
|
92
|
+
result[attr] = typeof callback === "function" ? callback(font[k]) : font[k];
|
|
93
|
+
});
|
|
94
|
+
return result;
|
|
62
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* 将样式属性对象转换为 CSS 样式字符串格式
|
|
98
|
+
*
|
|
99
|
+
* @param styleProps - 样式属性对象
|
|
100
|
+
* @returns 转换后的样式对象(含单位和 !important)
|
|
101
|
+
*/
|
|
63
102
|
function propsToStyle(styleProps = {}) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return wStyle;
|
|
103
|
+
const wStyle = {};
|
|
104
|
+
for (const prop in styleProps) wStyle[prop] = makeStyleProp(prop, styleProps[prop]);
|
|
105
|
+
return wStyle;
|
|
69
106
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
107
|
+
/**
|
|
108
|
+
* 不需要添加 px 单位的 CSS 属性列表
|
|
109
|
+
*/
|
|
110
|
+
var NOT_NEED_PX_STYLE = [
|
|
111
|
+
"opacity",
|
|
112
|
+
"zIndex",
|
|
113
|
+
"fontWeight",
|
|
114
|
+
"lineHeight",
|
|
115
|
+
"letterSpacing",
|
|
116
|
+
"wordSpacing",
|
|
117
|
+
"textAlign",
|
|
118
|
+
"textDecoration",
|
|
119
|
+
"textTransform",
|
|
120
|
+
"fontStyle",
|
|
121
|
+
"textDecorationLine"
|
|
82
122
|
];
|
|
123
|
+
/**
|
|
124
|
+
* 将单个样式属性值转换为带单位的 CSS 字符串
|
|
125
|
+
*
|
|
126
|
+
* @param prop - 属性名
|
|
127
|
+
* @param value - 属性值
|
|
128
|
+
* @returns 转换后的样式值字符串
|
|
129
|
+
*/
|
|
83
130
|
function makeStyleProp(prop, value) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (NOT_NEED_PX_STYLE.includes(prop)) {
|
|
88
|
-
return value + " !important";
|
|
89
|
-
}
|
|
90
|
-
return value + "px !important";
|
|
131
|
+
if (isNil(value) || isEmpty(value)) return "";
|
|
132
|
+
if (NOT_NEED_PX_STYLE.includes(prop)) return value + " !important";
|
|
133
|
+
return value + "px !important";
|
|
91
134
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
135
|
+
/**
|
|
136
|
+
* 对齐方式到 Flex 对齐值的映射
|
|
137
|
+
*/
|
|
138
|
+
var ALIGN_TO_FLEX_MAP = {
|
|
139
|
+
left: "flex-start",
|
|
140
|
+
center: "center",
|
|
141
|
+
right: "flex-end",
|
|
142
|
+
justify: "space-between"
|
|
97
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* 将对齐属性值转换为 Flex 对齐值
|
|
146
|
+
*
|
|
147
|
+
* @param align - 对齐方式(left、center、right、justify)
|
|
148
|
+
* @returns 对应的 Flex 对齐值
|
|
149
|
+
*/
|
|
98
150
|
function transAlign2flex(align) {
|
|
99
|
-
|
|
151
|
+
return ALIGN_TO_FLEX_MAP[align] || align;
|
|
100
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* 生成位置和尺寸样式对象
|
|
155
|
+
*
|
|
156
|
+
* @param style - 样式配置对象
|
|
157
|
+
* @returns 位置和尺寸样式对象
|
|
158
|
+
*/
|
|
101
159
|
function generatePositionStyles(style) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
160
|
+
return {
|
|
161
|
+
position: addImportant(style.position),
|
|
162
|
+
top: addPxUnit(style.top),
|
|
163
|
+
left: addPxUnit(style.left),
|
|
164
|
+
right: addPxUnit(style.right),
|
|
165
|
+
bottom: addPxUnit(style.bottom),
|
|
166
|
+
width: addPxUnit(style.width),
|
|
167
|
+
height: addPxUnit(style.height)
|
|
168
|
+
};
|
|
111
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* 生成背景和间距样式对象
|
|
172
|
+
*
|
|
173
|
+
* @param style - 样式配置对象
|
|
174
|
+
* @returns 背景和间距样式对象
|
|
175
|
+
*/
|
|
112
176
|
function generateSpacingStyles(style) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
177
|
+
return {
|
|
178
|
+
backgroundColor: addImportant(style.backgroundColor),
|
|
179
|
+
marginTop: addPxUnit(style.marginTop),
|
|
180
|
+
marginRight: addPxUnit(style.marginRight),
|
|
181
|
+
marginBottom: addPxUnit(style.marginBottom),
|
|
182
|
+
marginLeft: addPxUnit(style.marginLeft),
|
|
183
|
+
paddingTop: addPxUnit(style.paddingTop),
|
|
184
|
+
paddingRight: addPxUnit(style.paddingRight),
|
|
185
|
+
paddingBottom: addPxUnit(style.paddingBottom),
|
|
186
|
+
paddingLeft: addPxUnit(style.paddingLeft)
|
|
187
|
+
};
|
|
124
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* 生成边框样式对象
|
|
191
|
+
*
|
|
192
|
+
* @param style - 样式配置对象
|
|
193
|
+
* @returns 边框样式对象
|
|
194
|
+
*/
|
|
125
195
|
function generateBorderStyles(style) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
196
|
+
return {
|
|
197
|
+
borderLeft: formatBorder(style.borderLeft),
|
|
198
|
+
borderRight: formatBorder(style.borderRight),
|
|
199
|
+
borderBottom: formatBorder(style.borderBottom),
|
|
200
|
+
borderTop: formatBorder(style.borderTop),
|
|
201
|
+
borderTopRightRadius: addPxUnit(style.borderTopRightRadius),
|
|
202
|
+
borderTopLeftRadius: addPxUnit(style.borderTopLeftRadius),
|
|
203
|
+
borderBottomRightRadius: addPxUnit(style.borderBottomRightRadius),
|
|
204
|
+
borderBottomLeftRadius: addPxUnit(style.borderBottomLeftRadius)
|
|
205
|
+
};
|
|
136
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* 生成完整的包装样式对象
|
|
209
|
+
* 合并位置、间距、边框等所有样式
|
|
210
|
+
*
|
|
211
|
+
* @param style - 样式配置对象
|
|
212
|
+
* @param ignoringStyle - 需要忽略的样式属性数组
|
|
213
|
+
* @returns 合并后的完整样式对象
|
|
214
|
+
*/
|
|
137
215
|
function generateWrapperStyle(style, ignoringStyle = []) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
return styleData;
|
|
216
|
+
const styleData = {
|
|
217
|
+
...generatePositionStyles(style),
|
|
218
|
+
...generateSpacingStyles(style),
|
|
219
|
+
...generateBorderStyles(style)
|
|
220
|
+
};
|
|
221
|
+
ignoringStyle.forEach((key) => {
|
|
222
|
+
delete styleData[key];
|
|
223
|
+
});
|
|
224
|
+
Object.keys(styleData).forEach((key) => {
|
|
225
|
+
const val = styleData[key];
|
|
226
|
+
if (isNil(val) || isEmpty(val)) delete styleData[key];
|
|
227
|
+
});
|
|
228
|
+
return styleData;
|
|
153
229
|
}
|
|
154
|
-
|
|
230
|
+
//#endregion
|
|
155
231
|
export { ALIGN_TO_FLEX_MAP, addImportant, addPxUnit, extractFontStyle, formatBorder, generateBorderStyles, generatePositionStyles, generateSpacingStyles, generateWrapperStyle, makeStyleProp, propsToStyle, pxToVw, transAlign2flex };
|