wkjp-list-page 1.0.25 → 1.0.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wkjp-list-page",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -120,12 +120,13 @@
120
120
  </template>
121
121
  </el-table-column>
122
122
  <el-table-column
123
- v-else-if="col.type !== 'slot' && isBuiltinCellColumn(col)"
123
+ v-else-if="isBuiltinCellColumn(col)"
124
124
  :key="'col-builtin-' + idx + '-' + col.type"
125
- v-bind="tableColumnBind(col)"
125
+ :type="col.type"
126
+ v-bind="builtinTableColumnBind(col)"
126
127
  />
127
128
  <el-table-column
128
- v-else-if="col.type !== 'slot'"
129
+ v-else-if="col.type !== 'slot' && !isBuiltinCellColumn(col)"
129
130
  :key="'col-' + idx + '-' + (col.prop || col.label)"
130
131
  v-bind="tableColumnBind(col)"
131
132
  >
@@ -666,66 +667,22 @@ export default {
666
667
  if (col.showInColumnConfig === false) return false;
667
668
  return true;
668
669
  },
670
+ /** 估算展示宽度:中文等宽字符按 2 计,避免表头所需宽度被低估 */
669
671
  textDisplayLength(text) {
670
- return String(text == null ? "" : text).length;
671
- },
672
- /** 折算列宽用的「显示宽度单位」:中文等宽字符 1,ASCII 约 0.6 */
673
- textDisplayWidthUnits(text) {
674
672
  var s = String(text == null ? "" : text);
675
- var units = 0;
673
+ var len = 0;
676
674
  for (var i = 0; i < s.length; i++) {
677
- units += s.charCodeAt(i) > 255 ? 1 : 0.6;
675
+ len += s.charCodeAt(i) > 255 ? 2 : 1;
678
676
  }
679
- return units;
680
- },
681
- getColumnLabelText(col) {
682
- return (col && (col.label || col.prop || col.slot)) || "";
677
+ return len;
683
678
  },
684
679
  columnOverflowThreshold() {
685
680
  var n = Number(this.columnOverflowTooltipChars);
686
681
  return Number.isFinite(n) && n > 0 ? Math.floor(n) : 20;
687
682
  },
688
- getColumnAutoWidthMetrics() {
689
- var charPx = Number(this.columnAutoWidthCharPx);
690
- var pad = Number(this.columnAutoWidthPadding);
691
- if (!Number.isFinite(charPx) || charPx <= 0) charPx = 14;
692
- if (!Number.isFinite(pad) || pad < 0) pad = 24;
693
- return {
694
- charPx: charPx,
695
- pad: pad,
696
- headerCharPx: charPx * 1.08,
697
- headerPad: Math.max(pad, 48)
698
- };
699
- },
700
- estimateColumnWidthPx(units, charPx, paddingPx) {
701
- var u = Number(units);
702
- if (!Number.isFinite(u) || u <= 0) u = 1;
703
- return Math.ceil(u * charPx + paddingPx);
704
- },
705
- /** 表头文案折算的最小列宽(不参与内容超长封顶) */
706
- getColumnHeaderMinWidthPx(col) {
707
- var metrics = this.getColumnAutoWidthMetrics();
708
- var labelUnits = this.textDisplayWidthUnits(this.getColumnLabelText(col));
709
- return this.estimateColumnWidthPx(labelUnits, metrics.headerCharPx, metrics.headerPad);
710
- },
711
- /** 当前页单元格内容折算的最小列宽(超长按 threshold 封顶,仅影响内容侧) */
712
- getColumnContentMinWidthPx(col) {
713
- if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) return 0;
714
- var metrics = this.getColumnAutoWidthMetrics();
715
- var maxCellUnits = 0;
716
- var rows = this.innerTableData || [];
717
- for (var i = 0; i < rows.length; i++) {
718
- var text = this.resolveCellText(col, rows[i], i);
719
- maxCellUnits = Math.max(maxCellUnits, this.textDisplayWidthUnits(text));
720
- }
721
- var threshold = this.columnOverflowThreshold();
722
- var contentUnits =
723
- maxCellUnits > threshold ? threshold : Math.max(maxCellUnits, 1);
724
- return this.estimateColumnWidthPx(contentUnits, metrics.charPx, metrics.pad);
725
- },
726
- /** 表头 + 当前页数据中最长展示文本的字符数(slot 列仅表头;用于 tooltip 判断) */
683
+ /** 表头 + 当前页数据中最长展示文本的字符数(slot 列仅表头) */
727
684
  getColumnMaxContentLength(col) {
728
- var labelLen = this.textDisplayLength(this.getColumnLabelText(col));
685
+ var labelLen = this.textDisplayLength((col && (col.label || col.prop || col.slot)) || "");
729
686
  if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) {
730
687
  return labelLen;
731
688
  }
@@ -737,35 +694,55 @@ export default {
737
694
  }
738
695
  return Math.max(labelLen, maxCell);
739
696
  },
