@94ai/nf-popup-lazy-select 3.2.80 → 3.2.82

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/index.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import NfPopupLazySelect from './nf-popup-lazy-select.vue'
2
2
  import { Vue2, PluginObject } from 'vue-demi'
3
+ import CustomSelectDropdown from './custom-select-dropdown.vue'
3
4
 
4
5
  NfPopupLazySelect.install = (app: typeof Vue2) => {
5
6
  app!.component('nf-popup-lazy-select', NfPopupLazySelect)
7
+ app!.component('custom-select-dropdown', CustomSelectDropdown)
6
8
  }
7
9
 
8
10
  export default NfPopupLazySelect as typeof NfPopupLazySelect & PluginObject<undefined>
@@ -22,9 +22,12 @@
22
22
  >
23
23
  <slot slot="reference" name="default"></slot>
24
24
  <nf-lazy-select
25
- :key="refreshLazySelect"
26
25
  v-model="currentVal"
27
26
  ref="popLazySelectRef"
27
+ :visible-change-keyword-cached="visibleChangeKeywordCached"
28
+ :visible-change-select-list-cached="visibleChangeSelectListCached"
29
+ :emit-selected-item-on-click="emitSelectedItemOnClick"
30
+ :tag="tag"
28
31
 
29
32
  :request="request"
30
33
  :page-size="pageSize"
@@ -35,7 +38,7 @@
35
38
 
36
39
  :loading-desc="loadingDesc"
37
40
  :no-data-text="noDataText"
38
- :placeholder="placeholderComputed"
41
+ :placeholder="placeholder"
39
42
 
40
43
  :multiple-limit="multipleLimit"
41
44
  :collapse-tags="collapseTags"
@@ -83,6 +86,8 @@
83
86
  :max-width="maxWidth"
84
87
  :height="dataList.length ? height : '0'"
85
88
 
89
+ @get-selected-data="getSelectedData"
90
+ @select-item="selectItem"
86
91
  @scroll="e => $emit('scroll', e)"
87
92
  @totop="e => $emit('totop', e)"
88
93
  @tobottom="e => $emit('tobottom', e)"
