@94ai/nf-popup-lazy-select 3.2.81 → 3.3.0

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,11 +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"
28
- visible-change-keyword-cached
29
- visible-change-select-list-cached
27
+ :visible-change-keyword-cached="visibleChangeKeywordCached"
28
+ :visible-change-select-list-cached="visibleChangeSelectListCached"
29
+ :emit-selected-item-on-click="emitSelectedItemOnClick"
30
+ :tag="tag"
30
31
 
31
32
  :request="request"
32
33
  :page-size="pageSize"
@@ -37,7 +38,7 @@
37
38
 
38
39
  :loading-desc="loadingDesc"
39
40
  :no-data-text="noDataText"
40
- :placeholder="placeholderComputed"
41
+ :placeholder="placeholder"
41
42
 
42
43
  :multiple-limit="multipleLimit"
43
44
  :collapse-tags="collapseTags"
@@ -85,6 +86,8 @@
85
86
  :max-width="maxWidth"
86
87
  :height="dataList.length ? height : '0'"
87
88
 
89
+ @get-selected-data="getSelectedData"
90
+ @select-item="selectItem"
88
91
  @scroll="e => $emit('scroll', e)"
89
92
  @totop="e => $emit('totop', e)"
90
93
  @tobottom="e => $emit('tobottom', e)"