697
+ /** 按字符数折算列最小像素宽(表头 + 单元格共用) */
698
+ columnWidthFromCharCount(charCount) {
699
+ var threshold = this.columnOverflowThreshold();
700
+ var widthChars =
701
+ charCount > threshold ? threshold : Math.max(charCount, 1);
702
+ var charPx = Number(this.columnAutoWidthCharPx);
703
+ var pad = Number(this.columnAutoWidthPadding);
704
+ if (!Number.isFinite(charPx) || charPx <= 0) charPx = 14;
705
+ if (!Number.isFinite(pad) || pad < 0) pad = 24;
706
+ var minW = Number(this.columnAutoMinWidth);
707
+ if (!Number.isFinite(minW) || minW <= 0) minW = 100;
708
+ return Math.max(minW, Math.ceil(widthChars * charPx + pad));
709
+ },
740
710
  resolveAutoColumnLayout(col) {
741
711
  if (!col) return {};
712
+ var maxLen = this.getColumnMaxContentLength(col);
713
+ var labelLen = this.textDisplayLength(
714
+ (col && (col.label || col.prop || col.slot)) || "",
715
+ );
716
+ var requiredMinWidth = Math.max(
717
+ this.columnWidthFromCharCount(maxLen),
718
+ this.columnWidthFromCharCount(labelLen),
719
+ );
742
720
  var hasWidth = col.width != null && col.width !== "";
743
721
  var hasMinWidth = col.minWidth != null && col.minWidth !== "";
744
- var headerMinWidth = this.getColumnHeaderMinWidthPx(col);
745
722
  var layout = {};
746
- if (hasMinWidth) {
747
- var explicitMin = Number(col.minWidth);
748
- if (Number.isFinite(explicitMin) && explicitMin < headerMinWidth) {
749
- layout.minWidth = headerMinWidth;
750
- }
751
- }
723
+
752
724
  if (hasWidth || hasMinWidth) {
725
+ var explicitPx = hasWidth ? Number(col.width) : Number(col.minWidth);
726
+ if (Number.isFinite(explicitPx) && explicitPx > 0 && explicitPx < requiredMinWidth) {
727
+ if (hasWidth) layout.width = requiredMinWidth;
728
+ layout.minWidth = requiredMinWidth;
729
+ } else if (hasMinWidth) {
730
+ var minPx = Number(col.minWidth);
731
+ if (Number.isFinite(minPx) && minPx < requiredMinWidth) {
732
+ layout.minWidth = requiredMinWidth;
733
+ }
734
+ }
753
735
  if (col.showOverflowTooltip !== undefined && col.showOverflowTooltip !== null) {
754
736
  return layout;
755
737
  }
756
- var maxLenExplicit = this.getColumnMaxContentLength(col);
757
- if (maxLenExplicit > this.columnOverflowThreshold()) {
738
+ if (maxLen > this.columnOverflowThreshold()) {
758
739
  layout.showOverflowTooltip = true;
759
740
  }
760
741
  return layout;
761
742
  }
762
- var maxLen = this.getColumnMaxContentLength(col);
763
- var threshold = this.columnOverflowThreshold();
764
- var contentMinWidth = this.getColumnContentMinWidthPx(col);
765
- var minW = Number(this.columnAutoMinWidth);
766
- if (!Number.isFinite(minW) || minW <= 0) minW = 100;
767
- layout.minWidth = Math.max(minW, headerMinWidth, contentMinWidth);
768
- if (maxLen > threshold) {
743
+
744
+ layout.minWidth = requiredMinWidth;
745
+ if (maxLen > this.columnOverflowThreshold()) {
769
746
  layout.showOverflowTooltip = true;
770
747
  } else if (col.showOverflowTooltip === true) {
771
748
  layout.showOverflowTooltip = true;
@@ -780,6 +757,15 @@ export default {
780
757
  });
781
758
  return Object.assign({}, rest, this.resolveAutoColumnLayout(col));
782
759
  },
760
+ /** selection / index / expand:type 须单独绑定,避免与数据列空值模板叠加出 `--` */
761
+ builtinTableColumnBind(col) {
762
+ var bind = this.tableColumnBind(col || {});
763
+ delete bind.type;
764
+ if (col && col.type === "index" && col.index != null) {
765
+ bind.index = col.index;
766
+ }
767
+ return bind;
768
+ },
783
769
  searchItemKey(item, index) {
784
770
  const id = item && (item.slot || item.prop || item.type || "");
785
771
  return "search-" + id + "-" + index;
@@ -955,6 +941,7 @@ export default {
955
941
  return display === null || display === undefined || display === "";
956
942
  },
957
943
  resolveCellText(col, row, index) {
944
+ if (this.isBuiltinCellColumn(col)) return "";
958
945
  const raw = typeof col.valueGetter === "function" ? col.valueGetter(row, index) : row[col.prop];
959
946
  let display;
960
947
  if (typeof col.textFormatter === "function") {
@@ -1744,8 +1731,9 @@ export default {
1744
1731
  color: #606266;
1745
1732
  border: none !important;
1746
1733
  border-radius: 2px;
1747
- outline: 1px solid #ebeef5;
1748
- outline-offset: -1px;
1734
+ /* 用 inset 描边代替 outline,避免圆角与 outline-offset 在左上角出现 1px 杂点 */
1735
+ outline: none;
1736
+ box-shadow: inset 0 0 0 1px #ebeef5;
1749
1737
  }
1750
1738
 
1751
1739
  .common-list-page /deep/ .el-table::before,
@@ -1787,6 +1775,10 @@ export default {
1787
1775
  border-bottom: 1px solid #ebeef5 !important;
1788
1776
  }
1789
1777
 
1778
+ .common-list-page /deep/ .el-table th.el-table__cell .cell {
1779
+ white-space: nowrap;
1780
+ }
1781
+
1790
1782
  .common-list-page /deep/ .el-table td.el-table__cell {
1791
1783
  padding: 10px 12px;
1792
1784
  border-bottom: 1px solid #f0f2f5 !important;