@94ai/nf-table 100.1.38 → 100.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -48,6 +48,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
48
48
  type: import("vue-demi").PropType<string[]>;
49
49
  default: undefined;
50
50
  };
51
+ dragCached: {
52
+ type: import("vue-demi").PropType<boolean>;
53
+ default: boolean;
54
+ };
51
55
  emptyImageSize: {
52
56
  type: import("vue-demi").PropType<number>;
53
57
  default: number;
@@ -319,6 +323,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
319
323
  type: import("vue-demi").PropType<string[]>;
320
324
  default: undefined;
321
325
  };
326
+ dragCached: {
327
+ type: import("vue-demi").PropType<boolean>;
328
+ default: boolean;
329
+ };
322
330
  emptyImageSize: {
323
331
  type: import("vue-demi").PropType<number>;
324
332
  default: number;
@@ -557,6 +565,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
557
565
  text: string;
558
566
  selectEmptyWarningTips: string;
559
567
  showColumn: string[];
568
+ dragCached: boolean;
560
569
  emptyImageSize: number;
561
570
  searchFormAttrs: import("./types").NfSearchFormAttributes;
562
571
  searchFormEvents: Partial<Record<import("./types").NfSearchFormEventKey, Function>>;
@@ -660,6 +669,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
660
669
  type: import("vue-demi").PropType<string[]>;
661
670
  default: undefined;
662
671
  };
672
+ dragCached: {
673
+ type: import("vue-demi").PropType<boolean>;
674
+ default: boolean;
675
+ };
663
676
  emptyImageSize: {
664
677
  type: import("vue-demi").PropType<number>;
665
678
  default: number;
@@ -957,7 +970,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
957
970
  calcTableHeight: () => void;
958
971
  syncLocalShowColumnToCookies: () => void;
959
972
  syncCookiesToLocalShowColumn: () => Promise<void>;
960
- syncCookiesToTableColumn: (readCached?: boolean) => Promise<void>;
973
+ syncCookiesToTableColumn: (readCached?: boolean, init?: boolean) => Promise<void>;
961
974
  elTableRefKey: import("vue-demi").Ref<number>;
962
975
  }> & import("vue/types/v3-component-options").ExtractComputedReturns<{}> & import("vue-demi").ComponentCustomProperties & Readonly<import("vue-demi").ExtractPropTypes<{
963
976
  background: {
@@ -1008,6 +1021,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
1008
1021
  type: import("vue-demi").PropType<string[]>;
1009
1022
  default: undefined;
1010
1023
  };
1024
+ dragCached: {
1025
+ type: import("vue-demi").PropType<boolean>;
1026
+ default: boolean;
1027
+ };
1011
1028
  emptyImageSize: {
1012
1029
  type: import("vue-demi").PropType<number>;
1013
1030
  default: number;
@@ -1279,6 +1296,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
1279
1296
  type: import("vue-demi").PropType<string[]>;
1280
1297
  default: undefined;
1281
1298
  };
1299
+ dragCached: {
1300
+ type: import("vue-demi").PropType<boolean>;
1301
+ default: boolean;
1302
+ };
1282
1303
  emptyImageSize: {
1283
1304
  type: import("vue-demi").PropType<number>;
1284
1305
  default: number;
@@ -1576,7 +1597,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
1576
1597
  calcTableHeight: () => void;
1577
1598
  syncLocalShowColumnToCookies: () => void;
1578
1599
  syncCookiesToLocalShowColumn: () => Promise<void>;
1579
- syncCookiesToTableColumn: (readCached?: boolean) => Promise<void>;
1600
+ syncCookiesToTableColumn: (readCached?: boolean, init?: boolean) => Promise<void>;
1580
1601
  elTableRefKey: import("vue-demi").Ref<number>;
1581
1602
  }, {}, {}, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {
1582
1603
  fieldsChange: (event: string[]) => void;
@@ -1594,6 +1615,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
1594
1615
  text: string;
1595
1616
  selectEmptyWarningTips: string;
1596
1617
  showColumn: string[];
1618
+ dragCached: boolean;
1597
1619
  emptyImageSize: number;
1598
1620
  searchFormAttrs: import("./types").NfSearchFormAttributes;
1599
1621
  searchFormEvents: Partial<Record<import("./types").NfSearchFormEventKey, Function>>;
@@ -1698,6 +1720,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
1698
1720
  type: import("vue-demi").PropType<string[]>;
1699
1721
  default: undefined;
1700
1722
  };
1723
+ dragCached: {
1724
+ type: import("vue-demi").PropType<boolean>;
1725
+ default: boolean;
1726
+ };
1701
1727
  emptyImageSize: {
1702
1728
  type: import("vue-demi").PropType<number>;
1703
1729
  default: number;
@@ -1926,9 +1952,6 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
1926
1952
  slot: any;
1927
1953
  }) => any>> & Partial<Record<any, (_: {
1928
1954
  slot: any;
1929
- }) => any>> & Partial<Record<any, (_: {
1930
- row: any;
1931
- index: any;
1932
1955
  }) => any>> & Partial<Record<any, (_: {}) => any>> & Partial<Record<any, (_: {
1933
1956
  $index: any;
1934
1957
  column: any;
@@ -5771,6 +5771,12 @@ const __sfc_main = vueDemi.defineComponent({
5771
5771
  name: "nf-table"
5772
5772
  });
5773
5773
  __sfc_main.props = {
5774
+ dragCached: {
5775
+ key: "dragCached",
5776
+ required: false,
5777
+ type: Boolean,
5778
+ default: true
5779
+ },
5774
5780
  emptyImageSize: {
5775
5781
  key: "emptyImageSize",
5776
5782
  required: false,
@@ -6294,7 +6300,7 @@ __sfc_main.setup = (__props, __ctx) => {
6294
6300
  index: index2
6295
6301
  };
6296
6302
  });
6297
- commonUtils.CachedManager.syncCachedSet(props.storageKey, columnState);
6303
+ return commonUtils.CachedManager.syncCachedSet(props.storageKey, columnState);
6298
6304
  }
6299
6305
  };
