瀏覽代碼

export word

star7th 7 年之前
父節點
當前提交
56d30423d1

+ 51 - 120
server/Application/Api/Controller/ExportController.class.php

@@ -5,11 +5,12 @@ class ExportController extends BaseController {
 
     //导出整个项目为word
     public function word(){
-    	set_time_limit(1000);
-    	ini_set('memory_limit','800M'); 
+        set_time_limit(100);
+        ini_set('memory_limit','800M');
         import("Vendor.Parsedown.Parsedown");
         $Parsedown = new \Parsedown();
         $item_id =  I("item_id/d");
+        $cat_id =  I("cat_id/d");
         $login_user = $this->checkLogin();
         if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
             $this->message(L('no_permissions'));
@@ -18,30 +19,38 @@ class ExportController extends BaseController {
 
         $item = D("Item")->where("item_id = '$item_id' ")->find();
 
-        //获取所有父目录id为0的页面
-        $pages = D("Page")->where("cat_id = '0' and item_id = '$item_id' and is_del = 0")->order(" `s_number` asc  ")->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  ")->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  ")->select();
-                        $catalog3['pages'] = $temp ? $temp: array();
-                    }                        
-                }               
+        $menu = D("Item")->getContent($item_id,"*","*",1);
+        if ($cat_id) {
+            foreach ($menu['catalogs'] as $key => $value) {
+                if ($cat_id == $value['cat_id']) {
+                    $pages = $value['pages'] ;
+                    $catalogs = $value['catalogs'] ;
+                }else{
+                    if ($value['catalogs']) {
+                        foreach ($value['catalogs'] as $key2 => $value2) {
+                            if ($cat_id == $value2['cat_id']) {
+                                $pages = $value2['pages'] ;
+                                $catalogs = $value2['catalogs'] ;
+                            }
+                        }
+                        if ($value2['catalogs']) {
+                            foreach ($value2['catalogs'] as $key3 => $value3) {
+                                if ($cat_id == $value3['cat_id']) {
+                                    $pages = $value3['pages'] ;
+                                    $catalogs = $value3['catalogs'] ;
+                                }
+                            }
+                        }
+                    }
+                }
             }
+        }else{
+            $pages = $menu['pages'] ;
+            $catalogs = $menu['catalogs'] ;
         }
 
+
         $data = '';
         $parent = 1;
 
@@ -84,6 +93,26 @@ class ExportController extends BaseController {
                                         $child2 ++;
                                     }
                                 }
+
+                                if ($value3['catalogs']) {
+                                    $parent3 = 1 ;
+                                    foreach ($value3['catalogs'] as $key4 => $value4) {
+                                        $data .= "<h2>{$parent}.{$parent2}.{$parent3}、{$value4['cat_name']}</h2>";
+                                        $data .= '<div style="margin-left:20px;">';
+                                            $child3 = 1 ;
+                                            if ($value4['pages']) {
+                                                foreach ($value4['pages'] as $page4) {
+                                                    $data .= "<h3>{$parent}.{$parent2}.{$child2}.{$child3}、{$page4['page_title']}</h3>";
+                                                    $data .= '<div style="margin-left:30px;">';
+                                                        $data .= htmlspecialchars_decode($Parsedown->text($page4['page_content']));
+                                                    $data .= '</div>';
+                                                    $child3 ++;
+                                                }
+                                            }
+                                        $data .= '</div>';
+                                        $parent3 ++;
+                                    }
+                                }
                             $data .= '</div>';
                             $parent2 ++;
                         }
@@ -96,103 +125,5 @@ class ExportController extends BaseController {
         output_word($data,$item['item_name']);
     }
 
