fantasy-ngzorro 2.1.37 → 2.1.39

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.
@@ -7559,6 +7559,10 @@
7559
7559
  * 可见列总宽,用于判断是否需要横向滚动
7560
7560
  */
7561
7561
  this.tableColWidthTotal = 0;
7562
+ /**
7563
+ * 数据更新后待复位纵向滚动位置
7564
+ */
7565
+ this.pendingResetScrollTop = false;
7562
7566
  /**
7563
7567
  * 当前排序,表格重建后用于恢复表头排序态
7564
7568
  */
@@ -7707,19 +7711,27 @@
7707
7711
  changes["tableData"]["previousValue"]["pageSize"] ||
7708
7712
  changes["tableData"]["currentValue"]["pageNumber"] !==
7709
7713
  changes["tableData"]["previousValue"]["pageNumber"]) {
7714
+ this.pendingResetScrollTop = true;
7710
7715
  if (this.virtualScroll) {
7711
7716
  // 仅虚拟/普通模式真正切换时重建,避免排序后数据刷新把排序态清掉
7712
7717
  this.applyTableScrollMode(false);
7713
7718
  }
7719
+ // 翻页/改 pageSize:主动多次复位,覆盖 CDK 异步渲染时序
7720
+ this.scheduleResetTableBodyScrollTop();
7714
7721
  return;
7715
7722
  }
7716
7723
  if (!this.isCrossPageSelectLocal) {
7717
7724
  this.resetStatus();
7718
7725
  }
7719
7726
  }
7720
- if (changes["tableData"] && this.virtualScroll) {
7721
- // 数据刷新不强制重建,只在滚动模式变化时 remount
7722
- this.applyTableScrollMode(false);
7727
+ if (changes["tableData"]) {
7728
+ this.pendingResetScrollTop = true;
7729
+ if (this.virtualScroll) {
7730
+ // 数据刷新不强制重建,只在滚动模式变化时 remount
7731
+ this.applyTableScrollMode(false);
7732
+ }
7733
+ // 数据更新后复位纵向滚动(含虚拟滚动场景)
7734
+ this.scheduleResetTableBodyScrollTop();
7723
7735
  }
7724
7736
  if (changes["tableCols"] &&
7725
7737
  JSON.stringify(changes["tableCols"].currentValue) !==
@@ -7819,16 +7831,32 @@
7819
7831
  enumerable: true,
7820
7832
  configurable: true
7821
7833
  });
