three-trees-ui 1.0.22 → 1.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-trees-ui",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "publicPath": "/ui",
5
5
  "author": "hotent",
6
6
  "private": false,
@@ -128,9 +128,17 @@
128
128
  />
129
129
  <p
130
130
  class="selector-selected__label"
131
- :title="`${select[selectLabel]}(${select['code']})`"
131
+ :title="
132
+ `${select[selectLabel]}${
133
+ select['code'] ? `(${select['code']})` : ''
134
+ }`
135
+ "
132
136
  >
133
- {{ `${select[selectLabel]}(${select['code']})` }}
137
+ {{
138
+ `${select[selectLabel]}${
139
+ select['code'] ? `(${select['code']})` : ''
140
+ }`
141
+ }}
134
142
  </p>
135
143
  </template>
136
144
  </ht-list-selector>
@@ -63,9 +63,17 @@
63
63
  />
64
64
  <p
65
65
  class="selector-selected__label"
66
- :title="`${select[selectLabel]}(${select['code']})`"
66
+ :title="
67
+ `${select[selectLabel]}${
68
+ select['code'] ? `(${select['code']})` : ''
69
+ }`
70
+ "
67
71
  >
68
- {{ `${select[selectLabel]}(${select['code']})` }}
72
+ {{
73
+ `${select[selectLabel]}${
74
+ select['code'] ? `(${select['code']})` : ''
75
+ }`
76
+ }}
69
77
  </p>
70
78
  </template>
71
79
  </ht-list-selector>
@@ -14,6 +14,15 @@
14
14
  </div>
15
15
  <div class="selector-main__body">
16
16
  <el-scrollbar v-if="data.length > 0" class="selector-list__scroll">
17
+ <el-checkbox
18
+ v-if="!single"
19
+ v-model="checkAll"
20
+ class="check-all"
21
+ :indeterminate="isIndeterminate"
22
+ @change="handleCheckAllChange"
23
+ >
24
+ 全选
25
+ </el-checkbox>
17
26
  <ul
18
27
  class="selector-main__list"
19
28
  :class="{ 'two-columns': isSearchMode }"
@@ -112,7 +121,8 @@
112
121
  <script>
113
122
  import Locale from '@/mixins/locale'
114
123
  import mobileMode from '@/mixins/mobileMode.js'
115
- import { debounce } from 'lodash'
124
+ import { debounce, cloneDeep } from 'lodash'
125
+ import utils from '@/utils.js'
116
126
  const draggable = require('vuedraggable')
117
127
 
118
128
  export default {
@@ -172,6 +182,8 @@
172
182
  currentSelectData: [],
173
183
  noDataImg: require('@/assets/no-data.png'),
174
184
  pageSizeArr: [10, 50, 100, 200, 300],
185
+ checkAll: false,
186
+ isIndeterminate: false,
175
187
  }
176
188
  },
177
189
  computed: {
@@ -239,6 +251,10 @@
239
251
  },
240
252
  deep: true,
241
253
  },
254
+ currentPageSelectedCount(val) {
255
+ this.checkAll = val === this.data.length
256
+ this.isIndeterminate = val > 0 && val < this.data.length
257
+ },
242
258
  },
243
259
  methods: {
244
260
  getSelectedData() {
@@ -294,6 +310,26 @@
294
310
  clearAllSelects() {
295
311
  this.selects = []
296
312
  },
313
+ handleCheckAllChange(val) {
314
+ if (val) {
315
+ const currentPageData = cloneDeep(this.data)
316
+ this.selects = this.selects.length
317
+ ? utils.uniqueArrayObject(
318
+ [...this.selects, ...currentPageData],
319
+ 'id'
320
+ )
321
+ : currentPageData
322
+ } else {
323
+ if (this.selects.length > this.data.length) {
324
+ const cancelSelectedIds = this.data.map((it) => it.id)
325
+ this.selects = this.selects.filter(
326
+ (item) => !cancelSelectedIds.includes(item.id)
327
+ )
328
+ } else {
329
+ this.selects = []
330
+ }
331
+ }
332
+ },
297
333
  },
298
334
  }
