@94ai/nf-search-form 3.2.4 → 3.2.21

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.
@@ -16,43 +16,60 @@
16
16
 
17
17
  :label-width="labelWidth+'px'"
18
18
 
19
- :columns='columns'
19
+ :expand-btn-type="expandBtnType"
20
+ :expand-btn-icon="expandBtnIcon"
21
+ :expand-btn-plain="expandBtnPlain"
22
+ :expand-btn-size="expandBtnSize"
23
+ :expand-btn-round="expandBtnRound"
24
+ :expand-btn-circle="expandBtnCircle"
25
+ :expand-btn-loading="expandBtnLoading"
26
+ :expand-btn-disabled="expandBtnDisabled"
27
+
28
+ :columns="inline ? newColumns : columns"
20
29
  :up-icon="upIcon"
21
30
  :down-icon="downIcon"
22
31
  :show-btn="showBtn"
23
32
  :is-collapse="isCollapse"
33
+
24
34
  @isCollapseChange="isCollapseChange"
35
+
25
36
  >
26
- <nf-form-item
27
- :class="(item.class || '') + ' nf-search-form-nf-form-item'"
28
- v-for="(item, index) in renderSearchFormItemOptions"
29
- :hidden="!!item.hidden"
30
- :key="newKeys[index]"
31
- :prop="item.prop"
32
- :label="item.label ? (item.isShowColon?item.label + ':':item.label) : ''"
33
- :rules="item.rules"
34
- :show-message="item.showMessage"
35
- :size="item.size"
36
- :inline-message="item.inlineMessage"
37
- :required="item.required"
38
- :label-width="item.labelWidth"
37
+ <template
38
+ v-for="item in renderSearchFormItemOptions"
39
+ >
40
+ <nf-form-item
41
+ v-if="itemIsShow(item)"
42
+ :class="(item.class || '') + ' nf-search-form-nf-form-item'"
43
+ :hidden="!!item.hidden"
44
+ :key="item.key"
45
+ :prop="item.prop"
46
+ :label="item.label ? (item.isShowColon?item.label + ':':item.label) : ''"
47
+ :rules="item.rules"
48
+ :show-message="item.showMessage"
49
+ :size="item.size"
50
+ :inline-message="item.inlineMessage"
51
+ :required="item.required"
52
+ :label-width="item.labelWidth"
53
+ >
54
+ <search-form-item v-model="nfSearchFormModel[item.prop]"
55
+ :item-width="itemWidth"
56
+ :item-options="item">
57
+ <!-- 定制化SearchItem?提示-->
58
+ <slot :name="item.tooltip.slot" v-if="item.tooltip" :slot="item.tooltip.slot" />
59
+ <!-- 定制化SearchItem插槽-->
60
+ <slot :name="item.slot" v-if="item.slot" :slot="item.slot" />
61
+ </search-form-item>
62
+ <!-- 控制显示该表单项-->
63
+ <div v-if="closable" class="nf-search-form-nf-form-item-close-icon">
64
+ <i class="el-icon-error" @click="hiddenNfSearchFormItemOptionField(item.prop)" />
65
+ </div>
66
+ </nf-form-item>
67
+ </template>
68
+ <nf-form-item :label="showBtnBoxLabel"
69
+ v-if="btnModel==='inline'"
70
+ class="nf-search-form-nf-form-item-btn-box-label"
71
+ ref="defaultButtonSlot"
39
72
  >
40
- <search-form-item v-model="nfSearchFormModel[item.prop]" :item-width="itemWidth" :label-width="labelWidth" :item-options="item">
41
- <!-- 定制化SearchItem?提示-->
42
- <template v-if="item.tooltip" :slot="item.tooltip.slot">
43
- <slot :name="item.tooltip.slot" />
44
- </template>
45
- <!-- 定制化SearchItem插槽-->
46
- <template v-if="item.slot" :slot="item.slot">
47
- <slot :name="item.slot" />
48
- </template>
49
- </search-form-item>
50
- <!-- 控制显示该表单项-->
51
- <div v-if="closable" class="nf-search-form-nf-form-item-close-icon">
52
- <i class="el-icon-error" @click="hiddenNfSearchFormItemOptionField(item.prop)" />
53
- </div>
54
- </nf-form-item>
55
- <nf-form-item :label="showBtnBoxLabel" v-if="btnModel==='inline'" class="nf-search-form-nf-form-item-btn-box-label" ref="defaultButtonSlot">
56
73
  <div class="nf-flex nf-flex-align-items-start">
57
74
  <slot v-if="isShowBtnBoxSlot && !reverseBtnSlot" name="btnBox" />
58
75
  <el-button
@@ -97,21 +114,21 @@
97
114
  @click="resetNfSearchFormModel"
98
115
  >{{ resetBtnText }}
99
116
  </el-button>
