@94ai/nf-table 3.2.54 → 3.2.57

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.
@@ -5,10 +5,6 @@
5
5
  ref="nfSearchFormRef"
6
6
  v-bind="searchFormAttrs"
7
7
  v-on="searchFormEvents"
8
- :operation-prop-key="operationPropKey"
9
- :storage-key="searchFormStorageKey"
10
- :property="priority"
11
- :select-empty-warning-tips="selectEmptyWarningTips"
12
8
  >
13
9
  <template v-for="item in (nfSearchFormRef?.renderSearchFormItemOptions || [])">
14
10
  <!-- 定制化SearchItem?提示-->
@@ -53,20 +49,13 @@
53
49
  >
54
50
  <template v-for="column in tableColumns">
55
51
  <template v-if="isShow(column)">
56
- <template v-if="column.type">
57
- <el-table-column :key="column.key || column.prop" :type="column.type" :label="column.label" v-bind="column.attr"
58
- v-if="column.render || column.prop || column.slot">
59
- <template slot-scope="scope">
60
- <render-component v-if="column.render" :render="column.render" :row="scope.row" />
61
- <template v-else>
62
- <slot v-if="column.slot" :name="column.slot" :row="scope.row" :index="scope.$index" />
63
- <span v-else>{{ scope.row[column.prop] }}</span>
64
- </template>
65
- </template>
66
- </el-table-column>
67
- <el-table-column :key="column.key || column.prop" :type="column.type" :label="column.label" v-bind="column.attr"
68
- v-else />
69
- </template>
52
+ <el-table-column
53
+ v-if="column.type"
54
+ :key="column.key || column.prop || column.type"
55
+ :type="column.type"
56
+ :label="column.label"
57
+ v-bind="column.attr"
58
+ />
70
59
  <template v-else>
71
60
  <el-table-column
72
61
  v-if="column.attr&&column.attr.formatter"
@@ -465,16 +454,16 @@
465
454
  </div>
466
455
  </div>
467
456
  <column-check-dialog
468
- v-if="nfColumCheckDialogVisible && checkMode === 'dialog'"
457
+ :title="columnCheckTitle"
458
+ :confirm-text="columnCheckConfirmButtonText"
459
+ :cancel-text="columnCheckCancelButtonText"
460
+ :basic-field-desc="columnCheckBasicFieldDesc"
461
+
469
462
  :show.sync="nfColumCheckDialogVisible"
470
463
  :table-columns="columns"
471
464
  :column-edit="columnEdit"
472
465
  :storage-key="storageKey"
473
- @save="fieldsConfirm"
474
- :title="columnCheckTitle"
475
466
  :width="columnCheckWidth"
476
- :confirm-text="columnCheckConfirmText"
477
- :cancel-text="columnCheckCancelText"
478
467
  :modal-append-to-body="columnCheckModalAppendToBody"
479
468
  :modal="columnCheckModal"
480
469
  :fullscreen="columnCheckFullscreen"
@@ -488,23 +477,28 @@
488
477
  :before-close="columnCheckBeforeClose"
489
478
  :center="columnCheckCenter"
490
479
  :destroy-on-close="columnCheckDestroyOnClose"
491
- ref="columnCheckDialog"
492
480
  :operation-prop-key="operationPropKey"
481
+
482
+ v-if="nfColumCheckDialogVisible && checkMode === 'dialog'"
483
+ ref="columnCheckDialog"
484
+ @save="fieldsConfirm"
493
485
  >
494
486
  <slot slot="tableColumnEditDialogTitle" name="title"></slot>
495
487
  <slot slot="tableColumnEditDialogFooter" name="footer"></slot>
496
488
  </column-check-dialog>
497
489
  <nf-drawer
498
- ref="columnCheckNfDrawer"
499
- size="680px"
500
- v-if="checkMode === 'drawer'"
501
490
  :title="columnCheckTitle"
502
491
  :cancel-button-text="columnCheckCancelButtonText"
503
492
  :confirm-button-text="columnCheckConfirmButtonText"
493
+
494
+ ref="columnCheckNfDrawer"
495
+ size="680px"
504
496
  :visible.sync="nfColumCheckDialogVisible"