@@ -115,13 +120,17 @@ export default defineComponent({
115
120
  <script lang="ts" setup>
116
121
  import {
117
122
  computed,
118
- nextTick,
119
123
  ref
120
124
  } from 'vue-demi'
121
125
 
122
126
  const props = withDefaults(defineProps<{
123
- popdownOnSelect?: boolean,
124
- assignmentOnSelect?: boolean,
127
+ tag?: string, // 定制下拉渲染标签
128
+ popdownOnSelect?: boolean, // 选中关闭浮层
129
+ assignmentOnSelect?: boolean, // 选中赋值
130
+ emitSelectedItemOnClick?: boolean, // 选中触发get
131
+ visibleChangeKeywordCached?: boolean, // focus时要不要缓存上一次搜索的keyword
132
+ visibleChangeSelectListCached?: boolean, // focus时要不要缓存上一次搜索的下拉列表
133
+
125
134
  /**
126
135
  * 输入时传递给后端key别名定制
127
136
  */
@@ -229,8 +238,13 @@ const props = withDefaults(defineProps<{
229
238
  size?: 'mini' | 'medium' | 'small'
230
239
  value?: string | number | string[] | number[]
231
240
  }>(), {
232
- popdownOnSelect: false,
233
- assignmentOnSelect: true,
241
+ tag: 'custom-select-dropdown', // 定制下拉渲染标签
242
+ popdownOnSelect: false, // 选中关闭浮层
243
+ assignmentOnSelect: true, // 选中赋值
244
+ emitSelectedItemOnClick: false, // 选中触发get-selected-data
245
+ visibleChangeKeywordCached: true, // focus时要不要缓存上一次搜索的keyword
246
+ visibleChangeSelectListCached: true, // focus时要不要缓存上一次搜索的下拉列表
247
+
234
248
  keywordAlias: 'keyword',
235
249
  pageNoAlias: 'pageNo',
236
250
  pageSizeAlias: 'pageSize',
@@ -246,7 +260,7 @@ const props = withDefaults(defineProps<{
246
260
  collapseTags: false,
247
261
  disabled: false,
248
262
  multiple: false,
249
- reserveKeyword: false,
263
+ reserveKeyword: true,
250
264
  popperClass: '',
251
265
  defaultFirstOption: false,
252
266
  placeholder: '请输入',
@@ -311,28 +325,28 @@ const emit = defineEmits<{
311
325
  (e: 'update:value', event?: string | number | string[] | number[]): void
312
326
 
313
327
  (e: 'fetch-data', event: {
314
- allCachedList: any[],
315
- currentList: any[],
316
- event: {
317
- total: number,
318
- current: number,
319
- hasMore: boolean,
320
- keyword: string,
321
- /**
322
- * 当前记录原始值
323
- */
324
- records: any[],
325
- /**
326
- * 原始渲染数据
327
- */
328
- originData: any[],
329
- /**
330
- * 组件渲染数据
331
- */
332
- data: any[]
333
- }
328
+ total: number,
329
+ current: number,
330
+ hasMore: boolean,
331
+ keyword: string,
332
+ /**
333
+ * 当前接口分页数据
334
+ */
335
+ records: any[],
336
+ /**
337
+ * 当前下拉所有分页数据
338
+ */
339
+ data: any[],
340
+ /**
341
+ * 当前下拉所有分页接口原始数据
342
+ */
343
+ originData: any[],
344
+ /**
345
+ * 所有经过组件的下拉原始数据
346
+ */
347
+ allCachedDataList: any[],
334
348
  }): void
335
- (e: 'select-item', event: any): void
349
+ (e: 'get-selected-data', event: any): void
336
350
 
337
351
  (e: 'visible-change', event: boolean): void
338
352
  (e: 'remove-tag', event: string | number): void
@@ -350,51 +364,57 @@ const emit = defineEmits<{
350
364
  (e: 'popup-hide', event: boolean): void
351
365
  (e: 'popup-show', event: boolean): void
352
366
  }>()
353
- const refreshLazySelect = ref(Date.now())
354
- const resetPlaceholder = ref(false)
355
- const placeholderComputed = computed(() => {
356
- return resetPlaceholder.value ? '' : (!props.multiple && !props.assignmentOnSelect && popLazySelectRef.value?.keyword) ? popLazySelectRef.value.keyword : props.placeholder
357
- })
367
+
368
+ const getSelectedData = (e) => {
369
+ emit('get-selected-data', e)
370
+ }
371
+
372
+ const visibleChange = async (e) => {
373
+ emit('visible-change', e)
374
+ }
358
375
  const changeHide = () => {
359
- emit('popup-hide', false)
360
- popLazySelectRef.value.visibleIntersect = false
361
- popLazySelectRef.value.nfLazySelect.reset()
362
- popLazySelectRef.value.nfLazySelect.init()
376
+ const visible = popLazySelectRef.value?.$refs?.nfLazySelect?.nfVirtualSelect?.visible
377
+ if (!popup.value && typeof visible === 'boolean' && visible) {
378
+ popLazySelectRef.value.$refs.nfLazySelect.nfVirtualSelect.toggleMenu()
379
+ }
380
+ emit('popup-hide', popup.value)
363
381
  }
364
382
 
365
383
  const changeShow = () => {
366
- const visible = popLazySelectRef.value?.$refs?.nfLazySelect?.$refs?.nfVirtualSelect?.visible
367
- if (popup.value && typeof visible === 'boolean' && !visible) { // 手动触发 显示具有副作用,需要定制visible-change
368
- popLazySelectRef.value.$refs.nfLazySelect.$refs.nfVirtualSelect.toggleMenu()
384
+ const visible = popLazySelectRef.value?.$refs?.nfLazySelect?.nfVirtualSelect?.visible
385
+ if (popup.value && typeof visible === 'boolean' && !visible) {
386
+ popLazySelectRef.value.$refs.nfLazySelect.nfVirtualSelect.toggleMenu()
369
387
  }
370
388
  emit('popup-show', popup.value)
371
389
  }
372
390
 
373
- const visibleChange = async (e) => {
374
- if (!e) {
375
- return 'break'
376
- } else if (!props.popdownOnSelect && !props.multiple && props.assignmentOnSelect) {
377
- return 'discard-cache'
378
- }
379
- }
380
391
 
381
392
  const popLazySelectRef = ref()
382
393
  const popup = ref(false) // 定制关闭浮层
383
394
  const dataList = ref<any[]>([]) // 收起缓存数据
384
- const dataMap = ref({})
395
+ const allCachedDataList = ref<any[]>([])
385
396
 
386
397
  const fetchDataHandler = (e) => {
387
- e.originData?.forEach(data => {
388
- if (!dataMap.value[data[props.valueAlias]]) {
389
- dataMap.value[data[props.valueAlias]] = true
390
- dataList.value.push(data)
398
+ dataList.value = e.data
399
+ allCachedDataList.value = e.allCachedDataList
400
+ emit('fetch-data', e)
401
+ }
402
+
403
+ const selectItem = (val) => {
404
+ if (!props.assignmentOnSelect) {
405
+ if (props.emitSelectedItemOnClick) {
406
+ const getValItem = () => { // 发射值
407
+ if (props.multiple) {
408
+ return (val as (number | string)[])?.map(it => allCachedDataList.value.find(item => item[props.valueAlias] === it))
409
+ } else {
410
+ return val ? allCachedDataList.value.find(item => item[props.valueAlias] === val) : val
411
+ }
412
+ }
413
+ emit('get-selected-data', getValItem())
414
+ } else {
415
+ emit('get-selected-data', val)
391
416
  }
392
- })
393
- emit('fetch-data', {
394
- allCachedList: dataList.value,
395
- currentList: e.originData,
396
- event: e
397
- })
417
+ }
398
418
  }
399
419
 
400
420
  const currentVal = computed({
@@ -402,58 +422,19 @@ const currentVal = computed({
402
422
  return props.value
403
423
  },
404
424
  set(val) {
405
- const changeVal = (value) => { // 更改v-model
406
- emit('input', value)
407
- emit('update:value', value)
408
- emit('change', value)
409
- }
410
- const getValItem = () => { // 发射值
411
- if (props.multiple) {
412
- return (val as (number | string)[])?.map(it => dataList.value.find(item => item[props.valueAlias] === it))
413
- } else {
414
- return val ? dataList.value.find(item => item[props.valueAlias] === val) : val
415
- }
416
- }
417
- if (!props.multiple && !props.assignmentOnSelect) {
418
- const elSelectRef = popLazySelectRef.value?.$refs?.nfLazySelect?.$refs?.nfVirtualSelect
419
- if (elSelectRef) {
420
- nextTick(() => {
421
- resetPlaceholder.value = true
422
- let timer: ReturnType<typeof setTimeout> | undefined = setTimeout(() => {
423
- clearTimeout(timer)
424
- timer = undefined
425
- resetPlaceholder.value = false
426
- elSelectRef.selectedLabel = popLazySelectRef.value.keyword
427
- }, 30)
428
- })
429
- }
430
- }
431
- if (!props.multiple) { // 单选
432
- if (props.popdownOnSelect) { // 选中关闭浮层
433
- changeVal(undefined)
434
- if (val) {
435
- popup.value = false
436
- }
437
- } else {
438
- if (!props.assignmentOnSelect) { // 选中要不要赋值回显
439
- changeVal(undefined)
440
- } else {
441
- changeVal(val)
442
- }
443
- }
444
- } else {
445
- changeVal(val)
425
+ if (!props.multiple && props.popdownOnSelect && val) { // 单选&选中关闭浮层&有可能是清空
426
+ popup.value = false
446
427
  }
447
- emit('select-item', getValItem())
428
+ emit('input', val)
429
+ emit('update:value', val)
430
+ emit('change', val)
448
431
  }
449
432
  })
450
433
 
451
434
  defineExpose({
452
- currentVal,
453
- dataMap,
454
- dataList,
455
- popup,
456
- popLazySelectRef,
435
+ currentVal, // 当前选中值
436
+ popup, // 手动关闭浮层
437
+ popLazySelectRef, // nf-lazy-select
457
438
  })
458
439
  </script>
459
440
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-popup-lazy-select",
3
- "version": "3.2.80",
3
+ "version": "3.2.82",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,8 +14,8 @@
14
14
  "url": "http://94ai.gitlab.com/ui/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-lazy-select": "^3.2.80",
18
- "@94ai/nf-theme-chalk": "^3.2.80",
17
+ "@94ai/nf-lazy-select": "^3.2.82",
18
+ "@94ai/nf-theme-chalk": "^3.2.82",
19
19
  "vue-demi": "^0.14.5"
20
20
  },
21
21
  "peerDependenciesMeta": {
@@ -31,5 +31,5 @@
31
31
  "types": "lib/index.d.ts",
32
32
  "main": "lib/nf-popup-lazy-select.cjs.js",
33
33
  "module": "lib/nf-popup-lazy-select.esm-bundler.js",
34
- "gitHead": "f26515aa4834a1babfc6731dc8156885882810e3"
34
+ "gitHead": "1a0dfe015520e800c5565377459cac24bb723ee6"
35
35
  }