Browse Source

新增记录退出时的spreadjs位置

olym 7 years ago
parent
commit
6a2372d2e4

+ 31 - 0
web/building_saas/js/global.js

@@ -47,3 +47,34 @@ $(function () {
     });
     });
 
 
 });
 });
+
+/**
+ * 设置本地缓存
+ *
+ * @param {String} key
+ * @param {String|Number} value
+ * @return {void}
+ */
+function setLocalCache(key, value) {
+    const storage = window.localStorage;
+    if (!storage || key === '' || value === '') {
+        return;
+    }
+
+    storage.setItem(key, value);
+}
+
+/**
+ * 获取本地缓存
+ *
+ * @param {String} key
+ * @return {String}
+ */
+function getLocalCache(key) {
+    const storage = window.localStorage;
+    if (!storage || key === '') {
+        return null;
+    }
+
+    return storage.getItem(key);
+}

+ 16 - 10
web/building_saas/main/js/main.js

@@ -28,6 +28,16 @@ $(function () {
         projectObj.mainSpread.refresh();
         projectObj.mainSpread.refresh();
         refreshSubSpread();
         refreshSubSpread();
     });
     });
+
+    const projectId = scUrlUtil.GetQueryString('project');
+    // 绑定点击事件
+    projectObj.mainSpread.bind(GC.Spread.Sheets.Events.CellClick, function(sender, info) {
+        if (info.row !== undefined && projectId !== undefined) {
+            setLocalCache('lastRow:' + projectId, info.row);
+            setLocalCache('lastCol:' + projectId, info.col);
+        }
+    });
+
 });
 });
 
 
 /**
 /**
@@ -85,12 +95,9 @@ function slideResize(rootElement, callback) {
             callback();
             callback();
             drag = false;
             drag = false;
             // 存入本地缓存
             // 存入本地缓存
-            const storage = window.localStorage;
-            if (storage) {
-                const id = rootElement.attr('id');
-                storage.setItem('topHeight:' + id, topChangeHeight);
-                storage.setItem('bottomHeight:' + id, bottomChangeHeight);
-            }
+            const id = rootElement.attr('id');
+            setLocalCache('topHeight:' + id, topChangeHeight);
+            setLocalCache('bottomHeight:' + id, bottomChangeHeight);
         }
         }
     });
     });
 }
 }
@@ -103,12 +110,11 @@ function slideResize(rootElement, callback) {
  * @return {void}
  * @return {void}
  */
  */
 function loadSize(tag, callback) {
 function loadSize(tag, callback) {
-    const storage = window.localStorage;
-    if (!storage || tag === '') {
+    if (tag === '') {
         return;
         return;
     }
     }
-    const topHeight = storage.getItem('topHeight:' + tag);
-    const bottomHeight = storage.getItem('bottomHeight:' + tag);
+    const topHeight = getLocalCache('topHeight:' + tag);
+    const bottomHeight = getLocalCache('bottomHeight:' + tag);
     if (topHeight === null || bottomHeight === null) {
     if (topHeight === null || bottomHeight === null) {
         return;
         return;
     }
     }

+ 13 - 0
web/building_saas/main/js/views/project_view.js

@@ -412,6 +412,7 @@ var projectObj = {
                 that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
                 that.mainSpread.bind(GC.Spread.Sheets.Events.EditEnded, that.mainSpreadEditEnded);
                 that.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, that.mainSpreadRangeChanged);
                 that.mainSpread.bind(GC.Spread.Sheets.Events.RangeChanged, that.mainSpreadRangeChanged);
                 that.loadMainSpreadContextMenu();
                 that.loadMainSpreadContextMenu();
+                that.loadFocusLocation();
             }
             }
             else {
             else {
 
 
@@ -531,6 +532,18 @@ var projectObj = {
         this.project.Bills.updateAll();
         this.project.Bills.updateAll();
         calc = null;
         calc = null;
     }*/
     }*/
+    // 获取上次退出时的焦点位置
+    loadFocusLocation: function() {
+        const projectId = scUrlUtil.GetQueryString('project');
+        let row = getLocalCache('lastRow:' + projectId);
+        let col = getLocalCache('lastCol:' + projectId);
+        if (row !== null && col !== null) {
+            row = parseInt(row);
+            col = parseInt(col);
+            const sheet = this.mainSpread.getActiveSheet();
+            sheet.setSelection(row, col, 1, 1);
+        }
+    },
 };
 };
 
 
 $('#insert').click(function () {
 $('#insert').click(function () {