6300
6306
  const syncShowItemToInitHidden = () => {
@@ -6347,33 +6353,44 @@ __sfc_main.setup = (__props, __ctx) => {
6347
6353
  }
6348
6354
  const cachedPriority = props.priority === "cached";
6349
6355
  if (cachedPriority ? cached : (_a2 = localShowColumn.value) == null ? void 0 : _a2.length) {
6350
- cachedPriority ? await syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies();
6356
+ cachedPriority ? await syncCookiesToLocalShowColumn() : await syncLocalShowColumnToCookies();
6351
6357
  } else if (cachedPriority ? (_b = localShowColumn.value) == null ? void 0 : _b.length : cached) {
6352
- cachedPriority ? syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn();
6358
+ cachedPriority ? await syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn();
6353
6359
  }
6354
6360
  } catch (e) {
6355
6361
  console.log(e);
6356
6362
  }
6357
6363
  }
6364
+ if (props.dragCached) {
6365
+ await commonUtils.CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`);
6366
+ }
6367
+ };
6368
+ const getMinWidth = (column) => {
6369
+ const fs = 14;
6370
+ const label = column.customLabel || column.label;
6371
+ const char = label.match(/[\u2E80-\u9FFF]/g);
6372
+ const charLen = char ? char.length : 0;
6373
+ const num = label.match(/\d|\./g);
6374
+ const numLen = num ? num.length : 0;
6375
+ const otherLen = label.length - charLen - numLen;
6376
+ return fs * (charLen * 1 + numLen * 0.7 + otherLen * 0.58) + 20 + (column.sortable ? 24 : 0);
6358
6377
  };
6359
- initCachedData();
6360
6378
  const tableColumns = vueDemi.ref([]);
6361
6379
  const elTableRefKey = vueDemi.ref(Date.now());
6362
- const syncCookiesToTableColumn = async (readCached = true) => {
6380
+ const syncCookiesToTableColumn = async (readCached = true, init = false) => {
6363
6381
  props.columns._skip = true;
6364
6382
  const columns = props.columns.map((item, index2) => {
6365
6383
  var _a2;
6366
- ((_a2 = item.label) == null ? void 0 : _a2.length) || 0;
6367
6384
  const attr = item.attr || {};
6368
6385
  if (!attr["min-width"] && item.label) {
6369
- const fs = 14;
6370
- const char = item.label.match(/[\u2E80-\u9FFF]/g);
6371
- const charLen = char ? char.length : 0;
6372
- const num = item.label.match(/\d|\./g);
6373
- const numLen = num ? num.length : 0;
6374
- const otherLen = item.label.length - charLen - numLen;
6375
- const minWidth = fs * (charLen * 1.1 + numLen * 0.65 + otherLen * 0.5) + 32 + (attr.sortable ? 24 : 0);
6376
- attr["min-width"] = String(minWidth) + "px";
6386
+ attr["min-width"] = String(getMinWidth(item)) + "px";
6387
+ }
6388
+ if (init && props.dragCached) {
6389
+ const prop = item.prop || ((_a2 = item.attr) == null ? void 0 : _a2.prop);
6390
+ let columnWidth = commonUtils.CachedManager.syncCachedGet(`${props.storageKey}$drag-column-width`) || {};
6391
+ if (columnWidth[prop]) {
6392
+ attr.width = columnWidth[prop];
6393
+ }
6377
6394
  }
6378
6395
  item.attr = {
6379
6396
  ...item.attr,
@@ -6423,7 +6440,11 @@ __sfc_main.setup = (__props, __ctx) => {
6423
6440
  });
6424
6441
  elTableRefKey.value = Date.now();
6425
6442
  };
6426
- syncCookiesToTableColumn();
6443
+ const initColumn = async () => {
6444
+ await initCachedData();
6445
+ syncCookiesToTableColumn(true, true);
6446
+ };
6447
+ initColumn();
6427
6448
  vueDemi.onBeforeMount(() => {
6428
6449
  vueDemi.watch(() => {
6429
6450
  return props.columns;
@@ -6548,8 +6569,14 @@ __sfc_main.setup = (__props, __ctx) => {
6548
6569
  const headerDragend = async (newWidth, oldWidth, column, event) => {
6549
6570
  var _a2, _b;
6550
6571
  await vueDemi.nextTick();
6551
- if (newWidth < column.minWidth) {
6552
- column.width = column.minWidth;
6572
+ const minWidth = getMinWidth(column);
6573
+ if (newWidth < minWidth) {
6574
+ column.width = minWidth;
6575
+ }
6576
+ if (props.dragCached) {
6577
+ const columnCachedData = await commonUtils.CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`) || {};
6578
+ columnCachedData[column.property] = column.width;
6579
+ await commonUtils.CachedManager.asyncCachedSet(`${props.storageKey}$drag-column-width`, columnCachedData);
6553
6580
  }
