fantasy-ngzorro 2.2.37 → 2.2.38

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.
@@ -1502,7 +1502,8 @@
1502
1502
  return getTableViewportWidth(nzTable, hostClass);
1503
1503
  }
1504
1504
  /**
1505
- * 无数据或列宽未超出容器时不启用横向 scroll(fluid:表宽 100%,勾选/序号列由 CSS 锁宽)
1505
+ * 无数据或列宽未超出容器时不启用横向 scroll(表宽 100%、table-layout: auto)。
1506
+ * auto 布局下单元格 max-width 不生效,固定宽列会被均摊撑开;需要锁宽的场景见 hd-table 的横向布局。
1506
1507
  * @param {?} nzTable
1507
1508
  * @param {?} hasData
1508
1509
  * @param {?=} colWidth
@@ -10951,6 +10952,67 @@
10951
10952
  * @fileoverview added by tsickle
10952
10953
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
10953
10954
  */
10955
+ /**
10956
+ * 勾选列宽(px),与模板 nzWidth、less 兜底保持一致
10957
+ * @type {?}
10958
+ */
10959
+ var SELECT_COL_WIDTH = 40;
10960
+ /**
10961
+ * 横向布局计算结果
10962
+ * @record
10963
+ */
10964
+ function HdTableHorizontalLayout() { }
10965
+ if (false) {
10966
+ /**
10967
+ * 传给 nzScroll.x;只有列宽总和 <= 0 时为 null
10968
+ * @type {?}
10969
+ */
10970
+ HdTableHorizontalLayout.prototype.scrollX;
10971
+ /**
10972
+ * 补到最后一列业务列上的宽度,列多时为 0
10973
+ * @type {?}
10974
+ */
10975
+ HdTableHorizontalLayout.prototype.fluidExtra;
10976
+ /**
10977
+ * 实际渲染总宽 = 声明总宽 + fluidExtra
10978
+ * @type {?}
10979
+ */
10980
+ HdTableHorizontalLayout.prototype.displayTotal;
10981
+ /**
10982
+ * 列少、靠补宽吃满容器,不需要真正横滚
10983
+ * @type {?}
10984
+ */
10985
+ HdTableHorizontalLayout.prototype.isFluid;
10986
+ }
10987
+ /**
10988
+ * 列多(或量不到容器宽):scroll.x = 声明总宽,正常横滚
10989
+ * @param {?} declaredWidth
10990
+ * @return {?}
10991
+ */
10992
+ function fixedLayout(declaredWidth) {
10993
+ return {
10994
+ scrollX: Math.ceil(declaredWidth) + "px",
10995
+ fluidExtra: 0,
10996
+ displayTotal: declaredWidth,
10997
+ isFluid: false,
10998
+ };
10999
+ }
11000
+ /**
11001
+ * 列少:scroll.x = 容器宽,差额补到最后一列业务列
11002
+ * @param {?} containerWidth
11003
+ * @param {?} declaredWidth
11004
+ * @return {?}
11005
+ */
11006
+ function fluidLayout(containerWidth, declaredWidth) {
11007
+ /** @type {?} */
11008
+ var fluidExtra = Math.max(0, containerWidth - declaredWidth);
11009
+ return {
11010
+ scrollX: containerWidth + "px",
11011
+ fluidExtra: fluidExtra,
11012
+ displayTotal: declaredWidth + fluidExtra,
11013
+ isFluid: true,
11014
+ };
11015
+ }
10954
11016
  var HdTableComponent = /** @class */ (function () {
10955
11017
  function HdTableComponent(hostEl, cdr, commonSessionService) {
10956
11018
  var _this = this;
@@ -11036,21 +11098,19 @@
11036
11098
  */
11037
11099
  this.virtualScrollActive = null;
11038
11100
  /**
11039
- * 列宽合计(含勾选/序号 + fluid 补宽),footer 表宽与横向 scroll 共用
11101
+ * 实际渲染列宽合计(含勾选/序号 + 补宽),合计 footer 表宽用
11040
11102
  */
11041
11103
  this.tableColWidthTotal = 0;
11042
11104
  /**
11043
- * fluid:声明列总宽 < 容器时,把差额补到最后一列业务列(不改缓存宽),
11044
- * 并设 scroll.x = 容器宽,避免表宽 100% 均摊撑开勾选列;拖拽改宽仍写 col.width。
11105
+ * 补到 fluidExtraTargetCol 上的宽度;只影响展示,不写回 col.width(列宽缓存、拖拽仍用声明宽)
11045
11106
  */
11046
11107
  this.fluidExtraWidth = 0;
11047
11108
  /**
11048
- * 列总宽未超出容器(fluid 补宽吃满):不需要真正横滚,
11049
- * 用于关掉 ng-zorro fixed-header 带来的常驻 X 轴滚动条。
11109
+ * 列少、靠补宽吃满容器:模板据此加 hd-table--fluid-x,隐藏 fixed-header 常驻的横滚槽
11050
11110
  */
11051
11111
  this.fluidHorizontal = false;
11052
11112
  /**
11053
- * fluid 补宽目标列缓存,避免模板每格 CD 时反复扫 tableCols
11113
+ * 接收补宽的列,缓存起来避免模板每个单元格都扫一遍 tableCols
11054
11114
  */
11055
11115
  this.fluidExtraTargetCol = null;
11056
11116
  /**
@@ -11274,10 +11334,8 @@
11274
11334
  changes["tableData"]["currentValue"]["pageNumber"] !==
11275
11335
  changes["tableData"]["previousValue"]["pageNumber"]) {
11276
11336
  this.pendingResetScrollTop = true;
11277
- // pageSize/pageNumber 变化也要重算 scroll / fluid。
11278
- // 业务常把 Page.pageSize 写成 content.length(如收款编辑 toPage),
11279
- // virtualScroll=false 时若这里跳过,空表初始化后的 fluid 不会补上,勾选列被撑开。
11280
- // applyTableScrollMode(false) 在模式未变时只 dealScroll,不会强制重建清排序态。
11337
+ // 业务可能把 Page.pageSize 写成 content.length,换数据时就会走到这里,
11338
+ // 必须重算横向布局。滚动模式不变时不会重建,排序态不会被清掉。
11281
11339
  this.applyTableScrollMode(false);
11282
11340
  // 翻页/改 pageSize:主动多次复位,覆盖 CDK 异步渲染时序
11283
11341
  this.scheduleResetTableBodyScrollTop();
@@ -11289,9 +11347,7 @@
11289
11347
  }
11290
11348
  if (changes["tableData"]) {
11291
11349
  this.pendingResetScrollTop = true;
11292
- // 不论是否虚拟滚动都要重算 scroll / fluid。
11293
- // 收款/付款编辑等页 [virtualScroll]=false + 异步灌数据:原先跳过会导致
11294
- // 空表初始化后不再补宽,勾选列被均摊撑开。
11350
+ // 不论是否虚拟滚动,数据变化后都要重算横向布局
11295
11351
  this.applyTableScrollMode(false);
11296
11352
  // 数据更新后复位纵向滚动(含虚拟滚动场景)
11297
11353
  this.scheduleResetTableBodyScrollTop();
@@ -11532,13 +11588,13 @@
11532
11588
  return col.fixed === "left" ? (col.fixedWidth || 0) + "px" : null;
11533
11589
  };
11534
11590
  Object.defineProperty(HdTableComponent.prototype, "lineNumberLeft", {
11535
- /** 开启合计时序号列的 left(勾选列占 40px) */
11591
+ /** 开启合计时序号列的 left(跟在勾选列后面) */
11536
11592
  get: /**
11537
- * 开启合计时序号列的 left(勾选列占 40px)
11593
+ * 开启合计时序号列的 left(跟在勾选列后面)
11538
11594
  * @return {?}
11539
11595
  */
11540
11596
  function () {
11541
- return this.showSelected ? "40px" : "0px";
11597
+ return (this.showSelected ? SELECT_COL_WIDTH : 0) + "px";
11542
11598
  },
11543
11599
  enumerable: true,
11544
11600
  configurable: true
@@ -11569,64 +11625,141 @@
11569
11625
  enumerable: true,
11570
11626
  configurable: true
11571
11627
  });
11572
- /** 展示用列宽:fluid 时最后一列业务列 = 声明宽 + fluidExtraWidth */
11573
11628
  /**
11574
- * 展示用列宽:fluid 时最后一列业务列 = 声明宽 + fluidExtraWidth
11629
+ * @private
11630
+ * @param {?} col
11631
+ * @return {?}
11632
+ */
11633
+ HdTableComponent.prototype.isColVisible = /**
11634
+ * @private
11635
+ * @param {?} col
11636
+ * @return {?}
11637
+ */
11638
+ function (col) {
11639
+ return !!col && col.isShow !== false;
11640
+ };
11641
+ /** 业务列声明宽:未配置时按 fixColWidth */
11642
+ /**
11643
+ * 业务列声明宽:未配置时按 fixColWidth
11644
+ * @private
11645
+ * @param {?} col
11646
+ * @return {?}
11647
+ */
11648
+ HdTableComponent.prototype.getColDeclaredWidth = /**
11649
+ * 业务列声明宽:未配置时按 fixColWidth
11650
+ * @private
11651
+ * @param {?} col
11652
+ * @return {?}
11653
+ */
11654
+ function (col) {
11655
+ return col && col.width > 0 ? col.width : ColWidth.fixColWidth;
11656
+ };
11657
+ /** 声明列宽合计:勾选列 + 序号列 + 可见业务列,不含补宽 */
11658
+ /**
11659
+ * 声明列宽合计:勾选列 + 序号列 + 可见业务列,不含补宽
11660
+ * @private
11661
+ * @return {?}
11662
+ */
11663
+ HdTableComponent.prototype.getDeclaredColWidthTotal = /**
11664
+ * 声明列宽合计:勾选列 + 序号列 + 可见业务列,不含补宽
11665
+ * @private
11666
+ * @return {?}
11667
+ */
11668
+ function () {
11669
+ var _this = this;
11670
+ /** @type {?} */
11671
+ var total = 0;
11672
+ if (this.showSelected) {
11673
+ total += SELECT_COL_WIDTH;
11674
+ }
11675
+ if (this.showTableTotal) {
11676
+ total += this.lineNumberColWidth;
11677
+ }
11678
+ (this.tableCols || []).forEach((/**
11679
+ * @param {?} col
11680
+ * @return {?}
11681
+ */
11682
+ function (col) {
11683
+ if (_this.isColVisible(col)) {
11684
+ total += _this.getColDeclaredWidth(col);
11685
+ }
11686
+ }));
11687
+ return total;
11688
+ };
11689
+ /** 模板里 th / td / 合计 col 用的列宽:补宽目标列 = 声明宽 + fluidExtraWidth */
11690
+ /**
11691
+ * 模板里 th / td / 合计 col 用的列宽:补宽目标列 = 声明宽 + fluidExtraWidth
11575
11692
  * @param {?} col
11576
11693
  * @return {?}
11577
11694
  */
11578
11695
  HdTableComponent.prototype.getColDisplayWidth = /**
11579
- * 展示用列宽:fluid 时最后一列业务列 = 声明宽 + fluidExtraWidth
11696
+ * 模板里 th / td / 合计 col 用的列宽:补宽目标列 = 声明宽 + fluidExtraWidth
11580
11697
  * @param {?} col
11581
11698
  * @return {?}
11582
11699
  */
11583
11700
  function (col) {
11584
11701
  /** @type {?} */
11585
- var base = col && col.width != null && col.width > 0
11586
- ? col.width
11587
- : ColWidth.fixColWidth;
11588
- if (this.fluidExtraWidth <= 0 ||
11589
- !col ||
11590
- !this.fluidExtraTargetCol ||
11591
- col !== this.fluidExtraTargetCol) {
11592
- return base;
11702
+ var declared = this.getColDeclaredWidth(col);
11703
+ if (this.fluidExtraWidth > 0 && col && col === this.fluidExtraTargetCol) {
11704
+ return declared + this.fluidExtraWidth;
11593
11705
  }
11594
- return base + this.fluidExtraWidth;
11706
+ return declared;
11595
11707
  };
11596
- /** 按当前 layout 刷新 fluid 补宽目标列(仅 dealScroll / sync 时调用) */
11597
11708
  /**
11598
- * 按当前 layout 刷新 fluid 补宽目标列(仅 dealScroll / sync 时调用)
11709
+ * 选出接收补宽的列:优先最后一列「非右侧固定」的可见列,
11710
+ * 避免把操作列等右固定列拉宽;全是右固定列时退回最后一列可见列。
11711
+ */
11712
+ /**
11713
+ * 选出接收补宽的列:优先最后一列「非右侧固定」的可见列,
11714
+ * 避免把操作列等右固定列拉宽;全是右固定列时退回最后一列可见列。
11599
11715
  * @private
11600
11716
  * @return {?}
11601
11717
  */
11602
- HdTableComponent.prototype.refreshFluidExtraTargetCol = /**
11603
- * 按当前 layout 刷新 fluid 补宽目标列(仅 dealScroll / sync 时调用)
11718
+ HdTableComponent.prototype.findFluidExtraTargetCol = /**
11719
+ * 选出接收补宽的列:优先最后一列「非右侧固定」的可见列,
11720
+ * 避免把操作列等右固定列拉宽;全是右固定列时退回最后一列可见列。
11604
11721
  * @private
11605
11722
  * @return {?}
11606
11723
  */
11607
11724
  function () {
11608
- this.fluidExtraTargetCol = null;
11609
- if (this.fluidExtraWidth <= 0 ||
11610
- !this.tableCols ||
11611
- !this.tableCols.length) {
11612
- return;
11613
- }
11614
- for (var i = this.tableCols.length - 1; i >= 0; i--) {
11725
+ /** @type {?} */
11726
+ var cols = this.tableCols || [];
11727
+ /** @type {?} */
11728
+ var lastVisible = null;
11729
+ for (var i = cols.length - 1; i >= 0; i--) {
11615
11730
  /** @type {?} */
11616
- var c = this.tableCols[i];
11617
- if (c && c.isShow && c.fixed !== "right") {
11618
- this.fluidExtraTargetCol = c;
11619
- return;
11731
+ var col = cols[i];
11732
+ if (!this.isColVisible(col)) {
11733
+ continue;
11620
11734
  }
11621
- }
11622
- for (var i = this.tableCols.length - 1; i >= 0; i--) {
11623
- /** @type {?} */
11624
- var c = this.tableCols[i];
11625
- if (c && c.isShow) {
11626
- this.fluidExtraTargetCol = c;
11627
- return;
11735
+ if (col.fixed !== "right") {
11736
+ return col;
11737
+ }
11738
+ if (!lastVisible) {
11739
+ lastVisible = col;
11628
11740
  }
11629
11741
  }
11742
+ return lastVisible;
11743
+ };
11744
+ /** 把横向布局结果写回组件状态(dealScroll / syncHorizontalScroll 共用) */
11745
+ /**
11746
+ * 把横向布局结果写回组件状态(dealScroll / syncHorizontalScroll 共用)
11747
+ * @private
11748
+ * @param {?} layout
11749
+ * @return {?}
11750
+ */
11751
+ HdTableComponent.prototype.applyHorizontalLayout = /**
11752
+ * 把横向布局结果写回组件状态(dealScroll / syncHorizontalScroll 共用)
11753
+ * @private
11754
+ * @param {?} layout
11755
+ * @return {?}
11756
+ */
11757
+ function (layout) {
11758
+ this.fluidExtraWidth = layout.fluidExtra;
11759
+ this.fluidHorizontal = layout.isFluid;
11760
+ this.fluidExtraTargetCol =
11761
+ layout.fluidExtra > 0 ? this.findFluidExtraTargetCol() : null;
11762
+ this.tableColWidthTotal = layout.displayTotal;
11630
11763
  };
11631
11764
  Object.defineProperty(HdTableComponent.prototype, "totalFooterTableWidth", {
11632
11765
  /** fluid → 100%;固定 → scroll.x(与表体同一套横向宽度) */
@@ -11754,7 +11887,6 @@
11754
11887
  * @return {?}
11755
11888
  */
11756
11889
  function (forceRemount) {
11757
- var _this = this;
11758
11890
  if (forceRemount === void 0) { forceRemount = false; }
11759
11891
  /** @type {?} */
11760
11892
  var useVirtual = this.useVirtualScroll;
@@ -11767,23 +11899,7 @@
11767
11899
  // ng-zorro 只在 AfterViewInit 绑一次 header/body 的 scroll 同步;
11768
11900
  // 若先以 y=null 创建再改成有 y,表头监听会丢,表现为列头不跟着横滚。
11769
11901
  this.presetScrollBeforeRemount(useVirtual);
11770
- this.showTable = false;
11771
- this.cdr.markForCheck();
11772
- setTimeout((/**
11773
- * @return {?}
11774
- */
11775
- function () {
11776
- _this.showTable = true;
11777
- _this.cdr.markForCheck();
11778
- setTimeout((/**
11779
- * @return {?}
11780
- */
11781
- function () {
11782
- _this.dealScroll();
11783
- _this.cdr.markForCheck();
11784
- _this.afterTableRender(useVirtual);
11785
- }));
11786
- }));
11902
+ this.remountTable(useVirtual);
11787
11903
  return;
11788
11904
  }
11789
11905
  /** @type {?} */
@@ -11795,32 +11911,48 @@
11795
11911
  var nextHasX = !!(this.scroll && this.scroll.x);
11796
11912
  /** @type {?} */
11797
11913
  var nextHasY = !!(this.scroll && this.scroll.y);
11798
- // 运行中 x/y 从有变无/从无变有时,也必须重建:
11799
- // - y:ng-zorro 只在 AfterViewInit 绑一次 header/body 同步
11800
- // - x:空表 scroll.x=null(table-layout:auto)→ 有数据后设 scroll.x(fixed),
11801
- // 不重建时勾选列仍按 auto 均摊撑开(收款编辑等异步灌数页)
11914
+ // scroll.x / scroll.y 从无到有(或反过来)时必须重建,原地改值不生效:
11915
+ // - y:ng-zorro 8 只在 AfterViewInit 绑一次表头/表体滚动同步,且决定表头是否拆成独立 table
11916
+ // - x:决定是否带 ant-table-fixed(table-layout: fixed),勾选列锁宽依赖它
11802
11917
  if (prevHasY !== nextHasY || prevHasX !== nextHasX) {
11803
- this.showTable = false;
11804
- this.cdr.markForCheck();
11918
+ this.remountTable(useVirtual);
11919
+ return;
11920
+ }
11921
+ this.cdr.markForCheck();
11922
+ this.afterTableRender(useVirtual);
11923
+ };
11924
+ /** 销毁并重建 nz-table:等 DOM 出来后再按真实容器宽重算一次横向布局 */
11925
+ /**
11926
+ * 销毁并重建 nz-table:等 DOM 出来后再按真实容器宽重算一次横向布局
11927
+ * @private
11928
+ * @param {?} useVirtual
11929
+ * @return {?}
11930
+ */
11931
+ HdTableComponent.prototype.remountTable = /**
11932
+ * 销毁并重建 nz-table:等 DOM 出来后再按真实容器宽重算一次横向布局
11933
+ * @private
11934
+ * @param {?} useVirtual
11935
+ * @return {?}
11936
+ */
11937
+ function (useVirtual) {
11938
+ var _this = this;
11939
+ this.showTable = false;
11940
+ this.cdr.markForCheck();
11941
+ setTimeout((/**
11942
+ * @return {?}
11943
+ */
11944
+ function () {
11945
+ _this.showTable = true;
11946
+ _this.cdr.markForCheck();
11805
11947
  setTimeout((/**
11806
11948
  * @return {?}
11807
11949
  */
11808
11950
  function () {
11809
- _this.showTable = true;
11951
+ _this.dealScroll();
11810
11952
  _this.cdr.markForCheck();
11811
- setTimeout((/**
11812
- * @return {?}
11813
- */
11814
- function () {
11815
- _this.dealScroll();
11816
- _this.cdr.markForCheck();
11817
- _this.afterTableRender(useVirtual);
11818
- }));
11953
+ _this.afterTableRender(useVirtual);
11819
11954
  }));
11820
- return;
11821
- }
11822
- this.cdr.markForCheck();
11823
- this.afterTableRender(useVirtual);
11955
+ }));
11824
11956
  };
11825
11957
  /** 重建前预设 scroll,保证 AfterViewInit 时 header/body 结构已正确 */
11826
11958
  /**
@@ -12685,48 +12817,62 @@
12685
12817
  function (maxOffset) {
12686
12818
  return "calc(100vh - " + maxOffset + "px)";
12687
12819
  };
12688
- /**
12689
- * @private
12690
- * @return {?}
12691
- */
12692
- HdTableComponent.prototype.hasTableData = /**
12693
- * @private
12694
- * @return {?}
12695
- */
12696
- function () {
12697
- return !!(this.tableData &&
12698
- this.tableData.content &&
12699
- this.tableData.content.length);
12700
- };
12701
- /**
12702
- * 按声明列总宽 + 容器宽,计算 scroll.x 与 fluid 补宽。
12703
- * 列少:scroll.x = 内容区宽(clientWidth),差额加到最后业务列(勾选保持 40);
12704
- * 列多:scroll.x = 声明总宽。
12705
- * 比较是否超宽用 offsetWidth(含 Y 槽),避免「仅因纵滚条」误开横滚;
12706
- * 补宽目标用 clientWidth,且 scroll.x 用 floor,避免表宽多 1px 逼出 X 轴滚动条。
12707
- */
12708
- /**
12709
- * 按声明列总宽 + 容器宽,计算 scroll.x 与 fluid 补宽。
12710
- * 列少:scroll.x = 内容区宽(clientWidth),差额加到最后业务列(勾选保持 40);
12711
- * 列多:scroll.x = 声明总宽。
12712
- * 比较是否超宽用 offsetWidth(含 Y 槽),避免「仅因纵滚条」误开横滚;
12713
- * 补宽目标用 clientWidth,且 scroll.x 用 floor,避免表宽多 1px 逼出 X 轴滚动条。
12820
+ /*
12821
+ * 横向布局(勾选列锁 40px 的关键)
12822
+ *
12823
+ * 勾选列只有在 table-layout: fixed 下才锁得住:ng-zorro 8 仅在 nzScroll.x 有值时
12824
+ * 给 table 加 ant-table-fixed;auto 布局下 table 宽 100%、每列都有 nzWidth,
12825
+ * 剩余空间会按比例摊到所有列(含勾选列),单元格上的 max-width 也不生效。
12826
+ * 所以只要有列(无论有没有数据)就一定设置 scroll.x:
12827
+ * - 列少:scroll.x = 容器宽,差额补到最后一列业务列(fluid,不出真横滚)
12828
+ * - 列多:scroll.x = 声明总宽,正常横滚
12829
+ * less 里勾选列的 40px 只是 fixed 布局下的兜底。
12830
+ */
12831
+ /**
12832
+ * 按声明列宽合计 + 容器宽算出横向布局。
12833
+ * 判断「是否超宽」用 offsetWidth(含竖滚条槽),避免只因竖滚条就误开横滚;
12834
+ * 补宽目标用 clientWidth 并向下取整,避免表宽多 1px 逼出横滚条。
12835
+ */
12836
+ /*
12837
+ * 横向布局(勾选列锁 40px 的关键)
12838
+ *
12839
+ * 勾选列只有在 table-layout: fixed 下才锁得住:ng-zorro 8 仅在 nzScroll.x 有值时
12840
+ * 给 table 加 ant-table-fixed;auto 布局下 table 宽 100%、每列都有 nzWidth,
12841
+ * 剩余空间会按比例摊到所有列(含勾选列),单元格上的 max-width 也不生效。
12842
+ * 所以只要有列(无论有没有数据)就一定设置 scroll.x:
12843
+ * - 列少:scroll.x = 容器宽,差额补到最后一列业务列(fluid,不出真横滚)
12844
+ * - 列多:scroll.x = 声明总宽,正常横滚
12845
+ * less 里勾选列的 40px 只是 fixed 布局下的兜底。
12846
+ */
12847
+ /**
12848
+ * 按声明列宽合计 + 容器宽算出横向布局。
12849
+ * 判断「是否超宽」用 offsetWidth(含竖滚条槽),避免只因竖滚条就误开横滚;
12850
+ * 补宽目标用 clientWidth 并向下取整,避免表宽多 1px 逼出横滚条。
12714
12851
  * @private
12715
12852
  * @param {?} declaredColWidth
12716
12853
  * @return {?}
12717
12854
  */
12718
- HdTableComponent.prototype.resolveHorizontalLayout = /**
12719
- * 按声明列总宽 + 容器宽,计算 scroll.x 与 fluid 补宽。
12720
- * 列少:scroll.x = 内容区宽(clientWidth),差额加到最后业务列(勾选保持 40);
12721
- * 列多:scroll.x = 声明总宽。
12722
- * 比较是否超宽用 offsetWidth(含 Y 槽),避免「仅因纵滚条」误开横滚;
12723
- * 补宽目标用 clientWidth,且 scroll.x 用 floor,避免表宽多 1px 逼出 X 轴滚动条。
12855
+ HdTableComponent.prototype.resolveHorizontalLayout = /*
12856
+ * 横向布局(勾选列锁 40px 的关键)
12857
+ *
12858
+ * 勾选列只有在 table-layout: fixed 下才锁得住:ng-zorro 8 仅在 nzScroll.x 有值时
12859
+ * 给 table 加 ant-table-fixed;auto 布局下 table 宽 100%、每列都有 nzWidth,
12860
+ * 剩余空间会按比例摊到所有列(含勾选列),单元格上的 max-width 也不生效。
12861
+ * 所以只要有列(无论有没有数据)就一定设置 scroll.x:
12862
+ * - 列少:scroll.x = 容器宽,差额补到最后一列业务列(fluid,不出真横滚)
12863
+ * - 列多:scroll.x = 声明总宽,正常横滚
12864
+ * less 里勾选列的 40px 只是 fixed 布局下的兜底。
12865
+ */
12866
+ /**
12867
+ * 按声明列宽合计 + 容器宽算出横向布局。
12868
+ * 判断「是否超宽」用 offsetWidth(含竖滚条槽),避免只因竖滚条就误开横滚;
12869
+ * 补宽目标用 clientWidth 并向下取整,避免表宽多 1px 逼出横滚条。
12724
12870
  * @private
12725
12871
  * @param {?} declaredColWidth
12726
12872
  * @return {?}
12727
12873
  */
12728
12874
  function (declaredColWidth) {
12729
- if (!this.hasTableData() || declaredColWidth <= 0) {
12875
+ if (declaredColWidth <= 0) {
12730
12876
  return {
12731
12877
  scrollX: null,
12732
12878
  fluidExtra: 0,
@@ -12735,115 +12881,63 @@
12735
12881
  };
12736
12882
  }
12737
12883
  /** @type {?} */
12738
- var viewportCompare = this.nzTableComponent
12884
+ var compareWidth = this.nzTableComponent
12739
12885
  ? getTableScrollXViewportWidth(this.nzTableComponent)
12740
12886
  : 0;
12741
- // 表体尚未量到宽时(异步灌数 / spin / 刚 remount),用宿主宽兜底
12742
- if (viewportCompare <= 0 && this.hostEl && this.hostEl.nativeElement) {
12743
- /** @type {?} */
12744
- var hostW = ((/** @type {?} */ (this.hostEl.nativeElement))).offsetWidth;
12745
- if (hostW > 0) {
12746
- viewportCompare = hostW;
12747
- }
12887
+ // 表体还没渲染出来(刚重建 / 在 spin 里)时用宿主宽兜底
12888
+ if (compareWidth <= 0 && this.hostEl && this.hostEl.nativeElement) {
12889
+ compareWidth = ((/** @type {?} */ (this.hostEl.nativeElement))).offsetWidth;
12748
12890
  }
12749
- if (viewportCompare > 0) {
12750
- if (declaredColWidth > viewportCompare + 1) {
12751
- return {
12752
- scrollX: Math.ceil(declaredColWidth) + "px",
12753
- fluidExtra: 0,
12754
- displayTotal: declaredColWidth,
12755
- isFluid: false,
12756
- };
12757
- }
12758
- /** @type {?} */
12759
- var fillWidth = this.nzTableComponent
12760
- ? getTableViewportWidth(this.nzTableComponent)
12761
- : 0;
12762
- /** @type {?} */
12763
- var target = Math.floor(fillWidth > 0 ? fillWidth : viewportCompare);
12764
- /** @type {?} */
12765
- var fluidExtra = Math.max(0, target - declaredColWidth);
12766
- return {
12767
- scrollX: target + "px",
12768
- fluidExtra: fluidExtra,
12769
- displayTotal: declaredColWidth + fluidExtra,
12770
- isFluid: true,
12771
- };
12891
+ // 仍量不到(如宿主在 display:none 里):先按声明宽走 fixed,等 ResizeObserver 触发再转 fluid
12892
+ if (compareWidth <= 0) {
12893
+ return fixedLayout(declaredColWidth);
12772
12894
  }
12773
- // 视口仍测不到:至少用声明宽设 scroll.x,强制 fixed 布局锁勾选列,
12774
- // 避免落回 table-layout:auto 被均摊撑开;后续 sync/remount 再转 fluid。
12775
- return {
12776
- scrollX: Math.ceil(declaredColWidth) + "px",
12777
- fluidExtra: 0,
12778
- displayTotal: declaredColWidth,
12779
- isFluid: false,
12780
- };
12895
+ // 1px 容差,避免亚像素误判
12896
+ if (declaredColWidth > compareWidth + 1) {
12897
+ return fixedLayout(declaredColWidth);
12898
+ }
12899
+ /** @type {?} */
12900
+ var fillWidth = this.nzTableComponent
12901
+ ? getTableViewportWidth(this.nzTableComponent)
12902
+ : 0;
12903
+ /** @type {?} */
12904
+ var containerWidth = Math.floor(fillWidth > 0 ? fillWidth : compareWidth);
12905
+ return fluidLayout(containerWidth, declaredColWidth);
12781
12906
  };
12782
- /** 表格渲染后按实际容器宽度校正横向 scroll / fluid 补宽 */
12907
+ /** 表格渲染后按真实容器宽校正横向布局;只改 x,y 保持不变 */
12783
12908
  /**
12784
- * 表格渲染后按实际容器宽度校正横向 scroll / fluid 补宽
12909
+ * 表格渲染后按真实容器宽校正横向布局;只改 x,y 保持不变
12785
12910
  * @private
12786
12911
  * @return {?}
12787
12912
  */
12788
12913
  HdTableComponent.prototype.syncHorizontalScroll = /**
12789
- * 表格渲染后按实际容器宽度校正横向 scroll / fluid 补宽
12914
+ * 表格渲染后按真实容器宽校正横向布局;只改 x,y 保持不变
12790
12915
  * @private
12791
12916
  * @return {?}
12792
12917
  */
12793
12918
  function () {
12794
12919
  var _this = this;
12795
12920
  /** @type {?} */
12796
- var declared = 0;
12797
- if (this.showSelected) {
12798
- declared += 40;
12799
- }
12800
- if (this.showTableTotal) {
12801
- declared += this.lineNumberColWidth;
12802
- }
12803
- if (this.tableCols) {
12804
- this.tableCols.forEach((/**
12805
- * @param {?} item
12806
- * @return {?}
12807
- */
12808
- function (item) {
12809
- if (item && item.isShow !== false) {
12810
- declared += item.width > 0 ? item.width : ColWidth.fixColWidth;
12811
- }
12812
- }));
12813
- }
12814
- /** @type {?} */
12815
12921
  var prevHasX = !!(this.scroll && this.scroll.x);
12816
12922
  /** @type {?} */
12817
- var layout = this.resolveHorizontalLayout(declared);
12818
- /** @type {?} */
12819
- var currentY = this.scroll ? this.scroll.y : null;
12820
- /** @type {?} */
12821
- var nextHasX = !!layout.scrollX;
12923
+ var layout = this.resolveHorizontalLayout(this.getDeclaredColWidthTotal());
12822
12924
  /** @type {?} */
12823
- var sameX = this.scroll && this.scroll.x === layout.scrollX;
12824
- /** @type {?} */
12825
- var sameExtra = this.fluidExtraWidth === layout.fluidExtra;
12826
- /** @type {?} */
12827
- var sameFluid = this.fluidHorizontal === layout.isFluid;
12828
- if (sameX &&
12829
- sameExtra &&
12830
- sameFluid &&
12831
- this.scroll &&
12832
- this.scroll.y === currentY) {
12925
+ var unchanged = this.scroll &&
12926
+ this.scroll.x === layout.scrollX &&
12927
+ this.fluidExtraWidth === layout.fluidExtra &&
12928
+ this.fluidHorizontal === layout.isFluid;
12929
+ if (unchanged) {
12833
12930
  setTimeout((/**
12834
12931
  * @return {?}
12835
12932
  */
12836
12933
  function () { return _this.syncTotalFooterWithBody(); }));
12837
12934
  return;
12838
12935
  }
12839
- this.fluidExtraWidth = layout.fluidExtra;
12840
- this.fluidHorizontal = layout.isFluid;
12841
- this.refreshFluidExtraTargetCol();
12842
- this.tableColWidthTotal = layout.displayTotal;
12843
- this.scroll = { x: layout.scrollX, y: currentY };
12936
+ this.applyHorizontalLayout(layout);
12937
+ this.scroll = { x: layout.scrollX, y: this.scroll ? this.scroll.y : null };
12844
12938
  this.cdr.markForCheck();
12845
- // sync 阶段若补上了 scroll.x,需重建才能切到 fixed 布局
12846
- if (prevHasX !== nextHasX) {
12939
+ // x 从无到有(或反过来)要重建才能切换 table-layout
12940
+ if (prevHasX !== !!layout.scrollX) {
12847
12941
  this.applyTableScrollMode(true);
12848
12942
  return;
12849
12943
  }
@@ -13163,13 +13257,15 @@
13163
13257
  * @return {?}
13164
13258
  */
13165
13259
  function () {
13260
+ var _this = this;
13261
+ // 左侧固定列:从左往右累计偏移(勾选列、序号列在最前面)
13166
13262
  /** @type {?} */
13167
- var colWidth = 0;
13263
+ var leftOffset = 0;
13168
13264
  if (this.showSelected) {
13169
- colWidth += 40;
13265
+ leftOffset += SELECT_COL_WIDTH;
13170
13266
  }
13171
13267
  if (this.showTableTotal) {
13172
- colWidth += this.lineNumberColWidth; // 序号列(固定宽,不随位数变化)
13268
+ leftOffset += this.lineNumberColWidth;
13173
13269
  }
13174
13270
  this.tableCols.forEach((/**
13175
13271
  * @param {?} item
@@ -13179,9 +13275,9 @@
13179
13275
  if (!item.width) {
13180
13276
  item.width = ColWidth.fixColWidth;
13181
13277
  }
13182
- if (item.isShow !== false) {
13183
- item.fixedWidth = colWidth;
13184
- colWidth += item.width;
13278
+ if (_this.isColVisible(item)) {
13279
+ item.fixedWidth = leftOffset;
13280
+ leftOffset += item.width;
13185
13281
  }
13186
13282
  }));
13187
13283
  // 右侧固定列:从右往左累计偏移,避免多列都 right:0 互相遮挡
@@ -13190,7 +13286,7 @@
13190
13286
  for (var i = this.tableCols.length - 1; i >= 0; i--) {
13191
13287
  /** @type {?} */
13192
13288
  var item = this.tableCols[i];
13193
- if (item.isShow === false) {
13289
+ if (!this.isColVisible(item)) {
13194
13290
  continue;
13195
13291
  }
13196
13292
  if (item.fixed === "right") {
@@ -13202,11 +13298,8 @@
13202
13298
  }
13203
13299
  }
13204
13300
  /** @type {?} */
13205
- var layout = this.resolveHorizontalLayout(colWidth);
13206
- this.fluidExtraWidth = layout.fluidExtra;
13207
- this.fluidHorizontal = layout.isFluid;
13208
- this.refreshFluidExtraTargetCol();
13209
- this.tableColWidthTotal = layout.displayTotal;
13301
+ var layout = this.resolveHorizontalLayout(this.getDeclaredColWidthTotal());
13302
+ this.applyHorizontalLayout(layout);
13210
13303
  /** @type {?} */
13211
13304
  var maxOffset = this.getScrollYMaxOffset();
13212
13305
  /** @type {?} */
@@ -14681,24 +14774,22 @@
14681
14774
  */
14682
14775
  HdTableComponent.prototype.virtualScrollActive;
14683
14776
  /**
14684
- * 列宽合计(含勾选/序号 + fluid 补宽),footer 表宽与横向 scroll 共用
14777
+ * 实际渲染列宽合计(含勾选/序号 + 补宽),合计 footer 表宽用
14685
14778
  * @type {?}
14686
14779
  */
14687
14780
  HdTableComponent.prototype.tableColWidthTotal;
14688
14781
  /**
14689
- * fluid:声明列总宽 < 容器时,把差额补到最后一列业务列(不改缓存宽),
14690
- * 并设 scroll.x = 容器宽,避免表宽 100% 均摊撑开勾选列;拖拽改宽仍写 col.width。
14782
+ * 补到 fluidExtraTargetCol 上的宽度;只影响展示,不写回 col.width(列宽缓存、拖拽仍用声明宽)
14691
14783
  * @type {?}
14692
14784
  */
14693
14785
  HdTableComponent.prototype.fluidExtraWidth;
14694
14786
  /**
14695
- * 列总宽未超出容器(fluid 补宽吃满):不需要真正横滚,
14696
- * 用于关掉 ng-zorro fixed-header 带来的常驻 X 轴滚动条。
14787
+ * 列少、靠补宽吃满容器:模板据此加 hd-table--fluid-x,隐藏 fixed-header 常驻的横滚槽
14697
14788
  * @type {?}
14698
14789
  */
14699
14790
  HdTableComponent.prototype.fluidHorizontal;
14700
14791
  /**
14701
- * fluid 补宽目标列缓存,避免模板每格 CD 时反复扫 tableCols
14792
+ * 接收补宽的列,缓存起来避免模板每个单元格都扫一遍 tableCols
14702
14793
  * @type {?}
14703
14794
  * @private
14704
14795
  */