@@ -117,13 +120,17 @@ export default defineComponent({
117
120
  <script lang="ts" setup>
118
121
  import {
119
122
  computed,
120
- nextTick,
121
123
  ref
122
124
  } from 'vue-demi'
123
125
 
124
126
  const props = withDefaults(defineProps<{
125
- popdownOnSelect?: boolean,
126
- 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
+
127
134
  /**
128
135
  * 输入时传递给后端key别名定制
129
136
  */
@@ -231,8 +238,13 @@ const props = withDefaults(defineProps<{
231
238
  size?: 'mini' | 'medium' | 'small'
232
239
  value?: string | number | string[] | number[]
233
240
  }>(), {
234
- popdownOnSelect: false,
235
- 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
+
236
248
  keywordAlias: 'keyword',
237
249
  pageNoAlias: 'pageNo',
238
250
  pageSizeAlias: 'pageSize',
@@ -248,7 +260,7 @@ const props = withDefaults(defineProps<{
248
260
  collapseTags: false,
249
261
  disabled: false,
250
262
  multiple: false,
251
- reserveKeyword: false,
263
+ reserveKeyword: true,
252
264
  popperClass: '',
253
265
  defaultFirstOption: false,
254
266
  placeholder: '请输入',
@@ -313,28 +325,28 @@ const emit = defineEmits<{
313
325
  (e: 'update:value', event?: string | number | string[] | number[]): void
314
326
 
315
327
  (e: 'fetch-data', event: {
316
- allCachedList: any[],
317
- currentList: any[],
318
- event: {
319
- total: number,
320
- current: number,
321
- hasMore: boolean,
322
- keyword: string,
323
- /**
324
- * 当前记录原始值
325
- */
326
- records: any[],
327
- /**
328
- * 原始渲染数据
329
- */
330
- originData: any[],
331
- /**
332
- * 组件渲染数据
333
- */
334
- data: any[]
335
- }
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[],
336
348
  }): void
337
- (e: 'select-item', event: any): void
349
+ (e: 'get-selected-data', event: any): void
338
350
 
339
351
  (e: 'visible-change', event: boolean): void
340
352
  (e: 'remove-tag', event: string | number): void
@@ -352,51 +364,57 @@ const emit = defineEmits<{
352
364
  (e: 'popup-hide', event: boolean): void
353
365
  (e: 'popup-show', event: boolean): void
354
366
  }>()
355
- const refreshLazySelect = ref(Date.now())
356
- const resetPlaceholder = ref(false)
357
- const placeholderComputed = computed(() => {
358
- return resetPlaceholder.value ? '' : (!props.multiple && !props.assignmentOnSelect && popLazySelectRef.value?.keyword) ? popLazySelectRef.value.keyword : props.placeholder
359
- })
367
+
368
+ const getSelectedData = (e) => {
369
+ emit('get-selected-data', e)
370
+ }
371
+
372
+ const visibleChange = async (e) => {
373
+ emit('visible-change', e)
374
+ }
360
375
  const changeHide = () => {
361
- emit('popup-hide', false)
362
- popLazySelectRef.value.visibleIntersect = false
363
- popLazySelectRef.value.nfLazySelect.reset()
364
- 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)
365
381
  }
366
382
 
367
383
  const changeShow = () => {
368
- const visible = popLazySelectRef.value?.$refs?.nfLazySelect?.$refs?.nfVirtualSelect?.visible
369
- if (popup.value && typeof visible === 'boolean' && !visible) { // 手动触发 显示具有副作用,需要定制visible-change
370
- 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()
371
387
  }
372
388
  emit('popup-show', popup.value)
373
389
  }
374
390
 
375
- const visibleChange = async (e) => {
376
- if (!e) {
377
- return 'break'
378
- } else if (!props.popdownOnSelect && !props.multiple && props.assignmentOnSelect) {
379
- return 'discard-cache'
380
- }
381
- }
382
391
 
383
392
  const popLazySelectRef = ref()
384
393
  const popup = ref(false) // 定制关闭浮层
385
394
  const dataList = ref<any[]>([]) // 收起缓存数据
386
- const dataMap = ref({})
395
+ const allCachedDataList = ref<any[]>([])
387
396
 
388
397
  const fetchDataHandler = (e) => {
389
- e.originData?.forEach(data => {
390
- if (!dataMap.value[data[props.valueAlias]]) {
391
- dataMap.value[data[props.valueAlias]] = true
392
- 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)
393
416
  }
394
- })
395
- emit('fetch-data', {
396
- allCachedList: dataList.value,
397
- currentList: e.originData,
398
- event: e
399
- })
417
+ }
400
418
  }
401
419
 
402
420
  const currentVal = computed({
@@ -404,58 +422,19 @@ const currentVal = computed({
404
422
  return props.value
405
423
  },
406
424
  set(val) {
407
- const changeVal = (value) => { // 更改v-model
408
- emit('input', value)
409
- emit('update:value', value)
410
- emit('change', value)
411
- }
412
- const getValItem = () => { // 发射值
413
- if (props.multiple) {
414
- return (val as (number | string)[])?.map(it => dataList.value.find(item => item[props.valueAlias] === it))
415
- } else {
416
- return val ? dataList.value.find(item => item[props.valueAlias] === val) : val
417
- }
418
- }
419
- if (!props.multiple && !props.assignmentOnSelect) {
420
- const elSelectRef = popLazySelectRef.value?.$refs?.nfLazySelect?.$refs?.nfVirtualSelect
421
- if (elSelectRef) {
422
- nextTick(() => {
423
- resetPlaceholder.value = true
424
- let timer: ReturnType<typeof setTimeout> | undefined = setTimeout(() => {
425
- clearTimeout(timer)
426
- timer = undefined
427
- resetPlaceholder.value = false
428
- elSelectRef.selectedLabel = popLazySelectRef.value.keyword
429
- }, 30)
430
- })
431
- }
432
- }
433
- if (!props.multiple) { // 单选
434
- if (props.popdownOnSelect) { // 选中关闭浮层
435
- changeVal(undefined)
436
- if (val) {
437
- popup.value = false
438
- }
439
- } else {
440
- if (!props.assignmentOnSelect) { // 选中要不要赋值回显
441
- changeVal(undefined)
442
- } else {
443
- changeVal(val)
444
- }
445
- }
446
- } else {
447
- changeVal(val)
425
+ if (!props.multiple && props.popdownOnSelect && val) { // 单选&选中关闭浮层&有可能是清空
426
+ popup.value = false
448
427
  }
449
- emit('select-item', getValItem())
428
+ emit('input', val)
429
+ emit('update:value', val)
430
+ emit('change', val)
450
431
  }
451
432
  })
452
433
 
453
434
  defineExpose({
454
- currentVal,
455
- dataMap,
456
- dataList,
457
- popup,
458
- popLazySelectRef,
435
+ currentVal, // 当前选中值
436
+ popup, // 手动关闭浮层
437
+ popLazySelectRef, // nf-lazy-select
459
438
  })
460
439
  </script>
461
440
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-popup-lazy-select",
3
- "version": "3.2.81",
3
+ "version": "3.3.0",
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.81",
18
- "@94ai/nf-theme-chalk": "^3.2.81",
17
+ "@94ai/nf-lazy-select": "^3.3.0",
18
+ "@94ai/nf-theme-chalk": "^3.3.0",
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": "4517e6794b427bda5e05900c761c66d0240d8608"
34
+ "gitHead": "3fb4167c1ba3abcf18bdce8af115483594286216"
35
35
  }