6554
6581
  await ((_b = (_a2 = props.tableEvents)["header-dragend"]) == null ? void 0 : _b.call(_a2, newWidth, oldWidth, column, event));
6555
6582
  };
@@ -6833,33 +6860,13 @@ var _sfc_render = function render3() {
6833
6860
  "height": _vm.elTableHeight
6834
6861
  }
6835
6862
  }, "el-table", _vm.tableAttrer, false), _vm.tableEventer), [_vm._l(_vm.tableColumns, function(column) {
6836
- return [_vm.isShow(column) ? [column.type ? [column.render || column.prop || column.slot ? _c("el-table-column", _vm._b({
6837
- key: column.key || column.prop,
6838
- attrs: {
6839
- "type": column.type,
6840
- "label": column.label
6841
- },
6842
- scopedSlots: _vm._u([{
6843
- key: "default",
6844
- fn: function(scope) {
6845
- return [column.render ? _c("render-component", {
6846
- attrs: {
6847
- "render": column.render,
6848
- "row": scope.row
6849
- }
6850
- }) : [column.slot ? _vm._t(column.slot, null, {
6851
- "row": scope.row,
6852
- "index": scope.$index
6853
- }) : _c("span", [_vm._v(_vm._s(scope.row[column.prop]))])]];
6854
- }
6855
- }], null, true)
6856
- }, "el-table-column", column.attr, false)) : _c("el-table-column", _vm._b({
6857
- key: column.key || column.prop,
6863
+ return [_vm.isShow(column) ? [column.type ? _c("el-table-column", _vm._b({
6864
+ key: column.key || column.prop || column.type,
6858
6865
  attrs: {
6859
6866
  "type": column.type,
6860
6867
  "label": column.label
6861
6868
  }
6862
- }, "el-table-column", column.attr, false))] : [column.attr && column.attr.formatter ? _c("el-table-column", _vm._b({
6869
+ }, "el-table-column", column.attr, false)) : [column.attr && column.attr.formatter ? _c("el-table-column", _vm._b({
6863
6870
  key: column.key || column.prop,
6864
6871
  attrs: {
6865
6872
  "prop": column.prop,
@@ -5769,6 +5769,12 @@ const __sfc_main = defineComponent({
5769
5769
  name: "nf-table"
5770
5770
  });
5771
5771
  __sfc_main.props = {
5772
+ dragCached: {
5773
+ key: "dragCached",
5774
+ required: false,
5775
+ type: Boolean,
5776
+ default: true
5777
+ },
5772
5778
  emptyImageSize: {
5773
5779
  key: "emptyImageSize",
5774
5780
  required: false,
@@ -6292,7 +6298,7 @@ __sfc_main.setup = (__props, __ctx) => {
6292
6298
  index: index2
6293
6299
  };
6294
6300
  });
6295
- CachedManager.syncCachedSet(props.storageKey, columnState);
6301
+ return CachedManager.syncCachedSet(props.storageKey, columnState);
6296
6302
  }
6297
6303
  };
6298
6304
  const syncShowItemToInitHidden = () => {
@@ -6345,33 +6351,44 @@ __sfc_main.setup = (__props, __ctx) => {
6345
6351
  }
6346
6352
  const cachedPriority = props.priority === "cached";
6347
6353
  if (cachedPriority ? cached : (_a2 = localShowColumn.value) == null ? void 0 : _a2.length) {
6348
- cachedPriority ? await syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies();
6354
+ cachedPriority ? await syncCookiesToLocalShowColumn() : await syncLocalShowColumnToCookies();
6349
6355
  } else if (cachedPriority ? (_b = localShowColumn.value) == null ? void 0 : _b.length : cached) {
6350
- cachedPriority ? syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn();
6356
+ cachedPriority ? await syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn();
6351
6357
  }
6352
6358
  } catch (e) {
6353
6359
  console.log(e);
6354
6360
  }
6355
6361
  }
6362
+ if (props.dragCached) {
6363
+ await CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`);
6364
+ }
6365
+ };
6366
+ const getMinWidth = (column) => {
6367
+ const fs = 14;
6368
+ const label = column.customLabel || column.label;
6369
+ const char = label.match(/[\u2E80-\u9FFF]/g);
6370
+ const charLen = char ? char.length : 0;
6371
+ const num = label.match(/\d|\./g);
6372
+ const numLen = num ? num.length : 0;
6373
+ const otherLen = label.length - charLen - numLen;
6374
+ return fs * (charLen * 1 + numLen * 0.7 + otherLen * 0.58) + 20 + (column.sortable ? 24 : 0);
6356
6375
  };
6357
- initCachedData();
6358
6376
  const tableColumns = ref([]);
6359
6377
  const elTableRefKey = ref(Date.now());
6360
- const syncCookiesToTableColumn = async (readCached = true) => {
6378
+ const syncCookiesToTableColumn = async (readCached = true, init = false) => {
6361
6379
  props.columns._skip = true;
6362
6380
  const columns = props.columns.map((item, index2) => {
6363
6381
  var _a2;
6364
- ((_a2 = item.label) == null ? void 0 : _a2.length) || 0;
6365
6382
  const attr = item.attr || {};
6366
6383
  if (!attr["min-width"] && item.label) {
6367
- const fs = 14;
6368
- const char = item.label.match(/[\u2E80-\u9FFF]/g);
6369
- const charLen = char ? char.length : 0;
6370
- const num = item.label.match(/\d|\./g);
6371
- const numLen = num ? num.length : 0;
6372
- const otherLen = item.label.length - charLen - numLen;
6373
- const minWidth = fs * (charLen * 1.1 + numLen * 0.65 + otherLen * 0.5) + 32 + (attr.sortable ? 24 : 0);
6374
- attr["min-width"] = String(minWidth) + "px";
6384
+ attr["min-width"] = String(getMinWidth(item)) + "px";
6385
+ }
6386
+ if (init && props.dragCached) {
6387
+ const prop = item.prop || ((_a2 = item.attr) == null ? void 0 : _a2.prop);
6388
+ let columnWidth = CachedManager.syncCachedGet(`${props.storageKey}$drag-column-width`) || {};
6389
+ if (columnWidth[prop]) {
6390
+ attr.width = columnWidth[prop];
6391
+ }
6375
6392
  }
6376
6393
  item.attr = {
6377
6394
  ...item.attr,
@@ -6421,7 +6438,11 @@ __sfc_main.setup = (__props, __ctx) => {
6421
6438
  });
6422
6439
  elTableRefKey.value = Date.now();
6423
6440
  };
6424
- syncCookiesToTableColumn();
6441
+ const initColumn = async () => {
6442
+ await initCachedData();
6443
+ syncCookiesToTableColumn(true, true);
6444
+ };
6445
+ initColumn();
6425
6446
  onBeforeMount(() => {
6426
6447
  watch(() => {
6427
6448
  return props.columns;
@@ -6546,8 +6567,14 @@ __sfc_main.setup = (__props, __ctx) => {
6546
6567
  const headerDragend = async (newWidth, oldWidth, column, event) => {
6547
6568
  var _a2, _b;
6548
6569
  await nextTick();
6549
- if (newWidth < column.minWidth) {
6550
- column.width = column.minWidth;
6570
+ const minWidth = getMinWidth(column);
6571
+ if (newWidth < minWidth) {
6572
+ column.width = minWidth;
6573
+ }
6574
+ if (props.dragCached) {
6575
+ const columnCachedData = await CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`) || {};
6576
+ columnCachedData[column.property] = column.width;
6577
+ await CachedManager.asyncCachedSet(`${props.storageKey}$drag-column-width`, columnCachedData);
6551
6578
  }
6552
6579
  await ((_b = (_a2 = props.tableEvents)["header-dragend"]) == null ? void 0 : _b.call(_a2, newWidth, oldWidth, column, event));
6553
6580
  };
@@ -6831,33 +6858,13 @@ var _sfc_render = function render3() {
6831
6858
  "height": _vm.elTableHeight
6832
6859
  }
6833
6860
  }, "el-table", _vm.tableAttrer, false), _vm.tableEventer), [_vm._l(_vm.tableColumns, function(column) {
6834
- return [_vm.isShow(column) ? [column.type ? [column.render || column.prop || column.slot ? _c("el-table-column", _vm._b({
6835
- key: column.key || column.prop,
6836
- attrs: {
6837
- "type": column.type,
6838
- "label": column.label
6839
- },
6840
- scopedSlots: _vm._u([{
6841
- key: "default",
6842
- fn: function(scope) {
6843
- return [column.render ? _c("render-component", {
6844
- attrs: {
6845
- "render": column.render,
6846
- "row": scope.row
6847
- }
6848
- }) : [column.slot ? _vm._t(column.slot, null, {
6849
- "row": scope.row,
6850
- "index": scope.$index
6851
- }) : _c("span", [_vm._v(_vm._s(scope.row[column.prop]))])]];
6852
- }
6853
- }], null, true)
6854
- }, "el-table-column", column.attr, false)) : _c("el-table-column", _vm._b({
6855
- key: column.key || column.prop,
6861
+ return [_vm.isShow(column) ? [column.type ? _c("el-table-column", _vm._b({
6862
+ key: column.key || column.prop || column.type,
6856
6863
  attrs: {
6857
6864
  "type": column.type,
6858
6865
  "label": column.label
6859
6866
  }
6860
- }, "el-table-column", column.attr, false))] : [column.attr && column.attr.formatter ? _c("el-table-column", _vm._b({
6867
+ }, "el-table-column", column.attr, false)) : [column.attr && column.attr.formatter ? _c("el-table-column", _vm._b({
6861
6868
  key: column.key || column.prop,
6862
6869
  attrs: {
6863
6870
  "prop": column.prop,
@@ -49,6 +49,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
49
49
  type: import("vue-demi").PropType<string[]>;
50
50
  default: undefined;
51
51
  };
52
+ dragCached: {
53
+ type: import("vue-demi").PropType<boolean>;
54
+ default: boolean;
55
+ };
52
56
  emptyImageSize: {
53
57
  type: import("vue-demi").PropType<number>;
54
58
  default: number;
@@ -346,7 +350,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
346
350
  calcTableHeight: () => void;
347
351
  syncLocalShowColumnToCookies: () => void;
348
352
  syncCookiesToLocalShowColumn: () => Promise<void>;
349
- syncCookiesToTableColumn: (readCached?: boolean) => Promise<void>;
353
+ syncCookiesToTableColumn: (readCached?: boolean, init?: boolean) => Promise<void>;
350
354
  elTableRefKey: import("vue-demi").Ref<number>;
351
355
  }, {}, {}, {}, import("vue/types/v3-component-options").ComponentOptionsMixin, import("vue/types/v3-component-options").ComponentOptionsMixin, {
352
356
  fieldsChange: (event: string[]) => void;
@@ -400,6 +404,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
400
404
  type: import("vue-demi").PropType<string[]>;
401
405
  default: undefined;
402
406
  };
407
+ dragCached: {
408
+ type: import("vue-demi").PropType<boolean>;
409
+ default: boolean;
410
+ };
403
411
  emptyImageSize: {
404
412
  type: import("vue-demi").PropType<number>;
405
413
  default: number;
@@ -635,6 +643,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
635
643
  text: string;
636
644
  selectEmptyWarningTips: string;
637
645
  showColumn: string[];
646
+ dragCached: boolean;
638
647
  emptyImageSize: number;
639
648
  searchFormAttrs: NfSearchFormAttributes;
640
649
  searchFormEvents: Partial<Record<NfSearchFormEventKey, Function>>;
@@ -693,9 +702,6 @@ declare const _default: __VLS_WithTemplateSlots<import("vue-demi").DefineCompone
693
702
  slot: any;
694
703
  }) => any>> & Partial<Record<any, (_: {
695
704
  slot: any;
696
- }) => any>> & Partial<Record<any, (_: {
697
- row: any;
698
- index: any;
699
705
  }) => any>> & Partial<Record<any, (_: {}) => any>> & Partial<Record<any, (_: {
700
706
  $index: any;
701
707
  column: any;
@@ -53,20 +53,13 @@
53
53
  >
54
54
  <template v-for="column in tableColumns">
55
55
  <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>
56
+ <el-table-column
57
+ v-if="column.type"
58
+ :key="column.key || column.prop || column.type"
59
+ :type="column.type"
60
+ :label="column.label"
61
+ v-bind="column.attr"
62
+ />
70
63
  <template v-else>
71
64
  <el-table-column
72
65
  v-if="column.attr&&column.attr.formatter"
@@ -568,6 +561,7 @@ import { ITabItem } from '@94ai/nf-drawer/lib/types'
568
561
  import { CachedManager } from '@94ai/common-utils'
569
562
 
570
563
  const props = withDefaults(defineProps<{
564
+ dragCached?: boolean,
571
565
  emptyImageSize?: number,
572
566
  data?: Record<string, any>[],
573
567
  columns?: NfTableColumnAttributes[] | any,
@@ -669,6 +663,7 @@ const props = withDefaults(defineProps<{
669
663
  */
670
664
  operationPropKey?: string
671
665
  }>(), {
666
+ dragCached: true,
672
667
  emptyImageSize: 145,
673
668
  selectEmptyWarningTips: '请选择至少一个选项',
674
669
  priority: 'cached',
@@ -852,7 +847,7 @@ const syncLocalShowColumnToCookies = () => {
852
847
  index
853
848
  }
854
849
  })
855
- CachedManager.syncCachedSet(props.storageKey, columnState)
850
+ return CachedManager.syncCachedSet(props.storageKey, columnState)
856
851
  }
857
852
  }
858
853
 
@@ -906,40 +901,46 @@ const initCachedData = async () => {
906
901
  }
907
902
  const cachedPriority = props.priority === 'cached'
908
903
  if (cachedPriority ? cached : localShowColumn.value?.length) {
909
- cachedPriority ? await syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies()
904
+ cachedPriority ? await syncCookiesToLocalShowColumn() : await syncLocalShowColumnToCookies()
910
905
  } else if (cachedPriority ? localShowColumn.value?.length : cached) {
911
- cachedPriority ? syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn()
906
+ cachedPriority ? await syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn()
912
907
  }
913
908
  } catch (e) {
914
909
  console.log(e)
915
910
  }
916
911
  }
912
+ if (props.dragCached) {
913
+ await CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`)
914
+ }
917
915
  }
918
916
 
919
- initCachedData()
917
+ const getMinWidth = (column) => {
918
+ const fs = 14
919
+ const label = column.customLabel || column.label
920
+ const char = label.match(/[\u2E80-\u9FFF]/g)
921
+ const charLen = char ? char.length : 0
922
+ const num = label.match(/\d|\./g)
923
+ const numLen = num ? num.length : 0
924
+ const otherLen = label.length - charLen - numLen
925
+ return fs * (charLen * 1 + numLen * 0.7 + otherLen * 0.58) + 20 + (column.sortable ? 24 : 0)
926
+ }
920
927
 
921
928
  const tableColumns = ref<NfTableColumnAttributes[]>([])
922
929
  const elTableRefKey = ref(Date.now())
923
- const syncCookiesToTableColumn = async (readCached = true) => {
930
+ const syncCookiesToTableColumn = async (readCached = true, init = false) => {
924
931
  props.columns._skip = true
925
932
  const columns = props.columns!.map((item, index) => {
926
- const len = item.label?.length || 0
927
- const fz = 15 // 每个字大小,其实是每个字的比例值,大概会比字体大小差不多大一点,
928
933
  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
934
  // 区分中文、数字、其他字符
934
935
  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'
936
+ attr['min-width'] = String(getMinWidth(item)) + 'px'
937
+ }
938
+ if (init && props.dragCached) {
939
+ const prop = item.prop || item.attr?.prop
940
+ let columnWidth = CachedManager.syncCachedGet(`${props.storageKey}$drag-column-width`) || {}
941
+ if (columnWidth[prop]) { // 读取缓存
942
+ attr.width = columnWidth[prop]
943
+ }
943
944
  }
944
945
  item.attr = {
945
946
  ...item.attr,
@@ -988,8 +989,12 @@ const syncCookiesToTableColumn = async (readCached = true) => {
988
989
  })
989
990
  elTableRefKey.value = Date.now()
990
991
  }
992
+ const initColumn = async () => {
993
+ await initCachedData()
994
+ syncCookiesToTableColumn(true, true)
995
+ }
991
996
 
992
- syncCookiesToTableColumn()
997
+ initColumn()
993
998
 
994
999
  onBeforeMount(() => {
995
1000
  watch(() => {
@@ -1110,8 +1115,14 @@ const sort = (prop, order) => {
1110
1115
 
1111
1116
  const headerDragend = async (newWidth, oldWidth, column, event) => {
1112
1117
  await nextTick()
1113
- if (newWidth < column.minWidth) {
1114
- column.width = column.minWidth
1118
+ const minWidth = getMinWidth(column)
1119
+ if (newWidth < minWidth) {
1120
+ column.width = minWidth
1121
+ }
1122
+ if (props.dragCached) { // 记录缓存
1123
+ const columnCachedData = await CachedManager.asyncCachedGet(`${props.storageKey}$drag-column-width`) || {}
1124
+ columnCachedData[column.property] = column.width
1125
+ await CachedManager.asyncCachedSet(`${props.storageKey}$drag-column-width`, columnCachedData)
1115
1126
  }
1116
1127
  await props.tableEvents['header-dragend']?.(newWidth, oldWidth, column, event)
1117
1128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-table",
3
- "version": "100.1.38",
3
+ "version": "100.1.45",
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": "^100.1.38",
18
- "@94ai/nf-button": "^100.1.38",
19
- "@94ai/nf-drawer": "^100.1.38",
20
- "@94ai/nf-message": "^100.1.38",
21
- "@94ai/nf-search-form": "^100.1.38",
22
- "@94ai/nf-theme-chalk": "^100.1.38",
17
+ "@94ai/common-utils": "^100.1.45",
18
+ "@94ai/nf-button": "^100.1.45",
19
+ "@94ai/nf-drawer": "^100.1.45",
20
+ "@94ai/nf-message": "^100.1.45",
21
+ "@94ai/nf-search-form": "^100.1.45",
22
+ "@94ai/nf-theme-chalk": "^100.1.45",
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": "9096bb8873817d24de7693e5d6aaa2a307b04d53"
40
+ "gitHead": "4c5a85d5403ee4fb6bb5a1810f2b77235a5a842e"
41
41
  }