km-card-layout-component-miniprogram 0.1.10 → 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/miniprogram_dist/components/card-layout/index.js +22 -1
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +1 -11
- package/miniprogram_dist/vendor/km-card-layout-core/index.js +9 -18
- 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 +22 -15
- 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/index.ts +30 -4
- package/src/vendor/km-card-layout-core/bindings.ts +1 -17
- 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/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 +55 -32
- package/src/vendor/km-card-layout-core/render/init.ts +107 -0
- package/src/vendor/km-card-layout-core/types.d.ts +32 -95
- 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/render/tool.ts +0 -21
- package/src/vendor/km-card-layout-core/utils.ts +0 -13
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const index_1 = require("../../vendor/km-card-layout-core/index");
|
|
4
|
+
const 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
|
+
baseCompanyDuty: user.company && user.duty
|
|
12
|
+
? `${user.company} ${user.duty}`
|
|
13
|
+
: user.baseCompanyDuty,
|
|
14
|
+
moreCardInfo: user.moreCardInfo
|
|
15
|
+
? {
|
|
16
|
+
...user.moreCardInfo,
|
|
17
|
+
company: Array.isArray(user.moreCardInfo.company)
|
|
18
|
+
? user.moreCardInfo.company.map(item => `${item.company} ${item.duty}`)
|
|
19
|
+
: user.moreCardInfo.company,
|
|
20
|
+
}
|
|
21
|
+
: user.moreCardInfo,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
4
25
|
const ensureArray = (input) => {
|
|
5
26
|
if (!input)
|
|
6
27
|
return [];
|
|
@@ -69,7 +90,7 @@ Component({
|
|
|
69
90
|
methods: {
|
|
70
91
|
rebuild() {
|
|
71
92
|
const layoutInput = ensureArray(this.data.layout);
|
|
72
|
-
const rootData = (this.data.data
|
|
93
|
+
const rootData = handleSpecialFields(this.data.data);
|
|
73
94
|
if (!layoutInput.length) {
|
|
74
95
|
this.setData({ cards: [], rootData });
|
|
75
96
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.applyItemCollectBindings = exports.stripLayoutBindings = void 0;
|
|
4
4
|
function stripLayoutBindings(layouts = []) {
|
|
5
5
|
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
6
6
|
const stripElement = (el) => {
|
|
@@ -66,13 +66,3 @@ function applyItemCollectBindings(layouts = [], items = []) {
|
|
|
66
66
|
}));
|
|
67
67
|
}
|
|
68
68
|
exports.applyItemCollectBindings = applyItemCollectBindings;
|
|
69
|
-
function getTemplateItems(ids, items) {
|
|
70
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
71
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
72
|
-
}
|
|
73
|
-
exports.getTemplateItems = getTemplateItems;
|
|
74
|
-
function getTemplateBackgrounds(ids, items) {
|
|
75
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
76
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
77
|
-
}
|
|
78
|
-
exports.getTemplateBackgrounds = getTemplateBackgrounds;
|
|
@@ -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,6 +1,6 @@
|
|
|
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
6
|
const data_1 = require("../data");
|
|
@@ -23,9 +23,6 @@ const buildCardStyle = (layout, unit = 'px') => ({
|
|
|
23
23
|
width: (0, helpers_1.addUnit)(layout.width, unit),
|
|
24
24
|
height: (0, helpers_1.addUnit)(layout.height, unit),
|
|
25
25
|
color: layout.fontColor,
|
|
26
|
-
borderRadius: layout.borderRadius !== undefined
|
|
27
|
-
? (0, helpers_1.addUnit)(layout.borderRadius, unit)
|
|
28
|
-
: undefined,
|
|
29
26
|
padding: layout.padding !== undefined ? (0, helpers_1.addUnit)(layout.padding, unit) : undefined,
|
|
30
27
|
position: 'relative',
|
|
31
28
|
overflow: 'hidden',
|
|
@@ -35,9 +32,6 @@ const buildCardStyle = (layout, unit = 'px') => ({
|
|
|
35
32
|
exports.buildCardStyle = buildCardStyle;
|
|
36
33
|
const buildBackgroundStyle = (layout, unit = 'px') => ({
|
|
37
34
|
zIndex: layout.backgroundZIndex,
|
|
38
|
-
borderRadius: layout.borderRadius !== undefined
|
|
39
|
-
? (0, helpers_1.addUnit)(layout.borderRadius, unit)
|
|
40
|
-
: undefined,
|
|
41
35
|
width: '100%',
|
|
42
36
|
height: '100%',
|
|
43
37
|
position: 'absolute',
|
|
@@ -76,15 +70,28 @@ const buildTextContentStyle = (el, unit = 'px') => {
|
|
|
76
70
|
return style;
|
|
77
71
|
};
|
|
78
72
|
exports.buildTextContentStyle = buildTextContentStyle;
|
|
79
|
-
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;
|
|
80
85
|
const style = { ...(el.style || {}) };
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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);
|
|
88
95
|
return style;
|
|
89
96
|
};
|
|
90
97
|
exports.buildImageContentStyle = buildImageContentStyle;
|
|
@@ -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
|
@@ -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;
|
|
@@ -100,16 +129,13 @@ Component({
|
|
|
100
129
|
methods: {
|
|
101
130
|
rebuild() {
|
|
102
131
|
const layoutInput = ensureArray(this.data.layout as CardLayoutInput);
|
|
103
|
-
const rootData = (this.data.data
|
|
104
|
-
|
|
132
|
+
const rootData = handleSpecialFields(this.data.data);
|
|
105
133
|
if (!layoutInput.length) {
|
|
106
134
|
this.setData({ cards: [], rootData });
|
|
107
135
|
return;
|
|
108
136
|
}
|
|
109
|
-
|
|
110
137
|
const normalizedLayouts = normalizeLayout(layoutInput);
|
|
111
138
|
const cards = buildCards(normalizedLayouts);
|
|
112
|
-
|
|
113
139
|
this.setData({ cards, rootData });
|
|
114
140
|
},
|
|
115
141
|
},
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { CardElement, CardLayoutSchema } from './interface';
|
|
2
|
-
import type {
|
|
3
|
-
TemplateBackground,
|
|
4
|
-
TemplateItem,
|
|
5
|
-
} from './interface/data/payload';
|
|
2
|
+
import type { TemplateItem } from './interface/data/payload';
|
|
6
3
|
|
|
7
4
|
export function stripLayoutBindings(
|
|
8
5
|
layouts: CardLayoutSchema[] = []
|
|
@@ -72,16 +69,3 @@ export function applyItemCollectBindings(
|
|
|
72
69
|
children: (layout.children || []).map(assignBinding),
|
|
73
70
|
}));
|
|
74
71
|
}
|
|
75
|
-
|
|
76
|
-
export function getTemplateItems(ids: string, items: TemplateItem[]) {
|
|
77
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
78
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function getTemplateBackgrounds(
|
|
82
|
-
ids: string,
|
|
83
|
-
items: TemplateBackground[]
|
|
84
|
-
) {
|
|
85
|
-
const idArray = ids.split(',').map(id => id.trim());
|
|
86
|
-
return items.filter(item => idArray.includes(String(item.id)));
|
|
87
|
-
}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* - 平台无关:不依赖 DOM/小程序 API,方便在 Web/小程序/Node 复用。
|
|
5
|
-
* - 职责:将布局 Schema 与业务数据合成可渲染树,外层只需将节点映射到各端组件。
|
|
2
|
+
* Core exports for card layout helpers.
|
|
3
|
+
* Platform-agnostic utilities shared by web/mini-program renderers.
|
|
6
4
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
5
|
export * from './interface/index';
|
|
13
6
|
export { addUnit, styleObjectToString, toNumber, isObject } from './helpers';
|
|
14
7
|
export {
|
|
@@ -17,27 +10,12 @@ export {
|
|
|
17
10
|
sanitizeElement,
|
|
18
11
|
roundToInt,
|
|
19
12
|
getAbsLayout,
|
|
20
|
-
collectBindings,
|
|
21
13
|
normalizeId,
|
|
22
14
|
parseLayout,
|
|
23
|
-
areChildrenEqual,
|
|
24
15
|
} from './layout';
|
|
25
16
|
export { resolveBindingValue } from './data';
|
|
26
|
-
export {
|
|
27
|
-
|
|
28
|
-
applyItemCollectBindings,
|
|
29
|
-
getTemplateItems,
|
|
30
|
-
getTemplateBackgrounds,
|
|
31
|
-
} from './bindings';
|
|
32
|
-
export {
|
|
33
|
-
backgroundChange,
|
|
34
|
-
DEFAULT_DECOR_COLOR,
|
|
35
|
-
resolveSpecialStyle,
|
|
36
|
-
applySpecialStyle,
|
|
37
|
-
applyBackground,
|
|
38
|
-
updateElementsStyle,
|
|
39
|
-
} from './ops/changeBackground';
|
|
40
|
-
export { buildRenderData } from './render/tool';
|
|
17
|
+
export { stripLayoutBindings, applyItemCollectBindings } from './bindings';
|
|
18
|
+
export { backgroundChange } from './ops/changeBackground';
|
|
41
19
|
export {
|
|
42
20
|
buildWrapperStyle,
|
|
43
21
|
buildCardStyle,
|
|
@@ -45,9 +23,12 @@ export {
|
|
|
45
23
|
buildBaseContentStyle,
|
|
46
24
|
buildPanelContentStyle,
|
|
47
25
|
buildTextContentStyle,
|
|
26
|
+
buildTextValueStyle,
|
|
48
27
|
buildImageContentStyle,
|
|
49
28
|
getTextValue,
|
|
50
29
|
getImageSrc,
|
|
51
30
|
getIconName,
|
|
52
31
|
buildTextIconMeta,
|
|
53
32
|
} from './render/helpers';
|
|
33
|
+
|
|
34
|
+
export { handleSpecialFields, processCardLayout } from './render/init';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CardLayoutSchema } from
|
|
1
|
+
import { CardLayoutSchema } from '../layout';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 背景项
|
|
@@ -20,11 +20,10 @@ export interface TemplateItem {
|
|
|
20
20
|
name: string;
|
|
21
21
|
bind: string;
|
|
22
22
|
key?: string;
|
|
23
|
-
icon?: string;
|
|
24
23
|
extra?: { icon?: string };
|
|
25
24
|
default?: string;
|
|
26
25
|
type: 'text' | 'image';
|
|
27
|
-
cate: number;
|
|
26
|
+
cate: number; // 1 内置 | 2 特殊
|
|
28
27
|
required?: 0 | 1;
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -43,4 +42,5 @@ export interface TemplateLayoutInfo {
|
|
|
43
42
|
isBgCustomize?: 0 | 1;
|
|
44
43
|
createAt?: string;
|
|
45
44
|
updateAt?: string;
|
|
45
|
+
illustration?: string;
|
|
46
46
|
}
|