@94ai/nf-virtual-select 100.1.45 → 100.1.47

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"
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}; 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: false
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,
@@ -235,24 +273,6 @@ export default {
235
273
  height: {
236
274
  type: String,
237
275
  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
276
  }
257
277
  },
258
278
  data() {
@@ -268,10 +288,6 @@ export default {
268
288
  default() {
269
289
  return {}
270
290
  }
271
- },
272
- showTip: { // 提示
273
- type: Boolean,
274
- default: true
275
291
  }
276
292
  },
277
293
  render(h) {
@@ -279,7 +295,7 @@ export default {
279
295
  attrs: {
280
296
  label: that.keyValue[0],
281
297
  value: that.keyValue[1],
282
- showTip: this.showTip,
298
+ showTip: that.showTip,
283
299
  source: this.source,
284
300
  index: this.index,
285
301
  },
@@ -298,18 +314,16 @@ export default {
298
314
  },
299
315
  set(v) {
300
316
  this.$emit('input', v)
317
+ this.$emit('change', v)
318
+ this.$emit('update:value', v)
301
319
  }
302
320
  },
303
- isSelect() {
304
- return ((Object.prototype.hasOwnProperty.call(this.itemOptions, 'virtualList') && !this.itemOptions.virtualList) || !this.virtualList)
305
- },
306
321
  isVirtualSelect() {
307
- return (this.virtualList || this.itemOptions.virtualList)
322
+ return this.virtualList || this.itemOptions.virtualList
308
323
  },
309
324
  // 绑定属性
310
325
  bindProps() {
311
326
  let obj = {
312
- size: this.size,
313
327
  clearable: true,
314
328
  ...this.$attrs,
315
329
  ...this.formatItemOptions
@@ -336,13 +350,10 @@ export default {
336
350
  formatItemOptions() {
337
351
  const that = this
338
352
  return {
339
- size: this.size,
340
353
  ...this.itemOptions,
341
354
  ...this.$attrs,
342
- element: 'el-select',
343
355
  virtualList: this.itemOptions.virtualList || this.virtualList,
344
356
  placeholder: this.itemOptions.placeholder || this.placeholder,
345
- filterable: this.itemOptions.filterable || this.filterable,
346
357
  multiple: this.itemOptions.multiple || this.multiple,
347
358
  options: this.optionsList,
348
359
  events: {
@@ -360,9 +371,6 @@ export default {
360
371
  } else {
361
372
  return [];
362
373
  }
363
- },
364
- maxLimitElWidth() {
365
- return this.isFitWidth ? this.width : null
366
374
  }
367
375
  },
368
376
  watch: {
@@ -437,13 +445,14 @@ export default {
437
445
  this.$emit('resized', event)
438
446
  }
439
447
  },
440
-
441
448
  handleChange(event) {
442
449
  if (this.itemOptions.events?.change) {
443
450
  this.itemOptions.events.change(event, this)
444
451
  }else{
445
452
  // @change 事件
446
453
  this.$emit('change', event)
454
+ this.$emit('input', event)
455
+ this.$emit('update:value', event)
447
456
  }
448
457
  },
449
458
  init() {
@@ -483,7 +492,11 @@ export default {
483
492
  })
484
493
  },
485
494
  // 搜索
486
- filterMethod(query) {
495
+ async filterMethod(query) {
496
+ const filterHandler = this.bindProps['filter-method']
497
+ if (filterHandler) {
498
+ await filterHandler(query)
499
+ }
487
500
  if (query !== '') {
488
501
  this.$refs.virtualSelectList.scrollToIndex(0)// 滚动到顶部
489
502
  let timer = setTimeout(() => {
@@ -522,6 +535,7 @@ export default {
522
535
  this.reset()
523
536
  this.init()
524
537
  }
538
+ this.$emit('visible-change', bool)
525
539
  }
526
540
  },
527
541
  beforeDestroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-virtual-select",
3
- "version": "100.1.45",
3
+ "version": "100.1.47",
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": "^100.1.45",
17
+ "@94ai/nf-theme-chalk": "^100.1.47",
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": "4c5a85d5403ee4fb6bb5a1810f2b77235a5a842e"
35
+ "gitHead": "583a12d28fca323699b25aa5931ad859ddb05ef8"
36
36
  }