xujunjie 1 年間 前
コミット
197d03cbca
3 ファイル変更153 行追加105 行削除
  1. 121 97
      src/core.js
  2. 28 7
      src/function/functionImplementation.js
  3. 4 1
      src/global/format.js

+ 121 - 97
src/core.js

@@ -178,31 +178,24 @@ luckysheet.create = function(setting) {
     // luckysheetsizeauto();
     initialWorkBook();
   } else {
-    $.get(authorityUrl, function(res) {
-      let arr = res.data.filter(
-        (item) => item.template?.template_id == templateId
-      );
-      console.log(arr);
-
-      $.post(loadurl, { gridKey: server.gridKey }, function(d) {
-        let data = new Function("return " + d)();
-        data.forEach((sheet) => {
-          initSheet(sheet, arr, authority);
-        });
+    $.post(loadurl, { gridKey: server.gridKey }, function(d) {
+      let data = new Function("return " + d)();
+      data.forEach((sheet) => {
+        initSheet(sheet, authority, setting.permissions);
+      });
 
-        console.log(data);
-        Store.luckysheetfile = data;
+      console.log(data);
+      Store.luckysheetfile = data;
 
-        sheetmanage.initialjfFile(menu, title);
-        // luckysheetsizeauto();
-        initialWorkBook();
+      sheetmanage.initialjfFile(menu, title);
+      // luckysheetsizeauto();
+      initialWorkBook();
 
-        //需要更新数据给后台时,建立WebSocket连接
-        if (server.allowUpdate) {
-          server.getUser = setting.getUser;
-          server.openWebSocket();
-        }
-      });
+      //需要更新数据给后台时,建立WebSocket连接
+      if (server.allowUpdate) {
+        server.getUser = setting.getUser;
+        server.openWebSocket();
+      }
     });
   }
 };
@@ -273,95 +266,126 @@ luckysheet.luckysheetextendData = luckysheetextendData;
 
 export { luckysheet };
 
-function initSheet(sheet, cellAuthority, authority) {
-  let allowRangeList = [],
-    colhidden = {};
-  let cache = {};
+// function initSheet(sheet, authority, permissions) {
+function initSheet(sheet, authority) {
+  let permissions = {
+    "func-psr-01": 1,
+    "func-psr-02": 0,
+    "func-psr-03": 0,
+    "func-psr-04": 0,
+    "func-psr-05": 0,
+    "func-psr-06": 0,
+    "func-actual-01": 1,
+    "func-actual-02": 0,
+    "func-actual-03": 0,
+    "func-actual-04": 0,
+    "func-actual-05": 0,
+    "func-list-01": 0,
+  };
+  let colhidden = {};
+  let rowhidden = {};
   if (sheet.config) {
     delete sheet.config.authority;
   }
-  sheet.celldata.forEach((item) => {
-    if (!cache[item.c]) cache[item.c] = [];
-    cache[item.c].push(item);
-  });
-  cellAuthority.forEach((item) => {
-    // 将A B C D....转换为0 1 2 3...
-    let col_idx = item.template.col_idx;
-    let col = col_idx.charCodeAt(0) - 65;
-    if (!item.can_read) {
-      colhidden[col] = 0;
-    }
-    if (item.can_write) {
-      // 区域保护
-      allowRangeList.push({
-        hintText: "",
-        sqref: `$${col_idx}$0:$${col_idx}$99999`,
-      });
-    }
-  });
-  // let celldata = []
-  // Object.values(cache).forEach(colItem => {
-  //     celldata = [...celldata,...colItem]
-  // })
-  // sheet.celldata = celldata
   sheet.config = sheet.config || {};
   // 处于审批时  所有人都无法修改
   if (authority) {
     sheet.config.authority = authority;
-  } else if (cellAuthority.length > 0) {
-    let newAuthority = {
-      sheet: true,
-      hintText: "没有编辑权限!",
-    };
-    if (allowRangeList.length > 0) {
-      // 可编辑内容
-      newAuthority.allowRangeList = allowRangeList;
-    }
-
-    sheet.config.authority = newAuthority;
   } else {
-    let lastCell = sheet.celldata[sheet.celldata.length - 1];
-    if (lastCell) {
-      let lastCol = String.fromCharCode(lastCell.c);
-      // 第一列禁止编辑但是可以增加
-      let canEditCell = sheet.celldata.filter((item) => {
-        if (item.r == 0) {
-          // 判断是否为空
-          if ((item?.v?.v ?? "") === "" && !item?.v?.ct?.s) return true;
+    let canEditRangeList = [];
+   
+    if (sheet.name == "PSR") {
+      canEditRangeList = [
+        {
+          hintText: "",
+          sqref: "$C$19:$C$20",
+        },
+        {
+          hintText: "",
+          sqref: "$C$47:$C$52",
+        },
+        {
+          hintText: "",
+          sqref: "$C$56:$C$56",
+        },
+        {
+          hintText: "",
+          sqref: "$C$57:$C$57",
+        },
+        {
+          hintText: "",
+          sqref: "$C$86:$C$87",
+        },
+      ];
+      // 隐藏PSR表
+      if (!permissions["func-psr-01"]) {
+        sheet.hide = 1;
+        sheet.status = 0;
+      }
+      // 隐藏项目经理预算
+      if (!permissions["func-psr-02"]) {
+        for (let i = 77; i <= 88; i++) {
+          rowhidden[i] = 0;
         }
-      });
-      let canEditRangeList = canEditCell.map((item) => {
-        let col = String.fromCharCode(item.c + 65);
-        return {
+      }
+      // 最下方预算
+      if (!permissions["func-psr-03"]) {
+        for (let i = 101; i <= 117; i++) {
+          rowhidden[i] = 0;
+        }
+      }
+      // 更新时间权限
+      if (permissions["func-psr-04"]) {
+        canEditRangeList.push({
           hintText: "",
-          sqref: `$${col}$1:$${col}$1`,
-        };
-      });
-      // 设置保护区域,lucksheet不能直接设置不允许编辑的区域
-      // 只能禁止整体编辑,设置例外区域
-      sheet.config.authority = {
-        sheet: 1,
-        hintText: "表头只能新增,禁止编辑!",
-        // insertColumns: 0,
-        allowRangeList: [
-          // 第一行以外都能编辑
-          {
-            hintText: "",
-            sqref: `$a$2:$z$99999`,
-          },
-
-          // 第一列未加载出来的row也允许编辑
-          {
-            hintText: "",
-            sqref: `$${lastCol}$1:$${lastCol}$1`,
-          },
-          ...canEditRangeList,
-        ],
-      };
+          sqref: "$B$2:$B$2",
+        });
+      }
+      // 预算列权限
+      if (permissions["func-psr-05"]) {
+        canEditRangeList.push({
+          hintText: "",
+          sqref: "$G$6:$G$89",
+        });
+      }
+    } else if (sheet.name == "现金流") {
+      if (!permissions["func-actual-01"]) {
+        sheet.hide = 1;
+        sheet.status = 0;
+      }
+      // 预计回款权限
+      if (permissions["func-psr-02"]) {
+        canEditRangeList.push({
+          hintText: "",
+          sqref: "$A$3:$CF$3",
+        });
+      }
+      // 实际回款权限
+      if (permissions["func-psr-03"]) {
+        canEditRangeList.push({
+          hintText: "",
+          sqref: "$A$4:$CF$4",
+        });
+      }
+    } else if (sheet.name == "清单") {
+      // 隐藏项目经理预算
+      if (!permissions["func-list-01"]) {
+        colhidden[8] = 0;
+        colhidden[9] = 0;
+      }
     }
+
+    // 设置保护区域,lucksheet不能直接设置不允许编辑的区域
+    // 只能禁止整体编辑,设置例外区域
+    sheet.config.authority = {
+      sheet: 1,
+      hintText: "禁止编辑",
+      allowRangeList: canEditRangeList,
+    };
   }
 
   sheet.config.colhidden = colhidden;
+  sheet.config.rowhidden = rowhidden;
 
   // 公式计算
   let calcChain = [];

+ 28 - 7
src/function/functionImplementation.js

@@ -11098,15 +11098,24 @@ const functionImplementation = {
             var range2;
             var result = formula.error.na;
 
+            if(!range && arguments[1] instanceof Array) {
+                range = arguments[1]
+            } else {
+                //获得两个范围的数组
+                range = formula.getRangeArray(range)[0];
+            }
             function sortNum(a,b){ //用于排序
                 return b - a;
             }
 
-            //获得两个范围的数组
-            range= formula.getRangeArray(range)[0];
             if(arguments[2]){
                 range2 = arguments[2].data;
-                range2 = formula.getRangeArray(range2)[0];
+                if(!range2 && arguments[2] instanceof Array) {
+                    range2 = arguments[2]
+                } else {
+                    //获得两个范围的数组
+                    range2 = formula.getRangeArray(range2)[0];
+                }
             }
 
             if(typeof(searchkey) == "string"){ //字符串直接判断是否相等
@@ -11200,6 +11209,7 @@ const functionImplementation = {
             var data_array = arguments[0];
             var array = [];
             let isReference = false;
+            var row_num, column_num;
             if(getObjType(data_array) == "array"){
                 if(getObjType(data_array[0]) == "array" && !func_methods.isDyadicArr(data_array)){
                     return formula.error.v;
@@ -11213,9 +11223,22 @@ const functionImplementation = {
             }
 
             var rowlen = array.length, collen = array[0].length;
+            if(arguments.length == 3) {
+                //选择数组中的某行,函数从该行返回数值
+                row_num = func_methods.getFirstValue(arguments[1]);
+                //选择数组中的某列,函数从该列返回数值
+                column_num = func_methods.getFirstValue(arguments[2]);
+
+            } else if(arguments.length == 2) {
+                if(data_array.data.length == 1) {
+                    row_num = 1
+                    column_num = func_methods.getFirstValue(arguments[1]);
+                } else {
+                    row_num = func_methods.getFirstValue(arguments[1]);
+                    column_num = 1
+                }
+            }
 
-            //选择数组中的某行,函数从该行返回数值
-            var row_num = func_methods.getFirstValue(arguments[1]);
             if(valueIsError(row_num)){
                 return row_num;
             }
@@ -11226,8 +11249,6 @@ const functionImplementation = {
 
             row_num = parseInt(row_num);
 
-            //选择数组中的某列,函数从该列返回数值
-            var column_num = func_methods.getFirstValue(arguments[2]);
             if(valueIsError(column_num)){
                 return column_num;
             }

+ 4 - 1
src/global/format.js

@@ -228,10 +228,13 @@ var make_ssf = function make_ssf(SSF) {
             dout = b2 ? [1317, 8, 29] : [1900, 1, 0];
             dow = 6;
         } else {
+            // 看不懂为什么要递减1,会导致天数与实际真实值差1
             if (date > 60) --date;
             /* 1 = Jan 1 1900 in Gregorian */
             var d = new Date(1900, 0, 1);
-            d.setDate(d.getDate() + date - 1);
+            // -1 以及上面的递减1会导致天数与实际相差2天,改为 +1弥补两天差距
+            // d.setDate(d.getDate() + date - 1);
+            d.setDate(d.getDate() + date + 1);
             dout = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
             dow = d.getDay();
             if (date < 60) dow = (dow + 6) % 7;