wkjp-list-page 1.0.24 → 1.0.25

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.24",
3
+ "version": "1.0.25",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -669,13 +669,63 @@ export default {
669
669
  textDisplayLength(text) {
670
670
  return String(text == null ? "" : text).length;
671
671
  },
672
+ /** 折算列宽用的「显示宽度单位」:中文等宽字符 1,ASCII 约 0.6 */
673
+ textDisplayWidthUnits(text) {
674
+ var s = String(text == null ? "" : text);
675
+ var units = 0;
676
+ for (var i = 0; i < s.length; i++) {
677
+ units += s.charCodeAt(i) > 255 ? 1 : 0.6;
678
+ }
679
+ return units;
680
+ },
681
+ getColumnLabelText(col) {
682
+ return (col && (col.label || col.prop || col.slot)) || "";
683
+ },
672
684
  columnOverflowThreshold() {
673
685
  var n = Number(this.columnOverflowTooltipChars);
674
686
  return Number.isFinite(n) && n > 0 ? Math.floor(n) : 20;
675
687
  },
676
- /** 表头 + 当前页数据中最长展示文本的字符数(slot 列仅表头) */
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 判断) */
677
727
  getColumnMaxContentLength(col) {
678
- var labelLen = this.textDisplayLength((col && (col.label || col.prop || col.slot)) || "");
728
+ var labelLen = this.textDisplayLength(this.getColumnLabelText(col));
679
729
  if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) {
680
730
  return labelLen;
681
731
  }
@@ -691,27 +741,30 @@ export default {
691
741
  if (!col) return {};
692
742
  var hasWidth = col.width != null && col.width !== "";
693
743
  var hasMinWidth = col.minWidth != null && col.minWidth !== "";
744
+ var headerMinWidth = this.getColumnHeaderMinWidthPx(col);
745
+ var layout = {};
746
+ if (hasMinWidth) {
747
+ var explicitMin = Number(col.minWidth);
748
+ if (Number.isFinite(explicitMin) && explicitMin < headerMinWidth) {
749
+ layout.minWidth = headerMinWidth;
750
+ }
751
+ }
694
752
  if (hasWidth || hasMinWidth) {
695
753
  if (col.showOverflowTooltip !== undefined && col.showOverflowTooltip !== null) {
696
- return {};
754
+ return layout;
697
755
  }
698
756
  var maxLenExplicit = this.getColumnMaxContentLength(col);
699
- return maxLenExplicit > this.columnOverflowThreshold()
700
- ? { showOverflowTooltip: true }
701
- : {};
757
+ if (maxLenExplicit > this.columnOverflowThreshold()) {
758
+ layout.showOverflowTooltip = true;
759
+ }
760
+ return layout;
702
761
  }
703
762
  var maxLen = this.getColumnMaxContentLength(col);
704
763
  var threshold = this.columnOverflowThreshold();
705
- var widthChars = maxLen > threshold ? threshold : Math.max(maxLen, 1);
706
- var charPx = Number(this.columnAutoWidthCharPx);
707
- var pad = Number(this.columnAutoWidthPadding);
708
- if (!Number.isFinite(charPx) || charPx <= 0) charPx = 14;
709
- if (!Number.isFinite(pad) || pad < 0) pad = 24;
764
+ var contentMinWidth = this.getColumnContentMinWidthPx(col);
710
765
  var minW = Number(this.columnAutoMinWidth);
711
766
  if (!Number.isFinite(minW) || minW <= 0) minW = 100;
712
- var layout = {
713
- minWidth: Math.max(minW, Math.ceil(widthChars * charPx + pad))
714
- };
767
+ layout.minWidth = Math.max(minW, headerMinWidth, contentMinWidth);
715
768
  if (maxLen > threshold) {
716
769
  layout.showOverflowTooltip = true;
717
770
  } else if (col.showOverflowTooltip === true) {