chenshilong 6 years ago
parent
commit
5ce14ed33f
2 changed files with 49 additions and 28 deletions
  1. 10 5
      web/building_saas/main/html/main.html
  2. 39 23
      web/building_saas/main/js/views/block_lib.js

+ 10 - 5
web/building_saas/main/html/main.html

@@ -39,6 +39,8 @@
         let userAccount = '<%- userAccount %>';
         let userID = '<%- userID %>';
         let projectReadOnly = JSON.parse('<%- projectReadOnly %>');
+//        const G_SHOW_BLOCK_LIB = true;
+        const G_SHOW_BLOCK_LIB = false;
     </script>
 </head>
 
@@ -123,12 +125,15 @@
                          <!-- <li class="nav-item">
                               <a class="nav-link px-3" href="javascript:void(0)" id = 'stdBillsTab' relaPanel="#qd">清单规则</a>
                           </li>-->
-                          <li class="nav-item">
+                          <li class="nav-item" id = "li_stdRationTab">
                               <a class="nav-link px-3" href="javascript:void(0)" id="stdRationTab" relaPanel="#de">定额库</a>
                           </li>
-<!--                          <li class="nav-item">
-                              <a class="nav-link px-3" href="javascript:void(0)" id="blockLibTab" relaPanel="#kmbk">块模板库</a>
-                          </li>-->
+                          <script>
+                              if (G_SHOW_BLOCK_LIB){
+                                  $("#li_stdRationTab").after('<li class="nav-item"> <a class="nav-link px-3" href="javascript:void(0)" ' +
+                                      'id="blockLibTab" relaPanel="#kmbk">块模板库2</a></li>');
+                              }
+                          </script>
                       </ul>
                   </div>
               </div>
@@ -455,7 +460,7 @@
                                       <div class="p-1 row">
                                           <button id="btn_block_collapse" class="btn btn-primary btn-sm" type="button">展开/折叠</button>
                                           <button id="btn_block_newFolder" class="btn btn-primary btn-sm" type="button">新建分类</button>
-                                          <button id="btn_block_newSubFolder" class="btn btn-warning btn-sm" type="button">新建子类</button>
+                                          <button id="btn_block_newSubFolder" class="btn btn-warning btn-sm" type="button">新建</button>
                                       </div>
                                   </div>
                                   <div class="top-content" style="overflow: hidden">

+ 39 - 23
web/building_saas/main/js/views/block_lib.js

@@ -38,14 +38,13 @@ var blockLibObj = {
         $.bootstrapLoading.start();
         let me = this;
         me.mainDatas = [
-            {ID: 1, ParentID: -1, NextSiblingID: 8, name: '我的块模板库1', type: 0},
-            {ID: 2, ParentID: 1, NextSiblingID: 3, name: '分类1', type: 1},
-            {ID: 3, ParentID: 1, NextSiblingID: -1, name: '分类2', type: 1},
-            {ID: 4, ParentID: 2, NextSiblingID: 5, name: '子类A', type: 1},
-            {ID: 5, ParentID: 2, NextSiblingID: -1, name: '子类B', type: 1},
-            {ID: 6, ParentID: 4, NextSiblingID: 7, name: '块1', type: 2},
-            {ID: 7, ParentID: 4, NextSiblingID: -1, name: '块2', type: 2},
-            {ID: 8, ParentID: -1, NextSiblingID: -1, name: '我的块模板库2', type: 0}
+            {ID: 2, ParentID: -1, NextSiblingID: 3, name: '分类2', type: 1},
+            {ID: 3, ParentID: -1, NextSiblingID: -1, name: '分类3', type: 1},
+            {ID: 6, ParentID: 2, NextSiblingID: 7, name: '块1', type: 2},
+            {ID: 7, ParentID: 2, NextSiblingID: -1, name: '块2', type: 2},
+            {ID: 52, ParentID: -1, NextSiblingID: 53, name: '分类52', type: 1},
+            {ID: 55, ParentID: -1, NextSiblingID: -1, name: '分类55', type: 1},
+            {ID: 88, ParentID: 52, NextSiblingID: -1, name: '块88', type: 2}
         ];
 
         if (me.mainSpread) {
@@ -53,6 +52,7 @@ var blockLibObj = {
             me.mainSpread = null;
         };
         me.mainSpread = SheetDataHelper.createNewSpread($('#div_block_tree')[0]);
+        // me.mainSpread = TREE_SHEET_HELPER.createNewSpread($('#div_block_tree')[0]);
         me.mainSheet = me.mainSpread.getSheet(0);
         me.mainSheet.name('blockLibSheet');
         sheetCommonObj.spreadDefaultStyle(me.mainSpread);
@@ -284,22 +284,40 @@ var blockLibObj = {
         };
         return new TreeCell();
     },
-    insert: function (insertType){    // 1 后兄弟; 2 孩子。
+    newNode: function (nodeType){     // 1 分类  2 块文件
         let tree = blockLibObj.mainTree;
+        let pID = -1, nID = -1;
         let select = tree.selected;
-        if (!select) select = tree.items[0];
-        let pID = (insertType == 1) ? select.getParentID() : select.getID();
-        let nID = (insertType == 1) ? select.getNextSiblingID() : -1;
-        let newNode = tree.insert(pID, nID);
-
-        if (!newNode.parent){
-            newNode.data.type = 0;
-            newNode.data.name = '我的块模板库';
-        }
-        else{
+        let newNode = null;
+        if (nodeType == 1){
+            if (!select) {
+                nID = -1;
+            }
+            else if (select.data.type == 1){
+                nID = select.getNextSiblingID();
+            }
+            else if (select.data.type == 2){
+                nID = select.parent.getNextSiblingID();
+            };
+            newNode = tree.insert(pID, nID);
             newNode.data.type = 1;
             newNode.data.name = '分类';
         }
+        else if (nodeType == 2) {
+            if (!select) {
+                pID = tree.items[0].getID();
+            }
+            else if (select.data.type == 1){
+                pID = select.getID();
+            }
+            else if (select.data.type == 2){
+                pID = select.getParentID();
+                nID = select.getNextSiblingID();
+            };
+            newNode = tree.insert(pID, nID);
+            newNode.data.type = 2;
+            newNode.data.name = '块文件';
+        }
 
         tree.selected = newNode;
 
@@ -327,11 +345,9 @@ $(document).ready(function(){
         }
     });
     $('#btn_block_newFolder').on('click', function (){
-        blockLibObj.insert(1);
+        blockLibObj.newNode(1);
     });
-
     $('#btn_block_newSubFolder').on('click', function (){
-        blockLibObj.insert(2);
+        blockLibObj.newNode(2);
     });
-
 });