wkjp-list-page 1.0.29 → 1.0.31

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.29",
3
+ "version": "1.0.31",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -122,6 +122,8 @@
122
122
  </div>
123
123
  </el-form>
124
124
 
125
+ <slot name="table-top"></slot>
126
+
125
127
  <el-table
126
128
  ref="listTable"
127
129
  :data="innerTableData"
@@ -343,6 +345,12 @@ export default {
343
345
  },
344
346
  props: {
345
347
  filters: { type: Object, required: true },
348
+ /**
349
+ * 重置基准:首次传入的默认查询条件(深拷贝后冻结,后续查询怎么改都不影响「重置」)。
350
+ * 建议传入页面 `data` 里单独保存的一份默认值对象(勿与 `filters` 共用同一引用)。
351
+ * 未传时:在实例首次初始化时对当时的 `filters` 做一次快照(`v-if` 反复挂载时仍会按每次挂载时的 filters 快照,多 tab 请务必传本项)。
352
+ */
353
+ initialFilters: { type: Object, default: null },
346
354
  searchOption: { type: Array, default: () => [] },
347
355
  columns: { type: Array, default: () => [] },
348
356
  /**
@@ -402,7 +410,7 @@ export default {
402
410
  showQueryButton: { type: Boolean, default: true },
403
411
  /** 主查询按钮文案 */
404
412
  queryButtonText: { type: String, default: "查询" },
405
- /** 是否显示「重置」按钮(在查询按钮右侧):将 `filters` 恢复为进入页面时的快照 */
413
+ /** 是否显示「重置」按钮(在查询按钮右侧):将 `filters` 恢复为 `initialFilters`(或首次快照) */
406
414
  showClearQueryButton: { type: Boolean, default: true },
407
415
  clearQueryButtonText: { type: String, default: "重置" },
408
416
  /**
@@ -479,9 +487,9 @@ export default {
479
487
  columnConfigPanelMaxHeight: null,
480
488
  configColumns: [],
481
489
  appliedColumns: [],
482
- /** 进入页时 filters 的快照,用于「重置」 */
490
+ /** 重置基准快照(深拷贝后冻结,仅初始化时写入一次) */
483
491
  initialFiltersSnapshot: null,
484
- initialFiltersCaptured: false
492
+ resetBaselineLocked: false
485
493
  };
486
494
  },
487
495
  computed: {
@@ -677,10 +685,25 @@ export default {
677
685
  this.innerPagination = Object.assign({}, this.innerPagination, v);
678
686
  }
679
687
  }
688
+ },
689
+ initialFilters: {
690
+ immediate: true,
691
+ handler(val) {
692
+ if (this.resetBaselineLocked) return;
693
+ if (val && typeof val === "object") {
694
+ this.lockResetBaseline(val);
695
+ }
696
+ }
680
697
  }
681
698
  },
682
699
  created() {
683
- this.captureInitialFilters();
700
+ if (!this.resetBaselineLocked) {
701
+ const baseline =
702
+ this.initialFilters && typeof this.initialFilters === "object"
703
+ ? this.initialFilters
704
+ : this.filters;
705
+ this.lockResetBaseline(baseline);
706
+ }
684
707
  this.applyInnerPaginationConfig();
685
708
  if (this.fetchOnCreated) {
686
709
  this.fetchList();
@@ -803,19 +826,43 @@ export default {
803
826
  handleQueryClick() {
804
827
  this.fetchList({ resetPage: true });
805
828
  },
806
- captureInitialFilters() {
807
- if (this.initialFiltersCaptured || !this.filters) return;
829
+ /**
830
+ * baseline 深拷贝为重置基准,仅首次调用生效;之后 filters 怎么变都不更新快照。
831
+ * @param {Object} baseline 优先使用 `initialFilters`,否则为首次 `filters`
832
+ */
833
+ lockResetBaseline(baseline) {
834
+ if (this.resetBaselineLocked || !this.filters) return;
835
+ if (!baseline || typeof baseline !== "object") return;
808
836
  try {
809
837
  const snap = {};
810
- Object.keys(this.filters).forEach((key) => {
811
- snap[key] = this.cloneFilterValue(this.filters[key]);
838
+ const keys = {};
839
+ Object.keys(this.filters).forEach(function (k) {
840
+ keys[k] = true;
841
+ });
842
+ Object.keys(baseline).forEach(function (k) {
843
+ keys[k] = true;
844
+ });
845
+ Object.keys(keys).forEach((key) => {
846
+ const val = Object.prototype.hasOwnProperty.call(baseline, key)
847
+ ? baseline[key]
848
+ : this.filters[key];
849
+ snap[key] = this.cloneFilterValue(val);
812
850
  });
813
851
  this.initialFiltersSnapshot = snap;
814
- this.initialFiltersCaptured = true;
852
+ this.resetBaselineLocked = true;
815
853
  } catch (e) {
816
854
  this.initialFiltersSnapshot = null;
817
855
  }
818
856
  },
857
+ /** @deprecated 请使用 lockResetBaseline */
858
+ captureInitialFilters() {
859
+ if (this.resetBaselineLocked) return;
860
+ const baseline =
861
+ this.initialFilters && typeof this.initialFilters === "object"
862
+ ? this.initialFilters
863
+ : this.filters;
864
+ this.lockResetBaseline(baseline);
865
+ },
819
866
  cloneFilterValue(val) {
820
867
  if (val === null || val === undefined) return val;
821
868
  if (typeof val !== "object") return val;