@94ai/nf-virtual-select 3.2.56 → 3.2.58

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.
@@ -1,19 +1,20 @@
1
1
  <template>
2
2
  <div class="nf-virtual-select">
3
- <template v-if="isVirtualSelect">
4
- <el-select
3
+ <el-select
4
+ v-if="isVirtualSelect"
5
5
  v-model="currentVal"
6
- popper-class="nf-virtual-list-select"
7
- class="nf-virtual-list-form-item-select"
6
+ v-on="bindEvents"
8
7
  v-bind="bindProps"
9
- :disabled="$attrs.disabled"
10
- :filter-method="filterMethod"
11
- @visible-change="visibleChange"
8
+ ref="nfVirtualSelect"
9
+ :class="['nf-virtual-select-el-select', bindProps['collapse-tags'] ? 'nf-virtual-select-collapse-tags' : '']"
10
+ popper-class="nf-virtual-select-virtual-list-popper"
12
11
  filterable
13
- :style="`width: ${width};`"
12
+ :filter-method="filterMethod"
14
13
  @change="handleChange"
15
- v-on="bindEvents"
14
+ @visible-change="visibleChange"
16
15
  >
16
+ <slot name="prefix" slot="prefix" />
17
+ <slot name="empty" slot="empty" />
17
18
  <virtual-list
18
19
  :offset="offset"
19
20
  :start="start"
@@ -35,31 +36,38 @@
35
36
  :footer-tag="footerTag"
36
37
  :footer-class="footerClass"
37
38
  :footer-style="footerStyle"
39
+ :extra-props="extraProps"
40
+ :data-component="itemComponent"
41
+ :data-sources="selectArr"
42
+ :data-key="dataKey"
43
+ :estimate-size="estimateSize"
44
+ :keeps="keeps"
45
+ ref="virtualSelectList"
46
+ class="nf-virtual-select-list"
38
47
  @scroll="scroll"
39
48
  @totop="totop"
40
49
  @tobottom="tobottom"
41
50
  @resized="resized"
42
- ref="virtualSelectList"
43
- class="nf-virtual-select-list"
44
- :style="`max-height: ${height};width: ${maxLimitElWidth}; overflow-y: auto;`"
45
- :data-key="dataKey"
46
- :estimate-size="estimateSize"
47
- :data-sources="selectArr"
48
- :data-component="itemComponent"
49
- :keeps="keeps"
50
- :extra-props="extraProps"
51
- />
51
+ :style="`max-height: ${height};min-width: ${width};max-width: ${maxWidth};overflow-y: auto;`"
52
+ >
53
+ <slot slot="footer" name="footer" />
54
+ <slot slot="header" name="header" />
55
+ </virtual-list>
56
+ <slot/>
52
57
  </el-select>
53
- </template>
54
58
  <el-select
55
- v-else-if="isSelect"
59
+ v-else
56
60
  v-model="currentVal"
57
61
  v-bind="bindProps"
58
- :style="`width: ${width};`"
59
- popper-class="select-popper"
60
- @change="handleChange"
61
62
  v-on="bindEvents"
63
+ ref="nfVirtualSelect"
64
+ class="nf-virtual-select-el-select"
65
+ popper-class="nf-virtual-select-el-select-popper"
66
+ @change="handleChange"
62
67
  >
68
+ <slot name="prefix" slot="prefix" />
69
+ <slot name="empty" slot="empty" />
70
+ <slot name="header" />
63
71
  <el-option
64
72
  v-for="(item, index) in selectArr"
65
73
  :key="item[keyValue[0]] + '_' + index"
@@ -67,10 +75,19 @@
67
75
  :value="item[keyValue[1]]"
68
76
  :disabled="item.disabled"
69
77
  >
70
- <el-tooltip :content="item[keyValue[0]]" :open-delay="1000" effect="dark" placement="left">
78
+ <el-tooltip :content="item[keyValue[0]]"
79
+ :open-delay="1000"
80
+ effect="dark"
81
+ placement="left"
82
+ v-if="showTip">
71
83
  <span>{{ item[keyValue[0]] }}</span>
72
84
  </el-tooltip>
85
+ <span v-else>
86
+ {{ item[keyValue[0]] }}
87
+ </span>
73
88
  </el-option>
