Przeglądaj źródła

第一列禁止编辑

xjj 2 lat temu
rodzic
commit
5d039f95f2
1 zmienionych plików z 11 dodań i 11 usunięć
  1. 11 11
      src/core.js

+ 11 - 11
src/core.js

@@ -321,40 +321,40 @@ function initSheet(sheet, cellAuthority, authority) {
     sheet.config.authority = newAuthority;
   } else {
     let lastCell = sheet.celldata[sheet.celldata.length - 1];
+    let lastCol = String.fromCharCode(lastCell.c);
     // 第一列禁止编辑但是可以增加
     let canEditCell = sheet.celldata.filter((item) => {
-      if (item.c == 0) {
+      if (item.r == 0) {
         // 判断是否为空
         if ((item?.v?.v ?? "") === "" && !item?.v?.ct?.s) return true;
       }
     });
     let canEditRangeList = canEditCell.map((item) => {
-      let row_idx = item.r + 1;
+      let col = String.fromCharCode(item.c + 65);
       return {
         hintText: "",
-        sqref: `$a$${row_idx}:$a$${row_idx}`,
+        sqref: `$${col}$1:$${col}$1`,
       };
     });
     // 设置保护区域,lucksheet不能直接设置不允许编辑的区域
     // 只能禁止整体编辑,设置例外区域
     sheet.config.authority = {
       sheet: 1,
-      hintText: "禁止编辑!",
-      insertColumns: 0,
+      hintText: "表头只能新增,禁止编辑!",
+      // insertColumns: 0,
       allowRangeList: [
-        // 第一以外都能编辑
+        // 第一以外都能编辑
         {
           hintText: "",
-          sqref: `$b$1:$z$99999`,
+          sqref: `$a$2:$z$99999`,
         },
-
+        
         // 第一列未加载出来的row也允许编辑
         {
           hintText: "",
-          sqref: `$a$${lastCell.r + 2}:$a$999999`,
+          sqref: `$${lastCol}$1:$${lastCol}$1`,
         },
-        // 第一列没有value的也允许编辑
-        ...canEditRangeList,
+        ...canEditRangeList
       ],
     };
   }