Pārlūkot izejas kodu

feat: 信息价地区表增加右键解锁、锁定

vian 2 mēneši atpakaļ
vecāks
revīzija
4171208be2
2 mainītis faili ar 56 papildinājumiem un 10 dzēšanām
  1. 23 0
      public/web/lock_util.js
  2. 33 10
      web/maintain/price_info_lib/js/priceArea.js

+ 23 - 0
public/web/lock_util.js

@@ -78,6 +78,28 @@ const lockUtil = (() => {
         $url.prop('href', curURL);
     }
 
+    function unLockSpreads(spreads) {
+        spreads.forEach(spread => {
+            spread.unbind(GC.Spread.Sheets.Events.ButtonClicked);
+            const sheetCount = spread.getSheetCount();
+            for (let i = 0; i < sheetCount; i++) {
+                const sheet = spread.getSheet(i);
+                sheet.suspendPaint();
+                sheet.suspendEvent();
+                sheet.options.isProtected = false;
+                const rowCount = sheet.getRowCount();
+                const colCount = sheet.getColumnCount();
+                for (let row = 0; row < rowCount; row++) {
+                    for (let col = 0; col < colCount; col++) {
+                        sheet.getCell(row, col).locked(false);
+                    }
+                }
+                sheet.resumePaint();
+                sheet.resumeEvent();
+            }
+        });
+    }
+
     function displayLock($lock, locked) {
         $lock.data('locked', locked);
         const innerHtml = locked ? '<i class="fa fa-unlock-alt"></i>' : '<i class="fa fa-lock"></i>';
@@ -107,6 +129,7 @@ const lockUtil = (() => {
         getLocked,
         lockTools,
         lockSpreads,
+        unLockSpreads,
         lockURL,
         displayLock,
         handleLockClick,

+ 33 - 10
web/maintain/price_info_lib/js/priceArea.js

@@ -1,5 +1,7 @@
 // 地区表
 const AREA_BOOK = (() => {
+  // 地区表格锁
+  let areaLocked = true;
   const cache = areaList;
   const setting = {
     header: [
@@ -9,7 +11,7 @@ const AREA_BOOK = (() => {
   };
   // 初始化表格
   const workBook = initSheet($('#area-spread')[0], setting);
-  lockUtil.lockSpreads([workBook], locked);
+  lockUtil.lockSpreads([workBook], locked || areaLocked);
   workBook.options.allowExtendPasteRange = false;
   workBook.options.allowUserDragDrop = false;
   workBook.options.allowUserDragFill = false;
@@ -55,13 +57,18 @@ const AREA_BOOK = (() => {
       });
     }
   }
-  sheet.bind(GC.Spread.Sheets.Events.ValueChanged, function (e, info) {
-    const changedCells = [{ row: info.row, col: info.col }];
-    handleEdit(changedCells);
-  });
-  sheet.bind(GC.Spread.Sheets.Events.RangeChanged, function (e, info) {
-    handleEdit(info.changedCells);
-  });
+
+  const bindEdit = () => {
+    sheet.bind(GC.Spread.Sheets.Events.ValueChanged, function (e, info) {
+      const changedCells = [{ row: info.row, col: info.col }];
+      handleEdit(changedCells);
+    });
+    sheet.bind(GC.Spread.Sheets.Events.RangeChanged, function (e, info) {
+      handleEdit(info.changedCells);
+    });
+  };
+
+  bindEdit();
 
   const curArea = { ID: null, name: '' };
   // 焦点变更处理
@@ -139,11 +146,27 @@ const AREA_BOOK = (() => {
           }
           return {
             items: {
+              lock: {
+                name: areaLocked ? '解锁' : '锁定',
+                icon: areaLocked ? "fa-unlock" : 'fa-lock',
+                disabled: function () {
+                  return locked;
+                },
+                callback: function (key, opt) {
+                  areaLocked = !areaLocked;
+                  if (locked || areaLocked) {
+                    lockUtil.lockSpreads([workBook], locked || areaLocked);
+                  } else {
+                    lockUtil.unLockSpreads([workBook]);
+                    bindEdit();
+                  }
+                }
+              },
               insert: {
                 name: '新增',
                 icon: "fa-arrow-left",
                 disabled: function () {
-                  return locked;
+                  return locked || areaLocked;
                 },
                 callback: function (key, opt) {
                   insert();
@@ -153,7 +176,7 @@ const AREA_BOOK = (() => {
                 name: '删除',
                 icon: "fa-arrow-left",
                 disabled: function () {
-                  return locked || !cache[target.row];
+                  return locked || areaLocked || !cache[target.row];
                 },
                 callback: function (key, opt) {
                   del();