-    //把指定目录导出为word
-    public function word_cat(){
-        import("Vendor.Parsedown.Parsedown");
-        $Parsedown = new \Parsedown();
-        $item_id =  I("item_id/d");
-        $cat_id =  I("cat_id/d");
-        $login_user = $this->checkLogin();
-        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
-            $this->message(L('no_permissions'));
-            return;
-        }
-
-        $item = D("Item")->where("item_id = '$item_id' ")->find();
-        //获取指定目录。先按照目录是二级目录的逻辑来处理
-        $catalog = D("Catalog")->where("item_id = '$item_id' and cat_id = '$cat_id' and level =2 ")->order(" `s_number` asc  ")->find();
-        if (!empty($catalog)) {
-                //该二级目录下的所有子页面
-                $temp = D("Page")->where("cat_id = '$catalog[cat_id]' and is_del = 0")->order(" `s_number` asc  ")->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  ")->select();
-                        $catalog3['pages'] = $temp ? $temp: array();
-                    }                        
-                } 
-        }else{
-            //获取指定目录。按照目录是三级目录的逻辑来处理
-            $catalog = D("Catalog")->where("item_id = '$item_id' and cat_id = '$cat_id' and level =3 ")->order(" `s_number` asc  ")->find();
-            if (!empty($catalog)) {
-                    //该三级目录下的所有子页面
-                    $temp = D("Page")->where("cat_id = '$catalog[cat_id]' and is_del = 0")->order(" `s_number` asc  ")->select();
-                    $catalog['pages'] = $temp ? $temp: array();
-            }
-        }
-
-
-        $data = '';
-        $parent = 1;
-        //var_export($catalog);exit();
-        $data .= "<h1>{$catalog['cat_name']}</h1>";
-        $data .= '<div style="margin-left:20px;">';
-            $child = 1 ;
-            if ($catalog['pages']) {
-                foreach ($catalog['pages'] as $page) {
-                    $data .= "<h2>{$child}、{$page['page_title']}</h2>";
-                    $data .= '<div style="margin-left:20px;">';
-                        $data .= htmlspecialchars_decode($Parsedown->text($page['page_content']));
-                    $data .= '</div>';
-                    $child ++;
-                }
-            }
-            if ($catalog['catalogs']) {
-                $parent2 = 1 ;
-                foreach ($catalog['catalogs'] as $key3 => $value3) {
-                    $data .= "<h2>{$parent2}、{$value3['cat_name']}</h2>";
-                    $data .= '<div style="margin-left:20px;">';
-                        $child2 = 1 ;
-                        if ($value3['pages']) {
-                            foreach ($value3['pages'] as $page3) {
-                                $data .= "<h3>{$parent2}.{$child2}、{$page3['page_title']}</h3>";
-                                $data .= '<div style="margin-left:30px;">';
-                                    $data .= htmlspecialchars_decode($Parsedown->text($page3['page_content']));
-                                $data .= '</div>';
-                                $child2 ++;
-                            }
-                        }
-                    $data .= '</div>';
-                    $parent2 ++;
-                }
-            }
-        $data .= '</div>';
-
-        output_word($data,$item['item_name']);
-
-    }
-
-    //把指定页面导出为word
-    public function word_page(){
-        import("Vendor.Parsedown.Parsedown");
-        $Parsedown = new \Parsedown();
-        $item_id =  I("item_id/d");
-        $page_id =  I("page_id/d");
-        $login_user = $this->checkLogin();
-        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
-            $this->message(L('no_permissions'));
-            return;
-        }
-        $temp = D("Page")->where("page_id = '$page_id' ")->order(" `s_number` asc  ")->find();
-        $page= $temp ? $temp: array();
-        $data = htmlspecialchars_decode($Parsedown->text($page['page_content']));
-        output_word($data,$page['page_title']);
-    }
 
 }

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

@@ -195,7 +195,7 @@ class ItemModel extends BaseModel {
             return $data ;
     }
 
-    public function getContent($item_id , $page_field ="*" , $catalog_field ="*"){
+    public function getContent($item_id , $page_field ="*" , $catalog_field ="*" , $uncompress = 0 ){
             //获取所有父目录id为0的页面
             $all_pages = D("Page")->where("item_id = '$item_id' and is_del = 0 ")->order(" `s_number` asc  ")->field($page_field)->select();
             $pages = array() ;

+ 51 - 57
web_src/src/components/item/export/Index.vue

@@ -13,16 +13,11 @@
 
 
               <el-form-item label="" >
-                  <el-select :disabled="export_type > 1 ? false :true" :placeholder="$t('select_cat_2')" 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 :disabled="export_type > 1 ? false :true" :placeholder="$t('catalog')" class="cat" v-model="cat_id" >
+                    <el-option  v-if="computed_catalogs" v-for="cat in computed_catalogs " :key="cat.cat_name" :label="cat.cat_name" :value="cat.cat_id"></el-option>
                   </el-select>
               </el-form-item>
 
-              <el-form-item label="" >
-                <el-select :disabled="export_type > 1 ? false :true" :placeholder="$t('select_cat_3')" 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-select>
-              </el-form-item>
 
 
                <el-form-item label="" >
@@ -51,51 +46,62 @@ export default {
   },
   data () {
     return {
-      cat2:[],
-      cat_id2:'',
-      cat3:[],
-      cat_id3:'',
+      catalogs:[],
+      cat_id:'',
       export_type:'1',
       item_id:0,
 
     }
 
   },
+  computed: {
+
+    //新建/编辑页面时供用户选择的归属目录列表
+    computed_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;
+
+    }
+  },
   methods: {
-    //获取二级目录
-    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 ;
-            
-          }else{
-            that.$alert(response.data.error_message);
-          }
-          
-        })
-        .catch(function (error) {
-          console.log(error);
-        });
-    },
-    //获取三级目录
-    get_cat3(cat_id){
-      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 ;
-            
+            var Info = response.data.data ;
+
+            that.catalogs =  Info;
           }else{
             that.$alert(response.data.error_message);
           }
@@ -106,23 +112,11 @@ export default {
         });
     },
     onSubmit() {
-        var val= this.export_type ;
-        if (val == 1 ) {
-            var url = DocConfig.server+'/api/export/word&item_id='+this.item_id ;
-            window.location.href = url;
-        }
-        else if (val == 2) {
-            var cat_id2 = this.cat_id2;
-            var cat_id3 = this.cat_id3;
-
-            if (cat_id2 > 0 ) {
-                var cat_id = cat_id3 > 0 ? cat_id3 : cat_id2 ;
-                var url = DocConfig.server+'/api/export/word_cat&item_id='+this.item_id+'&cat_id='+cat_id ;
-                window.location.href = url;
-            }else{
-                this.$alert("请选择目录");
-            }
-        }
+        if (this.export_type ==1 ) {
+          this.cat_id = ''
+        };
+        var url = DocConfig.server+'/api/export/word&item_id='+this.item_id+'&cat_id='+this.cat_id ;
+        window.location.href = url;
       },
     goback(){
       this.$router.go(-1);
@@ -130,7 +124,7 @@ export default {
 
   },
   mounted() {
-    this.get_cat2(this.$route.params.item_id);
+    this.get_catalog(this.$route.params.item_id);
     this.item_id = this.$route.params.item_id ;
     /*给body添加类,设置背景色*/
     document.getElementsByTagName("body")[0].className="grey-bg";