wkjp-list-page 1.0.18 → 1.0.20

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
 
@@ -325,10 +329,12 @@ deviceListTransformList(list) {
325
329
  ## 6. columns 列(常用)
326
330
 
327
331
  非 `slot` 列会 **透传** 到 `el-table-column`(`prop`、`label`、`width`、`fixed` 等)。
328
- 内置列类型 **`selection` / `index` / `expand`** 不做自定义单元格包装。
332
+ 内置列类型 **`selection` / `index`** 不做自定义单元格包装;**`expand`** 可写 **`type: 'expand'` + `slot`**,用父组件具名插槽渲染展开行内容。
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.20",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -109,7 +109,17 @@
109
109
  >
110
110
  <template v-for="(col, idx) in visibleColumns">
111
111
  <el-table-column
112
- v-if="col.type !== 'slot' && isBuiltinCellColumn(col)"
112
+ v-if="col.type === 'expand' && col.slot"
113
+ :key="'col-expand-' + idx + '-' + col.slot"
114
+ type="expand"
115
+ v-bind="tableColumnBind(omitExpandSlotMeta(col))"
116
+ >
117
+ <template slot-scope="scope">
118
+ <slot :name="col.slot" :row="scope.row" :scope="scope"></slot>
119
+ </template>
120
+ </el-table-column>
121
+ <el-table-column
122
+ v-else-if="col.type !== 'slot' && isBuiltinCellColumn(col)"
113
123
  :key="'col-builtin-' + idx + '-' + col.type"
114
124
  v-bind="tableColumnBind(col)"
115
125
  />
@@ -361,7 +371,18 @@ export default {
361
371
  /** 导出前校验:`(querys) => boolean`,返回 `false` 则中止导出 */
362
372
  exportBefore: { type: Function, default: null },
363
373
  /** 与列表当前 `total` 比较,超出则提示不导出;不传则不限制 */
364
- exportMaxLimit: { type: Number, default: null }
374
+ exportMaxLimit: { type: Number, default: null },
375
+ /**
376
+ * 未在列上写 `width` / `minWidth` 时,按表头与当前页单元格内容估算列宽;
377
+ * 内容最长超过该字符数则固定按该字数算宽并开启 `showOverflowTooltip`。
378
+ */
379
+ columnOverflowTooltipChars: { type: Number, default: 20 },
380
+ /** 自动列宽:每字符折算像素(12px 字号下约 12~14) */
381
+ columnAutoWidthCharPx: { type: Number, default: 14 },
382
+ /** 自动列宽:单元格左右内边距等额外宽度 */
383
+ columnAutoWidthPadding: { type: Number, default: 24 },
384
+ /** 自动列宽:未写 width / minWidth 时的默认最小宽度(px) */
385
+ columnAutoMinWidth: { type: Number, default: 100 }
365
386
  },
366
387
  data() {
367
388
  return {
@@ -592,13 +613,66 @@ export default {
592
613
  isConfigPanelColumn(col) {
593
614
  return col && col.type !== "selection";
594
615
  },
616
+ textDisplayLength(text) {
617
+ return String(text == null ? "" : text).length;
618
+ },
619
+ columnOverflowThreshold() {
620
+ var n = Number(this.columnOverflowTooltipChars);
621
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : 20;
622
+ },
623
+ /** 表头 + 当前页数据中最长展示文本的字符数(slot 列仅表头) */
624
+ getColumnMaxContentLength(col) {
625
+ var labelLen = this.textDisplayLength((col && (col.label || col.prop || col.slot)) || "");
626
+ if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) {
627
+ return labelLen;
628
+ }
629
+ var maxCell = 0;
630
+ var rows = this.innerTableData || [];
631
+ for (var i = 0; i < rows.length; i++) {
632
+ var text = this.resolveCellText(col, rows[i], i);
633
+ maxCell = Math.max(maxCell, this.textDisplayLength(text));
634
+ }
635
+ return Math.max(labelLen, maxCell);
636
+ },
637
+ resolveAutoColumnLayout(col) {
638
+ if (!col) return {};
639
+ var hasWidth = col.width != null && col.width !== "";
640
+ var hasMinWidth = col.minWidth != null && col.minWidth !== "";
641
+ if (hasWidth || hasMinWidth) {
642
+ if (col.showOverflowTooltip !== undefined && col.showOverflowTooltip !== null) {
643
+ return {};
644
+ }
645
+ var maxLenExplicit = this.getColumnMaxContentLength(col);
646
+ return maxLenExplicit > this.columnOverflowThreshold()
647
+ ? { showOverflowTooltip: true }
648
+ : {};
649
+ }
650
+ var maxLen = this.getColumnMaxContentLength(col);
651
+ var threshold = this.columnOverflowThreshold();
652
+ var widthChars = maxLen > threshold ? threshold : Math.max(maxLen, 1);
653
+ var charPx = Number(this.columnAutoWidthCharPx);
654
+ var pad = Number(this.columnAutoWidthPadding);
655
+ if (!Number.isFinite(charPx) || charPx <= 0) charPx = 14;
656
+ if (!Number.isFinite(pad) || pad < 0) pad = 24;
657
+ var minW = Number(this.columnAutoMinWidth);
658
+ if (!Number.isFinite(minW) || minW <= 0) minW = 100;
659
+ var layout = {
660
+ minWidth: Math.max(minW, Math.ceil(widthChars * charPx + pad))
661
+ };
662
+ if (maxLen > threshold) {
663
+ layout.showOverflowTooltip = true;
664
+ } else if (col.showOverflowTooltip === true) {
665
+ layout.showOverflowTooltip = true;
666
+ }
667
+ return layout;
668
+ },
595
669
  tableColumnBind(col) {
596
670
  var omit = ["valueGetter", "textFormatter", "defaultText", "emptyText", "hidden", "_visible", "_configKey"];
597
671
  var rest = {};
598
672
  Object.keys(col || {}).forEach(function (k) {
599
673
  if (omit.indexOf(k) === -1) rest[k] = col[k];
600
674
  });
601
- return rest;
675
+ return Object.assign({}, rest, this.resolveAutoColumnLayout(col));
602
676
  },
603
677
  searchItemKey(item, index) {
604
678
  const id = item && (item.slot || item.prop || item.type || "");
@@ -765,6 +839,11 @@ export default {
765
839
  }
766
840
  return display;
767
841
  },
842
+ omitExpandSlotMeta(col) {
843
+ const rest = Object.assign({}, col);
844
+ delete rest.slot;
845
+ return rest;
846
+ },
768
847
  omitSlotType(col) {
769
848
  const rest = Object.assign({}, col);
770
849
  delete rest.type;
@@ -773,7 +852,7 @@ export default {
773
852
  delete rest.textFormatter;
774
853
  delete rest.defaultText;
775
854
  delete rest.emptyText;
776
- return rest;
855
+ return Object.assign({}, rest, this.resolveAutoColumnLayout(col));
777
856
  },
778
857
  handleSizeChange(size) {
779
858
  this.innerPagination.pageSize = size;