505
497
  :tabs="columnCheckTabs"
506
498
  :destroy-on-close="true"
507
499
  :currentTab="columnCheckCurrentTab"
500
+
501
+ v-if="checkMode === 'drawer'"
508
502
  @confirm="columnCheckConfirm"
509
503
  @changeTab="(done) => $emit('changeTab', done)"
510
504
  @cancel="(name) => $emit('cancel', name)"
@@ -517,14 +511,15 @@
517
511
  :clear-desc="columnCheckClearDesc"
518
512
  :no-fixed-desc="columnCheckNoFixedDesc"
519
513
  :basic-field-desc="columnCheckBasicFieldDesc"
520
- :column-edit="columnEdit"
514
+ :select-empty-warning-tips="selectEmptyWarningTips"
521
515
  :get-checked-length-desc="columnCheckGetCheckedLengthDesc"
522
516
  :get-all-check-desc="columnCheckGetAllCheckDesc"
523
- :operation-prop-key="operationPropKey"
524
517
  ref="columnCheckDrawer"
518
+
519
+ :column-edit="columnEdit"
520
+ :operation-prop-key="operationPropKey"
525
521
  :storage-key="storageKey"
526
522
  :table-columns="columns"
527
- :select-empty-warning-tips="selectEmptyWarningTips"
528
523
  />
529
524
  </nf-drawer>
530
525
  </div>
@@ -568,7 +563,6 @@ import { ITabItem } from '@94ai/nf-drawer/lib/types'
568
563
  import { CachedManager } from '@94ai/common-utils'
569
564
 
