@94ai/nf-table 3.1.37 → 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,806 @@
1
+ <template>
2
+ <div class="nf-table" ref="nfTableRef">
3
+ <slot name="searchBox" ref="searchBox" >
4
+ <nf-search-form
5
+ ref="nfSearchFormRef"
6
+ v-bind="searchFormAttrs"
7
+ v-on="searchFormEvents"
8
+ >
9
+ <template v-for="item in (nfSearchFormRef?.renderSearchFormItemOptions || [])">
10
+ <!-- 定制化SearchItem?提示-->
11
+ <template v-if="item.tooltip?.slot">
12
+ <slot :name="item.tooltip.slot" :slot="item.tooltip.slot" />
13
+ </template>
14
+ <!-- 定制化SearchItem插槽-->
15
+ <template v-if="item.slot">
16
+ <slot :name="item.slot" :slot="item.slot" />
17
+ </template>
18
+ </template>
19
+ <slot name="btnBox" slot="btnBox" />
20
+ <slot name="searchFormColumnEditDialogTitle" slot="dialogTitle" />
21
+ <slot name="searchFormColumnEditDialogFooter" slot="dialogFooter" />
22
+ </nf-search-form>
23
+ </slot>
24
+ <div class="nf-table-content" ref="nfTableContent">
25
+ <slot name="columnEdit">
26
+ <el-button v-if="columnEdit"
27
+ @click="nfColumCheckDialogVisible = true"
28
+ :class="(columnDisplayBtnClass || '') + ' nf-column-display'"
29
+ :type="columnDisplayBtnType"
30
+ :plain="columnDisplayBtnPlain"
31
+ :icon="columnDisplayBtnIcon"
32
+ :size="columnDisplayBtnSize"
33
+ :round="columnDisplayBtnRound"
34
+ :circle="columnDisplayBtnCircle"
35
+ :loading="columnDisplayBtnLoading"
36
+ :disabled="columnDisplayBtnDisabled"
37
+ >
38
+ {{ columnDisplayBtnText }}
39
+ </el-button>
40
+ </slot>
41
+ <el-table
42
+ ref="elTableRef"
43
+ :class="{'nf-table-container': true, 'nf-default-table-border': !tableAttrs?.border }"
44
+ :data="showData"
45
+ :fit="tableAttrer?.fit ?? true"
46
+ :height="elTableHeight"
47
+ v-bind="tableAttrer"
48
+ v-on="tableEventer"
49
+ >
50
+ <template v-for="column in tableColumns">
51
+ <template v-if="isShow(column)">
52
+ <template v-if="column.type">
53
+ <el-table-column :key="column.label" :type="column.type" :label="column.label" v-bind="column.attr" v-if="column.render || column.prop || column.slot">
54
+ <template slot-scope="scope" >
55
+ <render-component v-if="column.render" :render="column.render" :row="scope.row" />
56
+ <template v-else>
57
+ <slot v-if="column.slot" :name="column.slot" :row="scope.row" :index="scope.$index" />
58
+ <span v-else>{{ scope.row[column.prop] }}</span>
59
+ </template>
60
+ </template>
61
+ </el-table-column>
62
+ <el-table-column :key="column.label" :type="column.type" :label="column.label" v-bind="column.attr" v-else />
63
+ </template>
64
+ <template v-else>
65
+ <el-table-column
66
+ v-if="column.attr&&column.attr.formatter"
67
+ :key="column.label"
68
+ :prop="column.prop"
69
+ :label="column.label"
70
+ v-bind="column.attr"
71
+ >
72
+ <slot v-if="column.singleHeadMutiColSlot" :name="column.singleHeadMutiColSlot" />
73
+ <template slot="header" slot-scope="scope">
74
+ <template v-if="column.headerSlot">
75
+ <slot :name="column.headerSlot" :$index="scope.$index" :column="scope.column" />
76
+ </template>
77
+ <span v-else>
78
+ {{ column.label }}
79
+ </span>
80
+ </template>
81
+ </el-table-column>
82
+ <el-table-column v-else :key="column.label" :prop="column.prop" :label="column.label" v-bind="column.attr">
83
+ <slot v-if="column.singleHeadMutiColSlot" :name="column.singleHeadMutiColSlot" />
84
+ <template slot="header" slot-scope="scope">
85
+ <template v-if="column.headerSlot">
86
+ <slot :name="column.headerSlot" :$index="scope.$index" :column="scope.column" />
87
+ </template>
88
+ <span v-else>
89
+ {{ column.label }}
90
+ </span>
91
+ </template>
92
+ <template slot-scope="scope">
93
+ <render-component v-if="column.render" :render="column.render" :row="scope.row" />
94
+ <template v-else>
95
+ <slot v-if="column.slot" :name="column.slot" :row="scope.row" :index="scope.$index" />
96
+ <template v-else>
97
+ <template v-if="column.prop === operationPropKey && !hasOperationSlot">
98
+ <el-button
99
+ :size="item.size || 'mini'"
100
+ :type="item.type || 'text'"
101
+ :disabled="item.disabled"
102
+ :loading="item.loading"
103
+ :class="item.class"
104
+ :plain="item.plain"
105
+ :icon="item.icon"
106
+ :round="item.round"
107
+ :circle="item.circle"
108
+ :style="item.style"
109
+ v-for="(item, index) in column.operationList"
110
+ v-on="item.events"
111
+ :key="item.key || index"
112
+ >{{ item.text }}</el-button>
113
+ </template>
114
+ <span v-else>{{ scope.row[column.prop] }}</span>
115
+ </template>
116
+ </template>
117
+ </template>
118
+ </el-table-column>
119
+ </template>
120
+ </template>
121
+ </template>
122
+ <slot name="append" slot="append"></slot>
123
+ <slot name="empty" slot="empty"></slot>
124
+ </el-table>
125
+ <div ref="nfTableActionContainerRef" class="nf-action-box nf-clearfix">
126
+ <slot name="actionBar" ref="nfTableActionBarRef" >
127
+ <template v-if="actionBarOptList?.length && !hasActionBarSlot">
128
+ <template v-for="(item, index) in actionBarOptList" >
129
+ <el-button
130
+ :key="item.key || index"
131
+ v-if="item.element === 'el-button'"
132
+ :size="item.size || 'mini'"
133
+ :type="item.type || 'text'"
134
+ :disabled="item.disabled"
135
+ :loading="item.loading"
136
+ :class="item.class"
137
+ :plain="item.plain"
138
+ :icon="item.icon"
139
+ :round="item.round"
140
+ :circle="item.circle"
141
+ :style="{...(item.style || {}), marginRight: '10px'}"
142
+ v-on="item.events"
143
+ >{{ item.value }}</el-button>
144
+ <el-checkbox
145
+ :key="item.key || index"
146
+ v-model="item.value"
147
+ :class="item.class"
148
+ :label="item.label"
149
+ :true-label="item['true-label']"
150
+ :false-label="item['false-label']"
151
+ :disabled="item.disabled"
152
+ :border="item.border"
153
+ :size="item.size"
154
+ :name="item.name"
155
+ :checked="item.checked"
156
+ :indeterminate="item.indeterminate"
157
+ :style="{...(item.style || {}), marginRight: '10px'}"
158
+ v-if="item.element === 'el-checkbox'"
159
+ v-on="item.events"
160
+ >{{ item.text }}</el-checkbox>
161
+ <el-checkbox-group
162
+ :key="item.key || index"
163
+ v-model="item.value"
164
+ :class="item.class"
165
+ :label="item.label"
166
+ :true-label="item['true-label']"
167
+ :false-label="item['false-label']"
168
+ :disabled="item.disabled"
169
+ :border="item.border"
170
+ :size="item.size"
171
+ :name="item.name"
172
+ :checked="item.checked"
173
+ :indeterminate="item.indeterminate"
174
+ :style="{...(item.style || {}), marginRight: '10px'}"
175
+ v-if="item.element === 'el-checkbox-group'"
176
+ v-on="item.events"
177
+ >
178
+ <template v-if="item.children?.length">
179
+ <template
180
+ v-for="(itemChildren, j) in item.children"
181
+ >
182
+ <el-checkbox
183
+ :key="itemChildren.key || j"
184
+ v-model="itemChildren.value"
185
+ :class="itemChildren.class"
186
+ :label="itemChildren.label"
187
+ :true-label="itemChildren['true-label']"
188
+ :false-label="itemChildren['false-label']"
189
+ :disabled="itemChildren.disabled"
190
+ :border="itemChildren.border"
191
+ :size="itemChildren.size"
192
+ :name="itemChildren.name"
193
+ :checked="itemChildren.checked"
194
+ :indeterminate="itemChildren.indeterminate"
195
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
196
+ v-if="itemChildren.element === 'el-checkbox'"
197
+ v-on="itemChildren.events"
198
+ >{{ item.text }}</el-checkbox>
199
+ <el-checkbox-button
200
+ :key="itemChildren.key || j"
201
+ v-model="itemChildren.value"
202
+ :class="itemChildren.class"
203
+ :label="itemChildren.label"
204
+ :true-label="itemChildren['true-label']"
205
+ :false-label="itemChildren['false-label']"
206
+ :disabled="itemChildren.disabled"
207
+ :border="itemChildren.border"
208
+ :size="itemChildren.size"
209
+ :name="itemChildren.name"
210
+ :checked="itemChildren.checked"
211
+ :indeterminate="itemChildren.indeterminate"
212
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
213
+ v-if="itemChildren.element === 'el-checkbox-button'"
214
+ v-on="itemChildren.events"
215
+ >{{ item.text }}</el-checkbox-button>
216
+ </template>
217
+ </template>
218
+ </el-checkbox-group>
219
+ <el-checkbox-button
220
+ :key="item.key || index"
221
+ v-model="item.value"
222
+ :class="item.class"
223
+ :label="item.label"
224
+ :true-label="item['true-label']"
225
+ :false-label="item['false-label']"
226
+ :disabled="item.disabled"
227
+ :border="item.border"
228
+ :size="item.size"
229
+ :name="item.name"
230
+ :checked="item.checked"
231
+ :indeterminate="item.indeterminate"
232
+ :style="{...(item.style || {}), marginRight: '10px'}"
233
+ v-if="item.element === 'el-checkbox-button'"
234
+ v-on="item.events"
235
+ >{{ item.text }}</el-checkbox-button>
236
+ <el-radio
237
+ :key="item.key || index"
238
+ v-model="item.value"
239
+ :label="item.label"
240
+ :disabled="item.disabled"
241
+ :border="item.border"
242
+ :name="item.name"
243
+ :size="item.size"
244
+ :class="item.class"
245
+ :style="{...(item.style || {}), marginRight: '10px'}"
246
+ v-if="item.element === 'el-radio'"
247
+ v-on="item.events"
248
+ >{{ item.text }}</el-radio>
249
+ <el-radio-group
250
+ :key="item.key || index"
251
+ v-model="item.value"
252
+ :disabled="item.disabled"
253
+ :size="item.size"
254
+ :class="item.class"
255
+ :text-color="item['text-color']"
256
+ :fill="item['fill']"
257
+ :style="{...(item.style || {}), marginRight: '10px'}"
258
+ v-if="item.element === 'el-radio-group'"
259
+ v-on="item.events"
260
+ >
261
+ <template v-if="item.children?.length">
262
+ <template
263
+ v-for="(itemChildren, j) in item.children"
264
+ >
265
+ <el-radio
266
+ :key="itemChildren.key || j"
267
+ v-model="itemChildren.value"
268
+ :label="itemChildren.label"
269
+ :disabled="itemChildren.disabled"
270
+ :border="itemChildren.border"
271
+ :name="itemChildren.name"
272
+ :size="itemChildren.size"
273
+ :class="itemChildren.class"
274
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
275
+ v-if="itemChildren.element === 'el-radio'"
276
+ v-on="itemChildren.events"
277
+ >{{ item.text }}</el-radio>
278
+ <el-radio-button
279
+ :key="itemChildren.key || j"
280
+ v-model="itemChildren.value"
281
+ :label="itemChildren.label"
282
+ :disabled="itemChildren.disabled"
283
+ :border="itemChildren.border"
284
+ :name="itemChildren.name"
285
+ :size="itemChildren.size"
286
+ :class="itemChildren.class"
287
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
288
+ v-if="itemChildren.element === 'el-radio-button'"
289
+ v-on="itemChildren.events"
290
+ >{{ item.text }}</el-radio-button>
291
+ </template>
292
+ </template>
293
+ </el-radio-group>
294
+ <el-radio-button
295
+ :key="item.key || index"
296
+ v-model="item.value"
297
+ :label="item.label"
298
+ :disabled="item.disabled"
299
+ :border="item.border"
300
+ :name="item.name"
301
+ :size="item.size"
302
+ :class="item.class"
303
+ :style="{...(item.style || {}), marginRight: '10px'}"
304
+ v-if="item.element === 'el-radio-button'"
305
+ v-on="item.events"
306
+ >{{ item.text }}</el-radio-button>
307
+ <el-input
308
+ :key="item.key || index"
309
+ v-model="item.value"
310
+ :class="item.class"
311
+ :show-word-limit="item['show-word-limit']"
312
+ :show-password="item['show-password']"
313
+ :prefix-icon="item['prefix-icon']"
314
+ :suffix-icon="item['suffix-icon']"
315
+ :validate-event="item['validate-event']"
316
+ :type="item.type"
317
+ :placeholder="item.placeholder"
318
+ :disabled="item.disabled"
319
+ :size="item.size"
320
+ :name="item.name"
321
+ :max="item.max"
322
+ :min="item.min"
323
+ :step="item.step"
324
+ :label="item.label"
325
+ :maxlength="item.maxlength"
326
+ :minlength="item.minlength"
327
+ :clearable="item.clearable"
328
+ :rows="item.rows"
329
+ :autosize="item.autosize"
330
+ :autocomplete="item.autocomplete"
331
+ :readonly="item.readonly"
332
+ :resize="item.resize"
333
+ :autofocus="item.autofocus"
334
+ :form="item.form"
335
+ :tabindex="item.tabindex"
336
+ :style="{...(item.style || {}), marginRight: '10px'}"
337
+ v-if="item.element === 'el-input'"
338
+ v-on="item.events"
339
+ >
340
+ <slot v-if='item.slot?.prefix' :name='item.slot.prefix' slot="prefix" />
341
+ <slot v-if='item.slot?.suffix' :name='item.slot.suffix' slot="suffix" />
342
+ <slot v-if='item.slot?.prepend' :name='item.slot.prepend' slot="prepend" />
343
+ <slot v-if='item.slot?.append' :name='item.slot.append' slot="append" />
344
+ </el-input>
345
+ <el-autocomplete
346
+ :key="item.key || index"
347
+ v-model="item.value"
348
+ :class="item.class"
349
+ :style="{...(item.style || {}), marginRight: '10px'}"
350
+ :value-key="item['value-key']"
351
+ :fetch-suggestions="item['fetch-suggestions']"
352
+ :popper-class="item['popper-class']"
353
+ :trigger-on-focus="item['trigger-on-focus']"
354
+ :select-when-unmatched="item['select-when-unmatched']"
355
+ :hide-loading="item['hide-loading']"
356
+ :popper-append-to-body="item['popper-append-to-body']"
357
+ :highlight-first-item="item['highlight-first-item']"
358
+ :prefix-icon="item['prefix-icon']"
359
+ :suffix-icon="item['suffix-icon']"
360
+ :placeholder="item.placeholder"
361
+ :disabled="item.disabled"
362
+ :debounce="item.debounce"
363
+ :placement="item.placement"
364
+ :label="item.label"
365
+ :name="item.name"
366
+ v-if="item.element === 'el-autocomplete'"
367
+ v-on="item.events"
368
+ >
369
+ <slot v-if='item.slot?.prefix' :name='item.slot.prefix' slot="prefix" />
370
+ <slot v-if='item.slot?.suffix' :name='item.slot.suffix' slot="suffix" />
371
+ <slot v-if='item.slot?.prepend' :name='item.slot.prepend' slot="prepend" />
372
+ <slot v-if='item.slot?.append' :name='item.slot.append' slot="append" />
373
+ </el-autocomplete>
374
+ <el-switch
375
+ :key="item.key || index"
376
+ v-model="item.value"
377
+ :disabled="item.disabled"
378
+ :width="item.width"
379
+ :name="item.name"
380
+ :active-icon-class="item['active-icon-class']"
381
+ :inactive-icon-class="item['inactive-icon-class']"
382
+ :active-text="item['active-text']"
383
+ :inactive-text="item['inactive-text']"
384
+ :active-value="item['active-value']"
385
+ :inactive-value="item['inactive-value']"
386
+ :active-color="item['active-color']"
387
+ :inactive-color="item['inactive-color']"
388
+ :validate-event="item['validate-event']"
389
+ :class="item.class"
390
+ :style="{...(item.style || {}), marginRight: '10px'}"
391
+ v-if="item.element === 'el-switch'"
392
+ v-on="item.events"
393
+ >{{ item.text }}</el-switch>
394
+ <el-input-number
395
+ :key="item.key || index"
396
+ v-model="item.value"
397
+ :class="item.class"
398
+ :min="item.min"
399
+ :max="item.max"
400
+ :step="item.step"
401
+ :step-strictly="item['step-strictly']"
402
+ :precision="item.precision"
403
+ :size="item.size"
404
+ :disabled="item.disabled"
405
+ :controls="item.controls"
406
+ :controls-position="item['controls-position']"
407
+ :name="item.name"
408
+ :label="item.label"
409
+ :placeholder="item.placeholder"
410
+ :style="{...(item.style || {}), marginRight: '10px'}"
411
+ v-if="item.element === 'el-input-number'"
412
+ v-on="item.events"
413
+ ></el-input-number>
414
+ <span
415
+ :key="item.key || index"
416
+ :class="item.class"
417
+ v-if="item.element === 'text'"
418
+ :style="{...(item.style || {}), marginRight: '10px'}"
419
+ v-on="item.events"
420
+ v-bind="item.attr"
421
+ >
422
+ {{ item.value }}
423
+ </span>
424
+ </template>
425
+ </template>
426
+ </slot>
427
+ <slot name="pagination">
428
+ <el-pagination ref="nfTablePaginationRef" v-if="renderPage" v-bind="pageAttrer" v-on="pageEvents" class="nf-pagination-box nf-fr" />
429
+ </slot>
430
+ </div>
431
+ </div>
432
+ <column-check-dialog v-if="nfColumCheckDialogVisible" :show.sync="nfColumCheckDialogVisible" :table-columns="tableColumns" :show-column="items" @save="fieldsSave" >
433
+ <slot slot="tableColumnEditDialogTitle" name="dialogTitle"></slot>
434
+ <slot slot="tableColumnEditDialogFooter" name="dialogFooter"></slot>
435
+ </column-check-dialog>
436
+ </div>
437
+ </template>
438
+
439
+ <script lang="ts">
440
+ import { defineComponent } from 'vue-demi'
441
+ export default defineComponent({
442
+ name: "nf-table",
443
+ })
444
+ </script>
445
+
446
+ <script lang="ts" setup>
447
+ import ColumnCheckDialog from './nf-column-check-dialog.vue'
448
+ import RenderComponent from './nf-render-component.vue'
449
+ import { Loading } from 'element-ui';
450
+ import {
451
+ computed,
452
+ getCurrentInstance,
453
+ nextTick,
454
+ onMounted,
455
+ ref,
456
+ watch
457
+ } from 'vue-demi'
458
+ import {
459
+ NfTableColumnAttributes,
460
+ ElTableColumnAttributes,
461
+ ElTableAttributes,
462
+ ElTableEventKey,
463
+ ElPaginationEventKey,
464
+ ElPaginationAttributes,
465
+ NfSearchFormAttributes,
466
+ NfSearchFormEventKey,
467
+ NfTableActionBtnAttributes
468
+ } from './types'
469
+
470
+ const props = withDefaults(defineProps<{
471
+ data?: Record<string, any>[],
472
+ columns?: NfTableColumnAttributes[],
473
+ searchFormAttrs?: NfSearchFormAttributes,
474
+ searchFormEvents?: Partial<Record<NfSearchFormEventKey, Function>>,
475
+ tableAttrs?: ElTableAttributes,
476
+ tableEvents?: Partial<Record<ElTableEventKey, Function>>,
477
+ pageAttrs?: ElPaginationAttributes,
478
+ pageEvents?: Partial<Record<ElPaginationEventKey, Function>>,
479
+ actionBarOptList?: NfTableActionBtnAttributes[],
480
+ /**
481
+ * 固定窗口满屏table自动计算table高度
482
+ */
483
+ calHeight?: boolean,
484
+ /**
485
+ * 列目显示开关
486
+ */
487
+ columnEdit?: boolean,
488
+ /**
489
+ * 要显示的表格项字段
490
+ */
491
+ showColumn?: string[],
492
+ /**
493
+ * 表格loading
494
+ */
495
+ loading?: boolean,
496
+ target?: HTMLElement,
497
+ body?: boolean,
498
+ fullscreen?: boolean,
499
+ lock?: boolean,
500
+ text?: string,
501
+ spinner?: string,
502
+ background?: string,
503
+ customClass?: string,
504
+
505
+ columnDisplayBtnClass?: string,
506
+ columnDisplayBtnIcon?: string,
507
+ columnDisplayBtnType?: string,
508
+ columnDisplayBtnPlain?: boolean,
509
+ columnDisplayBtnSize?: string,
510
+ columnDisplayBtnRound?: boolean,
511
+ columnDisplayBtnCircle?: boolean,
512
+ columnDisplayBtnLoading?: boolean,
513
+ columnDisplayBtnDisabled?: boolean,
514
+ columnDisplayBtnText?: string,
515
+
516
+ alwaysShowPage?: boolean,
517
+ operationPropKey?: string
518
+
519
+ }>(), {
520
+ data: () => [],
521
+ columns: () => [],
522
+ searchFormAttrs: () => ({}),
523
+ tableAttrs: () => ({}),
524
+ pageAttrs: () => ({}),
525
+ searchFormEvents: () => ({}),
526
+ tableEvents: () => ({}),
527
+ pageEvents: () => ({}),
528
+ actionBarOptList: () => [],
529
+ calHeight: false,
530
+ columnEdit: true,
531
+ showColumn: undefined,
532
+ loading: false,
533
+ target: undefined,
534
+ body: false,
535
+ fullscreen: false,
536
+ lock: true,
537
+ text: undefined,
538
+ spinner: undefined,
539
+ background: undefined,
540
+ customClass: undefined,
541
+ columnDisplayBtnIcon: 'el-icon-plus',
542
+ columnDisplayBtnType: 'primary',
543
+ columnDisplayBtnPlain: true,
544
+ columnDisplayBtnSize: 'mini',
545
+ columnDisplayBtnRound: false,
546
+ columnDisplayBtnCircle: false,
547
+ columnDisplayBtnLoading: false,
548
+ columnDisplayBtnDisabled: false,
549
+ columnDisplayBtnText: '定制表格列目显示隐藏',
550
+ columnDisplayBtnClass: '',
551
+ alwaysShowPage: true,
552
+ operationPropKey: 'operation'
553
+ })
554
+
555
+ const showData = computed(() => {
556
+ const pageSize = props.pageAttrs['page-size']
557
+ const currentPage = props.pageAttrs['current-page'] || 1
558
+ const noTotal = typeof props.pageAttrs.total === 'undefined'
559
+ if (!pageSize || !noTotal) return props.data
560
+ if(props.data.length > pageSize) {
561
+ return JSON.parse(JSON.stringify(props.data.slice((currentPage - 1) * pageSize, currentPage * pageSize)))
562
+ } else {
563
+ return JSON.parse(JSON.stringify(props.data))
564
+ }
565
+ })
566
+
567
+ const emit = defineEmits<{
568
+ (e: 'fieldsChange', event: string[]): void
569
+ }>()
570
+
571
+ const loadingInstance = ref()
572
+ watch(() => {
573
+ return props.loading
574
+ }, async () => {
575
+ if (props.loading) {
576
+ await nextTick()
577
+ const {
578
+ target,
579
+ lock,
580
+ fullscreen,
581
+ text,
582
+ spinner,
583
+ background,
584
+ customClass,
585
+ } = props
586
+ loadingInstance.value = Loading.service({
587
+ target: target || elTableRef.value?.$el || document.body,
588
+ lock,
589
+ fullscreen,
590
+ text,
591
+ spinner,
592
+ background,
593
+ customClass,
594
+ })
595
+ } else {
596
+ loadingInstance.value?.close();
597
+ }
598
+ }, {
599
+ immediate: true
600
+ })
601
+
602
+
603
+ const elTableHeight = ref()
604
+ const nfColumCheckDialogVisible = ref(false)
605
+
606
+ const items = ref<string[]>(props.showColumn)
607
+
608
+ const instance = getCurrentInstance()?.proxy
609
+
610
+
611
+ const elTableRef = ref()
612
+ const nfTableActionContainerRef = ref()
613
+ const nfTablePaginationRef = ref()
614
+ const nfTableActionBarRef = ref()
615
+ const nfTableRef = ref()
616
+ const nfTableContent = ref()
617
+ const searchBoxRef = ref()
618
+ const nfSearchFormRef = ref()
619
+
620
+ /**
621
+ * 定制按钮
622
+ */
623
+ const hasOperationSlot = computed(() => {
624
+ return instance?.$slots.operation
625
+ })
626
+ const hasActionBarSlot = computed(() => {
627
+ return instance?.$slots.actionBar
628
+ })
629
+
630
+ const tableColumns = computed(() => {
631
+ const columns = JSON.parse(JSON.stringify(props.columns))!.map(item => {
632
+ const len = item.label?.length || 0
633
+ const fz = 15 // 每个字大小,其实是每个字的比例值,大概会比字体大小差不多大一点,
634
+ const attr = (item.attr || {}) as ElTableColumnAttributes
635
+ const minWidth = fz * len + 20 + (attr.sortable ? 24 : 0)
636
+ if (!attr['min-width'] || minWidth > parseFloat(attr['min-width'])) {
637
+ attr['min-width'] = String(minWidth) + 'px' // 字大小乘个数即长度 ,注意不要加px像素,这里minWidth只是一个比例值,不是真正的长度,+20表示th左右两边的内边距
638
+ }
639
+ item.attr = {
640
+ ...item.attr,
641
+ ...attr
642
+ } as ElTableColumnAttributes
643
+ delete item.attr.prop
644
+ delete item.attr.label
645
+ return item || {}
646
+ })
647
+ return columns
648
+ })
649
+
650
+ const tableAttrer = computed(() => {
651
+ const obj:Record<string, any> = {
652
+ 'header-cell-style':{'text-align':'center','background': '#F5F7FA','height':'48px', 'color': '#303133', 'font-size': '14px'},
653
+ 'cell-style':{'text-align':'center'},
654
+ resizable: true,
655
+ border: true,
656
+ ...JSON.parse(JSON.stringify(props.tableAttrs))
657
+ }
658
+ delete obj.data
659
+ return obj
660
+ })
661
+
662
+ const headerDragend = async (newWidth, oldWidth, column, event) => {
663
+ await nextTick()
664
+ if (newWidth < column.minWidth) {
665
+ column.width = column.minWidth
666
+ }
667
+ await props.tableEvents['header-dragend']?.(newWidth, oldWidth, column, event)
668
+ }
669
+
670
+ const tableEventer = computed(() => {
671
+ const obj:Record<string, any> = {
672
+ ...props.tableEvents,
673
+ 'header-dragend': headerDragend,
674
+ }
675
+ return obj
676
+ })
677
+
678
+ const pageSizes = ref([10, 20, 30, 40, 50, 100, 200])
679
+ const initPageSizes = () => {
680
+ const pageSizeArr = props.pageAttrs['page-sizes']
681
+ if (props.pageAttrs['page-size']! < (pageSizeArr?.length ? pageSizeArr[0] : 10)) {
682
+ pageSizes.value.unshift(props.pageAttrs['page-size']!)
683
+ }
684
+ }
685
+
686
+ const showPage = computed(() => {
687
+ return showData.value.length > props.pageAttrs['page-size']!
688
+ })
689
+
690
+ const renderPage = computed(() => {
691
+ return props.alwaysShowPage || showPage.value
692
+ })
693
+
694
+ initPageSizes()
695
+
696
+ const pageAttrer = computed(() => {
697
+ return {
698
+ background: false,
699
+ layout: 'total, sizes, prev, pager, next',
700
+ 'page-sizes': pageSizes.value,
701
+ total: typeof props.pageAttrs.total === 'undefined' ? props.data?.length : undefined,
702
+ ...props.pageAttrs
703
+ }
704
+ })
705
+
706
+ const isShow = (row: Record<string, any>) => {
707
+ if (!items.value || row.type) {
708
+ return true
709
+ }
710
+ return items.value.includes(row.prop)
711
+ }
712
+
713
+
714
+ const resetNfSearchFormModel = () =>{
715
+ nfSearchFormRef.value?.resetNfSearchFormModel()
716
+ }
717
+ const onNfSearchFormValidate = (callback) =>{
718
+ nfSearchFormRef.value?.onNfSearchFormValidate(callback)
719
+ }
720
+ const onNfSearchFormSearch = () =>{
721
+ nfSearchFormRef.value?.onNfSearchFormSearch()
722
+ }
723
+ const onNfSearchFormExport = () =>{
724
+ nfSearchFormRef.value?.onNfSearchFormExport()
725
+ }
726
+
727
+ const clearSelection = () =>{
728
+ elTableRef.value?.clearSelection()
729
+ }
730
+ const toggleRowSelection = (row: Record<string, any>, selected: boolean) => {
731
+ elTableRef.value?.toggleRowSelection(row, selected)
732
+ }
733
+ const toggleAllSelection = () => {
734
+ elTableRef.value?.toggleAllSelection()
735
+ }
736
+ const toggleRowExpansion = (row: Record<string, any>, expanded: boolean) => {
737
+ elTableRef.value?.toggleRowExpansion(row, expanded)
738
+ }
739
+ const setCurrentRow = (row: Record<string, any>) => {
740
+ elTableRef.value?.setCurrentRow(row)
741
+ }
742
+ const clearSort = () => {
743
+ elTableRef.value?.clearSort()
744
+ }
745
+ const clearFilter = () => {
746
+ elTableRef.value?.clearFilter()
747
+ }
748
+ const doLayout = () => {
749
+ elTableRef.value?.doLayout?.()
750
+ }
751
+ const sort = (prop, order) => {
752
+ elTableRef.value?.sort(prop, order)
753
+ }
754
+ const fieldsSave = (value) => {
755
+ const itemResult: string[] = []
756
+ for (const key in value) {
757
+ if (value[key]) {
758
+ itemResult.push(key)
759
+ }
760
+ }
761
+ items.value = itemResult
762
+ emit('fieldsChange', itemResult)
763
+ }
764
+
765
+ onMounted(() => {
766
+ if (
767
+ props.calHeight && nfTableContent.value
768
+ ) {
769
+ const tableContentH = nfTableContent.value?.offsetHeight
770
+ const actionH = nfTableActionContainerRef.value.offsetHeight
771
+ const h = tableContentH - actionH
772
+ if (h > 0) {
773
+ elTableHeight.value = h
774
+ }
775
+ } else {
776
+ elTableHeight.value = props.tableAttrs?.height
777
+ }
778
+ })
779
+
780
+
781
+ defineExpose({
782
+ clearFilter,
783
+ sort,
784
+ doLayout,
785
+ clearSort,
786
+ setCurrentRow,
787
+ toggleRowExpansion,
788
+ toggleAllSelection,
789
+ toggleRowSelection,
790
+ clearSelection,
791
+ elTableRef,
792
+ nfTableActionContainerRef,
793
+ nfTablePaginationRef,
794
+ nfTableActionBarRef,
795
+ nfTableRef,
796
+ nfSearchFormRef,
797
+ searchBoxRef,
798
+ loadingInstance,
799
+ resetNfSearchFormModel,
800
+ onNfSearchFormValidate,
801
+ onNfSearchFormSearch,
802
+ onNfSearchFormExport,
803
+ nfColumCheckDialogVisible,
804
+ })
805
+
806
+ </script>