km-card-layout-component-miniprogram 0.1.12 → 0.1.14
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/elements/text-element/index.wxml +19 -6
- package/miniprogram_dist/components/card-layout/index.js +1 -1
- package/miniprogram_dist/vendor/km-card-layout-core/bindings.js +6 -4
- package/miniprogram_dist/vendor/km-card-layout-core/render/helpers.js +20 -5
- package/package.json +1 -1
- package/src/components/card-layout/elements/text-element/index.wxml +19 -6
- package/src/components/card-layout/index.ts +2 -1
- package/src/vendor/km-card-layout-core/bindings.ts +8 -3
- package/src/vendor/km-card-layout-core/interface/elements.ts +1 -1
- package/src/vendor/km-card-layout-core/interface/layout.ts +2 -0
- package/src/vendor/km-card-layout-core/render/helpers.ts +34 -6
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
<view class="km-node km-node--text" style="{{wrapperStyle}}">
|
|
2
2
|
<view class="km-node__text" style="{{contentStyle}}">
|
|
3
|
-
<block wx:if="{{iconMeta && iconMeta.name}}">
|
|
3
|
+
<block wx:if="{{(iconMeta && (iconMeta.name || iconMeta.text)) && (element.icon && element.icon.style !== 'text')}}">
|
|
4
4
|
<view class="km-node__text-content">
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
|
|
6
|
+
<!-- icon 在右侧 -->
|
|
7
|
+
<block wx:if="{{iconMeta && iconMeta.align === 'right'}}">
|
|
8
|
+
<text class="km-node__text-value">{{(element.icon && element.icon.style === 'text' && element.icon.enable) ? (element.label + ':') : ''}}{{textValue || ''}}</text>
|
|
9
|
+
<view
|
|
10
|
+
class="km-node__text-icon--wrapper"
|
|
11
|
+
style="{{iconMeta.wrapperStyle}}"
|
|
12
|
+
>
|
|
8
13
|
<text
|
|
9
14
|
class="km-node__text-icon icon"
|
|
10
15
|
style="font-size: {{iconMeta.size || '16px'}}; color: {{iconMeta.color || ''}}; margin-right: {{iconMeta.gap || ''}};"
|
|
11
16
|
>{{iconMeta.text || iconMeta.name || ''}}</text>
|
|
12
17
|
</view>
|
|
13
18
|
</block>
|
|
19
|
+
|
|
20
|
+
<!-- icon 在左侧 -->
|
|
14
21
|
<block wx:else>
|
|
15
|
-
<view
|
|
22
|
+
<view
|
|
23
|
+
class="km-node__text-icon--wrapper"
|
|
24
|
+
style="{{iconMeta.wrapperStyle}}"
|
|
25
|
+
>
|
|
16
26
|
<text
|
|
17
27
|
class="km-node__text-icon icon"
|
|
18
28
|
style="font-size: {{iconMeta.size || '16px'}}; color: {{iconMeta.color || ''}}; margin-right: {{iconMeta.gap || ''}};"
|
|
@@ -20,10 +30,13 @@
|
|
|
20
30
|
</view>
|
|
21
31
|
<text class="km-node__text-value">{{textValue || ''}}</text>
|
|
22
32
|
</block>
|
|
33
|
+
|
|
23
34
|
</view>
|
|
24
35
|
</block>
|
|
36
|
+
|
|
37
|
+
<!-- 无 icon -->
|
|
25
38
|
<block wx:else>
|
|
26
|
-
<text class="km-node__text-value">{{textValue || ''}}</text>
|
|
39
|
+
<text class="km-node__text-value">{{(element.icon && element.icon.style === 'text' && element.icon.enable) ? (element.label + ':') : ''}}{{textValue || ''}}</text>
|
|
27
40
|
</block>
|
|
28
41
|
</view>
|
|
29
42
|
</view>
|
|
@@ -89,7 +89,7 @@ Component({
|
|
|
89
89
|
},
|
|
90
90
|
methods: {
|
|
91
91
|
rebuild() {
|
|
92
|
-
const layoutInput =
|
|
92
|
+
const layoutInput = (0, index_1.processCardLayout)(this.data.layout, this.data.data);
|
|
93
93
|
const rootData = handleSpecialFields(this.data.data);
|
|
94
94
|
if (!layoutInput.length) {
|
|
95
95
|
this.setData({ cards: [], rootData });
|
|
@@ -20,6 +20,7 @@ function stripLayoutBindings(layouts = []) {
|
|
|
20
20
|
}
|
|
21
21
|
exports.stripLayoutBindings = stripLayoutBindings;
|
|
22
22
|
function applyItemCollectBindings(layouts = [], items = []) {
|
|
23
|
+
console.log('applyItemCollectBindings', layouts, items);
|
|
23
24
|
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
24
25
|
const metaMap = new Map();
|
|
25
26
|
const metaList = Array.isArray(items) ? items : [];
|
|
@@ -29,14 +30,13 @@ function applyItemCollectBindings(layouts = [], items = []) {
|
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
32
|
const assignBinding = (el) => {
|
|
32
|
-
var _a;
|
|
33
33
|
const meta = metaMap.get(String(el.id));
|
|
34
34
|
const binding = meta && meta.bind !== undefined && meta.bind !== null
|
|
35
35
|
? meta.bind
|
|
36
36
|
: el.binding;
|
|
37
37
|
const defaultValue = meta && meta.default !== undefined ? meta.default : el.defaultValue;
|
|
38
38
|
const key = meta && meta.key !== undefined ? meta.key : el.key;
|
|
39
|
-
const base = { ...el };
|
|
39
|
+
const base = { ...el, label: meta === null || meta === void 0 ? void 0 : meta.name };
|
|
40
40
|
if (binding !== undefined)
|
|
41
41
|
base.binding = binding;
|
|
42
42
|
else
|
|
@@ -49,8 +49,10 @@ function applyItemCollectBindings(layouts = [], items = []) {
|
|
|
49
49
|
base.key = key;
|
|
50
50
|
else
|
|
51
51
|
delete base.key;
|
|
52
|
-
if (el.type === 'text'
|
|
53
|
-
|
|
52
|
+
if (el.type === 'text') {
|
|
53
|
+
// if (meta?.extra?.icon) {
|
|
54
|
+
// base.icon = { ...(base.icon || {}), name: meta.extra.icon };
|
|
55
|
+
// }
|
|
54
56
|
}
|
|
55
57
|
if (el.type === 'layout-panel') {
|
|
56
58
|
return {
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
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 = exports.mockBaseCompanyDutyTemplateItem = void 0;
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
const layout_1 = require("../layout");
|
|
6
6
|
const data_1 = require("../data");
|
|
7
|
+
exports.mockBaseCompanyDutyTemplateItem = {
|
|
8
|
+
id: -1,
|
|
9
|
+
name: 'company_duty_custom',
|
|
10
|
+
bind: 'user.baseCompanyDuty',
|
|
11
|
+
key: 'company_duty_custom',
|
|
12
|
+
type: 'text',
|
|
13
|
+
cate: 0,
|
|
14
|
+
};
|
|
7
15
|
const buildWrapperStyle = (el, unit = 'px') => {
|
|
8
16
|
const abs = (0, layout_1.getAbsLayout)(el);
|
|
9
17
|
if (!abs)
|
|
@@ -32,8 +40,12 @@ const buildCardStyle = (layout, unit = 'px') => ({
|
|
|
32
40
|
exports.buildCardStyle = buildCardStyle;
|
|
33
41
|
const buildBackgroundStyle = (layout, unit = 'px') => ({
|
|
34
42
|
zIndex: layout.backgroundZIndex,
|
|
35
|
-
width:
|
|
36
|
-
|
|
43
|
+
width: layout.backgroundWidth
|
|
44
|
+
? (0, helpers_1.addUnit)(layout.backgroundWidth, unit)
|
|
45
|
+
: '100%',
|
|
46
|
+
height: layout.backgroundHeight
|
|
47
|
+
? (0, helpers_1.addUnit)(layout.backgroundHeight, unit)
|
|
48
|
+
: '100%',
|
|
37
49
|
position: 'absolute',
|
|
38
50
|
left: 0,
|
|
39
51
|
top: 0,
|
|
@@ -91,12 +103,15 @@ const buildImageContentStyle = (el, unit = 'px') => {
|
|
|
91
103
|
((_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
104
|
? (0, helpers_1.addUnit)(el.style.borderRadius, unit)
|
|
93
105
|
: '0';
|
|
94
|
-
console.log(style);
|
|
95
106
|
return style;
|
|
96
107
|
};
|
|
97
108
|
exports.buildImageContentStyle = buildImageContentStyle;
|
|
98
109
|
const getTextValue = (el, data) => {
|
|
99
|
-
|
|
110
|
+
// 如果 id 匹配,则使用 mock 的 binding,否则用原来的
|
|
111
|
+
const binding = el.id === String(exports.mockBaseCompanyDutyTemplateItem.id)
|
|
112
|
+
? exports.mockBaseCompanyDutyTemplateItem.bind
|
|
113
|
+
: el.binding;
|
|
114
|
+
const bound = binding && data ? (0, data_1.resolveBindingValue)(binding, data) : undefined;
|
|
100
115
|
const val = bound !== undefined && bound !== null
|
|
101
116
|
? bound
|
|
102
117
|
: el.defaultValue !== undefined && el.defaultValue !== null
|
package/package.json
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
<view class="km-node km-node--text" style="{{wrapperStyle}}">
|
|
2
2
|
<view class="km-node__text" style="{{contentStyle}}">
|
|
3
|
-
<block wx:if="{{iconMeta && iconMeta.name}}">
|
|
3
|
+
<block wx:if="{{(iconMeta && (iconMeta.name || iconMeta.text)) && (element.icon && element.icon.style !== 'text')}}">
|
|
4
4
|
<view class="km-node__text-content">
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
|
|
6
|
+
<!-- icon 在右侧 -->
|
|
7
|
+
<block wx:if="{{iconMeta && iconMeta.align === 'right'}}">
|
|
8
|
+
<text class="km-node__text-value">{{(element.icon && element.icon.style === 'text' && element.icon.enable) ? (element.label + ':') : ''}}{{textValue || ''}}</text>
|
|
9
|
+
<view
|
|
10
|
+
class="km-node__text-icon--wrapper"
|
|
11
|
+
style="{{iconMeta.wrapperStyle}}"
|
|
12
|
+
>
|
|
8
13
|
<text
|
|
9
14
|
class="km-node__text-icon icon"
|
|
10
15
|
style="font-size: {{iconMeta.size || '16px'}}; color: {{iconMeta.color || ''}}; margin-right: {{iconMeta.gap || ''}};"
|
|
11
16
|
>{{iconMeta.text || iconMeta.name || ''}}</text>
|
|
12
17
|
</view>
|
|
13
18
|
</block>
|
|
19
|
+
|
|
20
|
+
<!-- icon 在左侧 -->
|
|
14
21
|
<block wx:else>
|
|
15
|
-
<view
|
|
22
|
+
<view
|
|
23
|
+
class="km-node__text-icon--wrapper"
|
|
24
|
+
style="{{iconMeta.wrapperStyle}}"
|
|
25
|
+
>
|
|
16
26
|
<text
|
|
17
27
|
class="km-node__text-icon icon"
|
|
18
28
|
style="font-size: {{iconMeta.size || '16px'}}; color: {{iconMeta.color || ''}}; margin-right: {{iconMeta.gap || ''}};"
|
|
@@ -20,10 +30,13 @@
|
|
|
20
30
|
</view>
|
|
21
31
|
<text class="km-node__text-value">{{textValue || ''}}</text>
|
|
22
32
|
</block>
|
|
33
|
+
|
|
23
34
|
</view>
|
|
24
35
|
</block>
|
|
36
|
+
|
|
37
|
+
<!-- 无 icon -->
|
|
25
38
|
<block wx:else>
|
|
26
|
-
<text class="km-node__text-value">{{textValue || ''}}</text>
|
|
39
|
+
<text class="km-node__text-value">{{(element.icon && element.icon.style === 'text' && element.icon.enable) ? (element.label + ':') : ''}}{{textValue || ''}}</text>
|
|
27
40
|
</block>
|
|
28
41
|
</view>
|
|
29
42
|
</view>
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
buildPanelContentStyle,
|
|
11
11
|
buildWrapperStyle,
|
|
12
12
|
normalizeLayout,
|
|
13
|
+
processCardLayout,
|
|
13
14
|
styleObjectToString,
|
|
14
15
|
} from '../../vendor/km-card-layout-core/index';
|
|
15
16
|
|
|
@@ -128,7 +129,7 @@ Component({
|
|
|
128
129
|
},
|
|
129
130
|
methods: {
|
|
130
131
|
rebuild() {
|
|
131
|
-
const layoutInput =
|
|
132
|
+
const layoutInput = processCardLayout(this.data.layout, this.data.data);
|
|
132
133
|
const rootData = handleSpecialFields(this.data.data);
|
|
133
134
|
if (!layoutInput.length) {
|
|
134
135
|
this.setData({ cards: [], rootData });
|
|
@@ -26,6 +26,8 @@ export function applyItemCollectBindings(
|
|
|
26
26
|
layouts: CardLayoutSchema[] = [],
|
|
27
27
|
items: TemplateItem[] = []
|
|
28
28
|
): CardLayoutSchema[] {
|
|
29
|
+
console.log('applyItemCollectBindings', layouts, items);
|
|
30
|
+
|
|
29
31
|
const targetLayouts = Array.isArray(layouts) ? layouts : [];
|
|
30
32
|
const metaMap = new Map<string, TemplateItem>();
|
|
31
33
|
const metaList = Array.isArray(items) ? items : [];
|
|
@@ -44,15 +46,17 @@ export function applyItemCollectBindings(
|
|
|
44
46
|
const defaultValue =
|
|
45
47
|
meta && meta.default !== undefined ? meta.default : el.defaultValue;
|
|
46
48
|
const key = meta && meta.key !== undefined ? meta.key : el.key;
|
|
47
|
-
const base: any = { ...el };
|
|
49
|
+
const base: any = { ...el, label: meta?.name };
|
|
48
50
|
if (binding !== undefined) base.binding = binding;
|
|
49
51
|
else delete base.binding;
|
|
50
52
|
if (defaultValue !== undefined) base.defaultValue = defaultValue;
|
|
51
53
|
else delete base.defaultValue;
|
|
52
54
|
if (key !== undefined) base.key = key;
|
|
53
55
|
else delete base.key;
|
|
54
|
-
if (el.type === 'text'
|
|
55
|
-
|
|
56
|
+
if (el.type === 'text') {
|
|
57
|
+
// if (meta?.extra?.icon) {
|
|
58
|
+
// base.icon = { ...(base.icon || {}), name: meta.extra.icon };
|
|
59
|
+
// }
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
if (el.type === 'layout-panel') {
|
|
@@ -61,6 +65,7 @@ export function applyItemCollectBindings(
|
|
|
61
65
|
children: (el.children || []).map(assignBinding),
|
|
62
66
|
} as CardElement;
|
|
63
67
|
}
|
|
68
|
+
|
|
64
69
|
return base as CardElement;
|
|
65
70
|
};
|
|
66
71
|
|
|
@@ -7,9 +7,19 @@ import type {
|
|
|
7
7
|
IconElement,
|
|
8
8
|
ImageElement,
|
|
9
9
|
LayoutPanelElement,
|
|
10
|
+
TemplateItem,
|
|
10
11
|
TextElement,
|
|
11
12
|
} from '../interface';
|
|
12
13
|
|
|
14
|
+
export const mockBaseCompanyDutyTemplateItem: TemplateItem = {
|
|
15
|
+
id: -1,
|
|
16
|
+
name: 'company_duty_custom',
|
|
17
|
+
bind: 'user.baseCompanyDuty',
|
|
18
|
+
key: 'company_duty_custom',
|
|
19
|
+
type: 'text',
|
|
20
|
+
cate: 0,
|
|
21
|
+
};
|
|
22
|
+
|
|
13
23
|
export const buildWrapperStyle = (
|
|
14
24
|
el: CardElement,
|
|
15
25
|
unit: 'px' | 'rpx' = 'px'
|
|
@@ -47,8 +57,12 @@ export const buildBackgroundStyle = (
|
|
|
47
57
|
unit: 'px' | 'rpx' = 'px'
|
|
48
58
|
) => ({
|
|
49
59
|
zIndex: layout.backgroundZIndex,
|
|
50
|
-
width:
|
|
51
|
-
|
|
60
|
+
width: layout.backgroundWidth
|
|
61
|
+
? addUnit(layout.backgroundWidth, unit)
|
|
62
|
+
: '100%',
|
|
63
|
+
height: layout.backgroundHeight
|
|
64
|
+
? addUnit(layout.backgroundHeight, unit)
|
|
65
|
+
: '100%',
|
|
52
66
|
position: 'absolute',
|
|
53
67
|
left: 0,
|
|
54
68
|
top: 0,
|
|
@@ -104,7 +118,10 @@ export const buildTextValueStyle = (
|
|
|
104
118
|
return style;
|
|
105
119
|
};
|
|
106
120
|
|
|
107
|
-
export const buildImageContentStyle = (
|
|
121
|
+
export const buildImageContentStyle = (
|
|
122
|
+
el: ImageElement,
|
|
123
|
+
unit: 'px' | 'rpx' = 'px'
|
|
124
|
+
) => {
|
|
108
125
|
const style: Record<string, any> = { ...(el.style || {}) };
|
|
109
126
|
style.borderWidth =
|
|
110
127
|
el.style?.borderWidth !== undefined && el.style?.borderWidth !== null
|
|
@@ -114,22 +131,33 @@ export const buildImageContentStyle = (el: ImageElement, unit: 'px' | 'rpx' = 'p
|
|
|
114
131
|
el.style?.borderRadius !== undefined && el.style?.borderRadius !== null
|
|
115
132
|
? addUnit(el.style.borderRadius as any, unit)
|
|
116
133
|
: '0';
|
|
117
|
-
console.log(style);
|
|
118
134
|
return style;
|
|
119
135
|
};
|
|
120
136
|
|
|
121
|
-
export const getTextValue = (
|
|
137
|
+
export const getTextValue = (
|
|
138
|
+
el: TextElement,
|
|
139
|
+
data?: Record<string, any>
|
|
140
|
+
) => {
|
|
141
|
+
// 如果 id 匹配,则使用 mock 的 binding,否则用原来的
|
|
142
|
+
const binding =
|
|
143
|
+
el.id === String(mockBaseCompanyDutyTemplateItem.id)
|
|
144
|
+
? mockBaseCompanyDutyTemplateItem.bind
|
|
145
|
+
: el.binding;
|
|
146
|
+
|
|
122
147
|
const bound =
|
|
123
|
-
|
|
148
|
+
binding && data ? resolveBindingValue(binding, data) : undefined;
|
|
149
|
+
|
|
124
150
|
const val =
|
|
125
151
|
bound !== undefined && bound !== null
|
|
126
152
|
? bound
|
|
127
153
|
: el.defaultValue !== undefined && el.defaultValue !== null
|
|
128
154
|
? el.defaultValue
|
|
129
155
|
: '';
|
|
156
|
+
|
|
130
157
|
return `${val ?? ''}`;
|
|
131
158
|
};
|
|
132
159
|
|
|
160
|
+
|
|
133
161
|
export const getImageSrc = (el: ImageElement, data?: Record<string, any>) => {
|
|
134
162
|
const bound =
|
|
135
163
|
el.binding && data ? resolveBindingValue(el.binding, data) : undefined;
|