100
- <el-tooltip class="item" effect="dark" content="添加筛选条件" placement="bottom">
101
- <el-button v-if="isShowAdd"
102
- :type="checkBtnType"
103
- :plain="checkBtnPlain"
104
- :size="checkBtnSize"
105
- :round="checkBtnRound"
106
- :circle="checkBtnCircle"
107
- :loading="checkBtnLoading"
108
- :disabled="checkBtnDisabled"
109
- :class="(checkBtnClass || '') + ' nf-btn-check'"
110
- @click.stop="configNfSearchItemVisibleDialog = true"
111
- >
117
+ <el-button :type="checkBtnType"
118
+ :plain="checkBtnPlain"
119
+ :size="checkBtnSize"
120
+ :round="checkBtnRound"
121
+ :circle="checkBtnCircle"
122
+ :loading="checkBtnLoading"
123
+ :disabled="checkBtnDisabled"
124
+ :class="(checkBtnClass || '') + ' nf-btn-check'"
125
+ @click.stop="configNfSearchItemVisibleDialog = true"
126
+ v-if="columnEdit"
127
+ >
128
+ <el-tooltip :content="columnDisplayBtnText" placement="bottom">
112
129
  <i class="iconfont icon-shaixuan1 nf-fs12"></i>
113
- </el-button>
114
- </el-tooltip>
130
+ </el-tooltip>
131
+ </el-button>
115
132
  <slot v-if="isShowBtnBoxSlot && reverseBtnSlot" name="btnBox" />
116
133
  </div>
117
134
  </nf-form-item>
@@ -123,7 +140,7 @@
123
140
  :type="queryBtnType"
124
141
  :icon="queryBtnIcon"
125
142
  :plain="queryBtnPlain"
126
- :size="queryBtnSize"
143
+ :size="queryBtnSize || size"
127
144
  :round="queryBtnRound"
128
145
  :circle="queryBtnCircle"
129
146
  :loading="queryBtnLoading"
@@ -137,7 +154,7 @@
137
154
  :type="exportBtnType"
138
155
  :icon="exportBtnIcon"
139
156
  :plain="exportBtnPlain"
140
- :size="exportBtnSize"
157
+ :size="exportBtnSize || size"
141
158
  :round="exportBtnRound"
142
159
  :circle="exportBtnCircle"
143
160
  :loading="exportBtnLoading"
@@ -151,7 +168,7 @@
151
168
  :type="resetBtnType"
152
169
  :icon="resetBtnIcon"
153
170
  :plain="resetBtnPlain"
154
- :size="resetBtnSize"
171
+ :size="resetBtnSize || size"
155
172
  :round="resetBtnRound"
156
173
  :circle="resetBtnCircle"
157
174
  :loading="resetBtnLoading"
@@ -160,11 +177,10 @@
160
177
  @click="resetNfSearchFormModel"
161
178
  >{{ resetBtnText }}
162
179
  </el-button>
163
- <el-button v-if="isShowAdd"
164
- :type="checkBtnType"
165
- :icon="checkBtnIcon"
180
+ <el-button :type="checkBtnType"
181
+ v-if="columnEdit"
166
182
  :plain="checkBtnPlain"
167
- :size="checkBtnSize"
183
+ :size="checkBtnSize || size"
168
184
  :round="checkBtnRound"
169
185
  :circle="checkBtnCircle"
170
186
  :loading="checkBtnLoading"
@@ -172,12 +188,16 @@
172
188
  :class="(checkBtnClass || '') + ' nf-btn-check'"
173
189
  @click.stop="configNfSearchItemVisibleDialog = true"
174
190
  >
175
- {{ checkBtnText }}
191
+ <el-tooltip :content="columnDisplayBtnText" placement="bottom">
192
+ <i class="iconfont icon-shaixuan1 nf-fs12"></i>
193
+ </el-tooltip>
176
194
  </el-button>
177
195
  <slot v-if="isShowBtnBoxSlot && reverseBtnSlot" name="btnBox" />
178
196
  </div>
179
197
  <column-check-dialog
180
- v-if="configNfSearchItemVisibleDialog"
198
+ ref="columnCheckDialog"
199
+ :storage-key="storageKey"
200
+ v-if="configNfSearchItemVisibleDialog && checkMode === 'dialog'"
181
201
  :show.sync="configNfSearchItemVisibleDialog"
182
202
  :table-columns="formOptions"
183
203
  :title="moreDialogTitle"
@@ -205,6 +225,36 @@
205
225
  <slot slot="title" name="dialogTitle"></slot>
206
226
  <slot slot="footer" name="dialogFooter"></slot>
207
227
  </column-check-dialog>
