wkjp-list-page 1.0.33 → 1.0.35
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 +1 -1
- package/src/components/CommonListPage.vue +129 -35
package/package.json
CHANGED
|
@@ -93,13 +93,13 @@
|
|
|
93
93
|
@change="(val) => handleDateFieldChange(item, val)"
|
|
94
94
|
/>
|
|
95
95
|
</el-form-item>
|
|
96
|
-
<el-form-item v-if="searchCollapseActive && !
|
|
97
|
-
<el-button type="text" class="common-list-page__search-toggle-btn" @click="
|
|
96
|
+
<el-form-item v-if="searchCollapseActive && !internalSearchExpanded" class="common-list-page__search-toggle">
|
|
97
|
+
<el-button type="text" class="common-list-page__search-toggle-btn" @click="toggleSearchExpanded(true)">
|
|
98
98
|
{{ expandSearchText }}
|
|
99
99
|
</el-button>
|
|
100
100
|
</el-form-item>
|
|
101
|
-
<el-form-item v-if="searchCollapseActive &&
|
|
102
|
-
<el-button type="text" class="common-list-page__search-toggle-btn" @click="
|
|
101
|
+
<el-form-item v-if="searchCollapseActive && internalSearchExpanded" class="common-list-page__search-toggle">
|
|
102
|
+
<el-button type="text" class="common-list-page__search-toggle-btn" @click="toggleSearchExpanded(false)">
|
|
103
103
|
{{ foldSearchText }}
|
|
104
104
|
</el-button>
|
|
105
105
|
</el-form-item>
|
|
@@ -426,8 +426,10 @@ export default {
|
|
|
426
426
|
collapseSearch: { type: Boolean, default: undefined },
|
|
427
427
|
/** 折叠时默认展示的查询项条数;未传时按 **6**;显式传 ≤0 表示不折叠 */
|
|
428
428
|
searchVisibleMax: { type: Number, default: null },
|
|
429
|
+
/** 搜索区是否展开,支持 .sync 修饰符进行双向绑定,默认 true(展开状态) */
|
|
430
|
+
searchExpanded: { type: Boolean, default: true },
|
|
429
431
|
expandSearchText: { type: String, default: "展开查询" },
|
|
430
|
-
foldSearchText: { type: String, default: "
|
|
432
|
+
foldSearchText: { type: String, default: "收起查询" },
|
|
431
433
|
/** 为 true 且传入 `export-api` 时,在搜索区右侧显示内置导出按钮(基于 `exportFile`) */
|
|
432
434
|
showExport: { type: Boolean, default: false },
|
|
433
435
|
/**
|
|
@@ -447,19 +449,21 @@ export default {
|
|
|
447
449
|
exportMaxLimit: { type: Number, default: null },
|
|
448
450
|
/**
|
|
449
451
|
* 未在列上写 `width` / `minWidth` 时,按表头与当前页单元格内容估算列宽;
|
|
450
|
-
*
|
|
452
|
+
* 内容最长超过该字符宽度单位数则固定按该宽度算宽并开启 `showOverflowTooltip`。
|
|
453
|
+
* 注:中文字符宽度为2,英文字母和数字宽度为1。
|
|
451
454
|
*/
|
|
452
455
|
columnOverflowTooltipChars: { type: Number, default: 20 },
|
|
453
|
-
/**
|
|
454
|
-
columnAutoWidthCharPx: { type: Number, default:
|
|
456
|
+
/** 自动列宽:每字符宽度单位折算像素(12px 字号下,半角字符约8px,全角字符约16px) */
|
|
457
|
+
columnAutoWidthCharPx: { type: Number, default: 8 },
|
|
455
458
|
/** 自动列宽:单元格左右内边距等额外宽度 */
|
|
456
|
-
columnAutoWidthPadding: { type: Number, default:
|
|
459
|
+
columnAutoWidthPadding: { type: Number, default: 32 },
|
|
457
460
|
/** 自动列宽:未写 width / minWidth 时的默认最小宽度(px) */
|
|
458
|
-
columnAutoMinWidth: { type: Number, default:
|
|
461
|
+
columnAutoMinWidth: { type: Number, default: 120 }
|
|
459
462
|
},
|
|
460
463
|
data() {
|
|
461
464
|
return {
|
|
462
|
-
searchExpanded
|
|
465
|
+
// searchExpanded 现在作为 prop 传入,这里只用于内部状态管理
|
|
466
|
+
internalSearchExpanded: this.searchExpanded,
|
|
463
467
|
innerLoading: false,
|
|
464
468
|
innerTableData: [],
|
|
465
469
|
innerPagination: {
|
|
@@ -597,7 +601,7 @@ export default {
|
|
|
597
601
|
displaySearchOption() {
|
|
598
602
|
var max = this.effectiveSearchVisibleMax;
|
|
599
603
|
var list = this.visibleSearchOptionList;
|
|
600
|
-
if (!this.searchCollapseActive || this.
|
|
604
|
+
if (!this.searchCollapseActive || this.internalSearchExpanded) {
|
|
601
605
|
return list;
|
|
602
606
|
}
|
|
603
607
|
return list.slice(0, max);
|
|
@@ -660,16 +664,23 @@ export default {
|
|
|
660
664
|
var len = Array.isArray(list) ? list.length : 0;
|
|
661
665
|
var max = this.effectiveSearchVisibleMax;
|
|
662
666
|
if (!this.searchCollapseEnabled || max == null || len <= max) {
|
|
663
|
-
this.
|
|
667
|
+
this.toggleSearchExpanded(false);
|
|
664
668
|
}
|
|
665
669
|
},
|
|
666
670
|
deep: true
|
|
667
671
|
},
|
|
668
672
|
searchVisibleMax() {
|
|
669
|
-
this.
|
|
673
|
+
this.toggleSearchExpanded(false);
|
|
670
674
|
},
|
|
671
675
|
collapseSearch(val) {
|
|
672
|
-
if (val === false) this.
|
|
676
|
+
if (val === false) this.toggleSearchExpanded(false);
|
|
677
|
+
},
|
|
678
|
+
// 监听 searchExpanded prop 的变化,同步到内部状态
|
|
679
|
+
searchExpanded: {
|
|
680
|
+
immediate: true,
|
|
681
|
+
handler(val) {
|
|
682
|
+
this.internalSearchExpanded = val;
|
|
683
|
+
}
|
|
673
684
|
},
|
|
674
685
|
columns: {
|
|
675
686
|
immediate: true,
|
|
@@ -718,6 +729,11 @@ export default {
|
|
|
718
729
|
forwardSelectionChange(selection) {
|
|
719
730
|
this.$emit("selection-change", selection);
|
|
720
731
|
},
|
|
732
|
+
toggleSearchExpanded(expanded) {
|
|
733
|
+
this.internalSearchExpanded = expanded;
|
|
734
|
+
// 使用 .sync 修饰符更新父组件的值
|
|
735
|
+
this.$emit("update:searchExpanded", expanded);
|
|
736
|
+
},
|
|
721
737
|
isBuiltinCellColumn(col) {
|
|
722
738
|
return col && ["selection", "index", "expand"].indexOf(col.type) !== -1;
|
|
723
739
|
},
|
|
@@ -729,7 +745,25 @@ export default {
|
|
|
729
745
|
return true;
|
|
730
746
|
},
|
|
731
747
|
textDisplayLength(text) {
|
|
732
|
-
|
|
748
|
+
var str = String(text == null ? "" : text);
|
|
749
|
+
var length = 0;
|
|
750
|
+
for (var i = 0; i < str.length; i++) {
|
|
751
|
+
var charCode = str.charCodeAt(i);
|
|
752
|
+
// 判断字符是否为全角字符(中文字符、日文、韩文等)
|
|
753
|
+
// 全角字符范围:0x4E00-0x9FFF(CJK统一表意文字)
|
|
754
|
+
// 0x3000-0x303F(CJK符号和标点)
|
|
755
|
+
// 0xFF00-0xFFEF(全角ASCII、全角标点等)
|
|
756
|
+
if (
|
|
757
|
+
(charCode >= 0x4E00 && charCode <= 0x9FFF) || // 中文
|
|
758
|
+
(charCode >= 0x3000 && charCode <= 0x303F) || // CJK符号和标点
|
|
759
|
+
(charCode >= 0xFF00 && charCode <= 0xFFEF) // 全角字符
|
|
760
|
+
) {
|
|
761
|
+
length += 2; // 全角字符宽度为2
|
|
762
|
+
} else {
|
|
763
|
+
length += 1; // 半角字符宽度为1
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return length;
|
|
733
767
|
},
|
|
734
768
|
columnOverflowThreshold() {
|
|
735
769
|
var n = Number(this.columnOverflowTooltipChars);
|
|
@@ -764,34 +798,92 @@ export default {
|
|
|
764
798
|
if (col.minWidth != null && col.minWidth !== "") nestedLayout.minWidth = col.minWidth;
|
|
765
799
|
return nestedLayout;
|
|
766
800
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (
|
|
770
|
-
|
|
771
|
-
|
|
801
|
+
|
|
802
|
+
// slot 列不参与自动宽度计算,直接使用配置的宽度或最小宽度
|
|
803
|
+
if (col.type === "slot") {
|
|
804
|
+
var slotLayout = {};
|
|
805
|
+
if (col.width != null && col.width !== "") {
|
|
806
|
+
var userWidth = Number(col.width);
|
|
807
|
+
if (Number.isFinite(userWidth) && userWidth > 0) {
|
|
808
|
+
slotLayout.width = userWidth;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (col.minWidth != null && col.minWidth !== "") {
|
|
812
|
+
var userMinWidth = Number(col.minWidth);
|
|
813
|
+
if (Number.isFinite(userMinWidth) && userMinWidth > 0) {
|
|
814
|
+
slotLayout.minWidth = userMinWidth;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
// 如果既没有设置 width 也没有设置 minWidth,使用默认最小宽度
|
|
818
|
+
if (!slotLayout.width && !slotLayout.minWidth) {
|
|
819
|
+
var defaultMinW = Number(this.columnAutoMinWidth);
|
|
820
|
+
if (!Number.isFinite(defaultMinW) || defaultMinW <= 0) defaultMinW = 120;
|
|
821
|
+
slotLayout.minWidth = defaultMinW;
|
|
822
|
+
}
|
|
823
|
+
// slot 列可以设置 showOverflowTooltip
|
|
824
|
+
if (col.showOverflowTooltip === true) {
|
|
825
|
+
slotLayout.showOverflowTooltip = true;
|
|
772
826
|
}
|
|
773
|
-
|
|
774
|
-
return maxLenExplicit > this.columnOverflowThreshold()
|
|
775
|
-
? { showOverflowTooltip: true }
|
|
776
|
-
: {};
|
|
827
|
+
return slotLayout;
|
|
777
828
|
}
|
|
829
|
+
|
|
830
|
+
// 获取表头和内容的最大字符长度
|
|
778
831
|
var maxLen = this.getColumnMaxContentLength(col);
|
|
779
832
|
var threshold = this.columnOverflowThreshold();
|
|
780
|
-
|
|
833
|
+
|
|
834
|
+
// 计算基于内容的宽度(字符数转像素)
|
|
781
835
|
var charPx = Number(this.columnAutoWidthCharPx);
|
|
782
836
|
var pad = Number(this.columnAutoWidthPadding);
|
|
783
|
-
if (!Number.isFinite(charPx) || charPx <= 0) charPx =
|
|
784
|
-
if (!Number.isFinite(pad) || pad < 0) pad =
|
|
785
|
-
|
|
786
|
-
|
|
837
|
+
if (!Number.isFinite(charPx) || charPx <= 0) charPx = 16;
|
|
838
|
+
if (!Number.isFinite(pad) || pad < 0) pad = 32;
|
|
839
|
+
|
|
840
|
+
// 计算内容宽度(像素)
|
|
841
|
+
// 如果内容超过阈值,使用阈值计算宽度(显示省略号)
|
|
842
|
+
var widthChars = maxLen > threshold ? threshold : Math.max(maxLen, 1);
|
|
843
|
+
var contentWidthPx = Math.ceil(widthChars * charPx + pad);
|
|
844
|
+
|
|
845
|
+
// 获取用户设置的 minWidth(如果有)
|
|
846
|
+
var userMinWidth = null;
|
|
847
|
+
if (col.minWidth != null && col.minWidth !== "") {
|
|
848
|
+
userMinWidth = Number(col.minWidth);
|
|
849
|
+
if (!Number.isFinite(userMinWidth) || userMinWidth <= 0) {
|
|
850
|
+
userMinWidth = null;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// 获取默认的最小宽度
|
|
855
|
+
var defaultMinW = Number(this.columnAutoMinWidth);
|
|
856
|
+
if (!Number.isFinite(defaultMinW) || defaultMinW <= 0) defaultMinW = 120;
|
|
857
|
+
|
|
858
|
+
// 计算最终的最小宽度:max(用户设置的minWidth, 默认minWidth, 内容宽度)
|
|
859
|
+
var finalMinWidth = Math.max(
|
|
860
|
+
defaultMinW,
|
|
861
|
+
contentWidthPx
|
|
862
|
+
);
|
|
863
|
+
if (userMinWidth !== null) {
|
|
864
|
+
finalMinWidth = Math.max(finalMinWidth, userMinWidth);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// 如果用户设置了 width,则使用 width(优先级最高)
|
|
868
|
+
if (col.width != null && col.width !== "") {
|
|
869
|
+
var userWidth = Number(col.width);
|
|
870
|
+
if (Number.isFinite(userWidth) && userWidth > 0) {
|
|
871
|
+
return {
|
|
872
|
+
width: userWidth,
|
|
873
|
+
showOverflowTooltip: maxLen > threshold || col.showOverflowTooltip === true
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
787
878
|
var layout = {
|
|
788
|
-
minWidth:
|
|
879
|
+
minWidth: finalMinWidth
|
|
789
880
|
};
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
881
|
+
|
|
882
|
+
// 判断是否需要显示 tooltip
|
|
883
|
+
if (maxLen > threshold || col.showOverflowTooltip === true) {
|
|
793
884
|
layout.showOverflowTooltip = true;
|
|
794
885
|
}
|
|
886
|
+
|
|
795
887
|
return layout;
|
|
796
888
|
},
|
|
797
889
|
tableColumnBind(col) {
|
|
@@ -1962,7 +2054,9 @@ export default {
|
|
|
1962
2054
|
line-height: 1.5;
|
|
1963
2055
|
padding-left: 10px !important;
|
|
1964
2056
|
padding-right: 10px !important;
|
|
1965
|
-
|
|
2057
|
+
white-space: nowrap;
|
|
2058
|
+
overflow: hidden;
|
|
2059
|
+
text-overflow: ellipsis;
|
|
1966
2060
|
}
|
|
1967
2061
|
|
|
1968
2062
|
/* 操作列:多个文字按钮拉开间距(详情 / 推送 / 删除 等) */
|