wkjp-list-page 1.0.18 → 1.0.19

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/README.md CHANGED
@@ -301,6 +301,10 @@ deviceListTransformList(list) {
301
301
  | `collapseSearch` | (未传) | 未传时 **`searchOption.length > searchVisibleMax`** 自动折叠;`true` / `false` 强制开/关。 |
302
302
  | `searchVisibleMax` | `null` | 折叠时默认展示条数,**未传按 6**;查询项 **超过** 该值时出现「展开查询」;显式传 ≤0 则不折叠。 |
303
303
  | `expandSearchText` / `foldSearchText` | 展开查询 / 收起 | 折叠按钮文案。 |
304
+ | `columnOverflowTooltipChars` | `20` | 自动列宽:内容超过该字符数时按该字数定宽并 `show-overflow-tooltip`。 |
305
+ | `columnAutoWidthCharPx` | `14` | 自动列宽每字符折算像素。 |
306
+ | `columnAutoWidthPadding` | `24` | 自动列宽额外内边距像素。 |
307
+ | `columnAutoMinWidth` | `100` | 自动列宽默认最小宽度(px)。 |
304
308
 
305
309
  ---
306
310
 
@@ -329,6 +333,8 @@ deviceListTransformList(list) {
329
333
 
330
334
  最简写法:**`{ prop: 'name', label: '姓名' }`**,值为 `null` / `undefined` / `''`(以及 `textFormatter` 得到空串)时,默认显示 **`--`**;表格上 **`cell-empty-text`** 可改全局占位;列上 **`emptyText`**(优先)或 **`defaultText`** 可单独改该列。
331
335
 
336
+ **列宽(默认):** 列上 **未写 `width` / `minWidth`** 时,按 **表头文案** 与 **当前页单元格展示内容**(含 `valueGetter` / `textFormatter`)取最长字符数估算 **`minWidth`**,且不低于 **`column-auto-min-width`(默认 100px)**;**超过 20 个字符**(可用 **`column-overflow-tooltip-chars`** 改)时按 20 字折算,并自动 **`show-overflow-tooltip`**。已写 `width` / `minWidth` 的列不自动改宽,但若未写 `showOverflowTooltip` 且内容仍超阈值,会自动开 tooltip。`slot` 列无单元格文本时仅按表头估算。
337
+
332
338
  | 字段 | 说明 |
333
339
  |------|------|
334
340
  | `type: 'slot'` + `slot` | 自定义列,父组件具名插槽。 |
@@ -336,6 +342,8 @@ deviceListTransformList(list) {
336
342
  | `valueGetter` | `(row, index) => any`,取展示用原始值(不填则用 `row[prop]`)。 |
337
343
  | `textFormatter` | `(value, row, index) => any`,格式化后若为空仍走空值占位。 |
338
344
  | `emptyText` / `defaultText` | 空值时显示文案;**`emptyText` 优先**;都不设则用 **`cell-empty-text`**(默认 `--`)。 |
345
+ | `width` / `minWidth` | 显式指定后不再自动算宽;仍可配合上面的 tooltip 规则。 |
346
+ | `showOverflowTooltip` | 显式 `true` / `false` 时优先于自动规则。 |
339
347
 
340
348
  ---
341
349
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wkjp-list-page",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -361,7 +361,18 @@ export default {
361
361
  /** 导出前校验:`(querys) => boolean`,返回 `false` 则中止导出 */
362
362
  exportBefore: { type: Function, default: null },
363
363
  /** 与列表当前 `total` 比较,超出则提示不导出;不传则不限制 */
364
- exportMaxLimit: { type: Number, default: null }
364
+ exportMaxLimit: { type: Number, default: null },
365
+ /**
366
+ * 未在列上写 `width` / `minWidth` 时,按表头与当前页单元格内容估算列宽;
367
+ * 内容最长超过该字符数则固定按该字数算宽并开启 `showOverflowTooltip`。
368
+ */
369
+ columnOverflowTooltipChars: { type: Number, default: 20 },
370
+ /** 自动列宽:每字符折算像素(12px 字号下约 12~14) */
371
+ columnAutoWidthCharPx: { type: Number, default: 14 },
372
+ /** 自动列宽:单元格左右内边距等额外宽度 */
373
+ columnAutoWidthPadding: { type: Number, default: 24 },
374
+ /** 自动列宽:未写 width / minWidth 时的默认最小宽度(px) */
375
+ columnAutoMinWidth: { type: Number, default: 100 }
365
376
  },
366
377
  data() {
367
378
  return {
@@ -592,13 +603,66 @@ export default {
592
603
  isConfigPanelColumn(col) {
593
604
  return col && col.type !== "selection";
594
605
  },
606
+ textDisplayLength(text) {
607
+ return String(text == null ? "" : text).length;
608
+ },
609
+ columnOverflowThreshold() {
610
+ var n = Number(this.columnOverflowTooltipChars);
611
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : 20;
612
+ },
613
+ /** 表头 + 当前页数据中最长展示文本的字符数(slot 列仅表头) */
614
+ getColumnMaxContentLength(col) {
615
+ var labelLen = this.textDisplayLength((col && (col.label || col.prop || col.slot)) || "");
616
+ if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) {
617
+ return labelLen;
618
+ }
619
+ var maxCell = 0;
620
+ var rows = this.innerTableData || [];
621
+ for (var i = 0; i < rows.length; i++) {
622
+ var text = this.resolveCellText(col, rows[i], i);
623
+ maxCell = Math.max(maxCell, this.textDisplayLength(text));
624
+ }
625
+ return Math.max(labelLen, maxCell);
626
+ },
627
+ resolveAutoColumnLayout(col) {
628
+ if (!col) return {};
629
+ var hasWidth = col.width != null && col.width !== "";
630
+ var hasMinWidth = col.minWidth != null && col.minWidth !== "";
631
+ if (hasWidth || hasMinWidth) {
632
+ if (col.showOverflowTooltip !== undefined && col.showOverflowTooltip !== null) {
633
+ return {};
634
+ }
635
+ var maxLenExplicit = this.getColumnMaxContentLength(col);
636
+ return maxLenExplicit > this.columnOverflowThreshold()
637
+ ? { showOverflowTooltip: true }
638
+ : {};
639
+ }
640
+ var maxLen = this.getColumnMaxContentLength(col);
641
+ var threshold = this.columnOverflowThreshold();
642
+ var widthChars = maxLen > threshold ? threshold : Math.max(maxLen, 1);
643
+ var charPx = Number(this.columnAutoWidthCharPx);
644
+ var pad = Number(this.columnAutoWidthPadding);
645
+ if (!Number.isFinite(charPx) || charPx <= 0) charPx = 14;
646
+ if (!Number.isFinite(pad) || pad < 0) pad = 24;
647
+ var minW = Number(this.columnAutoMinWidth);
648
+ if (!Number.isFinite(minW) || minW <= 0) minW = 100;
649
+ var layout = {
650
+ minWidth: Math.max(minW, Math.ceil(widthChars * charPx + pad))
651
+ };
652
+ if (maxLen > threshold) {
653
+ layout.showOverflowTooltip = true;
654
+ } else if (col.showOverflowTooltip === true) {
655
+ layout.showOverflowTooltip = true;
656
+ }
657
+ return layout;
658
+ },
595
659
  tableColumnBind(col) {
596
660
  var omit = ["valueGetter", "textFormatter", "defaultText", "emptyText", "hidden", "_visible", "_configKey"];
597
661
  var rest = {};
598
662
  Object.keys(col || {}).forEach(function (k) {
599
663
  if (omit.indexOf(k) === -1) rest[k] = col[k];
600
664
  });
601
- return rest;
665
+ return Object.assign({}, rest, this.resolveAutoColumnLayout(col));
602
666
  },
603
667
  searchItemKey(item, index) {
604
668
  const id = item && (item.slot || item.prop || item.type || "");
@@ -773,7 +837,7 @@ export default {
773
837
  delete rest.textFormatter;
774
838
  delete rest.defaultText;
775
839
  delete rest.emptyText;
776
- return rest;
840
+ return Object.assign({}, rest, this.resolveAutoColumnLayout(col));
777
841
  },
778
842
  handleSizeChange(size) {
779
843
  this.innerPagination.pageSize = size;