299
335
  </script>
@@ -356,7 +392,9 @@
356
392
  .selector-list__scroll {
357
393
  height: calc(100% - 42px);
358
394
  }
359
-
395
+ .check-all {
396
+ padding: 16px 20px 2px 20px;
397
+ }
360
398
  .selector-main__list {
361
399
  list-style: none;
362
400
  padding: 10px 20px;
@@ -84,9 +84,17 @@
84
84
  />
85
85
  <p
86
86
  class="selector-selected__label"
87
- :title="`${select[selectLabel]}(${select['code']})`"
87
+ :title="
88
+ `${select[selectLabel]}${
89
+ select['code'] ? `(${select['code']})` : ''
90
+ }`
91
+ "
88
92
  >
89
- {{ `${select[selectLabel]}(${select['code']})` }}
93
+ {{
94
+ `${select[selectLabel]}${
95
+ select['code'] ? `(${select['code']})` : ''
96
+ }`
97
+ }}
90
98
  </p>
91
99
  </template>
92
100
  </ht-list-selector>
@@ -87,9 +87,17 @@
87
87
  />
88
88
  <p
89
89
  class="selector-selected__label"
90
- :title="`${select[selectLabel]}(${select['code']})`"
90
+ :title="
91
+ `${select[selectLabel]}${
92
+ select['code'] ? `(${select['code']})` : ''
93
+ }`
94
+ "
91
95
  >
92
- {{ `${select[selectLabel]}(${select['code']})` }}
96
+ {{
97
+ `${select[selectLabel]}${
98
+ select['code'] ? `(${select['code']})` : ''
99
+ }`
100
+ }}
93
101
  </p>
94
102
  </template>
95
103
  </ht-list-selector>
@@ -63,9 +63,17 @@
63
63
  />
64
64
  <p
65
65
  class="selector-selected__label"
66
- :title="`${select[selectLabel]}(${select['code']})`"
66
+ :title="
67
+ `${select[selectLabel]}${
68
+ select['code'] ? `(${select['code']})` : ''
69
+ }`
70
+ "
67
71
  >
68
- {{ `${select[selectLabel]}(${select['code']})` }}
72
+ {{
73
+ `${select[selectLabel]}${
74
+ select['code'] ? `(${select['code']})` : ''
75
+ }`
76
+ }}
69
77
  </p>
70
78
  </template>
71
79
  </ht-list-selector>
@@ -111,9 +111,17 @@
111
111
  />
112
112
  <p
113
113
  class="selector-selected__label"
114
- :title="`${select[selectLabel]}(${select['account']})`"
114
+ :title="
115
+ `${select[selectLabel]}${
116
+ select['account'] ? `(${select['account']})` : ''
117
+ }`
118
+ "
115
119
  >
116
- {{ `${select[selectLabel]}(${select['account']})` }}
120
+ {{
121
+ `${select[selectLabel]}${
122
+ select['account'] ? `(${select['account']})` : ''
123
+ }`
124
+ }}
117
125
  </p>
118
126
  </template>
119
127
  </ht-list-selector>
package/src/utils.js CHANGED
@@ -51,6 +51,20 @@ var utils = {
51
51
  })
52
52
  return result
53
53
  },
54
+ /**
55
+ *数组对象去重
56
+ *
57
+ * @export
58
+ * @param {any[]} array 要去重的数组
59
+ * @param {string} key 要去重的对象属性值
60
+ * @return {*} {any[]}
61
+ */
62
+ uniqueArrayObject(array, key) {
63
+ return array.reduce((pre, cur) => {
64
+ const keys = pre.map((item) => item[key])
65
+ return keys.includes(cur[key]) ? pre : [...pre, cur]
66
+ }, [])
67
+ },
54
68
  // 获取随机的名称
55
69
  getName: () => {
56
70
  return Math.random()