@94ai/nf-search-form 6.1.7 → 6.1.11

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,9 +1,14 @@
1
1
  <template>
2
2
  <div class="nf-search-form" ref="topDom">
3
+ <!-- 空行以下保留原有,未重新梳理 -->
3
4
  <nf-form ref="nfSearchFormRef"
4
5
  :model="nfSearchFormModel"
5
6
  :inline="inline"
6
7
  :label-position="labelPosition"
8
+ :label-width="useLabelWidth"
9
+ :size="size"
10
+ :disabled="disabled"
11
+
7
12
  :rules="rules"
8
13
  :label-suffix="labelSuffix"
9
14
  :hide-required-asterisk="hideRequiredAsterisk"
@@ -11,11 +16,6 @@
11
16
  :inline-message="inlineMessage"
12
17
  :status-icon="statusIcon"
13
18
  :validate-on-rule-change="validateOnRuleChange"
14
- :size="size"
15
- :disabled="disabled"
16
-
17
- :label-width="labelWidth+'px'"
18
-
19
19
  :expand-btn-type="expandBtnType"
20
20
  :expand-btn-icon="expandBtnIcon"
21
21
  :expand-btn-plain="expandBtnPlain"
@@ -24,7 +24,6 @@
24
24
  :expand-btn-circle="expandBtnCircle"
25
25
  :expand-btn-loading="expandBtnLoading"
26
26
  :expand-btn-disabled="expandBtnDisabled"
27
-
28
27
  :columns="inline ? newColumns : columns"
29
28
  :up-icon="upIcon"
30
29
  :down-icon="downIcon"
@@ -32,9 +31,7 @@
32
31
  :is-collapse="isCollapse"
33
32
  :expand-btn-tooltip-desc="expandBtnTooltipDesc"
34
33
  :shrink-btn-tooltip-desc="shrinkBtnTooltipDesc"
35
-
36
34
  @isCollapseChange="isCollapseChange"
37
-
38
35
  >
39
36
  <template
40
37
  v-for="item in renderSearchFormItemOptions"
@@ -59,11 +56,14 @@
59
56
  :key="item.key"
60
57
  :item-width="itemWidth"
61
58
  v-model="nfSearchFormModel[item.prop]"
62
- :item-options="item">
59
+ :item-options="item"
60
+ :nfSearchFormModel="nfSearchFormModel"
61
+ @handleChangeProps="handleChangeProps"
62
+ >
63
63
  <!-- 定制化SearchItem?提示-->
64
64
  <slot :name="item.tooltip.slot" v-if="item.tooltip" :slot="item.tooltip.slot" />
65
65
  <!-- 定制化SearchItem插槽-->
66
- <slot :name="item.slot" v-if="item.slot" :slot="item.slot" />
66
+ <slot :name="item.slot" v-if="item.slot" :slot="item.slot" :formData="nfSearchFormModel" />
67
67
  <slot :name="item.inputSlot?.prepend" v-if="item.inputSlot?.prepend" :slot="item.inputSlot?.prepend" />
68
68
  <slot :name="item.inputSlot?.append" v-if="item.inputSlot?.append" :slot="item.inputSlot?.append" />
69
69
  <slot :name="item.inputSlot?.suffix" v-if="item.inputSlot?.suffix" :slot="item.inputSlot?.suffix" />
@@ -80,6 +80,7 @@
80
80
  </div>
81
81
  </nf-form-item>
82
82
  </template>
83
+ <!-- 表单按钮 -->
83
84
  <nf-form-item :label="showBtnBoxLabel"
84
85
  v-if="btnModel==='inline'"
85
86
  class="nf-search-form-nf-form-item-btn-box-label"
@@ -87,48 +88,68 @@
87
88
  >
88
89
  <div class="nf-flex nf-flex-align-items-start">
89
90
  <slot v-if="isShowBtnBoxSlot && !reverseBtnSlot" name="btnBox" />
