wkjp-list-page 1.0.24 → 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.24",
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,8 +667,14 @@ 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;
672
+ var s = String(text == null ? "" : text);
673
+ var len = 0;
674
+ for (var i = 0; i < s.length; i++) {
675
+ len += s.charCodeAt(i) > 255 ? 2 : 1;
676
+ }
677
+ return len;
671
678
  },
672
679
  columnOverflowThreshold() {
673
680
  var n = Number(this.columnOverflowTooltipChars);
@@ -687,32 +694,55 @@ export default {
687
694
  }
688
695
  return Math.max(labelLen, maxCell);
689
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
+ },
690
710
  resolveAutoColumnLayout(col) {
691
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
+ );
692
720
  var hasWidth = col.width != null && col.width !== "";
693
721
  var hasMinWidth = col.minWidth != null && col.minWidth !== "";
722
+ var layout = {};
723
+
694
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
+ }
695
735
  if (col.showOverflowTooltip !== undefined && col.showOverflowTooltip !== null) {
696
- return {};
736
+ return layout;
737
+ }
738
+ if (maxLen > this.columnOverflowThreshold()) {
739
+ layout.showOverflowTooltip = true;
697
740
  }
698
- var maxLenExplicit = this.getColumnMaxContentLength(col);
699
- return maxLenExplicit > this.columnOverflowThreshold()
700
- ? { showOverflowTooltip: true }
701
- : {};
741
+ return layout;
702
742
  }
703
- var maxLen = this.getColumnMaxContentLength(col);
704
- 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;
710
- var minW = Number(this.columnAutoMinWidth);
711
- if (!Number.isFinite(minW) || minW <= 0) minW = 100;
712
- var layout = {
713
- minWidth: Math.max(minW, Math.ceil(widthChars * charPx + pad))
714
- };
715
- if (maxLen > threshold) {
743
+
744
+ layout.minWidth = requiredMinWidth;
745
+ if (maxLen > this.columnOverflowThreshold()) {
716
746
  layout.showOverflowTooltip = true;
717
747
  } else if (col.showOverflowTooltip === true) {
718
748
  layout.showOverflowTooltip = true;
@@ -727,6 +757,15 @@ export default {
727
757
  });
728
758
  return Object.assign({}, rest, this.resolveAutoColumnLayout(col));
729
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
+ },
730
769
  searchItemKey(item, index) {
731
770
  const id = item && (item.slot || item.prop || item.type || "");
732
771
  return "search-" + id + "-" + index;
@@ -902,6 +941,7 @@ export default {
902
941
  return display === null || display === undefined || display === "";
903
942
  },
904
943
  resolveCellText(col, row, index) {
944
+ if (this.isBuiltinCellColumn(col)) return "";
905
945
  const raw = typeof col.valueGetter === "function" ? col.valueGetter(row, index) : row[col.prop];
906
946
  let display;
907
947
  if (typeof col.textFormatter === "function") {
@@ -1691,8 +1731,9 @@ export default {
1691
1731
  color: #606266;
1692
1732
  border: none !important;
1693
1733
  border-radius: 2px;
1694
- outline: 1px solid #ebeef5;
1695
- outline-offset: -1px;
1734
+ /* 用 inset 描边代替 outline,避免圆角与 outline-offset 在左上角出现 1px 杂点 */
1735
+ outline: none;
1736
+ box-shadow: inset 0 0 0 1px #ebeef5;
1696
1737
  }
1697
1738
 
1698
1739
  .common-list-page /deep/ .el-table::before,
@@ -1734,6 +1775,10 @@ export default {
1734
1775
  border-bottom: 1px solid #ebeef5 !important;
1735
1776
  }
1736
1777
 
1778
+ .common-list-page /deep/ .el-table th.el-table__cell .cell {
1779
+ white-space: nowrap;
1780
+ }
1781
+
1737
1782
  .common-list-page /deep/ .el-table td.el-table__cell {
1738
1783
  padding: 10px 12px;
1739
1784
  border-bottom: 1px solid #f0f2f5 !important;