km-card-layout-component-miniprogram 0.1.5

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.
Files changed (35) hide show
  1. package/.editorconfig +15 -0
  2. package/.gitmodules +3 -0
  3. package/LICENSE +9 -0
  4. package/README.md +37 -0
  5. package/example/app.js +5 -0
  6. package/example/app.json +11 -0
  7. package/example/app.wxss +4 -0
  8. package/example/pages/home/index.js +270 -0
  9. package/example/pages/home/index.json +6 -0
  10. package/example/pages/home/index.wxml +7 -0
  11. package/example/pages/home/index.wxss +22 -0
  12. package/example/project.config.json +19 -0
  13. package/example/sitemap.json +9 -0
  14. package/miniprogram_dist/components/card-layout/icon-map.js +121 -0
  15. package/miniprogram_dist/components/card-layout/index.js +80 -0
  16. package/miniprogram_dist/components/card-layout/index.json +3 -0
  17. package/miniprogram_dist/components/card-layout/index.wxml +66 -0
  18. package/miniprogram_dist/components/card-layout/index.wxss +521 -0
  19. package/miniprogram_dist/index.js +12 -0
  20. package/miniprogram_dist/utils/card-schema.js +10 -0
  21. package/miniprogram_dist/vendor/km-card-layout-core/index.js +511 -0
  22. package/package.json +37 -0
  23. package/script/gulpfile.js +57 -0
  24. package/script/sync-core.js +35 -0
  25. package/src/components/card-layout/icon-map.ts +118 -0
  26. package/src/components/card-layout/index.json +3 -0
  27. package/src/components/card-layout/index.ts +96 -0
  28. package/src/components/card-layout/index.wxml +66 -0
  29. package/src/components/card-layout/index.wxss +521 -0
  30. package/src/index.ts +9 -0
  31. package/src/utils/card-schema.ts +17 -0
  32. package/src/vendor/km-card-layout-core/index.ts +768 -0
  33. package/src/vendor/km-card-layout-core/types.d.ts +191 -0
  34. package/tsconfig.json +16 -0
  35. package/types/index.d.ts +7 -0
