mali-applet-ui 1.0.63 → 1.0.65

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.
@@ -67,9 +67,8 @@ export default {
67
67
 
68
68
  <style lang="scss">
69
69
  .ml-text {
70
- display: inline-block;
70
+ display: inline-flex;
71
71
  padding: 0 4rpx;
72
- vertical-align: middle;
73
72
  &.is-underline {
74
73
  text-decoration: underline;
75
74
  // #ifdef H5
@@ -1,5 +1,15 @@
1
1
  <template>
2
2
  <view class="ml-tree" :class="[className || '']">
3
+ <view v-if="showCheckbox && (showAllCheckbox || showCheckboxBtn)" class="ml-tree-checkbox-btns">
4
+ <view v-if="showAllCheckbox" class="ml-tree-checkbox-btns-left">
5
+ <ml-checkbox v-model="isAllCheckboxChecked" :indeterminate="isAllCheckboxIndeterminate" @change="toggleAllCheckboxEvent">全选</ml-checkbox>
6
+ </view>
7
+ <view v-if="showCheckboxBtn" class="ml-tree-checkbox-btns-right">
8
+ <ml-button size="mini" status="primary" @click="setAllTreeExpand(true)">一键展开</ml-button>
9
+ <ml-button size="mini" status="primary" @click="setAllTreeExpand(false)">一键收起</ml-button>
10
+ </view>
11
+ </view>
12
+ <ml-tree-node v-for="(item, index) in treeData" :key="index" :node-data="item"></ml-tree-node>
3
13
  </view>
4
14
  </template>
5
15
 
@@ -9,12 +19,247 @@ import XEUtils from 'xe-utils'
9
19
  export default {
10
20
  name: 'MlTree',
11
21
  props: {
12
- value: Array
22
+ data: Array,
23
+ height: String,
24
+ checkStrictly: Boolean,
25
+ showRadio: Boolean,
26
+ showCheckbox: Boolean,
27
+ showAllCheckbox: Boolean,
28
+ indeterminateToChecked: Boolean,
29
+ showCheckboxBtn: Boolean,
30
+ checkRowKeys: Array,
31
+ nodeProps: Object
32
+ },
33
+ provide () {
34
+ return {
35
+ mlTree: this
36
+ }
37
+ },
38
+ data () {
39
+ return {
40
+ treeData: [],
41
+ isAllCheckboxChecked: false,
42
+ isAllCheckboxIndeterminate: false,
43
+ indeterminateRowKeys: [],
44
+ selectCheckboxRowKeys: [],
45
+ expandRowKeys: []
46
+ }
47
+ },
48
+ computed: {
49
+ styles () {
50
+ return this.height ? `height: ${this.height};` : ''
51
+ },
52
+ nodeOpts () {
53
+ const nodeProps = this.nodeProps || {}
54
+ return {
55
+ title: nodeProps.name || 'name',
56
+ key: nodeProps.key || 'key',
57
+ children: nodeProps.children || 'children'
58
+ }
59
+ },
60
+ titleField () {
61
+ return this.nodeOpts.title
62
+ },
63
+ keyField () {
64
+ return this.nodeOpts.key
65
+ },
66
+ childrenField () {
67
+ return this.nodeOpts.children
68
+ }
69
+ },
70
+ watch: {
71
+ data (value) {
72
+ this.treeData = value
73
+ },
74
+ checkRowKeys (value) {
75
+ if (!this.isCheckboxModelUpdate) {
76
+ this.selectCheckboxRowKeys = []
77
+ this.setCheckboxRow(value, true)
78
+ }
79
+ this.isCheckboxModelUpdate = false
80
+ }
81
+ },
82
+ created () {
83
+ this.treeData = this.data
13
84
  },
14
85
  methods: {
86
+ selectCheckboxNodeEvent ({ nodeData, nodeKey }) {
87
+ const { keyField, childrenField } = this
88
+ const checked = this.selectCheckboxRowKeys.indexOf(nodeKey) === -1
89
+ if (checked) {
90
+ if (this.checkStrictly) {
91
+ if (!this.selectCheckboxRowKeys.includes(nodeKey)) {
92
+ this.selectCheckboxRowKeys.push(nodeKey)
93
+ }
94
+ const halfIndex = this.indeterminateRowKeys.indexOf(nodeKey)
95
+ if (halfIndex > -1) {
96
+ this.indeterminateRowKeys.splice(halfIndex, 1)
97
+ }
98
+ } else {
99
+ XEUtils.eachTree([nodeData], (item) => {
100
+ if (!this.selectCheckboxRowKeys.includes(item[keyField])) {
101
+ this.selectCheckboxRowKeys.push(item[keyField])
102
+ }
103
+ const halfIndex = this.indeterminateRowKeys.indexOf(item[keyField])
104
+ if (halfIndex > -1) {
105
+ this.indeterminateRowKeys.splice(halfIndex, 1)
106
+ }
107
+ }, { children: childrenField })
108
+ }
109
+ } else {
110
+ if (this.checkStrictly) {
111
+ const nodeIndex = this.selectCheckboxRowKeys.indexOf(nodeKey)
112
+ if (nodeIndex > -1) {
113
+ this.selectCheckboxRowKeys.splice(nodeIndex, 1)
114
+ }
115
+ const halfIndex = this.indeterminateRowKeys.indexOf(nodeKey)
116
+ if (halfIndex > -1) {
117
+ this.indeterminateRowKeys.splice(halfIndex, 1)
118
+ }
119
+ } else {
120
+ XEUtils.eachTree([nodeData], (item) => {
121
+ const nodeIndex = this.selectCheckboxRowKeys.indexOf(item[keyField])
122
+ if (nodeIndex > -1) {
123
+ this.selectCheckboxRowKeys.splice(nodeIndex, 1)
124
+ }
125
+ const halfIndex = this.indeterminateRowKeys.indexOf(item[keyField])
126
+ if (halfIndex > -1) {
127
+ this.indeterminateRowKeys.splice(halfIndex, 1)
128
+ }
129
+ }, { children: childrenField })
130
+ }
131
+ }
132
+ if (!this.checkStrictly) {
133
+ this.updateParentIndeterminateStatus(nodeData)
134
+ }
135
+ this.updateCheckStatus()
136
+ this.isCheckboxModelUpdate = true
137
+ this.$emit('checkbox-change', { row: nodeData, checked, checkedKeys: this.selectCheckboxRowKeys })
138
+ this.$emit('update:checkRowKeys', [...this.selectCheckboxRowKeys])
139
+ },
140
+ expandNodeEvent ({ nodeData, nodeKey }) {
141
+ const nodeIndex = this.expandRowKeys.indexOf(nodeKey)
142
+ const expanded = nodeIndex === -1
143
+ if (expanded) {
144
+ this.expandRowKeys.push(nodeKey)
145
+ } else {
146
+ this.expandRowKeys.splice(nodeIndex, 1)
147
+ }
148
+ this.$emit('expand-change', { row: nodeData, expanded, expandedKeys: this.expandRowKeys })
149
+ },
150
+ updateParentIndeterminateStatus (nodeData) {
151
+ const { keyField, childrenField } = this
152
+ const rest = XEUtils.findTree(this.treeData, item => item[keyField] === nodeData[keyField])
153
+ if (rest) {
154
+ XEUtils.lastEach(rest.nodes.slice(0, rest.nodes.length - 1), (item) => {
155
+ const currKey = item[keyField]
156
+ const childs = item[childrenField]
157
+ const isAllChecked = childs.every(item => this.selectCheckboxRowKeys.includes(item[keyField]))
158
+ const isAllIndeterminate = !isAllChecked && childs.some(item => this.selectCheckboxRowKeys.includes(item[keyField]) || this.indeterminateRowKeys.includes(item[keyField]))
159
+ const nodeIndex = this.selectCheckboxRowKeys.indexOf(currKey)
160
+ if (isAllChecked) {
161
+ if (nodeIndex === -1) {
162
+ this.selectCheckboxRowKeys.push(currKey)
163
+ }
164
+ } else {
165
+ if (nodeIndex > -1) {
166
+ this.selectCheckboxRowKeys.splice(nodeIndex, 1)
167
+ }
168
+ }
169
+ const halfIndex = this.indeterminateRowKeys.indexOf(currKey)
170
+ if (isAllIndeterminate) {
171
+ if (halfIndex === -1) {
172
+ this.indeterminateRowKeys.push(currKey)
173
+ }
174
+ } else {
175
+ if (halfIndex > -1) {
176
+ this.indeterminateRowKeys.splice(halfIndex, 1)
177
+ }
178
+ }
179
+ }, { children: childrenField })
180
+ }
181
+ },
182
+ updateCheckStatus () {
183
+ const { keyField } = this
184
+ this.isAllCheckboxChecked = this.treeData.every(item => this.selectCheckboxRowKeys.includes(item[keyField]))
185
+ this.isAllCheckboxIndeterminate = !this.isAllCheckboxChecked && this.treeData.some(item => this.selectCheckboxRowKeys.includes(item[keyField]))
186
+ },
187
+ setCheckboxRow (key, checked) {
188
+ let keys = key
189
+ if (!XEUtils.isArray(key)) {
190
+ keys = [key]
191
+ }
192
+ if (checked) {
193
+ keys.forEach(nodeKey => {
194
+ if (!this.selectCheckboxRowKeys.includes(nodeKey)) {
195
+ this.selectCheckboxRowKeys.push(nodeKey)
196
+ }
197
+ })
198
+ } else {
199
+ keys.forEach(nodeKey => {
200
+ const nodeIndex = this.selectCheckboxRowKeys.indexOf(nodeKey)
201
+ if (nodeIndex > -1) {
202
+ this.selectCheckboxRowKeys.splice(nodeIndex, 1)
203
+ }
204
+ })
205
+ }
206
+ this.updateCheckStatus()
207
+ },
208
+ toggleAllCheckboxEvent () {
209
+ this.toggleAllCheckboxRow()
210
+ this.isCheckboxModelUpdate = true
211
+ this.$emit('checkbox-all', { checkedKeys: this.selectCheckboxRowKeys, checkedRows: [] })
212
+ this.$emit('update:checkRowKeys', [...this.selectCheckboxRowKeys])
213
+ },
214
+ toggleAllCheckboxRow () {
215
+ const { keyField, childrenField } = this
216
+ const rowKeys = []
217
+ if (this.isAllCheckboxChecked) {
218
+ XEUtils.eachTree(this.treeData, (item) => {
219
+ rowKeys.push(item[keyField])
220
+ }, { children: childrenField })
221
+ }
222
+ this.selectCheckboxRowKeys = rowKeys
223
+ this.updateCheckStatus()
224
+ },
225
+ setAllTreeExpand (expanded) {
226
+ const { keyField, childrenField } = this
227
+ const rowKeys = []
228
+ if (expanded) {
229
+ XEUtils.eachTree(this.treeData, (item) => {
230
+ if (item[childrenField] && item[childrenField].length > 0) {
231
+ rowKeys.push(item[keyField])
232
+ }
233
+ }, { children: childrenField })
234
+ }
235
+ this.expandRowKeys = rowKeys
236
+ }
15
237
  }
16
238
  }
17
239
  </script>
18
240
 
19
241
  <style lang="scss">
242
+ .ml-tree {
243
+ padding-left: 16rpx;
244
+ overflow: auto;
245
+ .ml-tree-checkbox-btns {
246
+ position: sticky;
247
+ left: 0;
248
+ top: 0;
249
+ display: flex;
250
+ flex-direction: row;
251
+ align-items: center;
252
+ height: 80rpx;
253
+ border-bottom: 1px solid #e5e5e5;
254
+ background: #ffffff;
255
+ }
256
+ .ml-tree-checkbox-btns-left {
257
+ flex-grow: 1;
258
+ }
259
+ .ml-tree-checkbox-btns-right {
260
+ display: flex;
261
+ flex-direction: row;
262
+ flex-shrink: 0;
263
+ }
264
+ }
20
265
  </style>
@@ -0,0 +1,150 @@
1
+ <template>
2
+ <view class="ml-tree-node" :class="[className || '']">
3
+ <view class="ml-tree-node-warpper">
4
+ <view v-if="showCheckbox" class="ml-tree-node-checkbox" :class="{'is-checked': checkCheckbox, 'is-indeterminate': indeterminate}">
5
+ <view class="ml-tree-node-checkbox-icon" @click="changeCheckboxEvent">
6
+ <ml-icon :name="checkCheckbox ? 'checkbox-checked' : (indeterminate ? 'checkbox-indeterminate' : 'checkbox-unchecked')"></ml-icon>
7
+ </view>
8
+ </view>
9
+ <view class="ml-tree-node-expand" :class="{'is-expand': hasExpand}">
10
+ <view v-if="hasChild" class="ml-tree-node-expand-icon" @click="expandEvent">
11
+ <ml-icon name="arrow-right-filling"></ml-icon>
12
+ </view>
13
+ </view>
14
+ <view class="ml-tree-node-name">{{ nodeContent }}</view>
15
+ </view>
16
+ <view v-if="hasChild && hasExpand" class="ml-tree-node-childs">
17
+ <ml-tree-node v-for="(item, index) in nodeChilds" :key="index" :node-data="item"></ml-tree-node>
18
+ </view>
19
+ </view>
20
+ </template>
21
+
22
+ <script>
23
+ import XEUtils from 'xe-utils'
24
+
25
+ export default {
26
+ props: {
27
+ nodeData: Object,
28
+ nodeProps: Object
29
+ },
30
+ inject: {
31
+ tree: {
32
+ from: 'mlTree',
33
+ default: null
34
+ }
35
+ },
36
+ data () {
37
+ return {
38
+ treeData: []
39
+ }
40
+ },
41
+ computed: {
42
+ nodeKey () {
43
+ return this.nodeData ? this.nodeData[this.keyField] : null
44
+ },
45
+ nodeContent () {
46
+ return this.nodeData ? XEUtils.toValueString(this.nodeData[this.titleField]) : ''
47
+ },
48
+ nodeChilds () {
49
+ return this.nodeData ? (this.nodeData[this.childrenField] || []) : []
50
+ },
51
+ titleField () {
52
+ return this.tree ? this.tree.titleField : 'name'
53
+ },
54
+ keyField () {
55
+ return this.tree ? this.tree.keyField : 'key'
56
+ },
57
+ childrenField () {
58
+ return this.tree ? this.tree.childrenField : 'children'
59
+ },
60
+ indeterminateRowKeys () {
61
+ return this.tree ? (this.tree.indeterminateRowKeys || []) : []
62
+ },
63
+ selectCheckboxRowKeys () {
64
+ return this.tree ? (this.tree.selectCheckboxRowKeys || []) : []
65
+ },
66
+ expandRowKeys () {
67
+ return this.tree ? (this.tree.expandRowKeys || []) : []
68
+ },
69
+ showRadio () {
70
+ return this.tree ? this.tree.showRadio : false
71
+ },
72
+ showCheckbox () {
73
+ return this.tree ? this.tree.showCheckbox : false
74
+ },
75
+ hasChild () {
76
+ return this.nodeChilds.length > 0
77
+ },
78
+ hasExpand () {
79
+ return this.expandRowKeys.includes(this.nodeKey)
80
+ },
81
+ indeterminate () {
82
+ return this.showCheckbox ? this.indeterminateRowKeys.includes(this.nodeKey) : false
83
+ },
84
+ checkCheckbox () {
85
+ return this.showCheckbox ? this.selectCheckboxRowKeys.includes(this.nodeKey) : false
86
+ }
87
+ },
88
+ methods: {
89
+ changeCheckboxEvent () {
90
+ if (this.tree) {
91
+ this.tree.selectCheckboxNodeEvent({
92
+ nodeData: this.nodeData,
93
+ nodeKey: this.nodeKey
94
+ })
95
+ }
96
+ },
97
+ expandEvent () {
98
+ if (this.tree) {
99
+ this.tree.expandNodeEvent({
100
+ nodeData: this.nodeData,
101
+ nodeKey: this.nodeKey
102
+ })
103
+ }
104
+ }
105
+ }
106
+ }
107
+ </script>
108
+
109
+ <style lang="scss">
110
+ .ml-tree-node {
111
+ .ml-tree-node-warpper {
112
+ display: flex;
113
+ flex-direction: row;
114
+ align-items: center;
115
+ height: 80rpx;
116
+ border-bottom: 1px solid #e5e5e5;
117
+ }
118
+ .ml-tree-node-checkbox-icon,
119
+ .ml-tree-node-expand-icon {
120
+ font-size: 1.3em;
121
+ }
122
+ .ml-tree-node-checkbox {
123
+ width: 50rpx;
124
+ text-align: center;
125
+ &.is-checked,
126
+ &.is-indeterminate {
127
+ color: $uni-color-primary;
128
+ }
129
+ }
130
+ .ml-tree-node-expand {
131
+ width: 50rpx;
132
+ text-align: center;
133
+ &.is-expand {
134
+ .ml-tree-node-expand-icon {
135
+ transform: rotate(90deg);
136
+ }
137
+ }
138
+ }
139
+ .ml-tree-node-expand-icon {
140
+ display: inline-block;
141
+ width: 40rpx;
142
+ height: 40rpx;
143
+ line-height: 40rpx;
144
+ transition: transform .1s ease-in-out;
145
+ }
146
+ .ml-tree-node-childs {
147
+ padding-left: 24rpx;
148
+ }
149
+ }
150
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "1.0.63",
3
+ "version": "1.0.65",
4
4
  "description": "码里云小程序组件库",
5
5
  "files": [
6
6
  "lib",