89
+ <slot/>
90
+ <slot name="footer"/>
74
91
  </el-select>
75
92
  </div>
76
93
  </template>
@@ -78,12 +95,15 @@
78
95
  <script>
79
96
  import virtualList from 'vue-virtual-scroll-list'
80
97
  import ElOptionNode from './el-option-node.vue'
81
- import { isEqual, cloneDeep } from 'lodash-es'
98
+ import { isEqual } from 'lodash-es'
82
99
  export default {
83
100
  name: 'nf-virtual-select',
84
101
  components: { 'virtual-list': virtualList },
85
102
  inheritAttrs: false,
86
103
  props: {
104
+ /**
105
+ * 虚拟滚动属性
106
+ */
87
107
  offset: {
88
108
  type: Number,
89
109
  default: 0
@@ -161,7 +181,7 @@ export default {
161
181
  },
162
182
  footerTag: {
163
183
  type: String,
164
- default: 'div'
184
+ default: 'span'
165
185
  },
166
186
  footerClass: {
167
187
  type: String,
@@ -177,32 +197,49 @@ export default {
177
197
  type: Number,
178
198
  default: 30
179
199
  },
180
- /**
181
- * 每个项目的估计大小,如果它更接近平均大小,滚动条长度看起来更准确。建议指定自己计算的平均值。
182
- */
200
+ // 每个项目的估计大小,如果它更接近平均大小,滚动条长度看起来更准确。建议指定自己计算的平均值。
183
201
  estimateSize: {
184
202
  type: Number,
185
203
  default: 50
186
204
  },
205
+ extraProps: {
206
+ type: Object,
207
+ default: () => ({
208
+ label: 'label',
209
+ value: 'value'
210
+ })
211
+ },
212
+ dataComponent: {
213
+ type: Object,
214
+ },
215
+ dataKey: {
216
+ type: [String , Function],
217
+ default: 'templateId'
218
+ },
219
+ /**
220
+ * 选中值
221
+ */
187
222
  value: {
188
223
  type: [String, Number, Array],
189
224
  default: () => {
190
225
  return ''
191
226
  }
192
227
  },
193
- size: {
194
- type: String,
195
- default: undefined
228
+ /**
229
+ * 开启tooltip
230
+ */
231
+ showTip: {
232
+ type: Boolean,
233
+ default: true
196
234
  },
197
- // 默认['label','value']
235
+ /**
236
+ * keyValue别名
237
+ */
198
238
  keyValue: {
199
239
  type: Array,
200
240
  default: () => ['label', 'value']
201
241
  },
202
- placeholder: {
203
- type: String,
204
- default: '请选择'
205
- },
242
+
206
243
  itemOptions: {
207
244
  type: Object,
208
245
  default() {
@@ -220,9 +257,10 @@ export default {
220
257
  type: Array,
221
258
  default: () => []
222
259
  },
223
- filterable: {
224
- type: Boolean,
225
- default: false
260
+
261
+ placeholder: {
262
+ type: String,
263
+ default: '请选择'
226
264
  },
227
265
  multiple: {
228
266
  type: Boolean,
@@ -232,27 +270,13 @@ export default {
232
270
  type: String,
233
271
  default: '100%'
234
272
  },
273
+ maxWidth: {
274
+ type: String,
275
+ default: null
276
+ },
235
277
  height: {
236
278
  type: String,
237
279
  default: '245px'
238
- },
239
- isFitWidth: {
240
- type: Boolean,
241
- default: true
242
- },
243
- dataComponent: {
244
- type: Object,
245
- },
246
- extraProps: {
247
- type: Object,
248
- default: () => ({
249
- label: 'label',
250
- value: 'value'
251
- })
252
- },
253
- dataKey: {
254
- type: [String , Function],
255
- default: 'templateId'
256
280
  }
257
281
  },
258
282
  data() {
@@ -268,10 +292,6 @@ export default {
268
292
  default() {
269
293
  return {}
270
294
  }
271
- },
272
- showTip: { // 提示
273
- type: Boolean,
274
- default: true
275
295
  }
276
296
  },
277
297
  render(h) {
@@ -279,7 +299,7 @@ export default {
279
299
  attrs: {
280
300
  label: that.keyValue[0],
281
301
  value: that.keyValue[1],
282
- showTip: this.showTip,
302
+ showTip: that.showTip,
283
303
  source: this.source,
284
304
  index: this.index,
285
305
  },
@@ -298,18 +318,16 @@ export default {
298
318
  },
299
319
  set(v) {
300
320
  this.$emit('input', v)
321
+ this.$emit('change', v)
322
+ this.$emit('update:value', v)
301
323
  }
302
324
  },
303
- isSelect() {
304
- return ((Object.prototype.hasOwnProperty.call(this.itemOptions, 'virtualList') && !this.itemOptions.virtualList) || !this.virtualList)
305
- },
306
325
  isVirtualSelect() {
307
- return (this.virtualList || this.itemOptions.virtualList)
326
+ return this.virtualList || this.itemOptions.virtualList
308
327
  },
309
328
  // 绑定属性
310
329
  bindProps() {
311
330
  let obj = {
312
- size: this.size,
313
331
  clearable: true,
314
332
  ...this.$attrs,
315
333
  ...this.formatItemOptions
@@ -336,13 +354,10 @@ export default {
336
354
  formatItemOptions() {
337
355
  const that = this
338
356
  return {
339
- size: this.size,
340
357
  ...this.itemOptions,
341
358
  ...this.$attrs,
342
- element: 'el-select',
343
359
  virtualList: this.itemOptions.virtualList || this.virtualList,
344
360
  placeholder: this.itemOptions.placeholder || this.placeholder,
345
- filterable: this.itemOptions.filterable || this.filterable,
346
361
  multiple: this.itemOptions.multiple || this.multiple,
347
362
  options: this.optionsList,
348
363
  events: {
@@ -360,9 +375,6 @@ export default {
360
375
  } else {
361
376
  return [];
362
377
  }
363
- },
364
- maxLimitElWidth() {
365
- return this.isFitWidth ? this.width : null
366
378
  }
367
379
  },
368
380
  watch: {
@@ -437,13 +449,14 @@ export default {
437
449
  this.$emit('resized', event)
438
450
  }
439
451
  },
440
-
441
452
  handleChange(event) {
442
453
  if (this.itemOptions.events?.change) {
443
454
  this.itemOptions.events.change(event, this)
444
455
  }else{
445
456
  // @change 事件
446
457
  this.$emit('change', event)
458
+ this.$emit('input', event)
459
+ this.$emit('update:value', event)
447
460
  }
448
461
  },
449
462
  init() {
@@ -483,7 +496,15 @@ export default {
483
496
  })
484
497
  },
485
498
  // 搜索
486
- filterMethod(query) {
499
+ async filterMethod(query) {
500
+ const filterHandler = this.bindProps['filter-method']
501
+ let interrupt = false
502
+ if (filterHandler) {
503
+ interrupt = await filterHandler(query)
504
+ }
505
+ if (interrupt) {
506
+ return
507
+ }
487
508
  if (query !== '') {
488
509
  this.$refs.virtualSelectList.scrollToIndex(0)// 滚动到顶部
489
510
  let timer = setTimeout(() => {
@@ -522,6 +543,7 @@ export default {
522
543
  this.reset()
523
544
  this.init()
524
545
  }
546
+ this.$emit('visible-change', bool)
525
547
  }
526
548
  },
527
549
  beforeDestroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-virtual-select",
3
- "version": "3.2.56",
3
+ "version": "3.2.58",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "DESKTOP-1EDDQ79\\dev026 <liuxiangxiang@94ai.com>",
@@ -14,7 +14,7 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-theme-chalk": "^3.2.56",
17
+ "@94ai/nf-theme-chalk": "^3.2.58",
18
18
  "lodash-es": "^4.17.21",
19
19
  "vue-demi": "^0.14.5",
20
20
  "vue-virtual-scroll-list": "^2.3.5"
@@ -32,5 +32,5 @@
32
32
  "types": "lib/index.d.ts",
33
33
  "main": "lib/nf-virtual-select.cjs.js",
34
34
  "module": "lib/nf-virtual-select.esm-bundler.js",
35
- "gitHead": "a475b43138116c9b5cf8d660e000903f24dc5ba9"
35
+ "gitHead": "f08091dce410b101d5a5dcb1c97dcdfe09a75b34"
36
36
  }