7822
- Object.defineProperty(HdTableComponent.prototype, "useVirtualScroll", {
7823
- /** 当前页数据能完整展示时不启用虚拟滚动,避免少量数据也出现滚动条 */
7834
+ /**
7835
+ * 纵向可用高度扣减:按钮区/合计/分页等固定占位。
7836
+ * 必须与 dealScroll / presetScrollBeforeRemount 使用同一套,否则会误判「能放下」而不设 scroll.y。
7837
+ */
7838
+ /**
7839
+ * 纵向可用高度扣减:按钮区/合计/分页等固定占位。
7840
+ * 必须与 dealScroll / presetScrollBeforeRemount 使用同一套,否则会误判「能放下」而不设 scroll.y。
7841
+ * @private
7842
+ * @return {?}
7843
+ */
7844
+ HdTableComponent.prototype.getScrollYMaxOffset = /**
7845
+ * 纵向可用高度扣减:按钮区/合计/分页等固定占位。
7846
+ * 必须与 dealScroll / presetScrollBeforeRemount 使用同一套,否则会误判「能放下」而不设 scroll.y。
7847
+ * @private
7848
+ * @return {?}
7849
+ */
7850
+ function () {
7851
+ return (this.tableTotal ? 180 : 140) + 216;
7852
+ };
7853
+ Object.defineProperty(HdTableComponent.prototype, "needsVerticalScroll", {
7854
+ /** 当前页内容高度是否超出视口(需要表内纵向滚动) */
7824
7855
  get: /**
7825
- * 当前页数据能完整展示时不启用虚拟滚动,避免少量数据也出现滚动条
7856
+ * 当前页内容高度是否超出视口(需要表内纵向滚动)
7826
7857
  * @return {?}
7827
7858
  */
7828
7859
  function () {
7829
- if (!this.virtualScroll) {
7830
- return false;
7831
- }
7832
7860
  /** @type {?} */
7833
7861
  var rowCount = this.tableData && this.tableData.content
7834
7862
  ? this.tableData.content.length
@@ -7837,7 +7865,7 @@
7837
7865
  return false;
7838
7866
  }
7839
7867
  /** @type {?} */
7840
- var maxOffset = this.tableTotal ? 180 : 140;
7868
+ var maxOffset = this.getScrollYMaxOffset();
7841
7869
  /** @type {?} */
7842
7870
  var estimatedHeight = rowCount * this.effectiveVirtualItemSize;
7843
7871
  if (typeof window !== "undefined") {
@@ -7848,6 +7876,21 @@
7848
7876
  enumerable: true,
7849
7877
  configurable: true
7850
7878
  });
7879
+ Object.defineProperty(HdTableComponent.prototype, "useVirtualScroll", {
7880
+ /** 当前页数据能完整展示时不启用虚拟滚动,避免少量数据也出现滚动条 */
7881
+ get: /**
7882
+ * 当前页数据能完整展示时不启用虚拟滚动,避免少量数据也出现滚动条
7883
+ * @return {?}
7884
+ */
7885
+ function () {
7886
+ if (!this.virtualScroll) {
7887
+ return false;
7888
+ }
7889
+ return this.needsVerticalScroll;
7890
+ },
7891
+ enumerable: true,
7892
+ configurable: true
7893
+ });
7851
7894
  /**
7852
7895
  * @param {?} col
7853
7896
  * @return {?}
@@ -8027,7 +8070,7 @@
8027
8070
  */
8028
8071
  function (useVirtual) {
8029
8072
  /** @type {?} */
8030
- var maxOffset = (this.tableTotal ? 180 : 140) + 216;
8073
+ var maxOffset = this.getScrollYMaxOffset();
8031
8074
  /** @type {?} */
8032
8075
  var x = this.scroll ? this.scroll.x : null;
8033
8076
  if (this.virtualScroll && !useVirtual) {
@@ -8057,11 +8100,19 @@
8057
8100
  }
8058
8101
  if (this.virtualScroll) {
8059
8102
  this.measureVirtualItemSize(true);
8103
+ // 实测行高后可能从「能放下」变为「超出」,需切换滚动模式
8104
+ if (this.useVirtualScroll) {
8105
+ this.applyTableScrollMode(false);
8106
+ return;
8107
+ }
8060
8108
  }
8061
8109
  setTimeout((/**
8062
8110
  * @return {?}
8063
8111
  */
8064
- function () { return _this.syncHorizontalScroll(); }));
8112
+ function () {
8113
+ _this.syncHorizontalScroll();
8114
+ _this.flushResetTableBodyScrollTop();
8115
+ }));
8065
8116
  };
8066
8117
  /**
8067
8118
  * @param {?=} forceMeasure
@@ -8080,6 +8131,7 @@
8080
8131
  this.dealScroll();
8081
8132
  this.cdr.markForCheck();
8082
8133
  }
8134
+ this.flushResetTableBodyScrollTop();
8083
8135
  return;
8084
8136
  }
8085
8137
  setTimeout((/**
@@ -8090,6 +8142,7 @@
8090
8142
  var viewport = _this.nzTableComponent && _this.nzTableComponent.cdkVirtualScrollViewport;
8091
8143
  if (!viewport) {
8092
8144
  _this.syncHorizontalScroll();
8145
+ _this.flushResetTableBodyScrollTop();
8093
8146
  return;
8094
8147
  }
8095
8148
  /** @type {?} */
@@ -8105,14 +8158,131 @@
8105
8158
  _this.measureVirtualItemSize(forceMeasure);
8106
8159
  _this.syncHorizontalScroll();
8107
8160
  viewport.checkViewportSize();
8161
+ _this.flushResetTableBodyScrollTop();
8108
8162
  }));
8109
8163
  }
8110
8164
  else {
8111
8165
  viewport.checkViewportSize();
8112
8166
  _this.syncHorizontalScroll();
8167
+ _this.flushResetTableBodyScrollTop();
8113
8168
  }
8114
8169
  }));
8115
8170
  };