228
+ <nf-drawer
229
+ ref="columnCheckNfDrawer"
230
+ size="680px"
231
+ v-if="checkMode === 'drawer'"
232
+ :title="moreDialogTitle"
233
+ :cancel-button-text="columnCheckCancelButtonText"
234
+ :confirm-button-text="columnCheckConfirmButtonText"
235
+ :destroy-on-close="true"
236
+ :visible.sync="configNfSearchItemVisibleDialog"
237
+ :tabs="columnCheckTabs"
238
+ :current-tab="columnCheckCurrentTab"
239
+ @confirm="columnCheckConfirm"
240
+ @changeTab="(done) => $emit('changeTab', done)"
241
+ @cancel="(event) => $emit('cancel', event)"
242
+ >
243
+ <slot slot="title" name="columCheckTitle" />
244
+ <slot slot="footer" name="columCheckFooter" />
245
+ <column-check-drawer
246
+ :search-placeholder="columnCheckSearchPlaceholder"
247
+ :fixed-left-desc="columnCheckFixedLeftDesc"
248
+ :clear-desc="columnCheckClearDesc"
249
+ :no-fixed-desc="columnCheckNoFixedDesc"
250
+ :get-checked-length-desc="columnCheckGetCheckedLengthDesc"
251
+ :get-all-check-desc="columnCheckGetAllCheckDesc"
252
+ ref="columnCheckDrawer"
253
+ :storage-key="storageKey"
254
+ :table-columns="formOptions"
255
+ :select-empty-warning-tips="selectEmptyWarningTips"
256
+ />
257
+ </nf-drawer>
208
258
  </div>
209
259
  </template>
210
260
 
@@ -212,7 +262,7 @@
212
262
  import { defineComponent } from 'vue-demi'
213
263
 
214
264
  export default defineComponent({
215
- name: "nf-search-from",
265
+ name: 'nf-search-from'
216
266
  })
217
267
  </script>
218
268
 
