km-card-layout-component-miniprogram 0.1.9 → 0.1.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.
- package/example/pages/home/index.js +338 -63
- package/miniprogram_dist/components/card-layout/elements/custom-element/index.js +4 -0
- package/miniprogram_dist/components/card-layout/elements/icon-element/index.js +4 -0
- package/miniprogram_dist/components/card-layout/elements/image-element/index.js +6 -1
- package/miniprogram_dist/components/card-layout/elements/text-element/index.js +6 -1
- package/miniprogram_dist/components/card-layout/index.js +25 -2
- package/miniprogram_dist/components/card-layout/index.wxml +6 -6
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +1 -11
- package/miniprogram_dist/vendor/km-card-layout-core/data.js +1 -1
- package/miniprogram_dist/vendor/km-card-layout-core/index.js +9 -18
- package/miniprogram_dist/vendor/km-card-layout-core/interface/index.js +0 -1
- package/miniprogram_dist/vendor/km-card-layout-core/layout.js +1 -17
- package/miniprogram_dist/vendor/km-card-layout-core/ops/changeBackground.js +46 -97
- package/miniprogram_dist/vendor/km-card-layout-core/render/helpers.js +36 -19
- package/miniprogram_dist/vendor/km-card-layout-core/render/init.js +82 -0
- package/package.json +1 -1
- package/script/sync-core.js +0 -1
- package/src/components/card-layout/elements/custom-element/index.ts +4 -0
- package/src/components/card-layout/elements/icon-element/index.ts +4 -0
- package/src/components/card-layout/elements/image-element/index.ts +6 -1
- package/src/components/card-layout/elements/text-element/index.ts +6 -1
- package/src/components/card-layout/index.ts +33 -5
- package/src/components/card-layout/index.wxml +6 -6
- package/src/vendor/km-card-layout-core/bindings.ts +1 -17
- package/src/vendor/km-card-layout-core/data.ts +1 -3
- package/src/vendor/km-card-layout-core/index.ts +7 -26
- package/src/vendor/km-card-layout-core/interface/data/payload.ts +3 -3
- package/src/vendor/km-card-layout-core/interface/elements.ts +1 -0
- package/src/vendor/km-card-layout-core/interface/index.ts +0 -1
- package/src/vendor/km-card-layout-core/interface/layout.ts +0 -1
- package/src/vendor/km-card-layout-core/layout.ts +0 -18
- package/src/vendor/km-card-layout-core/ops/changeBackground.ts +47 -130
- package/src/vendor/km-card-layout-core/render/helpers.ts +64 -26
- package/src/vendor/km-card-layout-core/render/init.ts +107 -0
- package/src/vendor/km-card-layout-core/types.d.ts +35 -98
- package/miniprogram_dist/vendor/km-card-layout-core/interface/context.js +0 -2
- package/miniprogram_dist/vendor/km-card-layout-core/render/tool.js +0 -16
- package/miniprogram_dist/vendor/km-card-layout-core/utils.js +0 -25
- package/src/vendor/km-card-layout-core/interface/context.ts +0 -6
- package/src/vendor/km-card-layout-core/render/tool.ts +0 -21
- package/src/vendor/km-card-layout-core/utils.ts +0 -13
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* CardMaster 布局 JSON 渲染核心
|
|
4
|
-
*
|
|
5
|
-
* - 平台无关:不依赖 DOM/小程序 API,方便在 Web/小程序/Node 复用。
|
|
6
|
-
* - 职责:将布局 Schema 与业务数据合成可渲染树,外层只需将节点映射到各端组件。
|
|
7
|
-
*/
|
|
8
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
3
|
if (k2 === undefined) k2 = k;
|
|
10
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -20,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
15
|
};
|
|
22
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
17
|
+
exports.processCardLayout = exports.handleSpecialFields = exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextValueStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = exports.backgroundChange = exports.applyItemCollectBindings = exports.stripLayoutBindings = exports.resolveBindingValue = exports.parseLayout = exports.normalizeId = exports.getAbsLayout = exports.roundToInt = exports.sanitizeElement = exports.sanitizeLayout = exports.normalizeLayout = exports.isObject = exports.toNumber = exports.styleObjectToString = exports.addUnit = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Core exports for card layout helpers.
|
|
20
|
+
* Platform-agnostic utilities shared by web/mini-program renderers.
|
|
21
|
+
*/
|
|
24
22
|
__exportStar(require("./interface/index"), exports);
|
|
25
23
|
var helpers_1 = require("./helpers");
|
|
26
24
|
Object.defineProperty(exports, "addUnit", { enumerable: true, get: function () { return helpers_1.addUnit; } });
|
|
@@ -33,26 +31,15 @@ Object.defineProperty(exports, "sanitizeLayout", { enumerable: true, get: functi
|
|
|
33
31
|
Object.defineProperty(exports, "sanitizeElement", { enumerable: true, get: function () { return layout_1.sanitizeElement; } });
|
|
34
32
|
Object.defineProperty(exports, "roundToInt", { enumerable: true, get: function () { return layout_1.roundToInt; } });
|
|
35
33
|
Object.defineProperty(exports, "getAbsLayout", { enumerable: true, get: function () { return layout_1.getAbsLayout; } });
|
|
36
|
-
Object.defineProperty(exports, "collectBindings", { enumerable: true, get: function () { return layout_1.collectBindings; } });
|
|
37
34
|
Object.defineProperty(exports, "normalizeId", { enumerable: true, get: function () { return layout_1.normalizeId; } });
|
|
38
35
|
Object.defineProperty(exports, "parseLayout", { enumerable: true, get: function () { return layout_1.parseLayout; } });
|
|
39
|
-
Object.defineProperty(exports, "areChildrenEqual", { enumerable: true, get: function () { return layout_1.areChildrenEqual; } });
|
|
40
36
|
var data_1 = require("./data");
|
|
41
37
|
Object.defineProperty(exports, "resolveBindingValue", { enumerable: true, get: function () { return data_1.resolveBindingValue; } });
|
|
42
38
|
var bindings_1 = require("./bindings");
|
|
43
39
|
Object.defineProperty(exports, "stripLayoutBindings", { enumerable: true, get: function () { return bindings_1.stripLayoutBindings; } });
|
|
44
40
|
Object.defineProperty(exports, "applyItemCollectBindings", { enumerable: true, get: function () { return bindings_1.applyItemCollectBindings; } });
|
|
45
|
-
Object.defineProperty(exports, "getTemplateItems", { enumerable: true, get: function () { return bindings_1.getTemplateItems; } });
|
|
46
|
-
Object.defineProperty(exports, "getTemplateBackgrounds", { enumerable: true, get: function () { return bindings_1.getTemplateBackgrounds; } });
|
|
47
41
|
var changeBackground_1 = require("./ops/changeBackground");
|
|
48
42
|
Object.defineProperty(exports, "backgroundChange", { enumerable: true, get: function () { return changeBackground_1.backgroundChange; } });
|
|
49
|
-
Object.defineProperty(exports, "DEFAULT_DECOR_COLOR", { enumerable: true, get: function () { return changeBackground_1.DEFAULT_DECOR_COLOR; } });
|
|
50
|
-
Object.defineProperty(exports, "resolveSpecialStyle", { enumerable: true, get: function () { return changeBackground_1.resolveSpecialStyle; } });
|
|
51
|
-
Object.defineProperty(exports, "applySpecialStyle", { enumerable: true, get: function () { return changeBackground_1.applySpecialStyle; } });
|
|
52
|
-
Object.defineProperty(exports, "applyBackground", { enumerable: true, get: function () { return changeBackground_1.applyBackground; } });
|
|
53
|
-
Object.defineProperty(exports, "updateElementsStyle", { enumerable: true, get: function () { return changeBackground_1.updateElementsStyle; } });
|
|
54
|
-
var tool_1 = require("./render/tool");
|
|
55
|
-
Object.defineProperty(exports, "buildRenderData", { enumerable: true, get: function () { return tool_1.buildRenderData; } });
|
|
56
43
|
var helpers_2 = require("./render/helpers");
|
|
57
44
|
Object.defineProperty(exports, "buildWrapperStyle", { enumerable: true, get: function () { return helpers_2.buildWrapperStyle; } });
|
|
58
45
|
Object.defineProperty(exports, "buildCardStyle", { enumerable: true, get: function () { return helpers_2.buildCardStyle; } });
|
|
@@ -60,8 +47,12 @@ Object.defineProperty(exports, "buildBackgroundStyle", { enumerable: true, get:
|
|
|
60
47
|
Object.defineProperty(exports, "buildBaseContentStyle", { enumerable: true, get: function () { return helpers_2.buildBaseContentStyle; } });
|
|
61
48
|
Object.defineProperty(exports, "buildPanelContentStyle", { enumerable: true, get: function () { return helpers_2.buildPanelContentStyle; } });
|
|
62
49
|
Object.defineProperty(exports, "buildTextContentStyle", { enumerable: true, get: function () { return helpers_2.buildTextContentStyle; } });
|
|
50
|
+
Object.defineProperty(exports, "buildTextValueStyle", { enumerable: true, get: function () { return helpers_2.buildTextValueStyle; } });
|
|
63
51
|
Object.defineProperty(exports, "buildImageContentStyle", { enumerable: true, get: function () { return helpers_2.buildImageContentStyle; } });
|
|
64
52
|
Object.defineProperty(exports, "getTextValue", { enumerable: true, get: function () { return helpers_2.getTextValue; } });
|
|
65
53
|
Object.defineProperty(exports, "getImageSrc", { enumerable: true, get: function () { return helpers_2.getImageSrc; } });
|
|
66
54
|
Object.defineProperty(exports, "getIconName", { enumerable: true, get: function () { return helpers_2.getIconName; } });
|
|
67
55
|
Object.defineProperty(exports, "buildTextIconMeta", { enumerable: true, get: function () { return helpers_2.buildTextIconMeta; } });
|
|
56
|
+
var init_1 = require("./render/init");
|
|
57
|
+
Object.defineProperty(exports, "handleSpecialFields", { enumerable: true, get: function () { return init_1.handleSpecialFields; } });
|
|
58
|
+
Object.defineProperty(exports, "processCardLayout", { enumerable: true, get: function () { return init_1.processCardLayout; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.normalizeLayout = exports.parseLayout = exports.normalizeId = exports.sanitizeLayout = exports.sanitizeElement = exports.getAbsLayout = exports.roundToInt = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const DEFAULT_CARD_WIDTH = 343;
|
|
6
6
|
const DEFAULT_CARD_HEIGHT = 210;
|
|
@@ -40,18 +40,6 @@ const sanitizeLayout = (layout) => ({
|
|
|
40
40
|
children: (layout.children || []).map(child => (0, exports.sanitizeElement)(child)),
|
|
41
41
|
});
|
|
42
42
|
exports.sanitizeLayout = sanitizeLayout;
|
|
43
|
-
const collectBindings = (elements = []) => {
|
|
44
|
-
const result = [];
|
|
45
|
-
elements.forEach(el => {
|
|
46
|
-
if (el.binding)
|
|
47
|
-
result.push(el.binding);
|
|
48
|
-
if (el.type === 'layout-panel' && el.children) {
|
|
49
|
-
result.push(...(0, exports.collectBindings)(el.children));
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return Array.from(new Set(result));
|
|
53
|
-
};
|
|
54
|
-
exports.collectBindings = collectBindings;
|
|
55
43
|
const normalizeId = (id) => {
|
|
56
44
|
if (id === undefined || id === null)
|
|
57
45
|
return undefined;
|
|
@@ -111,7 +99,3 @@ const normalizeLayout = (layout) => {
|
|
|
111
99
|
.filter((value) => Boolean(value));
|
|
112
100
|
};
|
|
113
101
|
exports.normalizeLayout = normalizeLayout;
|
|
114
|
-
const areChildrenEqual = (a, b) => {
|
|
115
|
-
return JSON.stringify(a === null || a === void 0 ? void 0 : a.children) === JSON.stringify(b === null || b === void 0 ? void 0 : b.children);
|
|
116
|
-
};
|
|
117
|
-
exports.areChildrenEqual = areChildrenEqual;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.backgroundChange = void 0;
|
|
4
4
|
const toNameArray = (name) => {
|
|
5
5
|
if (Array.isArray(name))
|
|
6
6
|
return name.filter(Boolean);
|
|
@@ -12,10 +12,10 @@ const toNameArray = (name) => {
|
|
|
12
12
|
.filter(Boolean);
|
|
13
13
|
};
|
|
14
14
|
function backgroundChange(bg, layout) {
|
|
15
|
+
var _a;
|
|
16
|
+
const extras = bg.fontColorExtra || [];
|
|
17
|
+
const iconSpecialColor = (_a = extras.find(sc => toNameArray(sc.name).some(n => n === 'icon'))) === null || _a === void 0 ? void 0 : _a.color;
|
|
15
18
|
const applySpecialColor = (el) => {
|
|
16
|
-
const extras = bg.fontColorExtra || [];
|
|
17
|
-
if (!extras.length)
|
|
18
|
-
return el;
|
|
19
19
|
const keys = [];
|
|
20
20
|
if (el.binding)
|
|
21
21
|
keys.push(String(el.binding));
|
|
@@ -26,13 +26,48 @@ function backgroundChange(bg, layout) {
|
|
|
26
26
|
if (el.type === 'custom')
|
|
27
27
|
keys.push('decor');
|
|
28
28
|
const matched = extras.find(sc => toNameArray(sc.name).some(n => keys.some(k => k === null || k === void 0 ? void 0 : k.startsWith(n))));
|
|
29
|
-
if (!matched)
|
|
30
|
-
return el;
|
|
31
29
|
const baseStyle = { ...(el.style || {}) };
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
let nextEl = el;
|
|
31
|
+
if (matched) {
|
|
32
|
+
if (el.type === 'custom') {
|
|
33
|
+
nextEl = { ...el, style: { ...baseStyle, backgroundColor: matched.color } };
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
nextEl = { ...el, style: { ...baseStyle, color: matched.color } };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const nextStyle = { ...baseStyle };
|
|
41
|
+
let changed = false;
|
|
42
|
+
if (el.type === 'custom') {
|
|
43
|
+
if ('backgroundColor' in nextStyle) {
|
|
44
|
+
delete nextStyle.backgroundColor;
|
|
45
|
+
changed = true;
|
|
46
|
+
}
|
|
47
|
+
if ('background' in nextStyle) {
|
|
48
|
+
delete nextStyle.background;
|
|
49
|
+
changed = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if ('color' in nextStyle) {
|
|
53
|
+
delete nextStyle.color;
|
|
54
|
+
changed = true;
|
|
55
|
+
}
|
|
56
|
+
if (changed) {
|
|
57
|
+
nextEl = { ...el, style: nextStyle };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (nextEl.type === 'text' && nextEl.icon) {
|
|
61
|
+
const nextIcon = { ...nextEl.icon };
|
|
62
|
+
if (iconSpecialColor) {
|
|
63
|
+
nextIcon.color = iconSpecialColor;
|
|
64
|
+
}
|
|
65
|
+
else if ('color' in nextIcon) {
|
|
66
|
+
delete nextIcon.color;
|
|
67
|
+
}
|
|
68
|
+
nextEl = { ...nextEl, icon: nextIcon };
|
|
34
69
|
}
|
|
35
|
-
return
|
|
70
|
+
return nextEl;
|
|
36
71
|
};
|
|
37
72
|
const traverse = (children = []) => children.map(el => {
|
|
38
73
|
if (!el)
|
|
@@ -45,98 +80,12 @@ function backgroundChange(bg, layout) {
|
|
|
45
80
|
}
|
|
46
81
|
return applySpecialColor(el);
|
|
47
82
|
});
|
|
83
|
+
const nextChildren = traverse(layout.children || []);
|
|
48
84
|
return {
|
|
49
85
|
...layout,
|
|
50
86
|
backgroundImage: bg.imgUrl,
|
|
51
87
|
fontColor: bg.fontColor || layout.fontColor,
|
|
52
|
-
children:
|
|
88
|
+
children: nextChildren,
|
|
53
89
|
};
|
|
54
90
|
}
|
|
55
91
|
exports.backgroundChange = backgroundChange;
|
|
56
|
-
exports.DEFAULT_DECOR_COLOR = '#94a3b8';
|
|
57
|
-
const resolveSpecialStyle = (element, background) => {
|
|
58
|
-
var _a;
|
|
59
|
-
if (!background)
|
|
60
|
-
return {};
|
|
61
|
-
const keys = [];
|
|
62
|
-
if (element.binding)
|
|
63
|
-
keys.push(String(element.binding));
|
|
64
|
-
if (element.id)
|
|
65
|
-
keys.push(String(element.id));
|
|
66
|
-
if (element.type === 'icon')
|
|
67
|
-
keys.push('icon');
|
|
68
|
-
if (element.type === 'custom')
|
|
69
|
-
keys.push('decor');
|
|
70
|
-
const matched = (_a = background.specialColors) === null || _a === void 0 ? void 0 : _a.find(sc => {
|
|
71
|
-
const names = toNameArray(sc.name);
|
|
72
|
-
return names.some(n => keys.some(k => k === null || k === void 0 ? void 0 : k.startsWith(n)));
|
|
73
|
-
});
|
|
74
|
-
if (!matched)
|
|
75
|
-
return {};
|
|
76
|
-
if (element.type === 'custom') {
|
|
77
|
-
return { backgroundColor: matched.color };
|
|
78
|
-
}
|
|
79
|
-
return { color: matched.color };
|
|
80
|
-
};
|
|
81
|
-
exports.resolveSpecialStyle = resolveSpecialStyle;
|
|
82
|
-
const applySpecialStyle = (el, background = null, options = {}) => {
|
|
83
|
-
const specialStyle = (0, exports.resolveSpecialStyle)(el, background);
|
|
84
|
-
const baseStyle = { ...(el.style || {}) };
|
|
85
|
-
const isCustom = el.type === 'custom';
|
|
86
|
-
const hasExplicit = isCustom
|
|
87
|
-
? Boolean(baseStyle.backgroundColor || baseStyle.background)
|
|
88
|
-
: baseStyle.color !== undefined && baseStyle.color !== null;
|
|
89
|
-
const overrideExisting = options.overrideExisting === true;
|
|
90
|
-
const hasSpecial = Object.keys(specialStyle).length > 0;
|
|
91
|
-
const defaultDecorColor = options.defaultDecorColor || exports.DEFAULT_DECOR_COLOR;
|
|
92
|
-
if (hasSpecial) {
|
|
93
|
-
if (hasExplicit && !overrideExisting)
|
|
94
|
-
return el;
|
|
95
|
-
return { ...el, style: { ...baseStyle, ...specialStyle } };
|
|
96
|
-
}
|
|
97
|
-
if (overrideExisting && hasExplicit) {
|
|
98
|
-
const nextStyle = { ...baseStyle };
|
|
99
|
-
if (isCustom) {
|
|
100
|
-
nextStyle.backgroundColor = (background === null || background === void 0 ? void 0 : background.mainColor) || defaultDecorColor;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
delete nextStyle.color;
|
|
104
|
-
}
|
|
105
|
-
return { ...el, style: nextStyle };
|
|
106
|
-
}
|
|
107
|
-
return el;
|
|
108
|
-
};
|
|
109
|
-
exports.applySpecialStyle = applySpecialStyle;
|
|
110
|
-
const applyBackground = (layout, background, _options = {}) => {
|
|
111
|
-
var _a;
|
|
112
|
-
const bgId = Number(background.id);
|
|
113
|
-
const payload = {
|
|
114
|
-
id: Number.isFinite(bgId) ? bgId : 0,
|
|
115
|
-
name: background.name,
|
|
116
|
-
imgUrl: background.imageUrl,
|
|
117
|
-
fontColor: background.mainColor,
|
|
118
|
-
fontColorExtra: ((_a = background.specialColors) === null || _a === void 0 ? void 0 : _a.map(sc => ({
|
|
119
|
-
name: sc.name,
|
|
120
|
-
color: sc.color,
|
|
121
|
-
}))) || [],
|
|
122
|
-
};
|
|
123
|
-
return backgroundChange(payload, layout);
|
|
124
|
-
};
|
|
125
|
-
exports.applyBackground = applyBackground;
|
|
126
|
-
const updateElementsStyle = (layout, targetIds, updates) => {
|
|
127
|
-
const targets = new Set(targetIds);
|
|
128
|
-
return {
|
|
129
|
-
...layout,
|
|
130
|
-
children: layout.children.map(el => targets.has(el.id)
|
|
131
|
-
? { ...el, style: { ...(el.style || {}), ...updates } }
|
|
132
|
-
: el),
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
exports.updateElementsStyle = updateElementsStyle;
|
|
136
|
-
const setElementVisible = (layout, key, visible) => {
|
|
137
|
-
return layout.map(la => ({
|
|
138
|
-
...la,
|
|
139
|
-
children: la.children.map(el => (el.key === key ? { ...el, visible } : el)),
|
|
140
|
-
}));
|
|
141
|
-
};
|
|
142
|
-
exports.setElementVisible = setElementVisible;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = void 0;
|
|
3
|
+
exports.buildTextIconMeta = exports.getIconName = exports.getImageSrc = exports.getTextValue = exports.buildImageContentStyle = exports.buildTextValueStyle = exports.buildTextContentStyle = exports.buildPanelContentStyle = exports.buildBaseContentStyle = exports.buildBackgroundStyle = exports.buildCardStyle = exports.buildWrapperStyle = void 0;
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
const layout_1 = require("../layout");
|
|
6
|
+
const data_1 = require("../data");
|
|
6
7
|
const buildWrapperStyle = (el, unit = 'px') => {
|
|
7
8
|
const abs = (0, layout_1.getAbsLayout)(el);
|
|
8
9
|
if (!abs)
|
|
@@ -22,9 +23,6 @@ const buildCardStyle = (layout, unit = 'px') => ({
|
|
|
22
23
|
width: (0, helpers_1.addUnit)(layout.width, unit),
|
|
23
24
|
height: (0, helpers_1.addUnit)(layout.height, unit),
|
|
24
25
|
color: layout.fontColor,
|
|
25
|
-
borderRadius: layout.borderRadius !== undefined
|
|
26
|
-
? (0, helpers_1.addUnit)(layout.borderRadius, unit)
|
|
27
|
-
: undefined,
|
|
28
26
|
padding: layout.padding !== undefined ? (0, helpers_1.addUnit)(layout.padding, unit) : undefined,
|
|
29
27
|
position: 'relative',
|
|
30
28
|
overflow: 'hidden',
|
|
@@ -34,9 +32,6 @@ const buildCardStyle = (layout, unit = 'px') => ({
|
|
|
34
32
|
exports.buildCardStyle = buildCardStyle;
|
|
35
33
|
const buildBackgroundStyle = (layout, unit = 'px') => ({
|
|
36
34
|
zIndex: layout.backgroundZIndex,
|
|
37
|
-
borderRadius: layout.borderRadius !== undefined
|
|
38
|
-
? (0, helpers_1.addUnit)(layout.borderRadius, unit)
|
|
39
|
-
: undefined,
|
|
40
35
|
width: '100%',
|
|
41
36
|
height: '100%',
|
|
42
37
|
position: 'absolute',
|
|
@@ -75,23 +70,45 @@ const buildTextContentStyle = (el, unit = 'px') => {
|
|
|
75
70
|
return style;
|
|
76
71
|
};
|
|
77
72
|
exports.buildTextContentStyle = buildTextContentStyle;
|
|
78
|
-
const
|
|
73
|
+
const buildTextValueStyle = (el, unit = 'px') => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
const style = {
|
|
76
|
+
letterSpacing: ((_a = el.style) === null || _a === void 0 ? void 0 : _a.letterSpacing) !== undefined && ((_b = el.style) === null || _b === void 0 ? void 0 : _b.letterSpacing) !== null
|
|
77
|
+
? (0, helpers_1.addUnit)(el.style.letterSpacing, unit)
|
|
78
|
+
: '0',
|
|
79
|
+
};
|
|
80
|
+
return style;
|
|
81
|
+
};
|
|
82
|
+
exports.buildTextValueStyle = buildTextValueStyle;
|
|
83
|
+
const buildImageContentStyle = (el, unit = 'px') => {
|
|
84
|
+
var _a, _b, _c, _d;
|
|
79
85
|
const style = { ...(el.style || {}) };
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
style.borderWidth =
|
|
87
|
+
((_a = el.style) === null || _a === void 0 ? void 0 : _a.borderWidth) !== undefined && ((_b = el.style) === null || _b === void 0 ? void 0 : _b.borderWidth) !== null
|
|
88
|
+
? (0, helpers_1.addUnit)(el.style.borderWidth, unit)
|
|
89
|
+
: '0';
|
|
90
|
+
style.borderRadius =
|
|
91
|
+
((_c = el.style) === null || _c === void 0 ? void 0 : _c.borderRadius) !== undefined && ((_d = el.style) === null || _d === void 0 ? void 0 : _d.borderRadius) !== null
|
|
92
|
+
? (0, helpers_1.addUnit)(el.style.borderRadius, unit)
|
|
93
|
+
: '0';
|
|
94
|
+
console.log(style);
|
|
87
95
|
return style;
|
|
88
96
|
};
|
|
89
97
|
exports.buildImageContentStyle = buildImageContentStyle;
|
|
90
|
-
const getTextValue = (el) =>
|
|
91
|
-
?
|
|
92
|
-
|
|
98
|
+
const getTextValue = (el, data) => {
|
|
99
|
+
const bound = el.binding && data ? (0, data_1.resolveBindingValue)(el.binding, data) : undefined;
|
|
100
|
+
const val = bound !== undefined && bound !== null
|
|
101
|
+
? bound
|
|
102
|
+
: el.defaultValue !== undefined && el.defaultValue !== null
|
|
103
|
+
? el.defaultValue
|
|
104
|
+
: '';
|
|
105
|
+
return `${val !== null && val !== void 0 ? val : ''}`;
|
|
106
|
+
};
|
|
93
107
|
exports.getTextValue = getTextValue;
|
|
94
|
-
const getImageSrc = (el) =>
|
|
108
|
+
const getImageSrc = (el, data) => {
|
|
109
|
+
const bound = el.binding && data ? (0, data_1.resolveBindingValue)(el.binding, data) : undefined;
|
|
110
|
+
return bound || el.defaultUrl || el.defaultValue || '';
|
|
111
|
+
};
|
|
95
112
|
exports.getImageSrc = getImageSrc;
|
|
96
113
|
const getIconName = (el) => (el.name || el.defaultValue || '');
|
|
97
114
|
exports.getIconName = getIconName;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processCardLayout = exports.handleSpecialFields = void 0;
|
|
4
|
+
function handleSpecialFields(data) {
|
|
5
|
+
var _a;
|
|
6
|
+
const user = (_a = data.user) !== null && _a !== void 0 ? _a : {};
|
|
7
|
+
return {
|
|
8
|
+
...data,
|
|
9
|
+
user: {
|
|
10
|
+
...user,
|
|
11
|
+
// 1. 构造 baseCompanyDuty
|
|
12
|
+
baseCompanyDuty: user.company && user.duty
|
|
13
|
+
? `${user.company} ${user.duty}`
|
|
14
|
+
: user.baseCompanyDuty,
|
|
15
|
+
// 2. 构造 moreCardInfo.company
|
|
16
|
+
moreCardInfo: user.moreCardInfo
|
|
17
|
+
? {
|
|
18
|
+
...user.moreCardInfo,
|
|
19
|
+
company: Array.isArray(user.moreCardInfo.company)
|
|
20
|
+
? user.moreCardInfo.company.map(item => `${item.company} ${item.duty}`)
|
|
21
|
+
: user.moreCardInfo.company,
|
|
22
|
+
}
|
|
23
|
+
: user.moreCardInfo,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.handleSpecialFields = handleSpecialFields;
|
|
28
|
+
const SHOW_KEYS = new Set([
|
|
29
|
+
"company_duty_custom",
|
|
30
|
+
"company_duty_1",
|
|
31
|
+
"company_duty_2",
|
|
32
|
+
]);
|
|
33
|
+
const HIDE_KEYS = new Set(["company", "duty"]);
|
|
34
|
+
function getCompanyLen(data) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const company = (_b = (_a = data === null || data === void 0 ? void 0 : data.user) === null || _a === void 0 ? void 0 : _a.moreCardInfo) === null || _b === void 0 ? void 0 : _b.company;
|
|
37
|
+
return Array.isArray(company) ? company.length : 0;
|
|
38
|
+
}
|
|
39
|
+
function updateElementsVisible(elements, showMore) {
|
|
40
|
+
if (!elements)
|
|
41
|
+
return elements;
|
|
42
|
+
return elements.map((el) => {
|
|
43
|
+
// 先递归处理 layout-panel 的 children
|
|
44
|
+
let next = el;
|
|
45
|
+
if (el.type === "layout-panel") {
|
|
46
|
+
next = {
|
|
47
|
+
...el,
|
|
48
|
+
children: updateElementsVisible(el.children, showMore),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const key = next.key;
|
|
52
|
+
if (!key)
|
|
53
|
+
return next;
|
|
54
|
+
// showMore=true: 显示 company_duty_*,隐藏 company/duty
|
|
55
|
+
// showMore=false: 反过来
|
|
56
|
+
if (SHOW_KEYS.has(key)) {
|
|
57
|
+
return { ...next, visible: showMore };
|
|
58
|
+
}
|
|
59
|
+
if (HIDE_KEYS.has(key)) {
|
|
60
|
+
return { ...next, visible: !showMore };
|
|
61
|
+
}
|
|
62
|
+
return next;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 根据 user.moreCardInfo.company 数组长度切换元素 visible:
|
|
67
|
+
* - length > 0: key in [company_duty_custom, company_duty_1, company_duty_2] => visible=true
|
|
68
|
+
* key in [company, duty] => visible=false
|
|
69
|
+
* - length === 0: 反之
|
|
70
|
+
*/
|
|
71
|
+
function processCardLayout(layout, data) {
|
|
72
|
+
const companyLen = getCompanyLen(data);
|
|
73
|
+
const showMore = companyLen > 0;
|
|
74
|
+
return layout.map((card) => {
|
|
75
|
+
var _a;
|
|
76
|
+
return ({
|
|
77
|
+
...card,
|
|
78
|
+
children: ((_a = updateElementsVisible(card.children, showMore)) !== null && _a !== void 0 ? _a : card.children),
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
exports.processCardLayout = processCardLayout;
|
package/package.json
CHANGED
package/script/sync-core.js
CHANGED
|
@@ -15,6 +15,10 @@ Component({
|
|
|
15
15
|
type: Object,
|
|
16
16
|
value: {},
|
|
17
17
|
},
|
|
18
|
+
rootData: {
|
|
19
|
+
type: Object,
|
|
20
|
+
value: {},
|
|
21
|
+
},
|
|
18
22
|
},
|
|
19
23
|
data: {
|
|
20
24
|
wrapperStyle: '',
|
|
@@ -25,9 +29,10 @@ Component({
|
|
|
25
29
|
observers: {
|
|
26
30
|
element(el: ImageElement) {
|
|
27
31
|
if (!el) return;
|
|
32
|
+
const data: Record<string, any> = this.data.rootData || {};
|
|
28
33
|
const wrapperStyle = styleObjectToString(buildWrapperStyle(el, 'rpx'), 'rpx');
|
|
29
34
|
const contentStyle = styleObjectToString(buildImageContentStyle(el), 'rpx');
|
|
30
|
-
const imageSrc = getImageSrc(el);
|
|
35
|
+
const imageSrc = getImageSrc(el, data);
|
|
31
36
|
const mode = el.fit === 'contain' ? 'aspectFit' : 'aspectFill';
|
|
32
37
|
this.setData({ wrapperStyle, contentStyle, imageSrc, mode });
|
|
33
38
|
},
|
|
@@ -24,6 +24,10 @@ Component({
|
|
|
24
24
|
type: Object,
|
|
25
25
|
value: {},
|
|
26
26
|
},
|
|
27
|
+
rootData: {
|
|
28
|
+
type: Object,
|
|
29
|
+
value: {},
|
|
30
|
+
},
|
|
27
31
|
},
|
|
28
32
|
data: {
|
|
29
33
|
wrapperStyle: '',
|
|
@@ -34,9 +38,10 @@ Component({
|
|
|
34
38
|
observers: {
|
|
35
39
|
element(el: TextElement) {
|
|
36
40
|
if (!el) return;
|
|
41
|
+
const data: Record<string, any> = this.data.rootData || {};
|
|
37
42
|
const wrapperStyle = styleObjectToString(buildWrapperStyle(el, 'rpx'), 'rpx');
|
|
38
43
|
const contentStyle = styleObjectToString(buildTextContentStyle(el, 'rpx'), 'rpx');
|
|
39
|
-
const textValue = getTextValue(el);
|
|
44
|
+
const textValue = getTextValue(el, data);
|
|
40
45
|
const iconRaw = buildTextIconMeta(el, 'rpx');
|
|
41
46
|
const iconMeta =
|
|
42
47
|
iconRaw && iconRaw.name
|
|
@@ -13,6 +13,35 @@ import {
|
|
|
13
13
|
styleObjectToString,
|
|
14
14
|
} from '../../vendor/km-card-layout-core/index';
|
|
15
15
|
|
|
16
|
+
type CompanyDuty = {
|
|
17
|
+
company: string;
|
|
18
|
+
duty: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const handleSpecialFields = (data: { user: Record<string, any> }) => {
|
|
22
|
+
const user = data.user ?? {};
|
|
23
|
+
return {
|
|
24
|
+
...data,
|
|
25
|
+
user: {
|
|
26
|
+
...user,
|
|
27
|
+
baseCompanyDuty:
|
|
28
|
+
user.company && user.duty
|
|
29
|
+
? `${user.company} ${user.duty}`
|
|
30
|
+
: user.baseCompanyDuty,
|
|
31
|
+
moreCardInfo: user.moreCardInfo
|
|
32
|
+
? {
|
|
33
|
+
...user.moreCardInfo,
|
|
34
|
+
company: Array.isArray(user.moreCardInfo.company)
|
|
35
|
+
? (user.moreCardInfo.company as CompanyDuty[]).map(
|
|
36
|
+
item => `${item.company} ${item.duty}`
|
|
37
|
+
)
|
|
38
|
+
: user.moreCardInfo.company,
|
|
39
|
+
}
|
|
40
|
+
: user.moreCardInfo,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
16
45
|
type PanelElement = LayoutPanelElement & {
|
|
17
46
|
wrapperStyle: string;
|
|
18
47
|
contentStyle: string;
|
|
@@ -82,6 +111,7 @@ Component({
|
|
|
82
111
|
},
|
|
83
112
|
data: {
|
|
84
113
|
cards: [] as RenderCard[],
|
|
114
|
+
rootData: {} as Record<string, any>,
|
|
85
115
|
},
|
|
86
116
|
observers: {
|
|
87
117
|
layout() {
|
|
@@ -99,16 +129,14 @@ Component({
|
|
|
99
129
|
methods: {
|
|
100
130
|
rebuild() {
|
|
101
131
|
const layoutInput = ensureArray(this.data.layout as CardLayoutInput);
|
|
102
|
-
|
|
132
|
+
const rootData = handleSpecialFields(this.data.data);
|
|
103
133
|
if (!layoutInput.length) {
|
|
104
|
-
this.setData({ cards: [] });
|
|
134
|
+
this.setData({ cards: [], rootData });
|
|
105
135
|
return;
|
|
106
136
|
}
|
|
107
|
-
|
|
108
137
|
const normalizedLayouts = normalizeLayout(layoutInput);
|
|
109
138
|
const cards = buildCards(normalizedLayouts);
|
|
110
|
-
|
|
111
|
-
this.setData({ cards });
|
|
139
|
+
this.setData({ cards, rootData });
|
|
112
140
|
},
|
|
113
141
|
},
|
|
114
142
|
});
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
mode="aspectFill"
|
|
11
11
|
/>
|
|
12
12
|
<block wx:for="{{item.elements}}" wx:key="id">
|
|
13
|
-
<template is="render-element" data="{{el:item}}" />
|
|
13
|
+
<template is="render-element" data="{{el:item, rootData: rootData}}" />
|
|
14
14
|
</block>
|
|
15
15
|
</view>
|
|
16
16
|
</view>
|
|
@@ -19,24 +19,24 @@
|
|
|
19
19
|
|
|
20
20
|
<template name="render-element">
|
|
21
21
|
<block wx:if="{{el.type === 'image'}}">
|
|
22
|
-
<image-element element="{{el}}" />
|
|
22
|
+
<image-element element="{{el}}" rootData="{{rootData}}" />
|
|
23
23
|
</block>
|
|
24
24
|
<block wx:elif="{{el.type === 'icon'}}">
|
|
25
|
-
<icon-element element="{{el}}" />
|
|
25
|
+
<icon-element element="{{el}}" rootData="{{rootData}}" />
|
|
26
26
|
</block>
|
|
27
27
|
<block wx:elif="{{el.type === 'layout-panel'}}">
|
|
28
28
|
<view class="km-node" style="{{el.wrapperStyle}}">
|
|
29
29
|
<view class="km-node__panel" style="{{el.contentStyle}}">
|
|
30
30
|
<block wx:for="{{el.children}}" wx:key="id">
|
|
31
|
-
<template is="render-element" data="{{el:item}}" />
|
|
31
|
+
<template is="render-element" data="{{el:item, rootData: rootData}}" />
|
|
32
32
|
</block>
|
|
33
33
|
</view>
|
|
34
34
|
</view>
|
|
35
35
|
</block>
|
|
36
36
|
<block wx:elif="{{el.type === 'custom'}}">
|
|
37
|
-
<custom-element element="{{el}}" />
|
|
37
|
+
<custom-element element="{{el}}" rootData="{{rootData}}" />
|
|
38
38
|
</block>
|
|
39
39
|
<block wx:else>
|
|
40
|
-
<text-element element="{{el}}" />
|
|
40
|
+
<text-element element="{{el}}" rootData="{{rootData}}" />
|
|
41
41
|
</block>
|
|
42
42
|
</template>
|