8171
+ /** 数据刷新后将表体纵向滚动复位到顶部 */
8172
+ /**
8173
+ * 数据刷新后将表体纵向滚动复位到顶部
8174
+ * @private
8175
+ * @return {?}
8176
+ */
8177
+ HdTableComponent.prototype.resetTableBodyScrollTop = /**
8178
+ * 数据刷新后将表体纵向滚动复位到顶部
8179
+ * @private
8180
+ * @return {?}
8181
+ */
8182
+ function () {
8183
+ if (!this.nzTableComponent) {
8184
+ return;
8185
+ }
8186
+ /** @type {?} */
8187
+ var nzTable = (/** @type {?} */ (this.nzTableComponent));
8188
+ /** @type {?} */
8189
+ var viewport = this.nzTableComponent.cdkVirtualScrollViewport;
8190
+ if (viewport) {
8191
+ if (typeof ((/** @type {?} */ (viewport))).scrollToOffset === "function") {
8192
+ ((/** @type {?} */ (viewport))).scrollToOffset(0);
8193
+ }
8194
+ if (typeof ((/** @type {?} */ (viewport))).scrollToIndex === "function") {
8195
+ ((/** @type {?} */ (viewport))).scrollToIndex(0);
8196
+ }
8197
+ /** @type {?} */
8198
+ var viewportEl = viewport.elementRef &&
8199
+ ((/** @type {?} */ (viewport.elementRef.nativeElement)));
8200
+ if (viewportEl) {
8201
+ viewportEl.scrollTop = 0;
8202
+ }
8203
+ }
8204
+ /** @type {?} */
8205
+ var bodyCandidates = [
8206
+ nzTable.mixTableBodyNativeElement,
8207
+ nzTable.tableBodyNativeElement,
8208
+ nzTable.tableBodyElement && nzTable.tableBodyElement.nativeElement,
8209
+ ];
8210
+ bodyCandidates.forEach((/**
8211
+ * @param {?} el
8212
+ * @return {?}
8213
+ */
8214
+ function (el) {
8215
+ if (el) {
8216
+ el.scrollTop = 0;
8217
+ }
8218
+ }));
8219
+ /** @type {?} */
8220
+ var tableMain = nzTable.tableMainElement &&
8221
+ ((/** @type {?} */ (nzTable.tableMainElement.nativeElement)));
8222
+ if (!tableMain) {
8223
+ return;
8224
+ }
8225
+ /** @type {?} */
8226
+ var nodes = tableMain.querySelectorAll(".ant-table-body, cdk-virtual-scroll-viewport");
8227
+ Array.prototype.forEach.call(nodes, (/**
8228
+ * @param {?} el
8229
+ * @return {?}
8230
+ */
8231
+ function (el) {
8232
+ el.scrollTop = 0;
8233
+ }));
8234
+ };
8235
+ /**
8236
+ * 数据更新后多次尝试复位。
8237
+ * ng-zorro 8 + CDK 虚拟滚动会在数据刷新后异步改写 scrollTop,单次复位经常被覆盖。
8238
+ */
8239
+ /**
8240
+ * 数据更新后多次尝试复位。
8241
+ * ng-zorro 8 + CDK 虚拟滚动会在数据刷新后异步改写 scrollTop,单次复位经常被覆盖。
8242
+ * @private
8243
+ * @return {?}
8244
+ */
8245
+ HdTableComponent.prototype.scheduleResetTableBodyScrollTop = /**
8246
+ * 数据更新后多次尝试复位。
8247
+ * ng-zorro 8 + CDK 虚拟滚动会在数据刷新后异步改写 scrollTop,单次复位经常被覆盖。
8248
+ * @private
8249
+ * @return {?}
8250
+ */
8251
+ function () {
8252
+ var _this = this;
8253
+ /** @type {?} */
8254
+ var delays = [0, 50, 120];
8255
+ delays.forEach((/**
8256
+ * @param {?} ms
8257
+ * @param {?} index
8258
+ * @return {?}
8259
+ */
8260
+ function (ms, index) {
8261
+ setTimeout((/**
8262
+ * @return {?}
8263
+ */
8264
+ function () {
8265
+ _this.resetTableBodyScrollTop();
8266
+ if (index === delays.length - 1) {
8267
+ _this.pendingResetScrollTop = false;
8268
+ }
8269
+ }), ms);
8270
+ }));
8271
+ };
8272
+ /**
8273
+ * @private
8274
+ * @return {?}
8275
+ */
8276
+ HdTableComponent.prototype.flushResetTableBodyScrollTop = /**
8277
+ * @private
8278
+ * @return {?}
8279
+ */
8280
+ function () {
8281
+ if (!this.pendingResetScrollTop) {
8282
+ return;
8283
+ }
8284
+ this.resetTableBodyScrollTop();
8285
+ };
8116
8286
  /** 未手动传 virtualItemSize 时,从已渲染行测量真实高度 */
8117
8287
  /**
8118
8288
  * 未手动传 virtualItemSize 时,从已渲染行测量真实高度
@@ -8853,8 +9023,7 @@
8853
9023
  }
8854
9024
  this.tableColWidthTotal = colWidth;
8855
9025
  /** @type {?} */
8856
- var maxOffset = this.tableTotal ? 180 : 140;
8857
- maxOffset += 216;
9026
+ var maxOffset = this.getScrollYMaxOffset();
8858
9027
  /** @type {?} */
8859
9028
  var useVirtual = this.useVirtualScroll;
8860
9029
  /** @type {?} */
@@ -9215,6 +9384,12 @@
9215
9384
  * @private
9216
9385
  */
9217
9386
  HdTableComponent.prototype.tableColWidthTotal;
9387
+ /**
9388
+ * 数据更新后待复位纵向滚动位置
9389
+ * @type {?}
9390
+ * @private
9391
+ */
9392
+ HdTableComponent.prototype.pendingResetScrollTop;
9218
9393
  /**
9219
9394
  * 当前排序,表格重建后用于恢复表头排序态
9220
9395
  * @type {?}