@@ -220,6 +270,8 @@ export default defineComponent({
220
270
  <script lang="ts" setup>
221
271
  import SearchFormItem from './nf-search-form-item.vue'
222
272
  import ColumnCheckDialog from './nf-column-check-dialog.vue'
273
+ import ColumnCheckDrawer from './nf-column-check-drawer.vue'
274
+
223
275
  import {
224
276
  createUniqueString,
225
277
  debounce
@@ -235,6 +287,11 @@ import {
235
287
  onUnmounted,
236
288
  nextTick
237
289
  } from 'vue-demi'
290
+ import { ITabItem } from '@94ai/nf-drawer/lib/types'
291
+ import {
292
+ ElTableColumnAttributes,
293
+ NfTableColumnAttributes
294
+ } from '@94ai/nf-table/lib/types'
238
295
 
239
296
 
240
297
  const props = withDefaults(defineProps<{
@@ -246,12 +303,17 @@ const props = withDefaults(defineProps<{
246
303
  columns?: number,
247
304
  showBtn?: boolean,
248
305
  isCollapse?: boolean,
249
-
306
+ expandBtnType?: string,
307
+ expandBtnIcon?: string,
308
+ expandBtnPlain?: boolean,
309
+ expandBtnSize?: string,
310
+ expandBtnRound?: boolean,
311
+ expandBtnCircle?: boolean,
312
+ expandBtnLoading?: boolean,
313
+ expandBtnDisabled?: boolean,
250
314
  /**
251
315
  * 以下同el-form配置项
252
316
  */
253
- labelPosition?: 'top' | 'right' | 'left'
254
- inline?: boolean
255
317
  rules?: Record<string, any>
256
318
  labelSuffix?: string
257
319
  hideRequiredAsterisk?: boolean
@@ -261,39 +323,44 @@ const props = withDefaults(defineProps<{
261
323
  validateOnRuleChange?: boolean
262
324
  size?: 'medium' | 'small' | 'mini'
263
325
  disabled?: boolean
264
- labelWidth?: number,
265
-
266
326
  /**
267
- * 所有的表单项
327
+ * 控制label和content和按钮的组合位置
268
328
  */
269
- formOptions?: NfSearchFormItemOption[],
329
+ labelPosition?: 'top' | 'right' | 'left'
330
+ inline?: boolean
331
+ btnBoxLabel?: string
332
+ btnModel?: 'inline' | 'block'
270
333
  /**
271
- * 显示的表单项,prop数组
334
+ * 兼容ai-search-form控制item父dom宽度
272
335
  */
273
- showItems?: string[],
274
-
336
+ itemWidth?: number,
275
337
  /**
276
- * 是否显示关闭选项功能
338
+ * label宽度
277
339
  */
278
- closable?: boolean,
279
-
340
+ labelWidth?: number,
280
341
  /**
281
- * 兼容ai-search-form控制item父dom宽度
342
+ * 所有的表单项
282
343
  */
283
- itemWidth?: number,
284
-
344
+ formOptions?: NfSearchFormItemOption[],
285
345
  /**
286
- * 以下兼容ai-search-form,控制额外的默认功能按钮
346
+ * 列编辑,是否显示关闭选项功能
287
347
  */
288
- btnItems?: string[] | 'search' | 'export' | 'reset' | '',
348
+ closable?: boolean,
289
349
  /**
290
- * 是否显示更多按钮配置表单项显示
350
+ * 列编辑,是否显示按钮配置表单项显示
291
351
  */
292
- isShowAdd?: boolean,
293
- btnBoxLabel?: string
294
- btnModel?: 'inline' | 'block'
352
+ columnEdit?: boolean,
353
+ /**
354
+ * 列编辑,显示的表单项,prop数组
355
+ */
356
+ showItems?: string[],
357
+ priority?: 'cached' | 'value',
358
+ storageKey?: string
359
+ checkMode?: 'dialog' | 'drawer',
360
+ selectEmptyWarningTips?: string,
361
+ columnDisplayBtnText?: string
295
362
  /**
296
- * 更多按钮
363
+ * 列编辑按钮修饰
297
364
  */
298
365
  checkBtnIcon?: string,
299
366
  checkBtnType?: string,
@@ -303,8 +370,46 @@ const props = withDefaults(defineProps<{
303
370
  checkBtnCircle?: boolean,
304
371
  checkBtnLoading?: boolean,
305
372
  checkBtnDisabled?: boolean,
306
- checkBtnText?: string,
307
373
  checkBtnClass?: string,
374
+ /**
375
+ * 列编辑drawer/dialog
376
+ */
377
+ columnCheckCancelButtonText?: string,
378
+ columnCheckConfirmButtonText?: string,
379
+ moreDialogTitle?: string,
380
+ /**
381
+ * 列编辑dialog设置
382
+ */
383
+ moreDialogWidth?: string,
384
+ modalAppendToBody?: boolean,
385
+ modal?: boolean,
386
+ fullscreen?: boolean,
387
+ top?: string,
388
+ appendToBody?: boolean,
389
+ lockScroll?: boolean,
390
+ customClass?: string,
391
+ closeOnlickModal?: boolean,
392
+ closeOnPressEscape?: boolean,
393
+ showClose?: boolean,
394
+ beforeClose?: Function,
395
+ center?: boolean,
396
+ destroyOnClose?: boolean,
397
+ /**
398
+ * 列编辑drawer
399
+ */
400
+ columnCheckSearchPlaceholder?: string
401
+ columnCheckFixedLeftDesc?: string
402
+ columnCheckClearDesc?: string
403
+ columnCheckNoFixedDesc?: string
404
+ columnCheckGetCheckedLengthDesc?: Function
405
+ columnCheckGetAllCheckDesc?: Function
406
+ columnCheckTabs?: ITabItem[],
407
+ columnCheckCurrentTab?: string,
408
+ /**
409
+ * 兼容ai-search-form,控制额外的默认功能按钮
410
+ */
411
+ btnItems?: string[] | 'search' | 'export' | 'reset' | '',
412
+ reverseBtnSlot?: boolean,
308
413
  /**
309
414
  * 导出按钮
310
415
  */
@@ -344,37 +449,23 @@ const props = withDefaults(defineProps<{
344
449
  resetBtnDisabled?: boolean,
345
450
  resetBtnText?: string,
346
451
  resetBtnClass?: string,
347
-
348
-
349
- reverseBtnSlot?: boolean,
350
-
351
- /**
352
- * 字段弹框设置
353
- */
354
- moreDialogWidth?: string,
355
- moreDialogTitle?: string,
356
- modalAppendToBody?: boolean,
357
- modal?: boolean,
358
- fullscreen?: boolean,
359
- top?: string,
360
- appendToBody?: boolean,
361
- lockScroll?: boolean,
362
- customClass?: string,
363
- closeOnlickModal?: boolean,
364
- closeOnPressEscape?: boolean,
365
- showClose?: boolean,
366
- beforeClose?: Function,
367
- center?: boolean,
368
- destroyOnClose?: boolean,
369
-
370
452
  }>(), {
371
-
453
+ selectEmptyWarningTips: '请选择至少一个选项',
454
+ priority: 'cached',
455
+ columnDisplayBtnText: '添加筛选条件',
456
+ storageKey: 'nf-search-form-columns-cached-key',
457
+ checkMode: 'drawer',
372
458
  upIcon: 'icon-xiangshang2',
373
459
  downIcon: 'icon-xiangxia2',
374
460
  showBtn: true,
375
- isCollapse: true,
461
+ isCollapse: false,
462
+ expandBtnType: 'default',
463
+ expandBtnPlain: false,
464
+ expandBtnRound: false,
465
+ expandBtnCircle: false,
466
+ expandBtnLoading: false,
467
+ expandBtnDisabled: false,
376
468
  columns: 3,
377
-
378
469
  labelPosition: 'top',
379
470
  inline: true,
380
471
  rules: undefined,
@@ -384,66 +475,53 @@ const props = withDefaults(defineProps<{
384
475
  inlineMessage: false,
385
476
  statusIcon: false,
386
477
  validateOnRuleChange: true,
387
- size: undefined,
478
+ size: 'mini',
388
479
  disabled: false,
389
480
  labelWidth: 150,
390
-
391
481
  formOptions: () => [],
392
- showItems:() => [],
482
+ showItems: () => [],
393
483
  closable: false,
394
484
  itemWidth: 190,
395
485
  btnItems: () => '',
396
-
397
- isShowAdd: true,
486
+ columnEdit: false,
398
487
  btnBoxLabel: '',
399
488
  btnModel: 'block',
400
-
401
- checkBtnIcon: 'el-icon-plus',
489
+ checkBtnIcon: '',
402
490
  checkBtnPlain: true,
403
491
  checkBtnType: '',
404
- checkBtnSize: 'mini',
405
492
  checkBtnRound: false,
406
493
  checkBtnCircle: false,
407
494
  checkBtnLoading: false,
408
495
  checkBtnDisabled: false,
409
- checkBtnText: '定制表单列目显示隐藏',
410
496
  checkBtnClass: '',
411
-
412
497
  queryBtnIcon: '',
413
498
  queryBtnPlain: false,
414
499
  queryBtnType: 'primary',
415
- queryBtnSize: 'mini',
416
500
  queryBtnRound: false,
417
501
  queryBtnCircle: false,
418
502
  queryBtnLoading: false,
419
503
  queryBtnDisabled: false,
420
504
  queryBtnText: '查询',
421
505
  queryBtnClass: '',
422
-
423
506
  resetBtnIcon: '',
424
507
  resetBtnPlain: true,
425
508
  resetBtnType: 'default',
426
- resetBtnSize: 'mini',
427
509
  resetBtnRound: false,
428
510
  resetBtnCircle: false,
429
511
  resetBtnLoading: false,
430
512
  resetBtnDisabled: false,
431
513
  resetBtnText: '重置',
432
514
  resetBtnClass: '',
433
-
434
515
  exportBtnIcon: '',
435
516
  exportBtnPlain: true,
436
517
  exportBtnType: 'primary',
437
- exportBtnSize: 'mini',
438
518
  exportBtnRound: false,
439
519
  exportBtnCircle: false,
440
520
  exportBtnLoading: false,
441
521
  exportBtnDisabled: false,
442
522
  exportBtnText: '导出',
443
523
  exportBtnClass: '',
444
-
445
524
  reverseBtnSlot: false,
446
-
447
525
  moreDialogWidth: '600',
448
526
  moreDialogTitle: '设置显示查询框',
449
527
  modalAppendToBody: true,
@@ -459,6 +537,14 @@ const props = withDefaults(defineProps<{
459
537
  beforeClose: undefined,
460
538
  center: false,
461
539
  destroyOnClose: false,
540
+ columnCheckCancelButtonText: '取消',
541
+ columnCheckConfirmButtonText: '确定',
542
+ columnCheckSearchPlaceholder: '搜索',
543
+ columnCheckFixedLeftDesc: '固定在左侧',
544
+ columnCheckClearDesc: '清除',
545
+ columnCheckNoFixedDesc: '不固定',
546
+ columnCheckGetCheckedLengthDesc: (length) => '已选(' + length + ')',
547
+ columnCheckGetAllCheckDesc: (length) => '全选(' + length + ')'
462
548
  })
463
549
 
464
550
  const emit = defineEmits<{
@@ -496,30 +582,113 @@ const emit = defineEmits<{
496
582
  * @param e
497
583
  */
498
584
  (e: 'isCollapseChange', event: boolean): void
585
+ /**
586
+ * 同步showItems
587
+ * @param e
588
+ * @param event
589
+ */
590
+ (e: 'update:showItems', event: string[] | undefined): void
499
591
  }>()
500
592
 
501
- const nfSearchFormRef = ref()
593
+ const instance = getCurrentInstance()?.proxy
502
594
  const defaultButtonSlot = ref()
595
+ const nfSearchFormRef = ref()
596
+ const columnCheckNfDrawer = ref()
597
+ const columnCheckDrawer = ref()
598
+ const columnCheckDialog = ref()
599
+
503
600
  /**
504
601
  * 表单填充的数据
505
602
  */
506
603
  const nfSearchFormModel = ref<Record<string, any>>({})
604
+
605
+ /**
606
+ * 同步用户参数
607
+ */
608
+ const initLocalShow = () => {
609
+ const result = props.formOptions.filter(item => {
610
+ if (props.showItems?.includes(item.prop!)) {
611
+ item.initHidden = true
612
+ }
613
+ return item.initHidden
614
+ }).map(item => item.prop!)
615
+ if (result.length) {
616
+ return result
617
+ }
618
+ return props.formOptions.map(item => item.prop!)
619
+ }
507
620
  /**
508
621
  * 表单显示的item集合
509
622
  */
510
- const localShowItems = ref<string[]>([])
623
+ const localShowItems = ref<string[]>(initLocalShow())
624
+ watch(() => localShowItems.value?.length, () => {
625
+ emit('update:showItems', localShowItems.value)
626
+ }, {
627
+ immediate: true
628
+ })
629
+ const syncLocalShowColumnToCookies = () => {
630
+ if (props.columnEdit) {
631
+ const columnState = {}
632
+ props.formOptions.map((i, index) => {
633
+ const prop = i.prop
634
+ columnState[prop!] = {
635
+ initHidden: i.initHidden || false,
636
+ prop,
637
+ index
638
+ }
639
+ })
640
+ // @ts-ignore
641
+ instance?.$cookies?.set(props.storageKey, JSON.stringify(columnState), -1)
642
+ }
643
+ }
644
+ const syncCookiesToLocalShowColumn = () => {
645
+ if (props.columnEdit) {
646
+ let columnState: string | NfTableColumnAttributes | null = instance?.$cookies?.get(props.storageKey)
647
+ if (columnState) {
648
+ if (typeof columnState === 'string') {
649
+ columnState = JSON.parse(columnState)
650
+ }
651
+ const showColumnItems: string[] = []
652
+ for (const key in columnState as NfTableColumnAttributes) {
653
+ if (!columnState![key].initHidden) {
654
+ showColumnItems.push(columnState![key].prop)
655
+ }
656
+ }
657
+ localShowItems.value = showColumnItems
658
+ syncShowItemToInitHidden()
659
+ }
660
+ }
661
+ }
662
+
663
+ const syncShowItemToInitHidden = () => {
664
+ props.formOptions.forEach(item => {
665
+ if (localShowItems.value?.includes(item.prop!)) {
666
+ item.initHidden = false
667
+ } else {
668
+ item.initHidden = true
669
+ }
670
+ })
671
+ }
672
+ if (props.columnEdit) {
673
+ // 同步缓存参数
674
+ const cached = instance?.$cookies?.get(props.storageKey)
675
+ const cachedPriority = props.priority === 'cached'
676
+
677
+ if (cachedPriority ? cached : localShowItems.value?.length) {
678
+ cachedPriority ? syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies()
679
+ } else if (cachedPriority ? localShowItems.value?.length : cached) {
680
+ cachedPriority ? syncLocalShowColumnToCookies() : syncCookiesToLocalShowColumn()
681
+ }
682
+ }
683
+
511
684
  /**
512
685
  * 超过数量显示更多
513
686
  */
514
687
  const configNfSearchItemVisibleDialog = ref(false)
515
-
516
- const instance = getCurrentInstance()?.proxy
517
-
518
- const newKeys = computed(() => {
519
- return props.formOptions.map(v => {
520
- return createUniqueString()
521
- })
522
- })
688
+ /**
689
+ * 计算一行展示的个数
690
+ */
691
+ const newColumns = ref(3)
523
692
 
524
693
  /**
525
694
  * 定制按钮
@@ -531,28 +700,47 @@ const isShowBtnBoxSlot = computed(() => {
531
700
  /**
532
701
  * 转换成最终的表单项渲染数据
533
702
  */
534
- const renderSearchFormItemOptions = computed(() => {
535
- if (!localShowItems.value?.length) { // 没有配置显示的选项,就显示全部
536
- return props.formOptions
537
- }
538
- const nfSearchFormItemOptions: NfSearchFormItemOption[] = []
539
- props.formOptions.map(item => {
540
- if (itemIsShow(item.prop!)) {
541
- nfSearchFormItemOptions.push(item)
542
- }
703
+ const renderSearchFormItemOptions = ref<NfSearchFormItemOption[]>([])
704
+ const syncCookiesToSearchFormItemOptions = (readCached = true) => {
705
+ const columns = props.formOptions!.map((item, index) => {
706
+ item._index = index
707
+ item.__index = index
708
+ item.key = item.key || createUniqueString()
709
+ return item
543
710
  })
544
- return nfSearchFormItemOptions
545
- })
711
+ if (readCached && props.columnEdit) {
712
+ // 读取缓存 Column 配置
713
+ let columnState: string | NfTableColumnAttributes | null = instance?.$cookies?.get(props.storageKey)
714
+ if (columnState) {
715
+ if (typeof columnState === 'string') {
716
+ columnState = JSON.parse(columnState)
717
+ }
718
+ for (const key in columnState as NfTableColumnAttributes) {
719
+ const state = columnState![key]
720
+ columns.every(i => {
721
+ if (i.prop === key) {
722
+ i.initHidden = state.initHidden
723
+ i._index = state.index
724
+ return false
725
+ }
726
+ return true
727
+ })
728
+ }
729
+ }
730
+ }
731
+ renderSearchFormItemOptions.value = columns.sort((a, b) => a._index! - b._index! < 0 ? -1 : a._index! - b._index! > 0 ? 1 : 0)
732
+ }
733
+ syncCookiesToSearchFormItemOptions()
546
734
 
547
735
  /**
548
736
  * 判断SearchItem是否显示
549
737
  * @param prop
550
738
  */
551
- const itemIsShow = (prop: string) => {
739
+ const itemIsShow = (item: NfSearchFormItemOption) => {
552
740
  if (!localShowItems.value?.length) {
553
741
  return true
554
742
  }
555
- return localShowItems.value.includes(prop)
743
+ return localShowItems.value.includes(item.prop!) && !item.initHidden
556
744
  }
557
745
 
558
746
 
@@ -563,9 +751,9 @@ watch(
563
751
  () => nfSearchFormModel.value,
564
752
  () => {
565
753
  emit('onChange', nfSearchFormModel.value)
566
- }, {
567
- deep: true
568
- })
754
+ }, {
755
+ deep: true
756
+ })
569
757
 
570
758
  const showBtnBoxLabel = ref('')
571
759
 
@@ -577,17 +765,6 @@ watch(() => {
577
765
  immediate: true
578
766
  })
579
767
 
580
- /**
581
- * 同步展示的数据项
582
- */
583
- watch(() => {
584
- return props.showItems
585
- }, () => {
586
- localShowItems.value = props.showItems?.length ? [...props.showItems] : (props.formOptions?.map(_ => _.prop!) || [])
587
- }, {
588
- immediate: true
589
- })
590
-
591
768
 
592
769
  /**
593
770
  * 初始化formData表单数据
@@ -601,6 +778,11 @@ onBeforeMount(() => {
601
778
  obj[v.prop!] = undefined
602
779
  }
603
780
  })
781
+ for (const key in obj) {
782
+ if (!localShowItems.value.includes(key)) {
783
+ delete obj[key]
784
+ }
785
+ }
604
786
  nfSearchFormModel.value = obj
605
787
  })
606
788
 
@@ -612,27 +794,48 @@ const isCollapseChange = async (val: boolean) => {
612
794
 
613
795
 
614
796
  const onResize = () => {
615
- if (props.btnModel==='inline' && !props.btnBoxLabel && props.labelPosition === 'top') {
797
+ if (props.btnModel === 'inline' && !props.btnBoxLabel && props.labelPosition === 'top') {
616
798
  if (nfSearchFormRef.value.$el.getBoundingClientRect().left === defaultButtonSlot.value.$el.getBoundingClientRect().left) {
617
799
  showBtnBoxLabel.value = ''
618
800
  } else {
619
- showBtnBoxLabel.value = '该部分透明度为0用来占位'
801
+ showBtnBoxLabel.value = '...'
620
802
  }
621
803
  }
622
804
  }
623
805
 
806
+ const calcColumns = () => {
807
+ if (!nfSearchFormRef.value) return
808
+ let count = 0
809
+ const formWidth = nfSearchFormRef.value.$el.offsetWidth
810
+ nfSearchFormRef.value.formItems.reduce((prev, cur) => {
811
+ // 每项的宽度加上marginRight:16
812
+ const ret = prev + cur.$el.offsetWidth + 16
813
+ if (ret > formWidth) return prev
814
+ count += 1
815
+ return ret
816
+ }, 0)
817
+ newColumns.value = count
818
+ }
819
+
624
820
  const debounceResize = debounce(onResize, 100, false)
821
+ const debounceCalcColumns = debounce(calcColumns, 100, false)
625
822
 
626
823
  onMounted(async () => {
627
824
  window.addEventListener('resize', debounceResize)
825
+ window.addEventListener('resize', debounceCalcColumns)
628
826
  await nextTick()
629
827
  onResize()
828
+ calcColumns()
630
829
  })
631
830
 
632
831
  onUnmounted(() => {
633
832
  window.removeEventListener('resize', debounceResize)
833
+ window.removeEventListener('resize', debounceCalcColumns)
634
834
  })
635
835
 
836
+ /**
837
+ * 重置校验
838
+ */
636
839
  const resetNfSearchFormModel = () => {
637
840
  nfSearchFormRef.value?.resetFields()
638
841
  emit('onResetFields')
@@ -643,19 +846,23 @@ const resetNfSearchFormModel = () => {
643
846
  * @param callback
644
847
  */
645
848
  const onNfSearchFormValidate = (callback) => {
646
- nfSearchFormRef.value.validate(valid => {
849
+ nfSearchFormRef.value.validate(valid => {
647
850
  if (valid) {
648
- callback()
851
+ callback?.()
649
852
  }
650
853
  })
651
854
  }
652
- // 搜索
855
+ /**
856
+ * 搜索
857
+ */
653
858
  const onNfSearchFormSearch = () => {
654
859
  onNfSearchFormValidate(() => {
655
860
  emit('onSearch', nfSearchFormModel.value)
656
861
  })
657
862
  }
658
- // 导出
863
+ /**
864
+ * 导出
865
+ */
659
866
  const onNfSearchFormExport = () => {
660
867
  onNfSearchFormValidate(() => {
661
868
  emit('onExport', nfSearchFormModel.value)
@@ -666,11 +873,16 @@ const onNfSearchFormExport = () => {
666
873
  * 把该item暂时隐藏
667
874
  * @param prop
668
875
  */
669
- const hiddenNfSearchFormItemOptionField = (prop) => {
876
+ const hiddenNfSearchFormItemOptionField = async (prop) => {
670
877
  const index = localShowItems.value.indexOf(prop)
671
878
  if (index > -1) {
672
879
  localShowItems.value.splice(index, 1)
880
+ syncShowItemToInitHidden()
881
+ syncLocalShowColumnToCookies()
882
+ syncCookiesToSearchFormItemOptions()
673
883
  refreshNfSearchFormModel()
884
+ await nextTick()
885
+ onResize()
674
886
  }
675
887
  }
676
888
 
@@ -678,62 +890,132 @@ const hiddenNfSearchFormItemOptionField = (prop) => {
678
890
  * 更新item对应的formData
679
891
  * @param prop
680
892
  */
681
- const refreshNfSearchFormModel = () => {
682
- let changeTimer: undefined | ReturnType<typeof setTimeout> = undefined
893
+ const refreshNfSearchFormModel = async () => {
683
894
  for (const key in nfSearchFormModel.value) {
684
895
  if (!localShowItems.value.includes(key)) {
685
896
  delete nfSearchFormModel.value[key]
686
897
  }
687
898
  }
688
899
  emit('onChange', nfSearchFormModel.value)
689
- if (changeTimer) {
690
- clearTimeout(changeTimer)
691
- changeTimer = undefined
900
+ await nextTick()
901
+ emit('itemsChange', localShowItems.value)
902
+ }
903
+
904
+ const columnCheckConfirmFeedback = (value: Record<string, any>) => {
905
+ if (!props.columnEdit) {
906
+ const itemsList: string[] = []
907
+ for (const key in value) {
908
+ if (value[key]) {
909
+ itemsList.push(key)
910
+ }
911
+ }
912
+ localShowItems.value = itemsList
913
+ syncShowItemToInitHidden()
692
914
  }
693
- changeTimer = setTimeout(() => {
694
- clearTimeout(changeTimer!)
695
- changeTimer = undefined
696
- emit('itemsChange', localShowItems.value)
697
- })
698
915
  }
699
916
 
917
+ // 抽屉确定
918
+ const columnCheckConfirm = async (cb, error) => {
919
+ try {
920
+ const value = columnCheckDrawer.value.syncTableColumnsToCookies()
921
+ columnCheckConfirmFeedback(value)
922
+ syncCookiesToLocalShowColumn()
923
+ syncCookiesToSearchFormItemOptions()
924
+ refreshNfSearchFormModel()
925
+ await nextTick()
926
+ onResize()
927
+ cb()
928
+ } catch (e) {
929
+ error()
930
+ console.log(e)
931
+ }
932
+ }
700
933
 
701
934
  /**
702
935
  * 保存表单显示的字段
703
- * @param value
704
936
  */
705
- const nfSearchFormItemOptionFieldsSave = (value) => {
706
- let changeTimer
707
- const itemsList: string[] = []
708
- for (const key in value) {
709
- if (value[key]) {
710
- itemsList.push(key)
711
- }
712
- }
713
- if (JSON.stringify(localShowItems.value) !== JSON.stringify(itemsList)) {
714
- localShowItems.value = itemsList
715
- emit('onChange', nfSearchFormModel.value)
716
- if (changeTimer) {
717
- clearTimeout(changeTimer)
718
- changeTimer = undefined
719
- }
720
- changeTimer = setTimeout(() => {
721
- clearTimeout(changeTimer)
722
- changeTimer = undefined
723
- emit('itemsChange', localShowItems.value)
724
- })
725
- }
937
+ const nfSearchFormItemOptionFieldsSave = async (value) => {
938
+ columnCheckConfirmFeedback(value)
939
+ syncCookiesToLocalShowColumn()
940
+ syncCookiesToSearchFormItemOptions()
941
+ refreshNfSearchFormModel()
942
+ await nextTick()
943
+ onResize()
726
944
  }
727
945
 
728
946
  defineExpose({
947
+ /**
948
+ * 列编辑显示的列prop
949
+ */
950
+ localShowItems,
951
+ /**
952
+ * 列编辑同步组件到cookies
953
+ */
954
+ syncLocalShowColumnToCookies,
955
+ /**
956
+ * 列编辑同步cookies到组件localShowItems
957
+ */
958
+ syncCookiesToLocalShowColumn,
959
+ /**
960
+ * showItems同步props.formOptions[i].initHidden
961
+ */
962
+ syncShowItemToInitHidden,
963
+ /**
964
+ * 列编辑隐藏某个表单列目
965
+ */
966
+ hiddenNfSearchFormItemOptionField,
967
+ /**
968
+ * 列编辑操作后刷新表单数据模式
969
+ */
970
+ refreshNfSearchFormModel,
971
+ /**
972
+ * 渲染表单项数据
973
+ */
729
974
  renderSearchFormItemOptions,
975
+ /**
976
+ * 重置
977
+ */
730
978
  resetNfSearchFormModel,
979
+ /**
980
+ * 校验
981
+ */
731
982
  onNfSearchFormValidate,
983
+ /**
984
+ * 搜索
985
+ */
732
986
  onNfSearchFormSearch,
987
+ /**
988
+ * 导出
989
+ */
733
990
  onNfSearchFormExport,
991
+ /**
992
+ * 表单数据
993
+ */
734
994
  nfSearchFormModel,
995
+ /**
996
+ * 表单 ref
997
+ */
735
998
  nfSearchFormRef,
999
+ /**
1000
+ * 列编辑nf-drawer ref
1001
+ */
1002
+ columnCheckNfDrawer,
1003
+ /**
1004
+ * 列编辑column-check-dialog ref
1005
+ */
1006
+ columnCheckDialog,
1007
+ /**
1008
+ * 列编辑column-check-drawer ref
1009
+ */
1010
+ columnCheckDrawer,
1011
+ /**
1012
+ * 列编辑dialog/drawer显示/隐藏
1013
+ */
736
1014
  configNfSearchItemVisibleDialog,
1015
+ /**
1016
+ * 列编辑同步cookies到组件渲染数据
1017
+ */
1018
+ syncCookiesToSearchFormItemOptions
737
1019
  })
738
1020
 
739
1021
  </script>