mali-applet-ui 1.0.69 → 1.0.71
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/lib/components/ml-checkbox-button/ml-checkbox-button.vue +4 -1
- package/lib/components/ml-radio-button/ml-radio-button.vue +4 -1
- package/lib/components/ml-tree-box/index.js +58 -0
- package/lib/components/ml-tree-box/ml-tree-box.vue +350 -0
- package/lib/components/ml-tree-box/ml-tree-icon.vue +30 -0
- package/package.json +1 -1
|
@@ -41,7 +41,7 @@ export default {
|
|
|
41
41
|
|
|
42
42
|
<style lang="scss">
|
|
43
43
|
.ml-checkbox-button {
|
|
44
|
-
display:
|
|
44
|
+
display: flex;
|
|
45
45
|
flex-wrap: wrap;
|
|
46
46
|
}
|
|
47
47
|
.ml-checkbox-button-item {
|
|
@@ -51,6 +51,9 @@ export default {
|
|
|
51
51
|
line-height: 60rpx;
|
|
52
52
|
border-radius: $ml-border-radius;
|
|
53
53
|
margin: 10rpx 20rpx 10rpx 0;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
text-overflow: ellipsis;
|
|
56
|
+
white-space: nowrap;
|
|
54
57
|
// #ifdef H5
|
|
55
58
|
cursor: pointer;
|
|
56
59
|
// #endif
|
|
@@ -45,7 +45,7 @@ export default {
|
|
|
45
45
|
|
|
46
46
|
<style lang="scss">
|
|
47
47
|
.ml-radio-button {
|
|
48
|
-
display:
|
|
48
|
+
display: flex;
|
|
49
49
|
flex-wrap: wrap;
|
|
50
50
|
}
|
|
51
51
|
.ml-radio-button-item {
|
|
@@ -55,6 +55,9 @@ export default {
|
|
|
55
55
|
line-height: 60rpx;
|
|
56
56
|
border-radius: $ml-border-radius;
|
|
57
57
|
margin: 10rpx 20rpx 10rpx 0;
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
text-overflow: ellipsis;
|
|
60
|
+
white-space: nowrap;
|
|
58
61
|
// #ifdef H5
|
|
59
62
|
cursor: pointer;
|
|
60
63
|
// #endif
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const findTreeKey = (list, props = { key: 'key', children: 'children' }) => {
|
|
2
|
+
let keys = []
|
|
3
|
+
const { key = 'key', children = 'children' } = props
|
|
4
|
+
for (let i = 0; i < list.length; i++) {
|
|
5
|
+
const item = list[i]
|
|
6
|
+
if (item[key]) {
|
|
7
|
+
keys.push(item[key])
|
|
8
|
+
}
|
|
9
|
+
if (item[children] && item[children].length) {
|
|
10
|
+
const findKeys = findTreeKey(item[children], props)
|
|
11
|
+
keys = [...keys, ...findKeys]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return keys
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 根据节点ID找到对应节点
|
|
18
|
+
export const findTreeByKey = (node, key, parent, props = { key: 'key', children: 'children' }) => {
|
|
19
|
+
const propsKey = props.key || 'key'
|
|
20
|
+
const propsChildren = props.children || 'children'
|
|
21
|
+
for (let i = 0; i < node.length; i++) {
|
|
22
|
+
const item = node[i]
|
|
23
|
+
if (item[propsKey] === key) {
|
|
24
|
+
return {
|
|
25
|
+
node: item,
|
|
26
|
+
parent: parent
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (item[propsChildren] && item[propsChildren].length) {
|
|
30
|
+
const children = item[propsChildren]
|
|
31
|
+
const findTree = findTreeByKey(children, key, item, props)
|
|
32
|
+
if (findTree) {
|
|
33
|
+
return findTree
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 根据节点ID找到对应节点
|
|
40
|
+
export const findNodesByKeys = (node, keys, props = { key: 'key', children: 'children' }) => {
|
|
41
|
+
const propsKey = props.key || 'key'
|
|
42
|
+
const propsChildren = props.children || 'children'
|
|
43
|
+
let list = []
|
|
44
|
+
for (let i = 0; i < node.length; i++) {
|
|
45
|
+
const item = node[i]
|
|
46
|
+
if (keys.indexOf(item[propsKey]) > -1) {
|
|
47
|
+
list.push(item)
|
|
48
|
+
}
|
|
49
|
+
if (item[propsChildren] && item[propsChildren].length) {
|
|
50
|
+
const children = item[propsChildren]
|
|
51
|
+
const findTree = findNodesByKeys(children, keys, props)
|
|
52
|
+
if (findTree && findTree.length) {
|
|
53
|
+
list = [...list, ...findTree]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return list
|
|
58
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ml-tree-box">
|
|
3
|
+
<view class="ml-tree-tool">
|
|
4
|
+
<view class="ml-tree-breadcrumb" v-if="breadcrumb">
|
|
5
|
+
<view class="breadcrumb-item" @click="handleToBreadcrumb()">
|
|
6
|
+
全部
|
|
7
|
+
<ml-icon v-if="cache && cache.length" name="arrow-right"></ml-icon>
|
|
8
|
+
</view>
|
|
9
|
+
<view class="breadcrumb-item" v-for="(item, index) in cache" :key="index" @click="handleToBreadcrumb(index)">
|
|
10
|
+
{{ item[useProps.label] || '' }}
|
|
11
|
+
<ml-icon v-if="index !== (cache.length - 1)" name="arrow-right"></ml-icon>
|
|
12
|
+
</view>
|
|
13
|
+
</view>
|
|
14
|
+
</view>
|
|
15
|
+
<view class="ml-tree-content">
|
|
16
|
+
<view class="ml-tree-node" v-if="cache && cache.length" @click="handleBack">
|
|
17
|
+
<view class="ml-tree-node__title back">
|
|
18
|
+
<ml-icon name="direction-left"></ml-icon>
|
|
19
|
+
<text class="ml-tree-node__text">返回</text>
|
|
20
|
+
</view>
|
|
21
|
+
</view>
|
|
22
|
+
<view class="ml-tree-node" v-for="(item, index) in showTree" :key="index">
|
|
23
|
+
<view class="ml-tree-node__action" v-if="check">
|
|
24
|
+
<ml-checkbox
|
|
25
|
+
:value="checkKey.indexOf(item[useProps.key]) > -1"
|
|
26
|
+
:indeterminate="indeterminate.indexOf(item[useProps.key]) > -1"
|
|
27
|
+
v-if="multiple"
|
|
28
|
+
@change="handleChangeCheckbox(item)"></ml-checkbox>
|
|
29
|
+
<ml-radio :value="checkIndex" :label="item[useProps.key]" v-else @change="handleChangeRadio"></ml-radio>
|
|
30
|
+
</view>
|
|
31
|
+
<MlTreeIcon @click="e => $emit('click-icon', 'prefix', item)" :info="getPrefixIcon(item)" :key="index"></MlTreeIcon>
|
|
32
|
+
<view class="ml-tree-node__title" @click="handleIntoChildren(item)">
|
|
33
|
+
<view>{{ item[useProps.label] || '' }}</view>
|
|
34
|
+
<view class="ml-tree-node__explain" v-if="item[useProps.explain]">{{ item[useProps.explain] }}</view>
|
|
35
|
+
</view>
|
|
36
|
+
<view class="ml-tree-node__extra">
|
|
37
|
+
<MlTreeIcon @click="e => $emit('click-icon', 'suffix', item)" :info="getSuffixIcon(item)" :key="index"></MlTreeIcon>
|
|
38
|
+
<MlTreeIcon @click="handleIntoChildren(item)" v-if="item.children && item.children.length" :info="{ icon: 'arrow-right' }" :key="index"></MlTreeIcon>
|
|
39
|
+
</view>
|
|
40
|
+
</view>
|
|
41
|
+
</view>
|
|
42
|
+
</view>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script>
|
|
46
|
+
import MlTreeIcon from './ml-tree-icon'
|
|
47
|
+
import { findNodesByKeys, findTreeByKey } from '@/components/ml-tree-box/index'
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
name: 'ml-tree-box',
|
|
51
|
+
components: { MlTreeIcon },
|
|
52
|
+
options: {
|
|
53
|
+
virtualHost: true
|
|
54
|
+
},
|
|
55
|
+
props: {
|
|
56
|
+
value: [Array, String, Number],
|
|
57
|
+
check: Boolean,
|
|
58
|
+
multiple: Boolean,
|
|
59
|
+
breadcrumb: Boolean,
|
|
60
|
+
strictly: Boolean,
|
|
61
|
+
arbitrary: Boolean,
|
|
62
|
+
props: {
|
|
63
|
+
type: Object,
|
|
64
|
+
default: () => ({})
|
|
65
|
+
},
|
|
66
|
+
tree: {
|
|
67
|
+
type: Array,
|
|
68
|
+
default: () => []
|
|
69
|
+
},
|
|
70
|
+
prefixIcon: [String, Object, Function],
|
|
71
|
+
suffixIcon: [String, Object, Function]
|
|
72
|
+
},
|
|
73
|
+
watch: {
|
|
74
|
+
value (val) {
|
|
75
|
+
const { multiple } = this
|
|
76
|
+
if (multiple) {
|
|
77
|
+
this.checkKey = val
|
|
78
|
+
} else {
|
|
79
|
+
this.checkIndex = val
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
data () {
|
|
84
|
+
return {
|
|
85
|
+
cache: [],
|
|
86
|
+
checkIndex: 0,
|
|
87
|
+
checkKey: [],
|
|
88
|
+
indeterminate: [],
|
|
89
|
+
defaultProps: {
|
|
90
|
+
key: 'key',
|
|
91
|
+
label: 'label',
|
|
92
|
+
children: 'children',
|
|
93
|
+
explain: 'explain',
|
|
94
|
+
user: 'user'
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
computed: {
|
|
99
|
+
showTree () {
|
|
100
|
+
const { current, tree } = this
|
|
101
|
+
if (current) {
|
|
102
|
+
return current.children
|
|
103
|
+
}
|
|
104
|
+
return tree
|
|
105
|
+
},
|
|
106
|
+
current () {
|
|
107
|
+
const { cache } = this
|
|
108
|
+
if (cache && cache.length) {
|
|
109
|
+
return cache[cache.length - 1]
|
|
110
|
+
}
|
|
111
|
+
return null
|
|
112
|
+
},
|
|
113
|
+
useProps () {
|
|
114
|
+
return { ...this.defaultProps, ...this.props }
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
methods: {
|
|
118
|
+
handleIntoChildren (item) {
|
|
119
|
+
if (item.children && item.children.length) {
|
|
120
|
+
this.cache.push(item)
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
handleBack () {
|
|
124
|
+
const { cache } = this
|
|
125
|
+
cache.splice(cache.length - 1, 1)
|
|
126
|
+
},
|
|
127
|
+
handleToBreadcrumb (index) {
|
|
128
|
+
const { cache } = this
|
|
129
|
+
if (index === (cache.length - 1)) return false
|
|
130
|
+
if (isNaN(+index)) {
|
|
131
|
+
this.cache = []
|
|
132
|
+
} else {
|
|
133
|
+
cache.splice(index + 1)
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
handleChangeRadio (e) {
|
|
137
|
+
this.checkIndex = e.value
|
|
138
|
+
this.handleEvent()
|
|
139
|
+
},
|
|
140
|
+
handleChangeCheckbox (row) {
|
|
141
|
+
const { checkKey, useProps } = this
|
|
142
|
+
const key = row[useProps.key]
|
|
143
|
+
if (key) {
|
|
144
|
+
const findIndex = checkKey.findIndex(item => item === key)
|
|
145
|
+
if (findIndex > -1) {
|
|
146
|
+
this.handleCheckOff(key)
|
|
147
|
+
} else {
|
|
148
|
+
this.handleCheckOn(key)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
this.handleEvent()
|
|
152
|
+
},
|
|
153
|
+
handleCheckOn (key) {
|
|
154
|
+
const { tree, useProps, checkKey } = this
|
|
155
|
+
const find = findTreeByKey(tree, key, null, useProps)
|
|
156
|
+
if (find) {
|
|
157
|
+
const { node, parent } = find
|
|
158
|
+
this.checkKey.push(key)
|
|
159
|
+
const children = node.children
|
|
160
|
+
if (children && children.length) {
|
|
161
|
+
for (let i = 0; i < children.length; i++) {
|
|
162
|
+
const item = children[i]
|
|
163
|
+
const findKey = item[useProps.key]
|
|
164
|
+
const findIndex = checkKey.findIndex(fd => fd === findKey)
|
|
165
|
+
if (findIndex === -1) {
|
|
166
|
+
this.handleCheckOn(findKey)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (parent) {
|
|
171
|
+
this.handleIndeterminateOn(parent)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
handleCheckOff (key) {
|
|
176
|
+
const { tree, useProps, checkKey } = this
|
|
177
|
+
const find = findTreeByKey(tree, key, null, useProps)
|
|
178
|
+
const { node, parent } = find
|
|
179
|
+
if (find) {
|
|
180
|
+
const findIndex = checkKey.findIndex(item => item === key)
|
|
181
|
+
this.checkKey.splice(findIndex, 1)
|
|
182
|
+
const children = node.children
|
|
183
|
+
if (children && children.length) {
|
|
184
|
+
this.handleIndeterminateChildrenOff(node)
|
|
185
|
+
for (let i = 0; i < children.length; i++) {
|
|
186
|
+
const item = children[i]
|
|
187
|
+
const findKey = item[useProps.key]
|
|
188
|
+
this.handleCheckOff(findKey)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (parent) {
|
|
193
|
+
this.handleIndeterminateParentOff(parent)
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
handleIndeterminateOn (node) {
|
|
197
|
+
const { indeterminate, useProps, checkKey } = this
|
|
198
|
+
const key = node[useProps.key]
|
|
199
|
+
const findIndex = indeterminate.findIndex(item => item === key)
|
|
200
|
+
if (findIndex === -1) {
|
|
201
|
+
indeterminate.push(key)
|
|
202
|
+
}
|
|
203
|
+
const children = node[useProps.children]
|
|
204
|
+
if (children && children.length && children.every(item => checkKey.indexOf(item[useProps.key]) > -1)) {
|
|
205
|
+
if (checkKey.findIndex(item => item === key) === -1) {
|
|
206
|
+
this.handleCheckOn(key)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
handleIndeterminateChildrenOff (node) {
|
|
211
|
+
const { indeterminate, useProps } = this
|
|
212
|
+
const key = node[useProps.key]
|
|
213
|
+
const indeterminateIndex = indeterminate.findIndex(item => item === key)
|
|
214
|
+
if (indeterminateIndex > -1) {
|
|
215
|
+
indeterminate.splice(indeterminateIndex, 1)
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
handleIndeterminateParentOff (node) {
|
|
219
|
+
const { indeterminate, checkKey, useProps } = this
|
|
220
|
+
const key = node[useProps.key]
|
|
221
|
+
const children = node[useProps.children]
|
|
222
|
+
if (!(children.every(item => checkKey.indexOf(item[useProps.key]) > -1))) {
|
|
223
|
+
const findIndex = checkKey.findIndex(item => item === key)
|
|
224
|
+
if (findIndex > -1) {
|
|
225
|
+
checkKey.splice(findIndex, 1)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (children.every(item => checkKey.indexOf(item[useProps.key]) === -1)) {
|
|
229
|
+
const findIndex = indeterminate.findIndex(item => item === key)
|
|
230
|
+
if (findIndex > -1) {
|
|
231
|
+
indeterminate.splice(findIndex, 1)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
handleEvent () {
|
|
236
|
+
const { tree, multiple, checkKey, checkIndex, useProps } = this
|
|
237
|
+
if (multiple) {
|
|
238
|
+
const checkRows = findNodesByKeys(tree, checkKey, useProps)
|
|
239
|
+
this.$emit('input', checkKey)
|
|
240
|
+
this.$emit('change', checkKey, checkRows)
|
|
241
|
+
} else {
|
|
242
|
+
const { node } = findTreeByKey(tree, checkIndex, null, useProps)
|
|
243
|
+
this.$emit('input', checkIndex)
|
|
244
|
+
this.$emit('change', checkIndex, node)
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
// 自定义图标
|
|
248
|
+
getPrefixIcon (row) {
|
|
249
|
+
const { prefixIcon } = this
|
|
250
|
+
let icon = ''
|
|
251
|
+
if (typeof prefixIcon === 'function') {
|
|
252
|
+
icon = prefixIcon(row)
|
|
253
|
+
} else {
|
|
254
|
+
icon = prefixIcon
|
|
255
|
+
}
|
|
256
|
+
if (typeof icon === 'object') {
|
|
257
|
+
return icon
|
|
258
|
+
} else if (typeof icon === 'string') {
|
|
259
|
+
return {
|
|
260
|
+
icon,
|
|
261
|
+
color: ''
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return false
|
|
265
|
+
},
|
|
266
|
+
// 自定义图标
|
|
267
|
+
getSuffixIcon (row) {
|
|
268
|
+
const { suffixIcon } = this
|
|
269
|
+
let icon = ''
|
|
270
|
+
if (typeof suffixIcon === 'function') {
|
|
271
|
+
icon = suffixIcon(row)
|
|
272
|
+
} else {
|
|
273
|
+
icon = suffixIcon
|
|
274
|
+
}
|
|
275
|
+
if (typeof icon === 'object') {
|
|
276
|
+
return icon
|
|
277
|
+
} else if (typeof icon === 'string') {
|
|
278
|
+
return {
|
|
279
|
+
icon,
|
|
280
|
+
color: ''
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return false
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
</script>
|
|
288
|
+
|
|
289
|
+
<style lang="scss" scoped>
|
|
290
|
+
.ml-tree-box {
|
|
291
|
+
background-color: #ffffff;
|
|
292
|
+
|
|
293
|
+
.ml-tree-content {
|
|
294
|
+
padding: 0 30rpx;
|
|
295
|
+
|
|
296
|
+
.ml-tree-node {
|
|
297
|
+
font-size: 34rpx;
|
|
298
|
+
display: flex;
|
|
299
|
+
align-items: center;
|
|
300
|
+
height: 116rpx;
|
|
301
|
+
border-bottom: 1rpx solid #efefef;
|
|
302
|
+
|
|
303
|
+
.ml-tree-node__title {
|
|
304
|
+
flex: 1;
|
|
305
|
+
|
|
306
|
+
&.back {
|
|
307
|
+
color: #6e6e6e;
|
|
308
|
+
font-size: 26rpx;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.ml-tree-node__text {
|
|
312
|
+
margin: 0 10rpx;
|
|
313
|
+
}
|
|
314
|
+
.ml-tree-node__explain {
|
|
315
|
+
color: #989898;
|
|
316
|
+
font-size: 26rpx;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.ml-tree-node__extra {
|
|
321
|
+
padding: 0 20rpx;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
&:last-child {
|
|
325
|
+
border-bottom: none;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.ml-tree-tool {
|
|
331
|
+
.ml-tree-breadcrumb {
|
|
332
|
+
display: flex;
|
|
333
|
+
background-color: #f3f3f3;
|
|
334
|
+
padding: 0 30rpx;
|
|
335
|
+
|
|
336
|
+
.breadcrumb-item {
|
|
337
|
+
position: relative;
|
|
338
|
+
height: 50rpx;
|
|
339
|
+
line-height: 50rpx;
|
|
340
|
+
color: #afafaf;
|
|
341
|
+
font-size: 26rpx;
|
|
342
|
+
|
|
343
|
+
&:last-child {
|
|
344
|
+
color: #6e6e6e;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
</style>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ml-tree-node__icon" :style="useStyle" v-if="info && info.icon" @click="e => $emit('click', e)">
|
|
3
|
+
<ml-icon :name="info.icon"></ml-icon>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
name: 'ml-tree-icon',
|
|
10
|
+
options: {
|
|
11
|
+
virtualHost: true
|
|
12
|
+
},
|
|
13
|
+
props: {
|
|
14
|
+
info: Object
|
|
15
|
+
},
|
|
16
|
+
computed: {
|
|
17
|
+
useStyle () {
|
|
18
|
+
const { info } = this
|
|
19
|
+
return `color: ${info?.color}; font-size: ${Number(info?.fontSize)}rpx`
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<style lang="scss" scoped>
|
|
26
|
+
.ml-tree-node__icon {
|
|
27
|
+
display: inline-flex;
|
|
28
|
+
margin-right: 10rpx;
|
|
29
|
+
}
|
|
30
|
+
</style>
|