wkjp-list-page 1.0.35 → 1.0.36
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
|
@@ -765,6 +765,56 @@ export default {
|
|
|
765
765
|
}
|
|
766
766
|
return length;
|
|
767
767
|
},
|
|
768
|
+
// 判断文本是否需要显示省略号
|
|
769
|
+
// 中文字符:超过20个字符宽度单位(约10个中文字)
|
|
770
|
+
// 英文字母/数字:超过40个字符宽度单位(约40个英文字母/数字)
|
|
771
|
+
shouldShowOverflowTooltip(text) {
|
|
772
|
+
var str = String(text == null ? "" : text);
|
|
773
|
+
var fullWidthCount = 0; // 全角字符计数
|
|
774
|
+
var halfWidthCount = 0; // 半角字符计数
|
|
775
|
+
|
|
776
|
+
for (var i = 0; i < str.length; i++) {
|
|
777
|
+
var charCode = str.charCodeAt(i);
|
|
778
|
+
if (
|
|
779
|
+
(charCode >= 0x4E00 && charCode <= 0x9FFF) || // 中文
|
|
780
|
+
(charCode >= 0x3000 && charCode <= 0x303F) || // CJK符号和标点
|
|
781
|
+
(charCode >= 0xFF00 && charCode <= 0xFFEF) // 全角字符
|
|
782
|
+
) {
|
|
783
|
+
fullWidthCount++;
|
|
784
|
+
} else {
|
|
785
|
+
halfWidthCount++;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// 计算总宽度单位:全角字符*2 + 半角字符*1
|
|
790
|
+
var totalWidth = fullWidthCount * 2 + halfWidthCount;
|
|
791
|
+
|
|
792
|
+
// 如果包含全角字符,使用20个宽度单位的阈值
|
|
793
|
+
// 如果只有半角字符,使用40个宽度单位的阈值
|
|
794
|
+
var threshold = fullWidthCount > 0 ? 20 : 40;
|
|
795
|
+
|
|
796
|
+
return totalWidth > threshold;
|
|
797
|
+
},
|
|
798
|
+
// 根据字符类型获取动态阈值
|
|
799
|
+
getDynamicThreshold(text) {
|
|
800
|
+
var str = String(text == null ? "" : text);
|
|
801
|
+
var fullWidthCount = 0; // 全角字符计数
|
|
802
|
+
|
|
803
|
+
for (var i = 0; i < str.length; i++) {
|
|
804
|
+
var charCode = str.charCodeAt(i);
|
|
805
|
+
if (
|
|
806
|
+
(charCode >= 0x4E00 && charCode <= 0x9FFF) || // 中文
|
|
807
|
+
(charCode >= 0x3000 && charCode <= 0x303F) || // CJK符号和标点
|
|
808
|
+
(charCode >= 0xFF00 && charCode <= 0xFFEF) // 全角字符
|
|
809
|
+
) {
|
|
810
|
+
fullWidthCount++;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// 如果包含全角字符,使用20个宽度单位的阈值
|
|
815
|
+
// 如果只有半角字符,使用40个宽度单位的阈值
|
|
816
|
+
return fullWidthCount > 0 ? 20 : 40;
|
|
817
|
+
},
|
|
768
818
|
columnOverflowThreshold() {
|
|
769
819
|
var n = Number(this.columnOverflowTooltipChars);
|
|
770
820
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 20;
|
|
@@ -790,6 +840,40 @@ export default {
|
|
|
790
840
|
}
|
|
791
841
|
return Math.max(labelLen, maxCell);
|
|
792
842
|
},
|
|
843
|
+
/** 获取列中最长内容的字符串 */
|
|
844
|
+
getColumnMaxContentText(col) {
|
|
845
|
+
var labelText = (col && (col.label || col.prop || col.slot)) || "";
|
|
846
|
+
var maxText = labelText;
|
|
847
|
+
var maxLength = this.textDisplayLength(labelText);
|
|
848
|
+
|
|
849
|
+
if (col && col.children && col.children.length) {
|
|
850
|
+
// 对于嵌套列,返回子列中最长的内容
|
|
851
|
+
for (var c = 0; c < col.children.length; c++) {
|
|
852
|
+
var childText = this.getColumnMaxContentText(col.children[c]);
|
|
853
|
+
var childLength = this.textDisplayLength(childText);
|
|
854
|
+
if (childLength > maxLength) {
|
|
855
|
+
maxText = childText;
|
|
856
|
+
maxLength = childLength;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return maxText;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) {
|
|
863
|
+
return labelText;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
var rows = this.innerTableData || [];
|
|
867
|
+
for (var i = 0; i < rows.length; i++) {
|
|
868
|
+
var text = this.resolveCellText(col, rows[i], i);
|
|
869
|
+
var textLength = this.textDisplayLength(text);
|
|
870
|
+
if (textLength > maxLength) {
|
|
871
|
+
maxText = text;
|
|
872
|
+
maxLength = textLength;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return maxText;
|
|
876
|
+
},
|
|
793
877
|
resolveAutoColumnLayout(col) {
|
|
794
878
|
if (!col) return {};
|
|
795
879
|
if (col.children && col.children.length) {
|
|
@@ -821,6 +905,8 @@ export default {
|
|
|
821
905
|
slotLayout.minWidth = defaultMinW;
|
|
822
906
|
}
|
|
823
907
|
// slot 列可以设置 showOverflowTooltip
|
|
908
|
+
// 对于 slot 列,我们只检查用户是否显式设置了 showOverflowTooltip
|
|
909
|
+
// 因为 slot 列的内容是自定义的,无法自动判断是否需要省略号
|
|
824
910
|
if (col.showOverflowTooltip === true) {
|
|
825
911
|
slotLayout.showOverflowTooltip = true;
|
|
826
912
|
}
|
|
@@ -838,8 +924,14 @@ export default {
|
|
|
838
924
|
if (!Number.isFinite(pad) || pad < 0) pad = 32;
|
|
839
925
|
|
|
840
926
|
// 计算内容宽度(像素)
|
|
841
|
-
//
|
|
842
|
-
var
|
|
927
|
+
// 获取最长内容的字符串来判断应该使用哪个阈值
|
|
928
|
+
var maxContentText = this.getColumnMaxContentText(col);
|
|
929
|
+
var shouldShowTooltip = this.shouldShowOverflowTooltip(maxContentText);
|
|
930
|
+
|
|
931
|
+
// 根据字符类型动态调整阈值
|
|
932
|
+
// 如果应该显示省略号,使用动态阈值计算宽度
|
|
933
|
+
var dynamicThreshold = this.getDynamicThreshold(maxContentText);
|
|
934
|
+
var widthChars = shouldShowTooltip ? dynamicThreshold : Math.max(maxLen, 1);
|
|
843
935
|
var contentWidthPx = Math.ceil(widthChars * charPx + pad);
|
|
844
936
|
|
|
845
937
|
// 获取用户设置的 minWidth(如果有)
|
|
@@ -868,9 +960,12 @@ export default {
|
|
|
868
960
|
if (col.width != null && col.width !== "") {
|
|
869
961
|
var userWidth = Number(col.width);
|
|
870
962
|
if (Number.isFinite(userWidth) && userWidth > 0) {
|
|
963
|
+
// 获取最长内容的字符串来判断是否需要显示省略号
|
|
964
|
+
var maxContentText = this.getColumnMaxContentText(col);
|
|
965
|
+
var shouldShowTooltip = this.shouldShowOverflowTooltip(maxContentText) || col.showOverflowTooltip === true;
|
|
871
966
|
return {
|
|
872
967
|
width: userWidth,
|
|
873
|
-
showOverflowTooltip:
|
|
968
|
+
showOverflowTooltip: shouldShowTooltip
|
|
874
969
|
};
|
|
875
970
|
}
|
|
876
971
|
}
|
|
@@ -880,7 +975,10 @@ export default {
|
|
|
880
975
|
};
|
|
881
976
|
|
|
882
977
|
// 判断是否需要显示 tooltip
|
|
883
|
-
|
|
978
|
+
// 获取最长内容的字符串来判断是否需要显示省略号
|
|
979
|
+
var maxContentText = this.getColumnMaxContentText(col);
|
|
980
|
+
var shouldShowTooltip = this.shouldShowOverflowTooltip(maxContentText) || col.showOverflowTooltip === true;
|
|
981
|
+
if (shouldShowTooltip) {
|
|
884
982
|
layout.showOverflowTooltip = true;
|
|
885
983
|
}
|
|
886
984
|
|