@@ -0,0 +1,118 @@
1
+ export const ICON_CODE_MAP: Record<string, string> = {
2
+ Frame4: 'e674',
3
+ chain: 'e673',
4
+ 'swap-setting': 'e672',
5
+ email1: 'e670',
6
+ mobile1: 'e671',
7
+ website: 'e66f',
8
+ calendar: 'e66e',
9
+ 'contact-fill': 'e66d',
10
+ 'card-holder': 'e66c',
11
+ link: 'e66b',
12
+ 'buy-vip-13': 'e66a',
13
+ 'buy-vip-11': 'e669',
14
+ 'buy-vip-12': 'e668',
15
+ 'contact-phone': 'e666',
16
+ 'contact-wechat': 'e667',
17
+ group: 'e665',
18
+ bag: 'e605',
19
+ 'column-group': 'e664',
20
+ minichat: 'e617',
21
+ helper: 'e663',
22
+ 'remove-module': 'e660',
23
+ 'add-module': 'e662',
24
+ drag: 'e661',
25
+ 'switch-company': 'e65f',
26
+ 'switch-person': 'e65e',
27
+ 'manual-entry': 'e65d',
28
+ play: 'e65c',
29
+ 'file-pdf': 'e65b',
30
+ 'file-video': 'e65a',
31
+ plus: 'e659',
32
+ upload: 'e650',
33
+ 'cert-company': 'e64f',
34
+ 'qr-code': 'e658',
35
+ 'company-card': 'e657',
36
+ 'card-import': 'e64e',
37
+ camera: 'e655',
38
+ 'card-apply': 'e632',
39
+ 'check-2': 'e616',
40
+ check: 'e614',
41
+ 'buy-vip-4': 'e613',
42
+ 'buy-vip-10': 'e656',
43
+ 'weixin-2': 'e653',
44
+ 'qrcode-1': 'e654',
45
+ local: 'e652',
46
+ 'cert-job': 'e64d',
47
+ 'cert-name': 'e651',
48
+ 'card-style-1': 'e64c',
49
+ 'add-pic': 'e646',
50
+ 'add-text': 'e647',
51
+ 'buy-vip-2': 'e648',
52
+ 'company-upload-logo': 'e649',
53
+ 'Headset-one': 'e64a',
54
+ 'edit-info': 'e64b',
55
+ 'more-action': 'e645',
56
+ 'upload-video': 'e644',
57
+ 'upload-image': 'e643',
58
+ 'company-info': 'e62a',
59
+ contact: 'e642',
60
+ 'notice-1': 'e641',
61
+ visitor: 'e640',
62
+ 'mobile-2': 'e63e',
63
+ 'weixin-1': 'e63f',
64
+ share: 'e63d',
65
+ 'refund-mistake': 'e637',
66
+ 'buy-vip-7': 'e63b',
67
+ 'table-import': 'e63c',
68
+ misService: 'e63a',
69
+ 'buy-vip-6': 'e634',
70
+ import: 'e638',
71
+ download: 'e639',
72
+ image: 'e636',
73
+ 'buy-vip-9': 'e635',
74
+ 'buy-vip-5': 'e62f',
75
+ 'buy-vip-3': 'e630',
76
+ 'buy-vip-1': 'e631',
77
+ 'buy-vip-8': 'e633',
78
+ companyWx: 'e62b',
79
+ dingding: 'e62c',
80
+ shui: 'e62d',
81
+ gongzhang: 'e62e',
82
+ wait: 'e629',
83
+ addImg: 'e628',
84
+ copy: 'e625',
85
+ 'mobile-1': 'e627',
86
+ 'functional-config': 'e604',
87
+ 'module-config': 'e601',
88
+ 'select-right': 'e626',
89
+ like: 'e624',
90
+ weixin: 'e620',
91
+ 'column-user': 'e621',
92
+ 'column-card': 'e622',
93
+ 'column-company-card': 'e623',
94
+ 'on-job': 'e61e',
95
+ person: 'e61f',
96
+ wallet: 'e615',
97
+ opinion: 'e618',
98
+ 'sys-set': 'e619',
99
+ 'sys-msg': 'e61d',
100
+ add: 'e61a',
101
+ search: 'e61b',
102
+ delete: 'e61c',
103
+ enter: 'e60f',
104
+ 'card-style': 'e610',
105
+ switch: 'e612',
106
+ 'card-edit': 'e60a',
107
+ close: 'e60d',
108
+ notice: 'e611',
109
+ edit: 'e60b',
110
+ 'help-info': 'e60c',
111
+ 'tag-filtering': 'e60e',
112
+ 'kuanmai-logo': 'e603',
113
+ company: 'e606',
114
+ email: 'e607',
115
+ round: 'e608',
116
+ address: 'e609',
117
+ mobile: 'e602',
118
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "component": true
3
+ }
@@ -0,0 +1,96 @@
1
+ import type { CardLayoutInput, RenderNode } from '../../vendor/km-card-layout-core/index'
2
+ import { buildRenderResult } from '../../vendor/km-card-layout-core/index'
3
+ import { ICON_CODE_MAP } from './icon-map'
4
+
5
+ type LayoutData = {
6
+ user?: Record<string, any>
7
+ [key: string]: any
8
+ }
9
+
10
+ interface RenderCard {
11
+ id: string
12
+ cardStyle: string
13
+ backgroundImage: string
14
+ backgroundStyle: string
15
+ nodes: RenderNode[]
16
+ }
17
+
18
+ const ensureArray = (input: CardLayoutInput | any): CardLayoutInput => {
19
+ if (!input) return []
20
+ return Array.isArray(input) ? input : [input]
21
+ }
22
+
23
+ const pickCardId = (layout: any, idx: number) => {
24
+ if (layout && (layout.name || layout.id)) return layout.name || layout.id
25
+ return `card-${idx}`
26
+ }
27
+
28
+ Component({
29
+ options: {
30
+ styleIsolation: 'apply-shared'
31
+ },
32
+ properties: {
33
+ layout: {
34
+ type: Array,
35
+ optionalTypes: [Object],
36
+ value: []
37
+ },
38
+ data: {
39
+ type: Object,
40
+ value: {
41
+ user: {}
42
+ }
43
+ }
44
+ },
45
+ data: {
46
+ cards: [] as RenderCard[]
47
+ },
48
+ observers: {
49
+ layout() {
50
+ this.rebuild()
51
+ },
52
+ data() {
53
+ this.rebuild()
54
+ }
55
+ },
56
+ lifetimes: {
57
+ attached() {
58
+ this.rebuild()
59
+ }
60
+ },
61
+ methods: {
62
+ normalizeIconGlyph(nodes: RenderNode[]): RenderNode[] {
63
+ return nodes.map(node => {
64
+ if (node.type === 'icon') {
65
+ const glyph = ICON_CODE_MAP[node.name || node.text || '']
66
+ const text = glyph ? String.fromCharCode(parseInt(glyph, 16)) : node.text
67
+ return { ...node, text }
68
+ }
69
+ if (node.children && node.children.length) {
70
+ return { ...node, children: this.normalizeIconGlyph(node.children) }
71
+ }
72
+ return node
73
+ })
74
+ },
75
+ rebuild() {
76
+ const layoutInput = ensureArray(this.data.layout as CardLayoutInput)
77
+ const dataInput = (this.data.data || {}) as LayoutData
78
+
79
+ if (!layoutInput.length) {
80
+ this.setData({ cards: [] })
81
+ return
82
+ }
83
+
84
+ const rendered = buildRenderResult(layoutInput, dataInput, 'rpx')
85
+ const cards = rendered.map((card, idx) => ({
86
+ id: pickCardId(layoutInput[idx], idx),
87
+ cardStyle: card.cardStyle,
88
+ backgroundImage: card.backgroundImage,
89
+ backgroundStyle: card.backgroundStyle,
90
+ nodes: this.normalizeIconGlyph(card.renderTree)
91
+ }))
92
+
93
+ this.setData({ cards })
94
+ }
95
+ }
96
+ })
@@ -0,0 +1,66 @@
1
+ <view class="km-card-layout-list">
2
+ <block wx:for="{{cards}}" wx:key="id">
3
+ <view class="km-card-layout-item">
4
+ <view class="km-card" style="{{item.cardStyle}}">
5
+ <image
6
+ wx:if="{{item.backgroundImage}}"
7
+ class="km-card__bg"
8
+ style="{{item.backgroundStyle}}"
9
+ src="{{item.backgroundImage}}"
10
+ mode="aspectFill"
11
+ />
12
+ <block wx:for="{{item.nodes}}" wx:key="id">
13
+ <template is="render-node" data="{{node:item}}" />
14
+ </block>
15
+ </view>
16
+ </view>
17
+ </block>
18
+ </view>
19
+
20
+ <template name="render-node">
21
+ <block wx:if="{{node.type === 'image'}}">
22
+ <view class="km-node" style="{{node.wrapperStyle}}">
23
+ <image
24
+ class="km-node__image"
25
+ style="{{node.contentStyle}}"
26
+ src="{{node.src}}"
27
+ mode="{{node.mode || 'aspectFill'}}"
28
+ />
29
+ </view>
30
+ </block>
31
+ <block wx:elif="{{node.type === 'icon'}}">
32
+ <view class="km-node km-node--icon" style="{{node.wrapperStyle}}">
33
+ <view
34
+ wx:if="{{node.name === 'dot'}}"
35
+ class="km-node__icon-dot"
36
+ style="{{node.contentStyle}}"
37
+ />
38
+ <view
39
+ wx:else
40
+ class="km-node__icon icon"
41
+ style="{{node.contentStyle}}"
42
+ >{{node.text}}</view>
43
+ </view>
44
+ </block>
45
+ <block wx:elif="{{node.type === 'layout-panel'}}">
46
+ <view class="km-node" style="{{node.wrapperStyle}}">
47
+ <view class="km-node__panel" style="{{node.contentStyle}}">
48
+ <block wx:for="{{node.children}}" wx:key="id">
49
+ <template is="render-node" data="{{node:item}}" />
50
+ </block>
51
+ </view>
52
+ </view>
53
+ </block>
54
+ <block wx:elif="{{node.type === 'custom'}}">
55
+ <view class="km-node km-node--custom" style="{{node.wrapperStyle}}">
56
+ <view class="km-node__custom" style="{{node.contentStyle}}">
57
+ <slot name="{{node.id}}"></slot>
58
+ </view>
59
+ </view>
60
+ </block>
61
+ <block wx:else>
62
+ <view class="km-node km-node--text" style="{{node.wrapperStyle}}">
63
+ <view style="{{node.contentStyle}}">{{node.text}}</view>
64
+ </view>
65
+ </block>
66
+ </template>