Przeglądaj źródła

refactor(filesjs): 重构 SpreadJS 列宽调整逻辑以适配冻结列

- 添加 frozenColCount 和 frozenLineColor 配置项支持冻结列
- 使用 getViewportWidth API 替代手动计算容器宽度
- 处理分栏骤窄时冻结列占满视口的边界情况
- 基于 sheet.zoom() 计算实际可用宽度提升缩放兼容性
- 仅在宽度实际变化时调用 setColumnWidth 减少无效重绘
caipin 1 dzień temu
rodzic
commit
c0488925f1
1 zmienionych plików z 11 dodań i 13 usunięć
  1. 11 13
      app/public/js/filesjs.js

+ 11 - 13
app/public/js/filesjs.js

@@ -64,6 +64,8 @@ $(document).ready(function() {
                 headRowHeight: [32],
                 defaultRowHeight: 21,
                 headColWidth: [25],
+                frozenColCount: 1,
+                frozenLineColor: '#d9d9d9',
                 headerFont: '12px 微软雅黑',
                 font: '12px 微软雅黑',
                 readOnly: false,
@@ -212,20 +214,16 @@ $(document).ready(function() {
          * 根据目录区域宽度调整树表列宽,拖动分隔条时保持 SpreadJS 填满容器。
          */
         resizeSpreadColumns() {
-            const containerWidth = Math.floor($('#filing-spread').innerWidth() || 0);
-            if (containerWidth <= 0) return;
-
-            const rowHeaderWidth = 25;
-            const fileCountWidth = 70;
-            const scrollbarWidth = 18;
-            const borderWidth = 2;
-            const nameWidth = Math.max(
-                containerWidth - rowHeaderWidth - fileCountWidth - scrollbarWidth - borderWidth,
-                60
-            );
-            this.sheet.setColumnWidth(0, nameWidth);
-            this.sheet.setColumnWidth(1, fileCountWidth);
+            if (!this.spread.getHost().clientWidth) return;
             this.spread.refresh();
+            const sheet = this.sheet;
+            // 分栏骤然变窄时,旧的冻结列可能占满视口;先缩小它,才能量到实际可用宽度。
+            if (sheet.getViewportWidth(1) === 0) sheet.setColumnWidth(0, 1);
+            const viewportWidth = sheet.getViewportWidth(0) + sheet.getViewportWidth(1);
+            const fileCountWidth = this.spreadSetting.cols[1].width;
+            const nameWidth = Math.max(1, Math.floor(viewportWidth / sheet.zoom()) - fileCountWidth);
+            if (sheet.getColumnWidth(0) !== nameWidth) sheet.setColumnWidth(0, nameWidth);
+            if (sheet.getColumnWidth(1) !== fileCountWidth) sheet.setColumnWidth(1, fileCountWidth);
         }
 
         /**