570
565
  const props = withDefaults(defineProps<{
571
- emptyImageSize?: number,
572
566
  data?: Record<string, any>[],
573
567
  columns?: NfTableColumnAttributes[] | any,
574
568
  searchFormAttrs?: NfSearchFormAttributes,
@@ -578,6 +572,14 @@ const props = withDefaults(defineProps<{
578
572
  pageAttrs?: ElPaginationAttributes,
579
573
  pageEvents?: Partial<Record<ElPaginationEventKey, Function>>,
580
574
  actionBarOptList?: NfTableActionBtnAttributes[],
575
+ /**
576
+ * 开启表格列拖拽缓存记录
577
+ */
578
+ dragCached?: boolean,
579
+ /**
580
+ * 表格空数据时空组件size
581
+ */
582
+ emptyImageSize?: number,
581
583
  /**
582
584
  * 固定窗口满屏table自动计算table高度
583
585
  */
@@ -615,12 +617,11 @@ const props = withDefaults(defineProps<{
615
617
  columnCheckTitle?: string,
616
618
  columnCheckCancelButtonText?: string,
617
619
  columnCheckConfirmButtonText?: string,
620
+ columnCheckBasicFieldDesc?: string
618
621
  /**
619
622
  * 列编辑dialog模式
620
623
  */
621
624
  columnCheckWidth?: string,
622
- columnCheckConfirmText?: string
623
- columnCheckCancelText?: string
624
625
  columnCheckModalAppendToBody?: boolean,
625
626
  columnCheckModal?: boolean,
626
627
  columnCheckFullscreen?: boolean,
@@ -641,7 +642,6 @@ const props = withDefaults(defineProps<{
641
642
  columnCheckFixedLeftDesc?: string
642
643
  columnCheckClearDesc?: string
643
644
  columnCheckNoFixedDesc?: string
644
- columnCheckBasicFieldDesc?: string
645
645
  columnCheckGetCheckedLengthDesc?: Function
646
646
  columnCheckGetAllCheckDesc?: Function
647
647
  columnCheckTabs?: ITabItem[],
@@ -668,9 +668,10 @@ const props = withDefaults(defineProps<{
668
668
  * 操作列属性key
669
669
  */
670
670
  operationPropKey?: string
671
+
671
672
  }>(), {
673
+ dragCached: true,
672
674
  emptyImageSize: 145,
673
- selectEmptyWarningTips: '请选择至少一个选项',
674
675
  priority: 'cached',
675
676
  storageKey: 'nf-table-columns-cached-key',
676
677
  searchFormStorageKey: 'nf-search-form-columns-cached-key',
@@ -705,14 +706,10 @@ const props = withDefaults(defineProps<{
705
706
  columnDisplayBtnCircle: false,
706
707
  columnDisplayBtnLoading: false,
707
708
  columnDisplayBtnDisabled: false,
708
- columnDisplayBtnText: '设置列表字段',
709
709
  columnDisplayBtnClass: '',
710
710
  alwaysShowPage: true,
711
711
  operationPropKey: 'operation',
712
- columnCheckTitle: '设置显示字段',
713
712
  columnCheckWidth: '600px',
714
- columnCheckConfirmText: '保 存',
715
- columnCheckCancelText: '取 消',
716
713
  columnCheckModalAppendToBody: true,
717
714
  columnCheckModal: true,
718
715
  columnCheckFullscreen: false,
@@ -726,6 +723,9 @@ const props = withDefaults(defineProps<{
726
723
  columnCheckBeforeClose: undefined,
727
724
  columnCheckCenter: false,
728
725
  columnCheckDestroyOnClose: false,
726
+ selectEmptyWarningTips: '请选择至少一个选项',
727
+ columnDisplayBtnText: '设置列表字段',
728
+ columnCheckTitle: '设置显示字段',
729
729
  columnCheckCancelButtonText: '取消',
730
730
  columnCheckConfirmButtonText: '确定',
731
731
  columnCheckSearchPlaceholder: '搜索',
@@ -852,7 +852,7 @@ const syncLocalShowColumnToCookies = () => {
852
852
  index
853
853
  }
854
854
  })
855
- CachedManager.syncCachedSet(props.storageKey, columnState)
855
+ return CachedManager.syncCachedSet(props.storageKey, columnState)
856
856
  }
857
857
  }
858
858
 
@@ -906,40 +906,46 @@ const initCachedData = async () => {
906
906
  }
907
907
  const cachedPriority = props.priority === 'cached'
908
908
  if (cachedPriority ? cached : localShowColumn.value?.length) {
909
- cachedPriority ? await syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies()
909
+ cachedPriority ? await syncCookiesToLocalShowColumn() : await syncLocalShowColumnToCookies()
910
910
  } else if (cachedPriority ? localShowColumn.value?.length : cached) {
911
- cachedPriority ? syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn()
911
+ cachedPriority ? await syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn()
912
912
  }
913
913
  } catch (e) {
914
914
  console.log(e)
915
915
  }
916
916
  }
917
+ if (props.dragCached) {
918
+ await CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`)
919
+ }
917
920
  }
918
921
 
919
- initCachedData()
922
+ const getMinWidth = (column) => {
923
+ const fs = 14
924
+ const label = column.customLabel || column.label
925
+ const char = label.match(/[\u2E80-\u9FFF]/g)
926
+ const charLen = char ? char.length : 0
927
+ const num = label.match(/\d|\./g)
928
+ const numLen = num ? num.length : 0
929
+ const otherLen = label.length - charLen - numLen
930
+ return fs * (charLen * 1 + numLen * 0.7 + otherLen * 0.58) + 20 + (column.sortable ? 24 : 0)
931
+ }
920
932
 
921
933
  const tableColumns = ref<NfTableColumnAttributes[]>([])
922
934
  const elTableRefKey = ref(Date.now())
923
- const syncCookiesToTableColumn = async (readCached = true) => {
935
+ const syncCookiesToTableColumn = async (readCached = true, init = false) => {
924
936
  props.columns._skip = true
925
937
  const columns = props.columns!.map((item, index) => {
926
- const len = item.label?.length || 0
927
- const fz = 15 // 每个字大小,其实是每个字的比例值,大概会比字体大小差不多大一点,
928
938
  const attr = (item.attr || {}) as ElTableColumnAttributes
929
- // const minWidth = fz * len + 32 + (attr.sortable ? 24 : 0)
930
- // if (!attr['min-width'] || minWidth > parseFloat(attr['min-width'])) {
931
- // attr['min-width'] = String(minWidth) + 'px' // 字大小乘个数即长度 ,注意不要加px像素,这里minWidth只是一个比例值,不是真正的长度,+32表示th左右两边的内边距
932
- // }
933
939
  // 区分中文、数字、其他字符
934
940
  if (!attr['min-width'] && item.label) {
935
- const fs = 14
936
- const char = item.label.match(/[\u2E80-\u9FFF]/g)
937
- const charLen = char ? char.length : 0
938
- const num = item.label.match(/\d|\./g)
939
- const numLen = num ? num.length : 0
940
- const otherLen = item.label.length - charLen - numLen
941
- const minWidth = fs * (charLen * 1.1 + numLen * 0.65 + otherLen * 0.5) + 32 + (attr.sortable ? 24 : 0)
942
- attr['min-width'] = String(minWidth) + 'px'
941
+ attr['min-width'] = String(getMinWidth(item)) + 'px'
942
+ }
943
+ if (init && props.dragCached) {
944
+ const prop = item.prop || item.attr?.prop
945
+ let columnWidth = CachedManager.syncCachedGet(`${props.storageKey}$drag-column-width`) || {}
946
+ if (columnWidth[prop]) { // 读取缓存
947
+ attr.width = columnWidth[prop]
948
+ }
943
949
  }
944
950
  item.attr = {
945
951
  ...item.attr,
@@ -988,8 +994,12 @@ const syncCookiesToTableColumn = async (readCached = true) => {
988
994
  })
989
995
  elTableRefKey.value = Date.now()
990
996
  }
997
+ const initColumn = async () => {
998
+ await initCachedData()
999
+ syncCookiesToTableColumn(true, true)
1000
+ }
991
1001
 
992
- syncCookiesToTableColumn()
1002
+ initColumn()
993
1003
 
994
1004
  onBeforeMount(() => {
995
1005
  watch(() => {
@@ -1110,8 +1120,14 @@ const sort = (prop, order) => {
1110
1120
 
1111
1121
  const headerDragend = async (newWidth, oldWidth, column, event) => {
1112
1122
  await nextTick()
1113
- if (newWidth < column.minWidth) {
1114
- column.width = column.minWidth
1123
+ const minWidth = getMinWidth(column)
1124
+ if (newWidth < minWidth) {
1125
+ column.width = minWidth
1126
+ }
1127
+ if (props.dragCached) { // 记录缓存
1128
+ const columnCachedData = await CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`) || {}
1129
+ columnCachedData[column.property] = column.width
1130
+ await CachedManager.asyncCachedSet(`${props.storageKey}$drag-column-width`, columnCachedData)
1115
1131
  }
1116
1132
  await props.tableEvents['header-dragend']?.(newWidth, oldWidth, column, event)
1117
1133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-table",
3
- "version": "3.2.54",
3
+ "version": "3.2.57",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,12 +14,12 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/common-utils": "^3.2.54",
18
- "@94ai/nf-button": "^3.2.54",
19
- "@94ai/nf-drawer": "^3.2.54",
20
- "@94ai/nf-message": "^3.2.54",
21
- "@94ai/nf-search-form": "^3.2.54",
22
- "@94ai/nf-theme-chalk": "^3.2.54",
17
+ "@94ai/common-utils": "^3.2.57",
18
+ "@94ai/nf-button": "^3.2.57",
19
+ "@94ai/nf-drawer": "^3.2.57",
20
+ "@94ai/nf-message": "^3.2.57",
21
+ "@94ai/nf-search-form": "^3.2.57",
22
+ "@94ai/nf-theme-chalk": "^3.2.57",
23
23
  "idb-keyval": "^6.2.1",
24
24
  "vue-demi": "^0.14.5",
25
25
  "vuedraggable": "^2.24.3"
@@ -37,5 +37,5 @@
37
37
  "types": "lib/index.d.ts",
38
38
  "main": "lib/nf-table.cjs.js",
39
39
  "module": "lib/nf-table.esm-bundler.js",
40
- "gitHead": "bfd522f9670244b10ad561f8d76ea7b09ce59917"
40
+ "gitHead": "1f0681c27c513e0a6ac75b9bf70dbde9dfadace0"
41
41
  }