90
- <nf-button
91
- v-if="btnItems.includes('search')"
92
- :type="queryBtnType"
93
- :icon="queryBtnIcon"
94
- :plain="queryBtnPlain"
95
- :size="queryBtnSize"
96
- :round="queryBtnRound"
97
- :circle="queryBtnCircle"
98
- :loading="queryBtnLoading"
99
- :disabled="queryBtnDisabled"
100
- :class="(queryBtnClass || '') + ' nf-btn-search'"
101
- @click="onNfSearchFormSearch"
102
- >{{ queryBtnText }}
103
- </nf-button>
104
- <nf-button
105
- v-if="btnItems.includes('export')"
106
- :type="exportBtnType"
107
- :icon="exportBtnIcon"
108
- :plain="exportBtnPlain"
109
- :size="exportBtnSize"
110
- :round="exportBtnRound"
111
- :circle="exportBtnCircle"
112
- :loading="exportBtnLoading"
113
- :disabled="exportBtnDisabled"
114
- :class="(exportBtnClass || '') + ' nf-btn-export'"
115
- @click="onNfSearchFormExport"
116
- >{{ exportBtnText }}
117
- </nf-button>
118
- <nf-button
119
- v-if="btnItems.includes('reset')"
120
- :type="resetBtnType"
121
- :icon="resetBtnIcon"
122
- :plain="resetBtnPlain"
123
- :size="resetBtnSize"
124
- :round="resetBtnRound"
125
- :circle="resetBtnCircle"
126
- :loading="resetBtnLoading"
127
- :disabled="resetBtnDisabled"
128
- :class="(resetBtnClass || '') + ' nf-btn-reset'"
129
- @click="resetNfSearchFormModel"
130
- >{{ resetBtnText }}
131
- </nf-button>
91
+ <template v-for="(item, idx) in cBtnItems">
92
+ <nf-button
93
+ v-if="item.btnType?.includes('search')"
94
+ :key="'btn-' + idx"
95
+ :type="queryBtnType"
96
+ :icon="queryBtnIcon"
97
+ :plain="queryBtnPlain"
98
+ :size="queryBtnSize || size"
99
+ :round="queryBtnRound"
100
+ :circle="queryBtnCircle"
101
+ :loading="queryBtnLoading"
102
+ :disabled="queryBtnDisabled"
103
+ :class="(queryBtnClass || '') + ' nf-btn-search'"
104
+ @click="onNfSearchFormSearch"
105
+ >{{ queryBtnText }}
106
+ </nf-button>
107
+ <nf-button
108
+ v-else-if="item.btnType?.includes('export')"
109
+ :key="'btn-' + idx"
110
+ :type="exportBtnType"
111
+ :icon="exportBtnIcon"
112
+ :plain="exportBtnPlain"
113
+ :size="exportBtnSize || size"
114
+ :round="exportBtnRound"
115
+ :circle="exportBtnCircle"
116
+ :loading="exportBtnLoading"
117
+ :disabled="exportBtnDisabled"
118
+ :class="(exportBtnClass || '') + ' nf-btn-export'"
119
+ @click="onNfSearchFormExport"
120
+ >{{ exportBtnText }}
121
+ </nf-button>
122
+ <nf-button
123
+ v-else-if="item.btnType?.includes('reset')"
124
+ :key="'btn-' + idx"
125
+ :type="resetBtnType"
126
+ :icon="resetBtnIcon"
127
+ :plain="resetBtnPlain"
128
+ :size="resetBtnSize || size"
129
+ :round="resetBtnRound"
130
+ :circle="resetBtnCircle"
131
+ :loading="resetBtnLoading"
132
+ :disabled="resetBtnDisabled"
133
+ :class="(resetBtnClass || '') + ' nf-btn-reset'"
134
+ @click="resetNfSearchFormModel"
135
+ >{{ resetBtnText }}
136
+ </nf-button>
137
+ <nf-button
138
+ v-else-if="btnIsShow(item)"
139
+ :key="'btn-' + idx"
140
+ :type="item.type || queryBtnType"
141
+ :icon="item.icon || queryBtnIcon"
142
+ :plain="item.plain || queryBtnPlain"
143
+ :size="item.size || size"
144
+ :round="item.round || queryBtnRound"
145
+ :circle="item.circle || queryBtnCircle"
146
+ :loading="item.loading || queryBtnLoading"
147
+ :disabled="item.disabled || queryBtnDisabled"
148
+ :class="item.class"
149
+ @click="onNfSearchFormClick(item)"
150
+ >{{ item.name }}
151
+ </nf-button>
152
+ </template>
132
153
  <nf-button :type="checkBtnType"
133
154
  :plain="checkBtnPlain"
134
155
  :size="checkBtnSize"
@@ -150,48 +171,68 @@
150
171
  </nf-form>
151
172
  <div class="nf-flex nf-flex-align-items nf-mt10" v-if="btnModel==='block'">
152
173
  <slot v-if="isShowBtnBoxSlot && !reverseBtnSlot" name="btnBox" />
