star7th 7 年之前
父节点
当前提交
1319acb344

+ 8 - 10
server/Application/Api/Controller/CatalogController.class.php

@@ -59,10 +59,15 @@ class CatalogController extends BaseController {
 
     //获取二级目录的子目录列表,即三级目录列表(如果存在的话)
     public function childCatList(){
+        $login_user = $this->checkLogin();
         $cat_id = I("cat_id/d");
         if ($cat_id > 0 ) {
             $row = D("Catalog")->where(" cat_id = '$cat_id' ")->find() ;
             $item_id = $row['item_id'] ;
+            if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
+                $this->sendError(10103);
+                return ;
+            }
             $ret =  D("Catalog")->getChlid($item_id , $cat_id);
         }
         if ($ret) {
@@ -100,7 +105,8 @@ class CatalogController extends BaseController {
         $data['item_id'] = $item_id ;
         $data['parent_cat_id'] = $parent_cat_id ;
         if ($parent_cat_id > 0 ) {
-           $data['level'] = 3;
+            $row = D("Catalog")->where(" cat_id = '$parent_cat_id' ")->find() ;
+            $data['level'] = $row['level'] +1 ;
         }else{
             $data['level'] = 2;
         }
@@ -199,15 +205,7 @@ class CatalogController extends BaseController {
             return;
         }
 
-        $Catalog = D("Catalog")->where(" cat_id = '$default_cat_id' ")->find();
-        if ($Catalog['parent_cat_id']) {
-            $default_cat_id2 = $Catalog['parent_cat_id'];
-            $default_cat_id3 = $default_cat_id;
-
-        }else{
-            $default_cat_id2 = $default_cat_id;
-        }
-        $this->sendResult(array("default_cat_id2"=>$default_cat_id2 , "default_cat_id3"=>$default_cat_id3));
+        $this->sendResult(array("default_cat_id"=>$default_cat_id ));
     }
 
 

+ 18 - 31
server/Application/Api/Controller/ItemController.class.php

@@ -55,36 +55,17 @@ class ItemController extends BaseController {
         $login_user = session("login_user");
         $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
         $is_login =   $uid > 0 ? true :false;
-            
+        $menu = array(
+            "pages" =>array(),
+            "catalogs" =>array(),
+            );
         //是否有搜索词
         if ($keyword) {
             $keyword = \SQLite3::escapeString($keyword) ;
             $pages = D("Page")->where("item_id = '$item_id' and is_del = 0  and ( page_title like '%{$keyword}%' or page_content like '%{$keyword}%' ) ")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
-        
+            $menu['pages'] = $pages ? $pages : array();
         }else{
-            //获取所有父目录id为0的页面
-            $pages = D("Page")->where("cat_id = '0' and item_id = '$item_id' and is_del = 0")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
-            //获取所有二级目录
-            $catalogs = D("Catalog")->where("item_id = '$item_id' and level = 2  ")->order(" `s_number` asc  ")->select();
-            if ($catalogs) {
-                foreach ($catalogs as $key => &$catalog) {
-                    //该二级目录下的所有子页面
-                    $temp = D("Page")->where("cat_id = '$catalog[cat_id]' and is_del = 0")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
-                    $catalog['pages'] = $temp ? $temp: array();
-
-                    //该二级目录下的所有子目录
-                    $temp = D("catalog")->where("parent_cat_id = '$catalog[cat_id]' ")->order(" `s_number` asc  ")->select();
-                    $catalog['catalogs'] = $temp ? $temp: array();
-                    if($catalog['catalogs']){
-                        //获取所有三级目录的子页面
-                        foreach ($catalog['catalogs'] as $key3 => &$catalog3) {
-                            //该二级目录下的所有子页面
-                            $temp = D("Page")->where("cat_id = '$catalog3[cat_id]' and is_del = 0")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
-                            $catalog3['pages'] = $temp ? $temp: array();
-                        }                        
-                    }               
-                }
-            }
+            $menu = D("Item")->getMemu($item_id) ;
         }
 
         $domain = $item['item_domain'] ? $item['item_domain'] : $item['item_id'];
@@ -94,11 +75,19 @@ class ItemController extends BaseController {
 
         $ItemCreator = $this->checkItemCreator($uid , $item_id);
 
-        //如果带了默认展开的页面id,则获取该页面所在的二级目录和三级目录
+        //如果带了默认展开的页面id,则获取该页面所在的二级目录/三级目录/四级目录
         if ($default_page_id) {
             $page = D("Page")->where(" page_id = '$default_page_id' ")->find();
             if ($page) {
-                $default_cat_id3 = $page['cat_id'] ;
+                $default_cat_id4 = $page['cat_id'] ;
+                $cat1 = D("Catalog")->where(" cat_id = '$default_cat_id4' and parent_cat_id > 0  ")->find();
+                if ($cat1) {
+                    $default_cat_id3 = $cat1['parent_cat_id'];
+                }else{
+                    $default_cat_id3 = $default_cat_id4;
+                    $default_cat_id4 = 0 ;
+                }
+
                 $cat2 = D("Catalog")->where(" cat_id = '$default_cat_id3' and parent_cat_id > 0  ")->find();
                 if ($cat2) {
                     $default_cat_id2 = $cat2['parent_cat_id'];
@@ -115,10 +104,7 @@ class ItemController extends BaseController {
         else{
             $help_url = "https://www.showdoc.cc/help";
         }
-        $menu =array(
-            "pages" => $pages ,
-            "catalogs" => $catalogs ,
-            ) ;
+
 
         $return = array(
             "item_id"=>$item_id ,
@@ -128,6 +114,7 @@ class ItemController extends BaseController {
             "default_page_id"=>(string)$default_page_id ,
             "default_cat_id2"=>$default_cat_id2 ,
             "default_cat_id3"=>$default_cat_id3 ,
+            "default_cat_id4"=>$default_cat_id4 ,
             "unread_count"=>$unread_count ,
             "item_type"=>1 ,
             "menu"=>$menu ,

+ 1 - 1
server/Application/Api/Model/CatalogModel.class.php

@@ -10,7 +10,7 @@ class CatalogModel extends BaseModel {
 	//获取目录列表。如果isGroup参数为true,则按分组返回
 	public function getList($item_id,$isGroup = false ){
         if ($item_id > 0 ) {
-            $ret = $this->where(" item_id = '%d' ",array($item_id))->order(" 's_number', cat_id asc  ")->select();
+            $ret = $this->where(" item_id = '%d' ",array($item_id))->order(" s_number, cat_id asc  ")->select();
         }
         if ($ret) {
 	        foreach ($ret as $key => $value) {

+ 90 - 0
server/Application/Api/Model/ItemModel.class.php

@@ -179,6 +179,96 @@ class ItemModel extends BaseModel {
         return $this->import($this->export($item_id),$uid,$item_name,$item_description,$item_password,$item_domain);
     }
 
+    //获取菜单结构
+    public function getMemu($item_id){
+            //获取所有父目录id为0的页面
+            $all_pages = D("Page")->where("item_id = '$item_id' and is_del = 0 ")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
+            $pages = array() ;
+            if ($all_pages) {
+                foreach ($all_pages as $key => $value) {
+                    if ($value['cat_id']) {
+                        # code...
+                    }else{
+                        $pages[] = $value ;
+                    }
+                }
+            }
+            
+            //获取该项目下的所有目录
+            $all_catalogs = D("Catalog")->where("item_id = '$item_id' ")->order(" `s_number` asc  ")->select();
+
+            //获取所有二级目录
+            $catalogs = array() ;
+            if ($all_catalogs) {
+                foreach ($all_catalogs as $key => $value) {
+                    if ($value['level'] == 2 ) {
+                        $catalogs[] = $value;
+                    }
+                }
+            }
+            if ($catalogs) {
+                foreach ($catalogs as $key => &$catalog2) {
+                    //该二级目录下的所有子页面
+                    $catalog2['pages'] = $this->_getPageByCatId($catalog2['cat_id'],$all_pages);
+
+                    //该二级目录下的所有子目录
+                    $catalog2['catalogs'] =  $this->_getCatByCatId($catalog2['cat_id'],$all_catalogs);
+                    if($catalog2['catalogs']){
+                        //获取所有三级目录的子页面
+                        foreach ($catalog2['catalogs'] as $key3 => &$catalog3) {
+                            //该三级目录下的所有子页面
+                            $catalog3['pages'] = $this->_getPageByCatId($catalog3['cat_id'],$all_pages);
+
+                            //该三级目录下的所有子目录
+                            $catalog3['catalogs'] =  $this->_getCatByCatId($catalog3['cat_id'],$all_catalogs);
+                            if($catalog3['catalogs']){
+                                //获取所有三级目录的子页面
+                                foreach ($catalog3['catalogs'] as $key4 => &$catalog4) {
+                                    //该三级目录下的所有子页面
+                                    $catalog4['pages'] = $this->_getPageByCatId($catalog4['cat_id'],$all_pages);
+                                }                        
+                            }
+
+                        }                        
+                    }             
+                }
+            }
+            $menu = array(
+                "pages" =>$pages,
+                "catalogs" =>$catalogs,
+                );
+            unset($pages);
+            unset($catalogs);
+            return $menu;
+    }
+    
+    //获取某个目录下的所有页面
+    private function _getPageByCatId($cat_id ,$all_pages){
+        $pages = array() ;
+        if ($all_pages) {
+            foreach ($all_pages as $key => $value) {
+                if ($value['cat_id'] == $cat_id) {
+                    $pages[] = $value ;
+                }
+            }
+        }
+        return $pages;
+    }
+
+    //获取某个目录下的所有子目录
+    private function _getCatByCatId($cat_id ,$all_catalogs){
+        $cats = array() ;
+        if ($all_catalogs) {
+            foreach ($all_catalogs as $key => $value) {
+                if ($value['parent_cat_id'] == $cat_id) {
+                    $cats[] = $value ;
+                }
+            }
+        }
+        return $cats;
+    }
+
+
     //删除项目
     public function delete_item($item_id){
         D("Page")->where("item_id = '$item_id' ")->delete();

+ 59 - 23
web_src/src/components/catalog/Index.vue

@@ -8,7 +8,7 @@
       <el-button  type="text" class="add-cat" @click="add_cat">{{$t('add_cat')}}</el-button>
       <el-button type="text" class="goback-btn" @click="goback">{{$t('goback')}}</el-button>
        <el-table align="left"
-            :data="catalogs"
+            :data="catalogs_table"
              height="400"
              :row-class-name="tableRowClassName"
             style="width: 100%">
@@ -47,7 +47,7 @@
             <el-form-item :label="$t('parent_cat_name')+' : '" >
               <el-select v-model="MyForm.parent_cat_id" :placeholder="$t('none')">
                   <el-option
-                    v-for="item in catalogs_level_2"
+                    v-for="item in parent_catalogs"
                     :key="item.cat_id"
                     :label="item.cat_name"
                     :value="item.cat_id">
@@ -92,6 +92,61 @@ export default {
     }
 
   },
+  computed: {
+    //表格形式展示目录数据
+    catalogs_table:function(){
+        var Info = this.catalogs.slice(0);
+        var cat_array = [] ;
+        for (var i = 0; i < Info.length; i++) {
+          Info[i]['cat_name'] = Info[i]['cat_name'];
+          cat_array.push(Info[i]);
+          var sub = Info[i]['sub'] 
+          if (sub.length > 0 ) {
+            for (var j = 0; j < sub.length; j++) {
+              cat_array.push( {
+                "cat_id":sub[j]['cat_id'] ,
+                "parent_cat_id":sub[j]['parent_cat_id'] ,
+                "s_number":sub[j]['s_number'] ,
+                "cat_name":' -- ' + sub[j]['cat_name']
+              });
+              var sub2 = sub[j]['sub'] ;
+              for (var k = 0; k < sub2.length; k++) {
+                cat_array.push( {
+                  "cat_id":sub2[k]['cat_id'] ,
+                  "s_number":sub2[k]['s_number'] ,
+                  "parent_cat_id":sub2[k]['parent_cat_id'] ,
+                  "cat_name":' ----- ' + sub2[k]['cat_name']
+                });
+              };
+
+            };
+          };
+          
+        };
+        return cat_array;
+    },
+    //新建/编辑目录时供用户选择的上级目录列表
+    parent_catalogs:function(){
+        var Info = this.catalogs.slice(0);
+        var cat_array = [] ;
+        for (var i = 0; i < Info.length; i++) {
+          cat_array.push(Info[i]);
+          var sub = Info[i]['sub'] 
+          if (sub.length > 0 ) {
+            for (var j = 0; j < sub.length; j++) {
+              cat_array.push( {
+                "cat_id":sub[j]['cat_id'] ,
+                "cat_name":Info[i]['cat_name']+' / ' + sub[j]['cat_name']
+              });
+            };
+          };
+        };
+        var no_cat = {"cat_id":0 ,"cat_name":this.$t("none")} ;
+        cat_array.push(no_cat);
+        return cat_array;
+
+    }
+  },
   methods: {
 
       tableRowClassName({row, rowIndex}) {
@@ -110,27 +165,7 @@ export default {
           .then(function (response) {
             if (response.data.error_code === 0 ) {
               var Info = response.data.data ;
-              
-              //创建上级目录选项
-              var Info2 = Info.slice(0) ;
-              var no_cat = {"cat_id":0 ,"cat_name":that.$t("none")} ;
-              Info2.unshift(no_cat);
-              that.catalogs_level_2 = Info2 ;
-              
-              var cat_array = [] ;
-              for (var i = 0; i < Info.length; i++) {
-                
-                Info[i]['cat_name'] = Info[i]['cat_name'];
-                cat_array.push(Info[i]);
-                if (Info[i]['sub'].length > 0 ) {
-                  for (var j = 0; j < Info[i]['sub'].length; j++) {
-                    Info[i]['sub'][j]['cat_name'] = ' -- ' + Info[i]['sub'][j]['cat_name'];
-                    cat_array.push(Info[i]['sub'][j]);
-                  };
-                };
-                
-              };
-              that.catalogs =  cat_array;
+              that.catalogs =  Info;
             }else{
               that.$alert(response.data.error_message);
             }
@@ -171,6 +206,7 @@ export default {
          temp = JSON.parse(JSON.stringify(row));  
         if (temp.cat_name) {
           temp.cat_name = temp.cat_name.replace(' -- ','');
+          temp.cat_name = temp.cat_name.replace(' ----- ','');
         };
         if (temp.parent_cat_id == '0') {
           temp.parent_cat_id = '';

+ 17 - 4
web_src/src/components/item/show/show_regular_item/LeftMenu.vue

@@ -39,7 +39,7 @@
         <template slot="title"> <img src="static/images/folder.png"  class="icon-folder menu-icon-folder ">{{catalog2.cat_name}}</template>
 
         <!-- 二级目录的页面 -->
-        <el-menu-item-group v-if="catalog2.pages" v-for="(page2 ,page2_index) in catalog2.pages" :key="page2.page_id">
+        <el-menu-item-group v-if="catalog2.pages" v-for="(page2 ,page2_index) in catalog2.pages"  :key="page2.page_id">
           <el-menu-item :index="page2.page_id">{{page2.page_title}}</el-menu-item>
         </el-menu-item-group>
 
@@ -47,10 +47,20 @@
         <el-submenu  v-if="catalog2.catalogs.length" v-for="(catalog3 ,catalog_index3) in catalog2.catalogs" :index="catalog3.cat_id" :key="catalog3.cat_id">
           <template slot="title">{{catalog3.cat_name}}</template>
           <!-- 三级目录的页面 -->
-          <el-menu-item  v-if="catalog3.pages" v-for="(page3 ,page3_index) in catalog3.pages" :index="page3.page_id" :key="page3.page_id">{{page3.page_title}}</el-menu-item>
+          <el-menu-item  v-if="catalog3.pages" v-for="(page3 ,page3_index) in catalog3.pages"  :index="page3.page_id" :key="page3.page_id">{{page3.page_title}}</el-menu-item>
+
+            <!-- 三级目录下的四级目录 -->
+            <el-submenu  v-if="catalog3.catalogs.length" v-for="(catalog4 ,catalog_index4) in catalog3.catalogs" :index="catalog4.cat_id" :key="catalog4.cat_id">
+              <template slot="title">{{catalog4.cat_name}}</template>
+              <!-- 四级目录的页面 -->
+              <el-menu-item  v-if="catalog4.pages" v-for="(page4 ,page4_index) in catalog4.pages" :index="page4.page_id"  :key="page4.page_id">{{page4.page_title}}</el-menu-item>
+            </el-submenu>
+
         </el-submenu>
 
-        
+
+
+
       </el-submenu>
 
     </el-menu>
@@ -115,7 +125,10 @@
     //默认展开页面
     if (item_info.default_page_id > 0 ) {
       that.select_menu(item_info.default_page_id);
-      if (item_info.default_cat_id3) {
+      if (item_info.default_cat_id4) {
+        that.openeds = [ item_info.default_cat_id4,item_info.default_cat_id3, item_info.default_cat_id2, item_info.default_page_id]; 
+      }
+      else if (item_info.default_cat_id3) {
         that.openeds = [ item_info.default_cat_id3, item_info.default_cat_id2, item_info.default_page_id]; 
       }
       else if (item_info.default_cat_id2) {

+ 54 - 54
web_src/src/components/page/edit/Index.vue

@@ -9,16 +9,13 @@
           <el-form-item :label="$t('title')+' : '">
             <el-input  placeholder="" v-model="title"></el-input>
           </el-form-item>
-          <el-form-item :label="$t('level_2_directory')+' : '" >
-            <el-select  :placeholder="$t('optional')" class="cat" v-model="cat_id2" @change="get_cat3">
-              <el-option v-if="cat2" v-for="cat in cat2 " :key="cat.cat_name" :label="cat.cat_name" :value="cat.cat_id"></el-option>
-            </el-select>
-          </el-form-item>
-          <el-form-item :label="$t('level_3_directory')+' : '" >
-            <el-select  :placeholder="$t('optional')" class="cat" v-model="cat_id3">
-              <el-option v-if="cat3" v-for="cat in cat3 " :label="cat.cat_name" :key="cat.cat_name" :value="cat.cat_id"></el-option>
+
+          <el-form-item :label="$t('catalog')+' : '" >
+            <el-select  :placeholder="$t('optional')" class="cat" v-model="cat_id">
+              <el-option v-if="belong_to_catalogs" v-for="cat in belong_to_catalogs " :key="cat.cat_name" :label="cat.cat_name" :value="cat.cat_id"></el-option>
             </el-select>
           </el-form-item>
+
           <el-form-item :label="$t('s_number')+' : '">
             <el-input  :placeholder="$t('optional')" class="num" v-model="s_number"></el-input>
           </el-form-item>
@@ -156,7 +153,7 @@
   }
 
   .cat{
-    width: 130px;
+    width: 200px;
   }
 
   .num{
@@ -185,16 +182,48 @@ export default {
       content:"",
       title:"",
       item_id:0,
-      cat2:[],
-      cat_id2:'',
-      cat3:[],
-      cat_id3:'',
+      cat_id:'',
       s_number:'',
       page_id:'',
       copy_page_id:'',
 
     };
   },
+  computed: {
+
+    //新建/编辑页面时供用户选择的归属目录列表
+    belong_to_catalogs:function(){
+        var Info = this.catalogs.slice(0);
+        var cat_array = [] ;
+        for (var i = 0; i < Info.length; i++) {
+          cat_array.push(Info[i]);
+          var sub = Info[i]['sub'] ;
+          if (sub.length > 0 ) {
+            for (var j = 0; j < sub.length; j++) {
+              cat_array.push( {
+                "cat_id":sub[j]['cat_id'] ,
+                "cat_name":Info[i]['cat_name']+' / ' + sub[j]['cat_name']
+              });
+
+              var sub_sub = sub[j]['sub'] ;
+              if (sub_sub.length > 0 ) {
+                for (var k = 0; k < sub_sub.length; k++) {
+                  cat_array.push( {
+                    "cat_id":sub_sub[k]['cat_id'] ,
+                    "cat_name":Info[i]['cat_name']+' / ' + sub[j]['cat_name']+' / ' + sub_sub[k]['cat_name']
+                  });
+                };
+              };
+
+            };
+          };
+        };
+        var no_cat = {"cat_id":'' ,"cat_name":this.$t("none")} ;
+        cat_array.unshift(no_cat);
+        return cat_array;
+
+    }
+  },
   components:{
     Editormd,
     JsonToTable,
@@ -241,46 +270,26 @@ export default {
           });
     },
 
-    //获取二级目录
-    get_cat2(item_id){
+    //获取所有目录
+    get_catalog(item_id){
       var that = this ;
-      var url = DocConfig.server+'/api/catalog/secondCatList';
+      var url = DocConfig.server+'/api/catalog/catListGroup';
       var params = new URLSearchParams();
       params.append('item_id',  item_id);
       that.axios.post(url, params)
         .then(function (response) {
           if (response.data.error_code === 0 ) {
-            //that.$message.success("加载成功");
-            that.cat2 = response.data.data ;
-            var no_cat = {"cat_id":'' ,"cat_name":" "} ;
-            that.cat2.unshift(no_cat);
-            that.get_default_cat();
-          }else{
-            that.$alert(response.data.error_message);
-          }
-          
-        });
-    },
-    //获取三级目录
-    get_cat3(cat_id,callback){
-      var that = this ;
-      var url = DocConfig.server+'/api/catalog/childCatList';
-      var params = new URLSearchParams();
-      params.append('cat_id',  cat_id);
-      that.axios.post(url, params)
-        .then(function (response) {
-          if (response.data.error_code === 0 ) {
-            //that.$message.success("加载成功");
-            that.cat_id3 = '';
-            that.cat3 = response.data.data ;
-            if(callback){
-              callback();
-            }
+            var Info = response.data.data ;
 
+            that.catalogs =  Info;
+            that.get_default_cat();
           }else{
             that.$alert(response.data.error_message);
           }
           
+        })
+        .catch(function (error) {
+          console.log(error);
         });
     },
     //获取默认该选中的目录
@@ -297,10 +306,7 @@ export default {
           if (response.data.error_code === 0 ) {
             //that.$message.success("加载成功");
             var json = response.data.data ;
-            that.cat_id2 = json.default_cat_id2 ;
-            that.get_cat3(json.default_cat_id2,function(){
-              that.cat_id3 = json.default_cat_id3 ;
-            }) ;
+            that.cat_id = json.default_cat_id ;
 
           }else{
             that.$alert(response.data.error_message);
@@ -378,13 +384,7 @@ export default {
       var loading = that.$loading();
       let childRef = this.$refs.Editormd ;
       var content = childRef.getMarkdown() ;
-      var cat_id = 0 ;
-      if (that.cat_id2 > 0 ) {
-        cat_id = that.cat_id2 ;
-      };     
-      if (that.cat_id3 > 0 ) {
-        cat_id = that.cat_id3 ;
-      };
+      var cat_id = this.cat_id ;
       var item_id = that.$route.params.item_id ;
       var page_id = that.$route.params.page_id ;
       var url = DocConfig.server+'/api/page/save';
@@ -526,7 +526,7 @@ export default {
       this.item_id = this.$route.params.item_id ;
       this.content = this.$t("welcome_use_showdoc") ;
     }
-    this.get_cat2(this.$route.params.item_id);
+    this.get_catalog(this.$route.params.item_id);
 
     /** 监听粘贴上传图片 **/
     document.addEventListener('paste', this.upload_paste_img);

+ 1 - 0
web_src/static/lang/en.js

@@ -152,6 +152,7 @@ exports.default = {
 
     //page
     'title':'title',
+    'catalog':'catalog',
     'level_2_directory':'level 2 catalog',
     'level_3_directory':'level 3 catalog',
     's_number':'order',

+ 1 - 0
web_src/static/lang/zh-CN.js

@@ -157,6 +157,7 @@ exports.default = {
 
     //page
     'title':'标题',
+    'catalog':'目录',
     'level_2_directory':'二级目录',
     'level_3_directory':'三级目录',
     's_number':'序号',