@94ai/nf-virtual-select 3.1.36 → 3.1.38

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.
@@ -0,0 +1,37 @@
1
+ <template>
2
+ <el-option :key="index" :label="source[label]" :value="source[value]" :title="source[label]" :disabled="source['disabled']">
3
+ <el-tooltip v-if="source?.slotContent?.firstCall || source?.slotContent?.recall" effect="dark" placement="right">
4
+ <div slot="content" style="max-width: 350px;">
5
+ {{ source?.slotContent?.firstCall }} <br> <br>
6
+ {{ source?.slotContent?.recall }}
7
+ </div>
8
+ <span>{{ source[label] }}</span>
9
+ </el-tooltip>
10
+ </el-option>
11
+ </template>
12
+
13
+ <script>
14
+ export default {
15
+ name: 'ItemComponent',
16
+ props: {
17
+ index: { // 每一行的索引
18
+ type: Number,
19
+ required: true
20
+ },
21
+ source: { // 每一行的内容
22
+ type: Object,
23
+ default() {
24
+ return {}
25
+ }
26
+ },
27
+ label: { // 要显示的名称
28
+ type: String,
29
+ required: true
30
+ },
31
+ value: { // 绑定的值
32
+ type: String,
33
+ required: true
34
+ }
35
+ }
36
+ }
37
+ </script>
@@ -0,0 +1,8 @@
1
+ import NfVirtualSelect from './nf-virtual-select.vue'
2
+ import { Vue2, PluginObject } from 'vue-demi'
3
+
4
+ NfVirtualSelect.install = (app: typeof Vue2) => {
5
+ app!.component('nf-virtual-select', NfVirtualSelect)
6
+ }
7
+
8
+ export default NfVirtualSelect as typeof NfVirtualSelect & PluginObject<undefined>
@@ -0,0 +1,497 @@
1
+ <template>
2
+ <div class="nf-virtual-select">
3
+ <template v-if="isVirtualSelect">
4
+ <el-select
5
+ v-model="currentVal"
6
+ popper-class="nf-virtual-list-select"
7
+ class="nf-virtual-list-form-item-select"
8
+ v-bind="bindProps"
9
+ :disabled="$attrs.disabled"
10
+ :filter-method="filterMethod"
11
+ filterable
12
+ :style="`width: ${width};`"
13
+ @change="handleChange"
14
+ v-on="bindEvents"
15
+ >
16
+ <virtual-list
17
+ :offset="offset"
18
+ :start="start"
19
+ :page-mode="pageMode"
20
+ :direction="direction"
21
+ :top-threshold="topThreshold"
22
+ :bottom-threshold="bottomThreshold"
23
+ :root-tag="rootTag"
24
+ :wrap-tag="wrapTag"
25
+ :wrap-style="wrapStyle"
26
+ :item-tag="itemTag"
27
+ :item-class="itemClass"
28
+ :item-class-add="itemClassAdd"
29
+ :item-style="itemStyle"
30
+ :item-scoped-slots="itemScopedSlots"
31
+ :header-tag="headerTag"
32
+ :header-class="headeClass"
33
+ :header-style="headerStyle"
34
+ :footer-tag="footerTag"
35
+ :footer-class="footerClass"
36
+ :footer-style="footerStyle"
37
+ @scroll="scroll"
38
+ @totop="totop"
39
+ @tobottom="tobottom"
40
+ @resized="resized"
41
+ ref="virtualSelectList"
42
+ class="nf-virtual-select-list"
43
+ :style="`max-height: ${height};width: ${width}; overflow-y: auto;`"
44
+ :data-key="dataKey"
45
+ :estimate-size="estimateSize"
46
+ :data-sources="selectArr"
47
+ :data-component="itemComponent"
48
+ :keeps="keeps"
49
+ :extra-props="extraProps"
50
+ />
51
+ </el-select>
52
+ </template>
53
+ <el-select
54
+ v-else-if="isSelect"
55
+ v-model="currentVal"
56
+ v-bind="bindProps"
57
+ :style="`width: ${width};`"
58
+ @change="handleChange"
59
+ v-on="bindEvents"
60
+ >
61
+ <el-option
62
+ v-for="(item, index) in selectArr"
63
+ :key="item.label + '_' + index"
64
+ :label="item.label"
65
+ :value="item.value"
66
+ :disabled="item.disabled"
67
+ />
68
+ </el-select>
69
+ </div>
70
+ </template>
71
+
72
+ <script>
73
+ import virtualList from 'vue-virtual-scroll-list'
74
+ import ElOptionNode from './el-option-node.vue'
75
+ import { isEqual, cloneDeep } from 'lodash'
76
+ export default {
77
+ name: 'nf-virtual-select',
78
+ components: { 'virtual-list': virtualList },
79
+ inheritAttrs: false,
80
+ props: {
81
+ offset: {
82
+ type: Number,
83
+ default: 0
84
+ },
85
+ start: {
86
+ type: Number,
87
+ default: 0
88
+ },
89
+ pageMode: {
90
+ type: Boolean,
91
+ default: false
92
+ },
93
+ direction: {
94
+ type: String,
95
+ default: 'vertical'
96
+ },
97
+ topThreshold: {
98
+ type: Number,
99
+ default: 0
100
+ },
101
+ bottomThreshold: {
102
+ type: Number,
103
+ default: 0
104
+ },
105
+ rootTag: {
106
+ type: String,
107
+ default: 'div'
108
+ },
109
+ wrapTag: {
110
+ type: String,
111
+ default: 'div'
112
+ },
113
+ wrapStyle: {
114
+ type: Object,
115
+ default: () => {
116
+ return {}
117
+ }
118
+ },
119
+ itemTag: {
120
+ type: String,
121
+ default: 'div'
122
+ },
123
+ itemClass: {
124
+ type: String,
125
+ default: ''
126
+ },
127
+ itemClassAdd: {
128
+ type: Function,
129
+ },
130
+ itemStyle: {
131
+ type: Object,
132
+ default: () => {
133
+ return {}
134
+ }
135
+ },
136
+ itemScopedSlots: {
137
+ type: Object,
138
+ default: () => {
139
+ return {}
140
+ }
141
+ },
142
+ headerTag: {
143
+ type: String,
144
+ default: 'div'
145
+ },
146
+ headeClass: {
147
+ type: String,
148
+ default: ''
149
+ },
150
+ headerStyle: {
151
+ type: Object,
152
+ default: () => {
153
+ return {}
154
+ }
155
+ },
156
+ footerTag: {
157
+ type: String,
158
+ default: 'div'
159
+ },
160
+ footerClass: {
161
+ type: String,
162
+ default: ''
163
+ },
164
+ footerStyle: {
165
+ type: Object,
166
+ default: () => {
167
+ return {}
168
+ }
169
+ },
170
+ keeps: {
171
+ type: Number,
172
+ default: 30
173
+ },
174
+ /**
175
+ * 每个项目的估计大小,如果它更接近平均大小,滚动条长度看起来更准确。建议指定自己计算的平均值。
176
+ */
177
+ estimateSize: {
178
+ type: Number,
179
+ default: 50
180
+ },
181
+ value: {
182
+ type: [String, Number, Array],
183
+ default: () => {
184
+ return ''
185
+ }
186
+ },
187
+ size: {
188
+ type: String,
189
+ default: 'medium'
190
+ },
191
+ // 默认['label','value']
192
+ keyValue: {
193
+ type: Array,
194
+ default: () => ['label', 'value']
195
+ },
196
+ placeholder: {
197
+ type: String,
198
+ default: '请选择'
199
+ },
200
+ itemOptions: {
201
+ type: Object,
202
+ default() {
203
+ return {
204
+ options: [],
205
+ virtualList: false
206
+ }
207
+ }
208
+ },
209
+ virtualList: {
210
+ type: Boolean,
211
+ default: false
212
+ },
213
+ options: {
214
+ type: Array,
215
+ default: () => []
216
+ },
217
+ filterable: {
218
+ type: Boolean,
219
+ default: false
220
+ },
221
+ multiple: {
222
+ type: Boolean,
223
+ default: false
224
+ },
225
+ width: {
226
+ type: String,
227
+ default: '100%'
228
+ },
229
+ height: {
230
+ type: String,
231
+ default: '245px'
232
+ },
233
+ dataComponent: {
234
+ type: Object,
235
+ },
236
+ extraProps: {
237
+ type: Object,
238
+ default: () => ({
239
+ label: 'label',
240
+ value: 'value'
241
+ })
242
+ },
243
+ dataKey: {
244
+ type: [String , Function],
245
+ default: 'templateId'
246
+ }
247
+ },
248
+ data() {
249
+ return {
250
+ itemComponent: this.dataComponent ?? ElOptionNode,
251
+ selectArr: []
252
+ }
253
+ },
254
+ computed: {
255
+ currentVal: {
256
+ get() {
257
+ return this.value
258
+ },
259
+ set(v) {
260
+ this.$emit('input', v)
261
+ }
262
+ },
263
+ isSelect() {
264
+ return ((Object.prototype.hasOwnProperty.call(this.itemOptions, 'virtualList') && !this.itemOptions.virtualList) || !this.virtualList)
265
+ },
266
+ isVirtualSelect() {
267
+ return (this.virtualList || this.itemOptions.virtualList)
268
+ },
269
+ // 绑定属性
270
+ bindProps() {
271
+ let obj = {
272
+ size: this.size,
273
+ clearable: true,
274
+ ...this.$attrs,
275
+ ...this.formatItemOptions
276
+ }
277
+ if (obj.element === 'custom-select' || (obj.element === 'el-select')) {
278
+ if (obj.multiple) {
279
+ obj = {
280
+ 'collapse-tags': true,
281
+ ...obj
282
+ }
283
+ }
284
+ delete obj.options
285
+ }
286
+ return obj
287
+ },
288
+ // 绑定方法
289
+ bindEvents() {
290
+ const events = { ...(this.$listeners || {}), ...this.itemOptions.events }
291
+ if (events?.change) {
292
+ delete events.change
293
+ }
294
+ return events || {}
295
+ },
296
+ formatItemOptions() {
297
+ const that = this
298
+ return {
299
+ size: this.size,
300
+ ...this.itemOptions,
301
+ ...this.$attrs,
302
+ element: 'el-select',
303
+ virtualList: this.itemOptions.virtualList || this.virtualList,
304
+ placeholder: this.itemOptions.placeholder || this.placeholder,
305
+ filterable: this.itemOptions.filterable || this.filterable,
306
+ multiple: this.itemOptions.multiple || this.multiple,
307
+ options: this.optionsList,
308
+ events: {
309
+ change(val) {
310
+ that.$emit('change', val)
311
+ }
312
+ }
313
+ }
314
+ },
315
+ optionsList() {
316
+ if (this.options.length) {
317
+ return this.options;
318
+ } else if (this.itemOptions.options?.length) {
319
+ return this.itemOptions.options;
320
+ } else {
321
+ return [];
322
+ }
323
+ }
324
+ },
325
+ watch: {
326
+ options(newVal, value) {
327
+ if (!isEqual(newVal, value)) {
328
+ this.init()
329
+ }
330
+ },
331
+ currentVal: {
332
+ handler(newVal, value) {
333
+ this.init()
334
+ }
335
+ }
336
+ },
337
+ mounted() {
338
+ this.init()
339
+ },
340
+ methods: {
341
+ reset() {
342
+ this.$refs.virtualSelectList?.reset()
343
+ },
344
+ scrollToBottom() {
345
+ this.$refs.virtualSelectList.scrollToBottom()
346
+ },
347
+ scrollToIndex(index) {
348
+ this.$refs.virtualSelectList.scrollToIndex(index)
349
+ },
350
+ scrollToOffset(offset) {
351
+ this.$refs.virtualSelectList.scrollToOffset(offset)
352
+ },
353
+ getSize(id) {
354
+ return this.$refs.virtualSelectList.getSize(id)
355
+ },
356
+ getClientSize() {
357
+ return this.$refs.virtualSelectList.getClientSize()
358
+ },
359
+ getScrollSize() {
360
+ return this.$refs.virtualSelectList.getScrollSize()
361
+ },
362
+ updatePageModeFront() {
363
+ this.$refs.virtualSelectList.updatePageModeFront()
364
+ },
365
+ scroll(event) {
366
+ if (this.itemOptions.events?.scroll) {
367
+ this.itemOptions.events.scroll(event, this)
368
+ }else{
369
+ // @scroll 事件
370
+ this.$emit('scroll', event)
371
+ }
372
+ },
373
+ totop(event) {
374
+ if (this.itemOptions.events?.totop) {
375
+ this.itemOptions.events.totop(event, this)
376
+ }else{
377
+ // @totop 事件
378
+ this.$emit('totop', event)
379
+ }
380
+ },
381
+ tobottom(event) {
382
+ if (this.itemOptions.events?.tobottom) {
383
+ this.itemOptions.events.tobottom(event, this)
384
+ }else{
385
+ // @tobottom 事件
386
+ this.$emit('tobottom', event)
387
+ }
388
+ },
389
+ resized(event) {
390
+ if (this.itemOptions.events?.resized) {
391
+ this.itemOptions.events.resized(event, this)
392
+ }else{
393
+ // @resized 事件
394
+ this.$emit('resized', event)
395
+ }
396
+ },
397
+
398
+ handleChange(event) {
399
+ if (this.itemOptions.events?.change) {
400
+ this.itemOptions.events.change(event, this)
401
+ }else{
402
+ // @change 事件
403
+ this.$emit('change', event)
404
+ }
405
+ },
406
+ init() {
407
+ this.$nextTick(() => {
408
+ if ((this.isVirtualSelect)) {
409
+ // 虚拟
410
+ if (!this.currentVal) {
411
+ // 无回显值
412
+ this.selectArr = this.optionsList?.map(it => ({
413
+ label: it[this.keyValue[0]],
414
+ value: it[this.keyValue[1]],
415
+ templateId: it[this.keyValue[1]],
416
+ disabled: it['disabled'] ?? false
417
+ })) ?? [];
418
+ } else {
419
+ // 有回显值
420
+ this.selectArr = this.optionsList ? cloneDeep(this.optionsList) : [];
421
+ if ((this.itemOptions.multiple || this.multiple) && Array.isArray(this.currentVal)) {
422
+ // 多选
423
+ const multiple_elements = this.selectArr.filter(item => this.currentVal.includes(item.value))
424
+ this.selectArr = [...multiple_elements, ...this.selectArr.filter(item => !multiple_elements.includes(item))];
425
+ } else {
426
+ // 单选
427
+ const index = this.selectArr.findIndex(item => item.value === this.currentVal);
428
+ if (index !== -1) {
429
+ const obj = this.selectArr.splice(index, 1)[0];
430
+ this.selectArr.unshift(obj);
431
+ }
432
+ }
433
+ }
434
+ } else {
435
+ // 非虚拟选择器
436
+ this.selectArr = (this.optionsList || []).map(it => ({
437
+ label: it[this.keyValue[0]],
438
+ value: it[this.keyValue[1]],
439
+ disabled: it['disabled'] ?? false
440
+ }))
441
+ }
442
+ })
443
+ },
444
+ // 搜索
445
+ filterMethod(query) {
446
+ if (query !== '') {
447
+ this.$refs.virtualSelectList.scrollToIndex(0)// 滚动到顶部
448
+ let timer = setTimeout(() => {
449
+ const selectArr = this.itemOptions.options.filter(item => {
450
+ if (item[this.keyValue[0]]) {
451
+ return item[this.keyValue[0]].toLowerCase().indexOf(query.toLowerCase()) > -1
452
+ }
453
+ })
454
+ this.selectArr = (selectArr || []).map(it => {
455
+ return {
456
+ label: it[this.keyValue[0]],
457
+ value: it[this.keyValue[1]],
458
+ templateId: it[this.keyValue[1]],
459
+ disabled: it['disabled'] ? it['disabled'] : false,
460
+ slotContent: it?.slotContent || {}
461
+ }
462
+ })
463
+ clearTimeout(timer)
464
+ timer = null
465
+ }, 100)
466
+ this.$once('hook:beforeDestroy', () => {
467
+ clearTimeout(timer)
468
+ timer = null
469
+ })
470
+ this.$once('hook:deactivated', () => {
471
+ clearTimeout(timer)
472
+ timer = null
473
+ })
474
+ } else {
475
+ this.init()
476
+ }
477
+ },
478
+ visibleChange(bool) {
479
+ if (!bool) {
480
+ this.reset()
481
+ this.init()
482
+ }
483
+ }
484
+ },
485
+ beforeDestroy() {
486
+ this.reset()
487
+ this.selectArr = []
488
+ },
489
+ activated() {
490
+ this.init()
491
+ },
492
+ deactivated() {
493
+ this.reset()
494
+ this.selectArr = []
495
+ }
496
+ }
497
+ </script>
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-virtual-select.css'
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-virtual-select.scss'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-virtual-select",
3
- "version": "3.1.36",
3
+ "version": "3.1.38",
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.1.36",
17
+ "@94ai/nf-theme-chalk": "^1.0.0",
18
18
  "vue-demi": "^0.14.5",
19
19
  "vue-virtual-scroll-list": "^2.3.5"
20
20
  },
@@ -31,5 +31,5 @@
31
31
  "types": "lib/index.d.ts",
32
32
  "main": "lib/nf-virtual-select.cjs.js",
33
33
  "module": "lib/nf-virtual-select.esm-bundler.js",
34
- "gitHead": "c95b0b2f85a3ec95a21f8a2448113370e6b826d8"
34
+ "gitHead": "2b60696b405feafbbaeed385e5bcf666ceefbf2c"
35
35
  }