Przeglądaj źródła

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

vian 2 miesięcy temu
rodzic
commit
e17eade3ba

+ 24 - 0
public/web/lock_util.js

@@ -70,6 +70,29 @@ const lockUtil = (() => {
             }
         });
     }
+
+    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 lockURL(locked, $url) {
         const originURL = $url.prop('href');
         const originLocked = !locked;
@@ -108,6 +131,7 @@ const lockUtil = (() => {
         getLocked,
         lockTools,
         lockSpreads,
+        unLockSpreads,
         lockURL,
         displayLock,
         handleLockClick,

+ 36 - 5
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,26 @@ const AREA_BOOK = (() => {
       });
     }
   }
-  sheet.bind(GC.Spread.Sheets.Events.ValueChanged, function (e, info) {
+
+  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();
+
+  /* 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 curArea = { ID: null, name: '' };
   // 焦点变更处理
@@ -139,11 +154,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 +184,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();