wkjp-list-page 1.0.35 → 1.0.37
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,78 @@ 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
|
+
|
|
774
|
+
// 如果字符串为空,不显示省略号
|
|
775
|
+
if (str.length === 0) {
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
var fullWidthCount = 0; // 全角字符计数
|
|
780
|
+
var halfWidthCount = 0; // 半角字符计数
|
|
781
|
+
var isPureNumberOrLetter = true; // 标记是否为纯数字或字母
|
|
782
|
+
|
|
783
|
+
for (var i = 0; i < str.length; i++) {
|
|
784
|
+
var charCode = str.charCodeAt(i);
|
|
785
|
+
var char = str.charAt(i);
|
|
786
|
+
|
|
787
|
+
// 检查是否为全角字符
|
|
788
|
+
if (
|
|
789
|
+
(charCode >= 0x4E00 && charCode <= 0x9FFF) || // 中文
|
|
790
|
+
(charCode >= 0x3000 && charCode <= 0x303F) || // CJK符号和标点
|
|
791
|
+
(charCode >= 0xFF00 && charCode <= 0xFFEF) // 全角字符
|
|
792
|
+
) {
|
|
793
|
+
fullWidthCount++;
|
|
794
|
+
isPureNumberOrLetter = false; // 包含全角字符,不是纯数字/字母
|
|
795
|
+
} else {
|
|
796
|
+
halfWidthCount++;
|
|
797
|
+
// 检查是否为数字或字母(半角)
|
|
798
|
+
if (!((charCode >= 48 && charCode <= 57) || // 数字 0-9
|
|
799
|
+
(charCode >= 65 && charCode <= 90) || // 大写字母 A-Z
|
|
800
|
+
(charCode >= 97 && charCode <= 122))) { // 小写字母 a-z
|
|
801
|
+
isPureNumberOrLetter = false; // 包含非数字字母字符
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// 纯数字或字母内容不显示省略号
|
|
807
|
+
if (isPureNumberOrLetter && halfWidthCount > 0 && fullWidthCount === 0) {
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// 计算总宽度单位:全角字符*2 + 半角字符*1
|
|
812
|
+
var totalWidth = fullWidthCount * 2 + halfWidthCount;
|
|
813
|
+
|
|
814
|
+
// 如果包含全角字符,使用20个宽度单位的阈值
|
|
815
|
+
// 如果只有半角字符,使用40个宽度单位的阈值
|
|
816
|
+
var threshold = fullWidthCount > 0 ? 20 : 40;
|
|
817
|
+
|
|
818
|
+
return totalWidth > threshold;
|
|
819
|
+
},
|
|
820
|
+
// 根据字符类型获取动态阈值
|
|
821
|
+
getDynamicThreshold(text) {
|
|
822
|
+
var str = String(text == null ? "" : text);
|
|
823
|
+
var fullWidthCount = 0; // 全角字符计数
|
|
824
|
+
|
|
825
|
+
for (var i = 0; i < str.length; i++) {
|
|
826
|
+
var charCode = str.charCodeAt(i);
|
|
827
|
+
if (
|
|
828
|
+
(charCode >= 0x4E00 && charCode <= 0x9FFF) || // 中文
|
|
829
|
+
(charCode >= 0x3000 && charCode <= 0x303F) || // CJK符号和标点
|
|
830
|
+
(charCode >= 0xFF00 && charCode <= 0xFFEF) // 全角字符
|
|
831
|
+
) {
|
|
832
|
+
fullWidthCount++;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// 如果包含全角字符,使用20个宽度单位的阈值
|
|
837
|
+
// 如果只有半角字符,使用40个宽度单位的阈值
|
|
838
|
+
return fullWidthCount > 0 ? 20 : 40;
|
|
839
|
+
},
|
|
768
840
|
columnOverflowThreshold() {
|
|
769
841
|
var n = Number(this.columnOverflowTooltipChars);
|
|
770
842
|
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 20;
|
|
@@ -790,6 +862,40 @@ export default {
|
|
|
790
862
|
}
|
|
791
863
|
return Math.max(labelLen, maxCell);
|
|
792
864
|
},
|
|
865
|
+
/** 获取列中最长内容的字符串 */
|
|
866
|
+
getColumnMaxContentText(col) {
|
|
867
|
+
var labelText = (col && (col.label || col.prop || col.slot)) || "";
|
|
868
|
+
var maxText = labelText;
|
|
869
|
+
var maxLength = this.textDisplayLength(labelText);
|
|
870
|
+
|
|
871
|
+
if (col && col.children && col.children.length) {
|
|
872
|
+
// 对于嵌套列,返回子列中最长的内容
|
|
873
|
+
for (var c = 0; c < col.children.length; c++) {
|
|
874
|
+
var childText = this.getColumnMaxContentText(col.children[c]);
|
|
875
|
+
var childLength = this.textDisplayLength(childText);
|
|
876
|
+
if (childLength > maxLength) {
|
|
877
|
+
maxText = childText;
|
|
878
|
+
maxLength = childLength;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return maxText;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) {
|
|
885
|
+
return labelText;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
var rows = this.innerTableData || [];
|
|
889
|
+
for (var i = 0; i < rows.length; i++) {
|
|
890
|
+
var text = this.resolveCellText(col, rows[i], i);
|
|
891
|
+
var textLength = this.textDisplayLength(text);
|
|
892
|
+
if (textLength > maxLength) {
|
|
893
|
+
maxText = text;
|
|
894
|
+
maxLength = textLength;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return maxText;
|
|
898
|
+
},
|
|
793
899
|
resolveAutoColumnLayout(col) {
|
|
794
900
|
if (!col) return {};
|
|
795
901
|
if (col.children && col.children.length) {
|
|
@@ -821,6 +927,8 @@ export default {
|
|
|
821
927
|
slotLayout.minWidth = defaultMinW;
|
|
822
928
|
}
|
|
823
929
|
// slot 列可以设置 showOverflowTooltip
|
|
930
|
+
// 对于 slot 列,我们只检查用户是否显式设置了 showOverflowTooltip
|
|
931
|
+
// 因为 slot 列的内容是自定义的,无法自动判断是否需要省略号
|
|
824
932
|
if (col.showOverflowTooltip === true) {
|
|
825
933
|
slotLayout.showOverflowTooltip = true;
|
|
826
934
|
}
|
|
@@ -838,8 +946,14 @@ export default {
|
|
|
838
946
|
if (!Number.isFinite(pad) || pad < 0) pad = 32;
|
|
839
947
|
|
|
840
948
|
// 计算内容宽度(像素)
|
|
841
|
-
//
|
|
842
|
-
var
|
|
949
|
+
// 获取最长内容的字符串来判断应该使用哪个阈值
|
|
950
|
+
var maxContentText = this.getColumnMaxContentText(col);
|
|
951
|
+
var shouldShowTooltip = this.shouldShowOverflowTooltip(maxContentText);
|
|
952
|
+
|
|
953
|
+
// 根据字符类型动态调整阈值
|
|
954
|
+
// 如果应该显示省略号,使用动态阈值计算宽度
|
|
955
|
+
var dynamicThreshold = this.getDynamicThreshold(maxContentText);
|
|
956
|
+
var widthChars = shouldShowTooltip ? dynamicThreshold : Math.max(maxLen, 1);
|
|
843
957
|
var contentWidthPx = Math.ceil(widthChars * charPx + pad);
|
|
844
958
|
|
|
845
959
|
// 获取用户设置的 minWidth(如果有)
|
|
@@ -868,9 +982,12 @@ export default {
|
|
|
868
982
|
if (col.width != null && col.width !== "") {
|
|
869
983
|
var userWidth = Number(col.width);
|
|
870
984
|
if (Number.isFinite(userWidth) && userWidth > 0) {
|
|
985
|
+
// 获取最长内容的字符串来判断是否需要显示省略号
|
|
986
|
+
var maxContentText = this.getColumnMaxContentText(col);
|
|
987
|
+
var shouldShowTooltip = this.shouldShowOverflowTooltip(maxContentText) || col.showOverflowTooltip === true;
|
|
871
988
|
return {
|
|
872
989
|
width: userWidth,
|
|
873
|
-
showOverflowTooltip:
|
|
990
|
+
showOverflowTooltip: shouldShowTooltip
|
|
874
991
|
};
|
|
875
992
|
}
|
|
876
993
|
}
|
|
@@ -880,7 +997,10 @@ export default {
|
|
|
880
997
|
};
|
|
881
998
|
|
|
882
999
|
// 判断是否需要显示 tooltip
|
|
883
|
-
|
|
1000
|
+
// 获取最长内容的字符串来判断是否需要显示省略号
|
|
1001
|
+
var maxContentText = this.getColumnMaxContentText(col);
|
|
1002
|
+
var shouldShowTooltip = this.shouldShowOverflowTooltip(maxContentText) || col.showOverflowTooltip === true;
|
|
1003
|
+
if (shouldShowTooltip) {
|
|
884
1004
|
layout.showOverflowTooltip = true;
|
|
885
1005
|
}
|
|
886
1006
|
|