153
- <nf-button
154
- v-if="btnItems.includes('search')"
155
- :type="queryBtnType"
156
- :icon="queryBtnIcon"
157
- :plain="queryBtnPlain"
158
- :size="queryBtnSize || size"
159
- :round="queryBtnRound"
160
- :circle="queryBtnCircle"
161
- :loading="queryBtnLoading"
162
- :disabled="queryBtnDisabled"
163
- :class="(queryBtnClass || '') + ' nf-btn-search'"
164
- @click="onNfSearchFormSearch"
165
- >{{ queryBtnText }}
166
- </nf-button>
167
- <nf-button
168
- v-if="btnItems.includes('export')"
169
- :type="exportBtnType"
170
- :icon="exportBtnIcon"
171
- :plain="exportBtnPlain"
172
- :size="exportBtnSize || size"
173
- :round="exportBtnRound"
174
- :circle="exportBtnCircle"
175
- :loading="exportBtnLoading"
176
- :disabled="exportBtnDisabled"
177
- :class="(exportBtnClass || '') + ' nf-btn-export'"
178
- @click="onNfSearchFormExport"
179
- >{{ exportBtnText }}
180
- </nf-button>
181
- <nf-button
182
- v-if="btnItems.includes('reset')"
183
- :type="resetBtnType"
184
- :icon="resetBtnIcon"
185
- :plain="resetBtnPlain"
186
- :size="resetBtnSize || size"
187
- :round="resetBtnRound"
188
- :circle="resetBtnCircle"
189
- :loading="resetBtnLoading"
190
- :disabled="resetBtnDisabled"
191
- :class="(resetBtnClass || '') + ' nf-btn-reset'"
192
- @click="resetNfSearchFormModel"
193
- >{{ resetBtnText }}
194
- </nf-button>
174
+ <template v-for="(item, idx) in cBtnItems">
175
+ <nf-button
176
+ v-if="item.btnType?.includes('search')"
177
+ :key="'btn-' + idx"
178
+ :type="queryBtnType"
179
+ :icon="queryBtnIcon"
180
+ :plain="queryBtnPlain"
181
+ :size="queryBtnSize || size"
182
+ :round="queryBtnRound"
183
+ :circle="queryBtnCircle"
184
+ :loading="queryBtnLoading"
185
+ :disabled="queryBtnDisabled"
186
+ :class="(queryBtnClass || '') + ' nf-btn-search'"
187
+ @click="onNfSearchFormSearch"
188
+ >{{ queryBtnText }}
189
+ </nf-button>
190
+ <nf-button
191
+ v-else-if="item.btnType?.includes('export')"
192
+ :key="'btn-' + idx"
193
+ :type="exportBtnType"
194
+ :icon="exportBtnIcon"
195
+ :plain="exportBtnPlain"
196
+ :size="exportBtnSize || size"
197
+ :round="exportBtnRound"
198
+ :circle="exportBtnCircle"
199
+ :loading="exportBtnLoading"
200
+ :disabled="exportBtnDisabled"
201
+ :class="(exportBtnClass || '') + ' nf-btn-export'"
202
+ @click="onNfSearchFormExport"
203
+ >{{ exportBtnText }}
204
+ </nf-button>
205
+ <nf-button
206
+ v-else-if="item.btnType?.includes('reset')"
207
+ :key="'btn-' + idx"
208
+ :type="resetBtnType"
209
+ :icon="resetBtnIcon"
210
+ :plain="resetBtnPlain"
211
+ :size="resetBtnSize || size"
212
+ :round="resetBtnRound"
213
+ :circle="resetBtnCircle"
214
+ :loading="resetBtnLoading"
215
+ :disabled="resetBtnDisabled"
216
+ :class="(resetBtnClass || '') + ' nf-btn-reset'"
217
+ @click="resetNfSearchFormModel"
218
+ >{{ resetBtnText }}
219
+ </nf-button>
220
+ <nf-button
221
+ v-else-if="btnIsShow(item)"
222
+ :key="'btn-' + idx"
223
+ :type="item.type || queryBtnType"
224
+ :icon="item.icon || queryBtnIcon"
225
+ :plain="item.plain || queryBtnPlain"
226
+ :size="item.size || size"
227
+ :round="item.round || queryBtnRound"
228
+ :circle="item.circle || queryBtnCircle"
229
+ :loading="item.loading || queryBtnLoading"
230
+ :disabled="item.disabled || queryBtnDisabled"
231
+ :class="item.class"
232
+ @click="onNfSearchFormClick(item)"
233
+ >{{ item.name }}
234
+ </nf-button>
235
+ </template>
195
236
  <nf-button :type="checkBtnType"
196
237
  v-if="columnEdit"
197
238
  :plain="checkBtnPlain"
@@ -219,7 +260,7 @@
219
260
  v-if="columnEdit && configNfSearchItemVisibleDialog && checkMode === 'dialog'"
220
261
  :show.sync="configNfSearchItemVisibleDialog"
221
262
  :modal-append-to-body="modalAppendToBody"
