km-card-layout-core 0.1.6 → 0.1.8
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.js +87 -58
- package/dist/utils.js +5 -0
- package/index.ts +196 -141
- package/interface/data/payload.ts +20 -2
- package/interface/render.ts +1 -0
- package/package.json +1 -1
- package/types.d.ts +7 -8
- package/utils.ts +10 -10
package/dist/index.js
CHANGED
|
@@ -193,49 +193,91 @@ const resolveBindingValue = (binding, rootData, context) => {
|
|
|
193
193
|
};
|
|
194
194
|
exports.resolveBindingValue = resolveBindingValue;
|
|
195
195
|
/** ---------- 样式构建 ---------- */
|
|
196
|
+
const buildCardStyle = (layout, unit) => (0, exports.styleObjectToString)({
|
|
197
|
+
width: (0, exports.addUnit)(layout.width, unit),
|
|
198
|
+
height: (0, exports.addUnit)(layout.height, unit),
|
|
199
|
+
color: layout.fontColor,
|
|
200
|
+
borderRadius: layout.borderRadius !== undefined
|
|
201
|
+
? (0, exports.addUnit)(layout.borderRadius, unit)
|
|
202
|
+
: undefined,
|
|
203
|
+
padding: layout.padding !== undefined ? (0, exports.addUnit)(layout.padding, unit) : undefined,
|
|
204
|
+
position: 'relative',
|
|
205
|
+
overflow: 'hidden',
|
|
206
|
+
boxSizing: 'border-box',
|
|
207
|
+
backgroundColor: 'transparent',
|
|
208
|
+
}, unit);
|
|
209
|
+
const buildBackgroundStyle = (layout, unit) => (0, exports.styleObjectToString)({
|
|
210
|
+
zIndex: layout.backgroundZIndex,
|
|
211
|
+
borderRadius: layout.borderRadius !== undefined
|
|
212
|
+
? (0, exports.addUnit)(layout.borderRadius, unit)
|
|
213
|
+
: undefined,
|
|
214
|
+
width: '100%',
|
|
215
|
+
height: '100%',
|
|
216
|
+
position: 'absolute',
|
|
217
|
+
left: 0,
|
|
218
|
+
top: 0,
|
|
219
|
+
}, unit);
|
|
196
220
|
/**
|
|
197
221
|
* 生成元素外层样式(绝对/弹性布局),始终返回内联样式字符串。
|
|
198
222
|
*/
|
|
199
223
|
const buildWrapperStyle = (el, unit) => {
|
|
200
|
-
var _a;
|
|
201
224
|
const abs = getAbsLayout(el);
|
|
202
|
-
if (abs)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return '';
|
|
225
|
+
if (!abs)
|
|
226
|
+
return '';
|
|
227
|
+
return (0, exports.styleObjectToString)({
|
|
228
|
+
position: 'absolute',
|
|
229
|
+
left: (0, exports.addUnit)(abs.x, unit),
|
|
230
|
+
top: (0, exports.addUnit)(abs.y, unit),
|
|
231
|
+
width: (0, exports.addUnit)(abs.width, unit),
|
|
232
|
+
height: (0, exports.addUnit)(abs.height, unit),
|
|
233
|
+
zIndex: abs.zIndex,
|
|
234
|
+
boxSizing: 'border-box',
|
|
235
|
+
display: 'flex',
|
|
236
|
+
alignItems: 'center',
|
|
237
|
+
}, unit);
|
|
216
238
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
239
|
+
const buildPanelContentStyle = (el, unit) => (0, exports.styleObjectToString)({
|
|
240
|
+
position: 'relative',
|
|
241
|
+
width: '100%',
|
|
242
|
+
height: '100%',
|
|
243
|
+
display: 'block',
|
|
244
|
+
boxSizing: 'border-box',
|
|
245
|
+
...(el.style || {}),
|
|
246
|
+
}, unit);
|
|
247
|
+
const buildTextContentStyle = (el, unit) => {
|
|
248
|
+
var _a, _b, _c;
|
|
249
|
+
const textAlign = ((_a = el.style) === null || _a === void 0 ? void 0 : _a.textAlign) || el.align || undefined;
|
|
224
250
|
const style = {
|
|
225
|
-
|
|
251
|
+
...(el.style || {}),
|
|
252
|
+
whiteSpace: 'pre-wrap',
|
|
253
|
+
wordBreak: 'break-word',
|
|
254
|
+
lineHeight: ((_b = el.style) === null || _b === void 0 ? void 0 : _b.lineHeight) !== undefined && ((_c = el.style) === null || _c === void 0 ? void 0 : _c.lineHeight) !== null
|
|
255
|
+
? el.style.lineHeight
|
|
256
|
+
: '1.2',
|
|
257
|
+
display: 'inline-flex',
|
|
258
|
+
alignItems: 'center',
|
|
226
259
|
};
|
|
260
|
+
if (textAlign)
|
|
261
|
+
style.textAlign = textAlign;
|
|
227
262
|
return (0, exports.styleObjectToString)(style, unit);
|
|
228
263
|
};
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
264
|
+
const buildBaseContentStyle = (el, unit) => (0, exports.styleObjectToString)({
|
|
265
|
+
...(el.style || {}),
|
|
266
|
+
boxSizing: 'border-box',
|
|
267
|
+
}, unit);
|
|
268
|
+
const buildImageContentStyle = (el, unit) => {
|
|
269
|
+
const style = { ...(el.style || {}) };
|
|
270
|
+
const borderWidth = Number(style.borderWidth);
|
|
271
|
+
if (Number.isFinite(borderWidth) && borderWidth > 0) {
|
|
272
|
+
if (!style.borderStyle)
|
|
273
|
+
style.borderStyle = 'solid';
|
|
274
|
+
if (!style.borderColor)
|
|
275
|
+
style.borderColor = '#000000';
|
|
276
|
+
}
|
|
235
277
|
return (0, exports.styleObjectToString)(style, unit);
|
|
236
278
|
};
|
|
237
279
|
const buildTextIcon = (el, unit) => {
|
|
238
|
-
var _a, _b, _c;
|
|
280
|
+
var _a, _b, _c, _d;
|
|
239
281
|
const icon = el.icon;
|
|
240
282
|
if (!icon || icon.enable === false)
|
|
241
283
|
return undefined;
|
|
@@ -262,6 +304,11 @@ const buildTextIcon = (el, unit) => {
|
|
|
262
304
|
gap: (0, exports.addUnit)(gap, unit),
|
|
263
305
|
color: color,
|
|
264
306
|
align: icon.align || 'left',
|
|
307
|
+
wrapperStyle: (0, exports.styleObjectToString)({
|
|
308
|
+
display: 'inline-flex',
|
|
309
|
+
alignItems: 'center',
|
|
310
|
+
height: ((_d = el.style) === null || _d === void 0 ? void 0 : _d.lineHeight) || 'auto',
|
|
311
|
+
}, unit),
|
|
265
312
|
};
|
|
266
313
|
};
|
|
267
314
|
/** ---------- 渲染树构建 ---------- */
|
|
@@ -286,7 +333,7 @@ exports.buildRenderNodes = buildRenderNodes;
|
|
|
286
333
|
* 构建单个渲染节点(layout-panel 递归处理子元素)。
|
|
287
334
|
*/
|
|
288
335
|
const buildNode = (el, rootData, unit, context) => {
|
|
289
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
336
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
290
337
|
if (!el || el.visible === false)
|
|
291
338
|
return null;
|
|
292
339
|
const wrapperStyle = buildWrapperStyle(el, unit);
|
|
@@ -296,40 +343,38 @@ const buildNode = (el, rootData, unit, context) => {
|
|
|
296
343
|
type: el.type,
|
|
297
344
|
visible: !!el.visible,
|
|
298
345
|
wrapperStyle,
|
|
299
|
-
contentStyle:
|
|
346
|
+
contentStyle: buildPanelContentStyle(el, unit),
|
|
300
347
|
children: (0, exports.buildRenderNodes)(el.children || [], rootData, unit, context),
|
|
301
348
|
};
|
|
302
349
|
}
|
|
303
|
-
const baseStyle =
|
|
350
|
+
const baseStyle = buildBaseContentStyle(el, unit);
|
|
304
351
|
if (el.type === 'text') {
|
|
305
|
-
const
|
|
306
|
-
const textStyle = align ? `${baseStyle};text-align:${align}` : baseStyle;
|
|
307
|
-
const value = (_c = (_b = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _b !== void 0 ? _b : el.defaultValue) !== null && _c !== void 0 ? _c : '';
|
|
352
|
+
const value = (_b = (_a = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _a !== void 0 ? _a : el.defaultValue) !== null && _b !== void 0 ? _b : '';
|
|
308
353
|
return {
|
|
309
354
|
id: el.id,
|
|
310
355
|
type: el.type,
|
|
311
356
|
wrapperStyle,
|
|
312
|
-
contentStyle:
|
|
357
|
+
contentStyle: buildTextContentStyle(el, unit),
|
|
313
358
|
text: `${value}`,
|
|
314
359
|
visible: !!el.visible,
|
|
315
360
|
icon: buildTextIcon(el, unit),
|
|
316
361
|
};
|
|
317
362
|
}
|
|
318
363
|
if (el.type === 'image') {
|
|
319
|
-
const src = (
|
|
364
|
+
const src = (_e = (_d = (_c = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _c !== void 0 ? _c : el.defaultUrl) !== null && _d !== void 0 ? _d : el.defaultValue) !== null && _e !== void 0 ? _e : '';
|
|
320
365
|
const mode = el.fit === 'contain' ? 'aspectFit' : 'aspectFill';
|
|
321
366
|
return {
|
|
322
367
|
id: el.id,
|
|
323
368
|
type: el.type,
|
|
324
369
|
wrapperStyle,
|
|
325
|
-
contentStyle:
|
|
370
|
+
contentStyle: buildImageContentStyle(el, unit),
|
|
326
371
|
src,
|
|
327
372
|
mode,
|
|
328
373
|
visible: !!el.visible,
|
|
329
374
|
};
|
|
330
375
|
}
|
|
331
376
|
if (el.type === 'icon') {
|
|
332
|
-
const name = (
|
|
377
|
+
const name = (_h = (_g = (_f = (0, exports.resolveBindingValue)(el.binding, rootData, context)) !== null && _f !== void 0 ? _f : el.name) !== null && _g !== void 0 ? _g : el.defaultValue) !== null && _h !== void 0 ? _h : '';
|
|
333
378
|
return {
|
|
334
379
|
id: el.id,
|
|
335
380
|
type: el.type,
|
|
@@ -357,24 +402,8 @@ const buildNode = (el, rootData, unit, context) => {
|
|
|
357
402
|
const buildRenderResult = (layoutInput, dataInput, unit = 'px') => {
|
|
358
403
|
const layouts = (0, exports.normalizeLayout)(layoutInput);
|
|
359
404
|
return layouts.map(layout => {
|
|
360
|
-
const cardStyle = (
|
|
361
|
-
|
|
362
|
-
height: (0, exports.addUnit)(layout.height, unit),
|
|
363
|
-
color: layout.fontColor,
|
|
364
|
-
borderRadius: layout.borderRadius !== undefined
|
|
365
|
-
? (0, exports.addUnit)(layout.borderRadius, unit)
|
|
366
|
-
: undefined,
|
|
367
|
-
padding: layout.padding !== undefined
|
|
368
|
-
? (0, exports.addUnit)(layout.padding, unit)
|
|
369
|
-
: undefined,
|
|
370
|
-
position: 'relative',
|
|
371
|
-
}, unit);
|
|
372
|
-
const bgStyle = (0, exports.styleObjectToString)({
|
|
373
|
-
zIndex: layout.backgroundZIndex,
|
|
374
|
-
borderRadius: layout.borderRadius !== undefined
|
|
375
|
-
? (0, exports.addUnit)(layout.borderRadius, unit)
|
|
376
|
-
: undefined,
|
|
377
|
-
}, unit);
|
|
405
|
+
const cardStyle = buildCardStyle(layout, unit);
|
|
406
|
+
const bgStyle = buildBackgroundStyle(layout, unit);
|
|
378
407
|
const renderTree = (0, exports.buildRenderNodes)(layout.children || [], dataInput || {}, unit);
|
|
379
408
|
return {
|
|
380
409
|
renderTree,
|
package/dist/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.backgroundChange = backgroundChange;
|
|
|
4
4
|
exports.stripLayoutBindings = stripLayoutBindings;
|
|
5
5
|
exports.applyItemCollectBindings = applyItemCollectBindings;
|
|
6
6
|
exports.getTemplateItems = getTemplateItems;
|
|
7
|
+
exports.getTemplateBackgrounds = getTemplateBackgrounds;
|
|
7
8
|
function backgroundChange(bg, layout) {
|
|
8
9
|
const toNameArray = (name) => {
|
|
9
10
|
if (Array.isArray(name))
|
|
@@ -124,3 +125,7 @@ function getTemplateItems(ids, items) {
|
|
|
124
125
|
const idArray = ids.split(',').map(id => id.trim());
|
|
125
126
|
return items.filter(item => idArray.includes(String(item.id)));
|
|
126
127
|
}
|
|
128
|
+
function getTemplateBackgrounds(ids, items) {
|
|
129
|
+
const idArray = ids.split(',').map(id => id.trim());
|
|
130
|
+
return items.filter(item => idArray.includes(String(item.id)));
|
|
131
|
+
}
|
package/index.ts
CHANGED
|
@@ -204,57 +204,131 @@ export const resolveBindingValue = (
|
|
|
204
204
|
return value === undefined ? undefined : value;
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
-
/** ---------- 样式构建 ---------- */
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
207
|
+
/** ---------- 样式构建 ---------- */
|
|
208
|
+
|
|
209
|
+
const buildCardStyle = (
|
|
210
|
+
layout: CardLayoutSchema,
|
|
211
|
+
unit: 'px' | 'rpx'
|
|
212
|
+
): string =>
|
|
213
|
+
styleObjectToString(
|
|
214
|
+
{
|
|
215
|
+
width: addUnit(layout.width, unit),
|
|
216
|
+
height: addUnit(layout.height, unit),
|
|
217
|
+
color: layout.fontColor,
|
|
218
|
+
borderRadius:
|
|
219
|
+
layout.borderRadius !== undefined
|
|
220
|
+
? addUnit(layout.borderRadius, unit)
|
|
221
|
+
: undefined,
|
|
222
|
+
padding:
|
|
223
|
+
layout.padding !== undefined ? addUnit(layout.padding, unit) : undefined,
|
|
224
|
+
position: 'relative',
|
|
225
|
+
overflow: 'hidden',
|
|
226
|
+
boxSizing: 'border-box',
|
|
227
|
+
backgroundColor: 'transparent',
|
|
228
|
+
},
|
|
229
|
+
unit
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const buildBackgroundStyle = (
|
|
233
|
+
layout: CardLayoutSchema,
|
|
234
|
+
unit: 'px' | 'rpx'
|
|
235
|
+
): string =>
|
|
236
|
+
styleObjectToString(
|
|
237
|
+
{
|
|
238
|
+
zIndex: layout.backgroundZIndex,
|
|
239
|
+
borderRadius:
|
|
240
|
+
layout.borderRadius !== undefined
|
|
241
|
+
? addUnit(layout.borderRadius, unit)
|
|
242
|
+
: undefined,
|
|
243
|
+
width: '100%',
|
|
244
|
+
height: '100%',
|
|
245
|
+
position: 'absolute',
|
|
246
|
+
left: 0,
|
|
247
|
+
top: 0,
|
|
248
|
+
},
|
|
249
|
+
unit
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 生成元素外层样式(绝对/弹性布局),始终返回内联样式字符串。
|
|
254
|
+
*/
|
|
255
|
+
const buildWrapperStyle = (el: CardElement, unit: 'px' | 'rpx'): string => {
|
|
256
|
+
const abs = getAbsLayout(el);
|
|
257
|
+
if (!abs) return '';
|
|
258
|
+
|
|
259
|
+
return styleObjectToString(
|
|
260
|
+
{
|
|
261
|
+
position: 'absolute',
|
|
262
|
+
left: addUnit(abs.x, unit),
|
|
263
|
+
top: addUnit(abs.y, unit),
|
|
264
|
+
width: addUnit(abs.width, unit),
|
|
265
|
+
height: addUnit(abs.height, unit),
|
|
266
|
+
zIndex: abs.zIndex,
|
|
267
|
+
boxSizing: 'border-box',
|
|
268
|
+
display: 'flex',
|
|
269
|
+
alignItems: 'center',
|
|
270
|
+
},
|
|
271
|
+
unit
|
|
272
|
+
);
|
|
273
|
+
};
|
|
274
|
+
const buildPanelContentStyle = (
|
|
275
|
+
el: LayoutPanelElement,
|
|
276
|
+
unit: 'px' | 'rpx'
|
|
277
|
+
): string =>
|
|
278
|
+
styleObjectToString(
|
|
279
|
+
{
|
|
280
|
+
position: 'relative',
|
|
281
|
+
width: '100%',
|
|
282
|
+
height: '100%',
|
|
283
|
+
display: 'block',
|
|
284
|
+
boxSizing: 'border-box',
|
|
285
|
+
...(el.style || {}),
|
|
286
|
+
},
|
|
287
|
+
unit
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const buildTextContentStyle = (el: TextElement, unit: 'px' | 'rpx') => {
|
|
291
|
+
const textAlign =
|
|
292
|
+
(el.style?.textAlign as string | undefined) || el.align || undefined;
|
|
293
|
+
const style: Record<string, any> = {
|
|
294
|
+
...(el.style || {}),
|
|
295
|
+
whiteSpace: 'pre-wrap',
|
|
296
|
+
wordBreak: 'break-word',
|
|
297
|
+
lineHeight:
|
|
298
|
+
el.style?.lineHeight !== undefined && el.style?.lineHeight !== null
|
|
299
|
+
? el.style.lineHeight
|
|
300
|
+
: '1.2',
|
|
301
|
+
display: 'inline-flex',
|
|
302
|
+
alignItems: 'center',
|
|
303
|
+
};
|
|
304
|
+
if (textAlign) style.textAlign = textAlign;
|
|
305
|
+
return styleObjectToString(style, unit);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const buildBaseContentStyle = (
|
|
309
|
+
el: CardElement,
|
|
310
|
+
unit: 'px' | 'rpx'
|
|
311
|
+
): string =>
|
|
312
|
+
styleObjectToString(
|
|
313
|
+
{
|
|
314
|
+
...(el.style || {}),
|
|
315
|
+
boxSizing: 'border-box',
|
|
316
|
+
},
|
|
317
|
+
unit
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const buildImageContentStyle = (
|
|
321
|
+
el: ImageElement,
|
|
322
|
+
unit: 'px' | 'rpx'
|
|
323
|
+
): string => {
|
|
324
|
+
const style: Record<string, any> = { ...(el.style || {}) };
|
|
325
|
+
const borderWidth = Number(style.borderWidth);
|
|
326
|
+
if (Number.isFinite(borderWidth) && borderWidth > 0) {
|
|
327
|
+
if (!style.borderStyle) style.borderStyle = 'solid';
|
|
328
|
+
if (!style.borderColor) style.borderColor = '#000000';
|
|
329
|
+
}
|
|
330
|
+
return styleObjectToString(style, unit);
|
|
331
|
+
};
|
|
258
332
|
|
|
259
333
|
const buildTextIcon = (
|
|
260
334
|
el: TextElement,
|
|
@@ -283,15 +357,23 @@ const buildTextIcon = (
|
|
|
283
357
|
| string
|
|
284
358
|
| undefined);
|
|
285
359
|
|
|
286
|
-
return {
|
|
287
|
-
name: `${name}`,
|
|
288
|
-
text: `${name}`,
|
|
289
|
-
size: addUnit(size as any, unit),
|
|
290
|
-
gap: addUnit(gap as any, unit),
|
|
291
|
-
color: color as any,
|
|
292
|
-
align: icon.align || 'left',
|
|
293
|
-
|
|
294
|
-
|
|
360
|
+
return {
|
|
361
|
+
name: `${name}`,
|
|
362
|
+
text: `${name}`,
|
|
363
|
+
size: addUnit(size as any, unit),
|
|
364
|
+
gap: addUnit(gap as any, unit),
|
|
365
|
+
color: color as any,
|
|
366
|
+
align: icon.align || 'left',
|
|
367
|
+
wrapperStyle: styleObjectToString(
|
|
368
|
+
{
|
|
369
|
+
display: 'inline-flex',
|
|
370
|
+
alignItems: 'center',
|
|
371
|
+
height: el.style?.lineHeight || 'auto',
|
|
372
|
+
},
|
|
373
|
+
unit
|
|
374
|
+
),
|
|
375
|
+
};
|
|
376
|
+
};
|
|
295
377
|
|
|
296
378
|
/** ---------- 渲染树构建 ---------- */
|
|
297
379
|
/**
|
|
@@ -326,54 +408,52 @@ const buildNode = (
|
|
|
326
408
|
if (!el || el.visible === false) return null;
|
|
327
409
|
const wrapperStyle = buildWrapperStyle(el, unit);
|
|
328
410
|
|
|
329
|
-
if (el.type === 'layout-panel') {
|
|
330
|
-
return {
|
|
331
|
-
id: el.id,
|
|
332
|
-
type: el.type,
|
|
333
|
-
visible: !!el.visible,
|
|
334
|
-
wrapperStyle,
|
|
335
|
-
contentStyle:
|
|
336
|
-
children: buildRenderNodes(el.children || [], rootData, unit, context),
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const baseStyle =
|
|
341
|
-
if (el.type === 'text') {
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
(el as ImageElement).defaultUrl ??
|
|
363
|
-
el.defaultValue ??
|
|
411
|
+
if (el.type === 'layout-panel') {
|
|
412
|
+
return {
|
|
413
|
+
id: el.id,
|
|
414
|
+
type: el.type,
|
|
415
|
+
visible: !!el.visible,
|
|
416
|
+
wrapperStyle,
|
|
417
|
+
contentStyle: buildPanelContentStyle(el as LayoutPanelElement, unit),
|
|
418
|
+
children: buildRenderNodes(el.children || [], rootData, unit, context),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const baseStyle = buildBaseContentStyle(el, unit);
|
|
423
|
+
if (el.type === 'text') {
|
|
424
|
+
const value =
|
|
425
|
+
resolveBindingValue(el.binding, rootData, context) ??
|
|
426
|
+
el.defaultValue ??
|
|
427
|
+
'';
|
|
428
|
+
return {
|
|
429
|
+
id: el.id,
|
|
430
|
+
type: el.type,
|
|
431
|
+
wrapperStyle,
|
|
432
|
+
contentStyle: buildTextContentStyle(el as TextElement, unit),
|
|
433
|
+
text: `${value}`,
|
|
434
|
+
visible: !!el.visible,
|
|
435
|
+
icon: buildTextIcon(el as TextElement, unit),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (el.type === 'image') {
|
|
440
|
+
const src =
|
|
441
|
+
resolveBindingValue(el.binding, rootData, context) ??
|
|
442
|
+
(el as ImageElement).defaultUrl ??
|
|
443
|
+
el.defaultValue ??
|
|
364
444
|
'';
|
|
365
|
-
const mode =
|
|
366
|
-
(el as ImageElement).fit === 'contain' ? 'aspectFit' : 'aspectFill';
|
|
367
|
-
return {
|
|
368
|
-
id: el.id,
|
|
369
|
-
type: el.type,
|
|
370
|
-
wrapperStyle,
|
|
371
|
-
contentStyle:
|
|
372
|
-
src,
|
|
373
|
-
mode,
|
|
374
|
-
visible: !!el.visible,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
445
|
+
const mode =
|
|
446
|
+
(el as ImageElement).fit === 'contain' ? 'aspectFit' : 'aspectFill';
|
|
447
|
+
return {
|
|
448
|
+
id: el.id,
|
|
449
|
+
type: el.type,
|
|
450
|
+
wrapperStyle,
|
|
451
|
+
contentStyle: buildImageContentStyle(el as ImageElement, unit),
|
|
452
|
+
src,
|
|
453
|
+
mode,
|
|
454
|
+
visible: !!el.visible,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
377
457
|
|
|
378
458
|
if (el.type === 'icon') {
|
|
379
459
|
const name =
|
|
@@ -412,39 +492,14 @@ export const buildRenderResult = (
|
|
|
412
492
|
dataInput: Record<string, any>,
|
|
413
493
|
unit: 'px' | 'rpx' = 'px'
|
|
414
494
|
): RenderResult => {
|
|
415
|
-
const layouts = normalizeLayout(layoutInput);
|
|
416
|
-
return layouts.map(layout => {
|
|
417
|
-
const cardStyle =
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
layout.borderRadius !== undefined
|
|
424
|
-
? addUnit(layout.borderRadius, unit)
|
|
425
|
-
: undefined,
|
|
426
|
-
padding:
|
|
427
|
-
layout.padding !== undefined
|
|
428
|
-
? addUnit(layout.padding, unit)
|
|
429
|
-
: undefined,
|
|
430
|
-
position: 'relative',
|
|
431
|
-
},
|
|
432
|
-
unit
|
|
433
|
-
);
|
|
434
|
-
const bgStyle = styleObjectToString(
|
|
435
|
-
{
|
|
436
|
-
zIndex: layout.backgroundZIndex,
|
|
437
|
-
borderRadius:
|
|
438
|
-
layout.borderRadius !== undefined
|
|
439
|
-
? addUnit(layout.borderRadius, unit)
|
|
440
|
-
: undefined,
|
|
441
|
-
},
|
|
442
|
-
unit
|
|
443
|
-
);
|
|
444
|
-
|
|
445
|
-
const renderTree = buildRenderNodes(
|
|
446
|
-
layout.children || [],
|
|
447
|
-
dataInput || {},
|
|
495
|
+
const layouts = normalizeLayout(layoutInput);
|
|
496
|
+
return layouts.map(layout => {
|
|
497
|
+
const cardStyle = buildCardStyle(layout, unit);
|
|
498
|
+
const bgStyle = buildBackgroundStyle(layout, unit);
|
|
499
|
+
|
|
500
|
+
const renderTree = buildRenderNodes(
|
|
501
|
+
layout.children || [],
|
|
502
|
+
dataInput || {},
|
|
448
503
|
unit
|
|
449
504
|
);
|
|
450
505
|
|
|
@@ -457,4 +512,4 @@ export const buildRenderResult = (
|
|
|
457
512
|
});
|
|
458
513
|
};
|
|
459
514
|
|
|
460
|
-
export * from './utils';
|
|
515
|
+
export * from './utils';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CardLayoutSchema } from "../layout";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 背景项
|
|
3
5
|
*/
|
|
@@ -6,11 +8,10 @@ export interface TemplateBackground {
|
|
|
6
8
|
name: string;
|
|
7
9
|
fileId?: number;
|
|
8
10
|
fontColor?: string;
|
|
9
|
-
fontColorExtra?: { name: string | string[]; color: string }[]
|
|
11
|
+
fontColorExtra?: { name: string | string[]; color: string }[];
|
|
10
12
|
imgUrl: string;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
|
|
14
15
|
/**
|
|
15
16
|
* 元素项
|
|
16
17
|
*/
|
|
@@ -25,3 +26,20 @@ export interface TemplateItem {
|
|
|
25
26
|
cate: number;
|
|
26
27
|
required?: 0 | 1;
|
|
27
28
|
}
|
|
29
|
+
|
|
30
|
+
export interface TemplateLayoutInfo {
|
|
31
|
+
id: number | string;
|
|
32
|
+
name?: string;
|
|
33
|
+
previewImg?: string;
|
|
34
|
+
height?: number;
|
|
35
|
+
width?: number;
|
|
36
|
+
enableBgIds?: string | null;
|
|
37
|
+
enableItemIds?: string | null;
|
|
38
|
+
content?: CardLayoutSchema[];
|
|
39
|
+
isVip?: 0 | 1;
|
|
40
|
+
isDouble?: 0 | 1;
|
|
41
|
+
isMoreCompany?: 0 | 1;
|
|
42
|
+
isBgCustomize?: 0 | 1;
|
|
43
|
+
createAt?: string;
|
|
44
|
+
updateAt?: string;
|
|
45
|
+
}
|
package/interface/render.ts
CHANGED
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -12,15 +12,10 @@ import type {
|
|
|
12
12
|
CardLayoutSchema,
|
|
13
13
|
RenderNode,
|
|
14
14
|
RenderResult,
|
|
15
|
+
TemplateBackground,
|
|
16
|
+
TemplateItem,
|
|
15
17
|
} from './interface';
|
|
16
18
|
|
|
17
|
-
export type ItemCollectMeta = {
|
|
18
|
-
id: string | number;
|
|
19
|
-
bind?: string | null;
|
|
20
|
-
default?: string | null;
|
|
21
|
-
key?: string | null;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
19
|
export function addUnit(
|
|
25
20
|
value: string | number | undefined | null,
|
|
26
21
|
unit: 'px' | 'rpx'
|
|
@@ -45,7 +40,7 @@ export function stripLayoutBindings(
|
|
|
45
40
|
|
|
46
41
|
export function applyItemCollectBindings(
|
|
47
42
|
layouts: CardLayoutSchema[],
|
|
48
|
-
items?:
|
|
43
|
+
items?: TemplateItem[]
|
|
49
44
|
): CardLayoutSchema[];
|
|
50
45
|
|
|
51
46
|
export function buildRenderNodes(
|
|
@@ -60,3 +55,7 @@ export function buildRenderResult(
|
|
|
60
55
|
data: Record<string, any>,
|
|
61
56
|
unit?: 'px' | 'rpx'
|
|
62
57
|
): RenderResult;
|
|
58
|
+
|
|
59
|
+
export function getTemplateItems(ids: string, items: TemplateItem[]): TemplateItem[];
|
|
60
|
+
|
|
61
|
+
export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]) : TemplateBackground[];
|
package/utils.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type { CardElement, CardLayoutSchema } from './interface';
|
|
1
|
+
import type { CardElement, CardLayoutSchema, TemplateItem } from './interface';
|
|
2
2
|
import { TemplateBackground } from './interface/data/payload';
|
|
3
3
|
|
|
4
|
-
export type ItemCollectMeta = {
|
|
5
|
-
id: string | number;
|
|
6
|
-
bind?: string | null;
|
|
7
|
-
default?: string | null;
|
|
8
|
-
key?: string | null;
|
|
9
|
-
};
|
|
10
4
|
|
|
11
5
|
export function backgroundChange(
|
|
12
6
|
bg: TemplateBackground,
|
|
@@ -92,10 +86,10 @@ export function stripLayoutBindings(
|
|
|
92
86
|
*/
|
|
93
87
|
export function applyItemCollectBindings(
|
|
94
88
|
layouts: CardLayoutSchema[] = [],
|
|
95
|
-
items:
|
|
89
|
+
items: TemplateItem[] = []
|
|
96
90
|
): CardLayoutSchema[] {
|
|
97
91
|
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
98
|
-
const metaMap = new Map<string,
|
|
92
|
+
const metaMap = new Map<string, TemplateItem>();
|
|
99
93
|
const metaList = Array.isArray(items) ? items : [];
|
|
100
94
|
metaList.forEach(item => {
|
|
101
95
|
if (item && item.id !== undefined && item.id !== null) {
|
|
@@ -135,7 +129,13 @@ export function applyItemCollectBindings(
|
|
|
135
129
|
}));
|
|
136
130
|
}
|
|
137
131
|
|
|
138
|
-
export function getTemplateItems(ids: string, items:
|
|
132
|
+
export function getTemplateItems(ids: string, items: TemplateItem[]) {
|
|
133
|
+
const idArray = ids.split(',').map(id => id.trim());
|
|
134
|
+
return items.filter(item => idArray.includes(String(item.id)));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
export function getTemplateBackgrounds(ids: string, items: TemplateBackground[]){
|
|
139
139
|
const idArray = ids.split(',').map(id => id.trim());
|
|
140
140
|
return items.filter(item => idArray.includes(String(item.id)));
|
|
141
141
|
}
|