Browse Source

资料归集,记住展开收起

MaiXinRong 2 years atrás
parent
commit
1a7775c19c
1 changed files with 21 additions and 1 deletions
  1. 21 1
      app/public/js/file_detail.js

+ 21 - 1
app/public/js/file_detail.js

@@ -13,8 +13,12 @@ $(document).ready(function() {
             this.setting = setting;
             this.filingTree = null;
             this.pageCount = 15;
+            this.expandKey = 'filing-' + window.location.pathname.split('/')[2];
+            const cache = getLocalCache(this.expandKey);
+            this.expandCache = cache ? cache.split(',') : [];
         }
         analysisFiling(data) {
+            const self = this;
             this.dragTree.loadDatas(data);
             this.dragTree.recursiveFun(this.dragTree.children, x => {
                 if (x.children && x.children.length > 0) {
@@ -36,6 +40,7 @@ $(document).ready(function() {
                     source_node: x,
                 };
                 if (result.source_node.is_fixed) result.isParent = true;
+                if (result.source_node.is_folder || result.source_node.is_fixed) result.open = self.expandCache.indexOf(result.id) >= 0;
                 return result;
             });
             this.filingTree = $.fn.zTree.init($('#filing'), this.setting, sortNodes);
@@ -235,6 +240,15 @@ $(document).ready(function() {
             }
             return result.join('/');
         }
+        expandFiling(node, expand) {
+            if (expand) {
+                this.expandCache.push(node.id);
+            } else{
+                const index = this.expandCache.indexOf(node.id);
+                if (index >= 0) this.expandCache.splice(index, 1);
+            }
+            setLocalCache(this.expandKey, this.expandCache.join(','));
+        }
     }
     const levelTreeSetting = {
         view: {
@@ -285,7 +299,13 @@ $(document).ready(function() {
             beforeRemove: function(e, key, node, isCancel) {
                 $('#del-filing').modal('show');
                 return false;
-            }
+            },
+            onExpand(e, key, node) {
+                filingObj.expandFiling(node, true);
+            },
+            onCollapse: function(e, key, node) {
+                filingObj.expandFiling(node, false);
+            },
         }
     };
     const filingObj = new FilingObj(levelTreeSetting);