222
- :storage-key="storageKey"
263
+ :storage-key="cStorageKey"
223
264
  :table-columns="formOptions"
224
265
  :width="moreDialogWidth"
225
266
  :modal="modal"
@@ -272,7 +313,7 @@
272
313
  :get-all-check-desc="columnCheckGetAllCheckDesc"
273
314
 
274
315
  ref="columnCheckDrawer"
275
- :storage-key="storageKey"
316
+ :storage-key="cStorageKey"
276
317
  :table-columns="formOptions"
277
318
  :column-edit="columnEdit"
278
319
  />
@@ -294,7 +335,6 @@ import SearchFormItem from './nf-search-form-item.vue'
294
335
  import ColumnCheckDialog from './nf-column-check-dialog.vue'
295
336
  import ColumnCheckDrawer from './nf-column-check-drawer.vue'
296
337
  import ResizeObserver from 'resize-observer-polyfill'
297
- import { createUniqueString } from '@94ai/common-utils'
298
338
  import { NfSearchFormItemOption } from './types'
299
339
  import {
300
340
  ref,
@@ -306,20 +346,48 @@ import {
306
346
  onBeforeUnmount,
307
347
  nextTick
308
348
  } from 'vue-demi'
309
- import { ITabItem } from '@94ai/nf-drawer/lib/types'
310
349
  import {
311
350
  NfTableColumnAttributes
312
351
  } from '@94ai/nf-table/lib/types'
313
352
  import { set } from 'vue'
314
353
  import {
315
354
  CachedManager,
355
+ deepClone,
356
+ createUniqueString,
357
+ validate as useValidate,
358
+ mapDispose
316
359
  } from '@94ai/common-utils'
317
360
  import {
318
361
  throttle
319
362
  } from 'lodash-es'
363
+ import { useRoute } from 'vue-router/composables'
364
+ import { ELEMENT_LABEL_TYPE_DEFAULT_VALUE, EXCHANGE_KEY_TYPE } from '@94ai/common-constants'
365
+ import { ITabItem } from '@94ai/nf-drawer/lib/types'
320
366
 
367
+ interface IBtnItems {
368
+ btnType?: 'search' | 'export' | 'reset'
369
+ name?: string,
370
+ type?: string,
371
+ icon?: string,
372
+ plain?: boolean,
373
+ size?: string,
374
+ round?: boolean,
375
+ circle?: boolean,
376
+ loading?: boolean,
377
+ disabled?: boolean,
378
+ class?: string,
379
+ validate?: boolean,
380
+ onClick?: (formData: Record<string, any>) => void,
381
+ show?: (formData: Record<string, any>) => boolean,
382
+ [key: string]: any,
383
+ }
321
384
 
322
385
  const props = withDefaults(defineProps<{
386
+ /**
387
+ * isMvc版本改造参数
388
+ */
389
+ isMvc?: boolean, // 单向数据流传版本
390
+ defaultFormData?: Object; // 默认的表单数据
323
391
  /**
324
392
  * nf-form扩展配置项
325
393
  */
@@ -365,7 +433,7 @@ const props = withDefaults(defineProps<{
365
433
  /**
366
434
  * label宽度
367
435
  */
368
- labelWidth?: number,
436
+ labelWidth?: number | string,
369
437
  /**
370
438
  * 所有的表单项
371
439
  */
@@ -437,7 +505,7 @@ const props = withDefaults(defineProps<{
437
505
  /**
438
506
  * 兼容ai-search-form,控制额外的默认功能按钮
439
507
  */
440
- btnItems?: string[] | 'search' | 'export' | 'reset' | '',
508
+ btnItems?: string[] | IBtnItems[] | 'search' | 'export' | 'reset' | '',
441
509
  reverseBtnSlot?: boolean,
442
510
  /**
443
511
  * 导出按钮
@@ -479,8 +547,13 @@ const props = withDefaults(defineProps<{
479
547
  resetBtnText?: string,
480
548
  resetBtnClass?: string,
481
549
  }>(), {
550
+ isMvc: false, // 单向数据流传版本
551
+ defaultFormData: () => {
552
+ return {}
553
+ }, // 默认的表单数据
554
+
482
555
  priority: 'cached',
483
- storageKey: 'nf-search-form-columns-cached-key',
556
+ storageKey: '', // 默认值为cStorageKey = nf-search-form-columns-cached-key-${routeName}
484
557
  checkMode: 'drawer',
485
558
  upIcon: 'icon-xiangshang2',
486
559
  downIcon: 'icon-xiangxia2',
@@ -621,18 +694,128 @@ const emit = defineEmits<{
621
694
  */
622
695
  (e: 'update:showItems', event: string[] | undefined): void
623
696
  }>()
624
-
697
+ const routeName = computed(() => useRoute().name)
625
698
  const instance = getCurrentInstance()?.proxy
626
699
  const defaultButtonSlot = ref()
627
700
  const nfSearchFormRef = ref()
628
701
  const columnCheckNfDrawer = ref()
629
702
  const columnCheckDrawer = ref()
630
703
  const columnCheckDialog = ref()
704
+ const useLabelWidth = ref<string | number>(useValidate.isNumber(props.labelWidth) ? `${props.labelWidth}px` : props.labelWidth)
705
+ const changeUpdateKeys = ref<string[]>([])
706
+ const cBtnItems = ref<object[]>([]) // 处理后的bthItems
707
+ const cStorageKey = ref(props.storageKey || `nf-search-form-columns-cached-key-${routeName.value}`)
631
708
 
632
709
  /**
633
710
  * 表单填充的数据
634
711
  */
635
- const nfSearchFormModel = ref<Record<string, any>>({})
712
+ const nfSearchFormModel = ref<Record<string, any>>(deepClone(props.defaultFormData))
713
+
714
+ // 获取value
715
+ const getValue = (item) => {
716
+ return mapDispose.getValue(nfSearchFormModel.value, item.prop)
717
+ }
718
+
719
+ // 设置值
720
+ const setValue = (item, val) => {
721
+ mapDispose.setValue(nfSearchFormModel.value, item.prop, val)
722
+ }
723
+
724
+ /**
725
+ * 设置默认值
726
+ * @param {Boolean} init 是否是初始化
727
+ */
728
+ const setDefaultVal = (item, init = true) => {
729
+ if (init) {
730
+ // // 拓展初始化属性
731
+ // if (item.extendMap) {
732
+ // handleMap.setRecursionValue(this.formData, this.$deepClone(item.extendMap))
733
+ // return
734
+ // } else
735
+ if (mapDispose.hasKey(nfSearchFormModel.value, item.prop)) {
736
+ return
737
+ }
738
+ }
739
+ const { element = '', multiple = false } = item
740
+ let initValue: any = null
741
+ if (item.hasOwnProperty('initValue')) {
742
+ initValue = item.initValue
743
+ } else if (multiple) {
744
+ initValue = []
745
+ } else if (ELEMENT_LABEL_TYPE_DEFAULT_VALUE.hasOwnProperty(element)) {
746
+ initValue = ELEMENT_LABEL_TYPE_DEFAULT_VALUE[element]
747
+ }
748
+ setValue(item, deepClone(initValue))
749
+ }
750
+
751
+ // 获取changeProps所有涉及的key
752
+ const getChangePropKeys = () => {
753
+ let list = []
754
+ props.formOptions.forEach(item => {
755
+ list = list.concat(item.changeProps || [])
756
+ })
757
+ changeUpdateKeys.value = list
758
+ }
759
+
760
+ // 动态获取option
761
+ const triggerGetOptions = async (item) => {
762
+ if (item.getOptions) {
763
+ const canSetParams = changeUpdateKeys.value.includes(item.prop)
764
+ await nextTick()
765
+ item['options'] = []
766
+ item['loading'] = true
767
+ item.getOptions((data) => {
768
+ nextTick(() => {
769
+ item.loading = false
770
+ item.options = data
771
+ })
772
+ // 依赖查询条件的才传formData
773
+ }, canSetParams ? getFormData() : {})
774
+ }
775
+ }
776
+
777
+ /**
778
+ * 初始化按钮列表
779
+ */
780
+ const btnItemsInit = () => {
781
+ if (!props.btnItems) return
782
+ let list = deepClone(props.btnItems)
783
+ // string类型
784
+ if (useValidate.isString(props.btnItems)) {
785
+ list = [
786
+ ...(props.btnItems ? [{ btnType: props.btnItems }] : [])
787
+ ]
788
+ }
789
+ list = list.map(item => {
790
+ if (useValidate.isString(item)) {
791
+ return { btnType: item }
792
+ } else {
793
+ return item
794
+ }
795
+ })
796
+ cBtnItems.value = list
797
+ }
798
+
799
+
800
+ /**
801
+ * changeProps: [k1, k2, ...] 需重新请求数据的key值数组
802
+ */
803
+ const handleChangeProps = (changeProps: string[]) => {
804
+ if (changeProps?.length) {
805
+ props.formOptions.forEach(item => {
806
+ if (!changeProps.includes(item.prop)) return
807
+ setDefaultVal(item, false)
808
+ triggerGetOptions(item)
809
+ // 联动changeProps
810
+ const list = (item.changeProps || []).filter(item => !changeProps.includes(item))
811
+ if (list.length) {
812
+ nextTick(() => {
813
+ handleChangeProps(list)
814
+ })
815
+ }
816
+ })
817
+ }
818
+ }
636
819
 
637
820
  /**
638
821
  * 同步用户参数
@@ -661,12 +844,16 @@ const initLocalShow = (init = false) => {
661
844
  * 表单显示的item集合
662
845
  */
663
846
  const localShowItems = ref<string[]>(initLocalShow(true))
664
- watch(() => localShowItems.value?.length, async () => {
665
- emit('update:showItems', localShowItems.value)
666
- if (Object.keys(nfSearchFormModel.value).length) { // 有可能用computed或异步引起数据更改实时同步model
667
- refreshNfSearchFormModel(false)
847
+ watch(() => localShowItems.value, async (newVal, oldVal) => {
848
+ emit('update:showItems', newVal)
849
+ if (deepClone(newVal).sort().join(',') !== deepClone(oldVal)?.sort().join(',')) {
850
+ emit('itemsChange', localShowItems.value)
851
+ if (Object.keys(nfSearchFormModel.value).length) { // 有可能用computed或异步引起数据更改实时同步model
852
+ refreshNfSearchFormModel()
853
+ }
668
854
  }
669
855
  }, {
856
+ deep: true,
670
857
  immediate: true
671
858
  })
672
859
  const syncLocalShowColumnToCookies = () => {
@@ -680,7 +867,7 @@ const syncLocalShowColumnToCookies = () => {
680
867
  index
681
868
  }
682
869
  })
683
- CachedManager.syncCachedSet(props.storageKey, columnState)
870
+ CachedManager.syncCachedSet(cStorageKey.value, columnState)
684
871
  }
685
872
  }
686
873
  const syncShowItemToInitHidden = () => {
@@ -710,9 +897,9 @@ const setLocalShowItems = (list, syncToInitHidden = false) => {
710
897
  const syncCookiesToLocalShowColumn = async (refreshModel = false) => {
711
898
  if (props.columnEdit) {
712
899
  try {
713
- let columnState: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(props.storageKey)
900
+ let columnState: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(cStorageKey.value)
714
901
  if (!columnState) {
715
- columnState = await CachedManager.asyncCachedGet(props.storageKey)
902
+ columnState = await CachedManager.asyncCachedGet(cStorageKey.value)
716
903
  }
717
904
  if (columnState) {
718
905
  if (typeof columnState === 'string') {
@@ -739,9 +926,9 @@ const syncCookiesToLocalShowColumn = async (refreshModel = false) => {
739
926
  const initCachedData = async () => {
740
927
  if (props.columnEdit) {
741
928
  // 同步缓存参数
742
- let cached: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(props.storageKey)
929
+ let cached: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(cStorageKey.value)
743
930
  if (!cached) {
744
- cached = await CachedManager.asyncCachedGet(props.storageKey)
931
+ cached = await CachedManager.asyncCachedGet(cStorageKey.value)
745
932
  }
746
933
  const cachedPriority = props.priority === 'cached'
747
934
  if (cachedPriority ? cached : localShowItems.value?.length) {
@@ -771,27 +958,16 @@ const isShowBtnBoxSlot = computed(() => {
771
958
  })
772
959
 
773
960
  /**
774
- * 转换成最终的表单项渲染数据
961
+ * 根据column配置,处理表单initHidden、_index字段
775
962
  */
776
- const renderSearchFormItemOptions = ref<NfSearchFormItemOption[]>([])
777
- let initSearchForm = true
778
- const syncCookiesToSearchFormItemOptions = async (readCached = true) => {
779
- props.formOptions._skip = true
780
- const columns = props.formOptions!.map((item, index) => {
781
- item.key = item.key || createUniqueString()
782
- item._index = index // 混合缓存后的数据
783
- item.__index = index // 原始顺序
784
- set(item, 'initHidden', !!item.initHidden)
785
- set(item, 'destory', !!item.destory)
786
- return item
787
- })
788
- if (readCached && props.columnEdit) {
963
+ const handleColumnsInitHideAndSort = async(columns: any[]) => {
964
+ if (props.columnEdit) {
789
965
  // 读取缓存 Column 配置
790
966
  try {
791
967
  // 同步缓存参数
792
- let columnState: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(props.storageKey)
968
+ let columnState: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(cStorageKey.value)
793
969
  if (!columnState) {
794
- columnState = await CachedManager.asyncCachedGet(props.storageKey)
970
+ columnState = await CachedManager.asyncCachedGet(cStorageKey.value)
795
971
  }
796
972
  props.formOptions._skip = true
797
973
  if (columnState) {
@@ -814,6 +990,28 @@ const syncCookiesToSearchFormItemOptions = async (readCached = true) => {
814
990
  console.log(e)
815
991
  }
816
992
  }
993
+ }
994
+
995
+ /**
996
+ * 转换成最终的表单项渲染数据
997
+ */
998
+ const renderSearchFormItemOptions = ref<NfSearchFormItemOption[]>([])
999
+ let initSearchForm = true
1000
+ const syncCookiesToSearchFormItemOptions = async (readCached = true) => {
1001
+ props.formOptions._skip = true
1002
+ const columns = props.formOptions!.map((item, index) => {
1003
+ item.key = item.key || createUniqueString()
1004
+ item._index = index // 混合缓存后的数据
1005
+ item.__index = index // 原始顺序
1006
+ set(item, 'initHidden', !!item.initHidden)
1007
+ set(item, 'destory', !!item.destory)
1008
+ if (!item.options) set(item, 'options', [])
1009
+ return item
1010
+ })
1011
+ if (readCached) {
1012
+ // 读取缓存 Column 配置(隐藏 & 排序)
1013
+ await handleColumnsInitHideAndSort(columns)
1014
+ }
817
1015
  renderSearchFormItemOptions.value = columns.sort((a, b) => a._index - b._index < 0 ? -1 : a._index - b._index > 0 ? 1 : 0);
818
1016
  nextTick(() => {
819
1017
  if (initSearchForm) {
@@ -823,6 +1021,8 @@ const syncCookiesToSearchFormItemOptions = async (readCached = true) => {
823
1021
  props.formOptions._skip = false;
824
1022
  })
825
1023
  }
1024
+
1025
+ // 初始化表单配置
826
1026
  syncCookiesToSearchFormItemOptions()
827
1027
 
828
1028
  /**
@@ -830,9 +1030,18 @@ syncCookiesToSearchFormItemOptions()
830
1030
  * @param prop
831
1031
  */
832
1032
  const itemIsShow = (item: NfSearchFormItemOption) => {
833
- return !item.initHidden && !item.destory
1033
+ return !item.initHidden && !item.destory && (
1034
+ useValidate.isFunction(item.show) ? item?.show?.(nfSearchFormModel.value) : true
1035
+ )
834
1036
  }
835
1037
 
1038
+ /**
1039
+ * 判断按钮是否显示
1040
+ * @param prop
1041
+ */
1042
+ const btnIsShow = (item: IBtnItems) => {
1043
+ return item.show ? item.show(nfSearchFormModel.value) : true
1044
+ }
836
1045
 
837
1046
  /**
838
1047
  * 实时触发onChange
@@ -879,32 +1088,35 @@ onBeforeMount(() => {
879
1088
  }, {
880
1089
  deep: true
881
1090
  })
882
- refreshNfSearchFormModel(false, true)
1091
+ btnItemsInit()
1092
+ formsInit()
883
1093
  })
884
1094
 
885
-
886
- const refreshNfSearchFormModel = (outEmit = true, init = false) => {
887
- const obj: Record<string, any> = {}
1095
+ /**
1096
+ * 剔除隐藏筛选项字段 | 刷新表单数据
1097
+ * @description 未勾选的筛选项,给予undefined;已勾选的若初次展示,设置默认值
1098
+ */
1099
+ const refreshNfSearchFormModel = () => {
888
1100
  props.formOptions.filter(item => !item.destory).forEach(v => {
889
- if (localShowItems.value.includes(v.prop)) {
890
- if (init) {
891
- if (v.initValue !== undefined) {
892
- obj[v.prop!] = v.initValue
893
- } else {
894
- obj[v.prop!] = null
895
- }
896
- } else {
897
- const value = nfSearchFormModel.value[v.prop]
898
- obj[v.prop!] = typeof value === 'undefined' ? null : value
899
- }
1101
+ if (!localShowItems.value.includes(v.prop)) {
1102
+ mapDispose.setValue(nfSearchFormModel.value, v.key, undefined)
1103
+ } else if (nfSearchFormModel.value[v.prop] === undefined) {
1104
+ setDefaultVal(v)
900
1105
  }
901
1106
  })
902
- if (JSON.stringify(nfSearchFormModel.value) !== JSON.stringify(obj)) {
903
- nfSearchFormModel.value = obj
904
- if (outEmit) {
905
- emit('itemsChange', localShowItems.value)
906
- }
907
- }
1107
+ }
1108
+
1109
+ // 初始化表单数据
1110
+ const formsInit = () => {
1111
+ // refreshNfSearchFormModel()
1112
+ getChangePropKeys()
1113
+ props.formOptions.forEach(item => {
1114
+ if (item.destory || !localShowItems.value.includes(item.prop)) return
1115
+ // 设置默认值
1116
+ setDefaultVal(item, true)
1117
+ // // 处理动态表单列表
1118
+ triggerGetOptions(item)
1119
+ })
908
1120
  }
909
1121
 
910
1122
  const isCollapseChange = async (val: boolean) => {
@@ -924,6 +1136,10 @@ const refreshLabel = () => {
924
1136
  }
925
1137
  }
926
1138
  }
1139
+
1140
+ /**
1141
+ * 计算收起展开的数量
1142
+ */
927
1143
  const calcColumns = () => {
928
1144
  if (props.columns) {
929
1145
  newColumns.value = props.columns
@@ -994,7 +1210,7 @@ const onNfSearchFormValidate = (callback) => {
994
1210
  */
995
1211
  const onNfSearchFormSearch = () => {
996
1212
  onNfSearchFormValidate(() => {
997
- emit('onSearch', nfSearchFormModel.value)
1213
+ emit('onSearch', getFormData())
998
1214
  })
999
1215
  }
1000
1216
  /**
@@ -1002,12 +1218,25 @@ const onNfSearchFormSearch = () => {
1002
1218
  */
1003
1219
  const onNfSearchFormExport = () => {
1004
1220
  onNfSearchFormValidate(() => {
1005
- emit('onExport', nfSearchFormModel.value)
1221
+ emit('onExport', getFormData())
1006
1222
  })
1007
1223
  }
1008
1224
 
1009
1225
  /**
1010
- * 把该item暂时隐藏
1226
+ * 其他按钮点击
1227
+ */
1228
+ const onNfSearchFormClick = (item) => {
1229
+ if (item.validate) { // 需要校验表单
1230
+ onNfSearchFormValidate(() => {
1231
+ item.onClick?.(getFormData())
1232
+ })
1233
+ } else {
1234
+ item.onClick?.(getFormData())
1235
+ }
1236
+ }
1237
+
1238
+ /**
1239
+ * 把该item暂时隐藏【❌有错误待修复,prop命名重复】
1011
1240
  * @param prop
1012
1241
  */
1013
1242
  const hiddenNfSearchFormItemOptionField = async (prop) => {
@@ -1060,11 +1289,11 @@ const columnCheckConfirm = async (cb, error) => {
1060
1289
  }
1061
1290
 
1062
1291
  async function clearDragCached() {
1063
- await CachedManager.asyncCachedSet(`${props.storageKey}$drag-column-width`, null)
1292
+ await CachedManager.asyncCachedSet(`${cStorageKey.value}$drag-column-width`, null)
1064
1293
  }
1065
1294
 
1066
1295
  async function clearColumnEditCached() {
1067
- await CachedManager.asyncCachedSet(props.storageKey, null)
1296
+ await CachedManager.asyncCachedSet(cStorageKey.value, null)
1068
1297
  }
1069
1298
 
1070
1299
  /**
@@ -1078,7 +1307,41 @@ const nfSearchFormItemOptionFieldsSave = async (value) => {
1078
1307
  refreshLabel()
1079
1308
  }
1080
1309
 
1310
+ /**
1311
+ * 数组值分割多个字段
1312
+ */
1313
+ const handleExchangeKey = (data) => {
1314
+ props.formOptions.forEach(item => {
1315
+ if (!item.exchangeKey) return
1316
+ const { type, value } = item.exchangeKey
1317
+ const key = item.prop
1318
+ // 日期时间范围变化字段
1319
+ if (type === EXCHANGE_KEY_TYPE.range) {
1320
+ value?.forEach?.((k, i) => {
1321
+ data[k] = data?.[key]?.[i] || null
1322
+ })
1323
+ delete data[key]
1324
+ } else if (type === EXCHANGE_KEY_TYPE.multiple) {
1325
+ // ids变化字段,字符串切割成数组
1326
+ data[key] = data[key]?.trim()?.split(value || ',')?.filter(s => s !== '')
1327
+ }
1328
+ })
1329
+ }
1330
+
1331
+ /**
1332
+ * 获取当前数据
1333
+ */
1334
+ const getFormData = () => {
1335
+ const data = deepClone(nfSearchFormModel.value)
1336
+ handleExchangeKey(data)
1337
+ return data
1338
+ }
1339
+
1081
1340
  defineExpose({
1341
+ /**
1342
+ * 获取表单实时数据(已深拷贝)
1343
+ */
1344
+ getFormData,
1082
1345
  /**
1083
1346
  * 列编辑显示的列prop
1084
1347
  */