wkjp-list-page 1.0.34 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wkjp-list-page",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -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 && !searchExpanded" class="common-list-page__search-toggle">
97
- <el-button type="text" class="common-list-page__search-toggle-btn" @click="searchExpanded = true">
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 && searchExpanded" class="common-list-page__search-toggle">
102
- <el-button type="text" class="common-list-page__search-toggle-btn" @click="searchExpanded = false">
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,11 +449,12 @@ export default {
447
449
  exportMaxLimit: { type: Number, default: null },
448
450
  /**
449
451
  * 未在列上写 `width` / `minWidth` 时,按表头与当前页单元格内容估算列宽;
450
- * 内容最长超过该字符数则固定按该字数算宽并开启 `showOverflowTooltip`。
452
+ * 内容最长超过该字符宽度单位数则固定按该宽度算宽并开启 `showOverflowTooltip`。
453
+ * 注:中文字符宽度为2,英文字母和数字宽度为1。
451
454
  */
452
455
  columnOverflowTooltipChars: { type: Number, default: 20 },
453
- /** 自动列宽:每字符折算像素(12px 字号下约 12~14) */
454
- columnAutoWidthCharPx: { type: Number, default: 16 },
456
+ /** 自动列宽:每字符宽度单位折算像素(12px 字号下,半角字符约8px,全角字符约16px) */
457
+ columnAutoWidthCharPx: { type: Number, default: 8 },
455
458
  /** 自动列宽:单元格左右内边距等额外宽度 */
456
459
  columnAutoWidthPadding: { type: Number, default: 32 },
457
460
  /** 自动列宽:未写 width / minWidth 时的默认最小宽度(px) */
@@ -459,7 +462,8 @@ export default {
459
462
  },
460
463
  data() {
461
464
  return {
462
- searchExpanded: false,
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.searchExpanded) {
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.searchExpanded = false;
667
+ this.toggleSearchExpanded(false);
664
668
  }
665
669
  },
666
670
  deep: true
667
671
  },
668
672
  searchVisibleMax() {
669
- this.searchExpanded = false;
673
+ this.toggleSearchExpanded(false);
670
674
  },
671
675
  collapseSearch(val) {
672
- if (val === false) this.searchExpanded = false;
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
- return String(text == null ? "" : text).length;
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);
@@ -765,6 +799,34 @@ export default {
765
799
  return nestedLayout;
766
800
  }
767
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;
826
+ }
827
+ return slotLayout;
828
+ }
829
+
768
830
  // 获取表头和内容的最大字符长度
769
831
  var maxLen = this.getColumnMaxContentLength(col);
770
832
  var threshold = this.columnOverflowThreshold();