Browse Source

导出word时可以指定目录

star7th 8 years ago
parent
commit
6f3dc73de7

+ 15 - 4
Application/Home/Controller/ItemController.class.php

@@ -356,10 +356,21 @@ class ItemController extends BaseController {
 
     //导出word
     public function export(){
-        $item_id = I("item_id/d");
-        $url = 'server/index.php?s=/api/export/word&item_id='.$item_id ;
-        header("location:{$url}");
-        //$this->display();
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d");  
+        $uid = $login_user['uid'] ;
+        $this->checkItemPermn($uid , $item_id) ; 
+
+        $item = D("Item")->where("item_id = '$item_id' ")->find();
+
+        //对于单页项目,直接导出。对于普通项目,则让其选择目录
+        if ($item['item_type'] == 2 ) {
+            $url = 'server/index.php?s=/api/export/word&item_id='.$item_id ;
+            header("location:{$url}");
+        }else{
+            $this->assign("item_id",$item_id);
+            $this->display();
+        }
     }
 
     public function itemList(){

+ 57 - 0
Application/Home/View/Item/export.html

@@ -0,0 +1,57 @@
+<include file="Common/header" />
+<link rel="stylesheet" href="__PUBLIC__/css/login.css" />
+<style type="text/css">
+.choose_type{
+    margin-bottom: 30px;
+    text-align: center;
+}
+.inline{
+    display: inline;
+}
+</style>
+    <div class="container">
+
+      <form class="form-signin" method="post">
+        <input type="hidden" id="item_id" name="item_id" value="{$item_id}">
+        <div class="choose_type">
+            <label class="radio inline">
+              <input type="radio" name="item_type" id="item_type1" value="1" checked="checked">
+              导出全部
+            </label>
+            <label class="radio inline">
+              <input type="radio" name="item_type" id="item_type2" value="2" >
+              按目录导出
+            </label>
+        </div>
+
+
+        <div >
+            <label class="inline">二级目录:</label>
+            <select class="inline level_2_directory" disabled="disabled">
+                <option >  全部 </option>
+            </select>
+        </div>
+        <div >
+            <label class="inline">三级目录:</label>
+            <select class="inline level_3_directory" disabled="disabled">
+                <option>  全部 </option>
+            </select>
+        </div>
+        <!--  
+        <div >
+            <label class="inline">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;页面:</label>
+            <select class="inline page" disabled="disabled">
+                <option>  全部 </option>
+            </select>
+        </div>
+        -->
+        <br>
+        <button class="btn  btn-primary export-submit" type="submit">{$Think.Lang.submit}</button>
+        <a href="javascript:history.go(-1)" class="btn">{$Think.Lang.goback}</a>
+      </form>
+
+    </div> <!-- /container -->
+
+
+ <include file="Common/footer" />
+<script src="__PUBLIC__/js/item/export.js"></script>

+ 90 - 0
Public/js/item/export.js

@@ -0,0 +1,90 @@
+$(".choose_type").change(function(){
+    if ($("#item_type2").is(":checked") ) {
+        $(".level_2_directory").removeAttr("disabled");
+        $(".level_3_directory").removeAttr("disabled");
+        $(".page").removeAttr("disabled");
+    }else{
+        $(".level_2_directory").attr("disabled","disabled");
+        $(".level_3_directory").attr("disabled","disabled"); 
+        $(".page").attr("disabled","disabled"); 
+    }
+}).trigger("change");
+
+/*加载二级目录*/
+secondCatList();
+
+//监听是否选择了二级目录。如果选择了,则跟后台判断是否还子目录
+$(".level_2_directory").change(function() {
+    getChildCatList();
+});
+
+function secondCatList() {
+    var item_id = $("#item_id").val();
+    $.post(
+      DocConfig.server+"/api/catalog/secondCatList", {
+        "item_id": item_id,
+      },
+      function(data) {
+        $(".level_2_directory").html('<OPTION value="0">请选择</OPTION>');
+        if (data.error_code == 0) {
+          json = data.data;
+          for (var i = 0; i < json.length; i++) {
+            cat_html = '<OPTION value="' + json[i].cat_id + '" ';
+            cat_html += ' ">' + json[i].cat_name + '</OPTION>';
+            $(".level_2_directory").append(cat_html);
+          };
+        };
+
+      },
+      "json"
+
+    );
+}
+
+/*加载三级目录*/
+function getChildCatList() {
+    var cat_id = $(".level_2_directory").val();
+    $.post(
+      DocConfig.server+"/api/catalog/childCatList", {
+        "cat_id": cat_id
+      },
+      function(data) {
+        $(".level_3_directory").html('<OPTION value="0">全部</OPTION>');
+        if (data.error_code == 0) {
+          json = data.data;
+          for (var i = 0; i < json.length; i++) {
+            cat_html = '<OPTION value="' + json[i].cat_id + '" ';
+            cat_html += ' ">' + json[i].cat_name + '</OPTION>';
+            $(".level_3_directory").append(cat_html);
+          };
+        } else {}
+
+      },
+      "json"
+
+    );
+}
+
+//提交
+$(".export-submit").click(function(){
+    var item_id = $("#item_id").val();
+    var val=$('input:radio[name="item_type"]:checked').val();
+    if (val == 1 ) {
+        var url = DocConfig.server+'/api/export/word&item_id='+item_id ;
+        window.location.href = url;
+    }
+    else if (val == 2) {
+        var cat_id2 = $(".level_2_directory").val();
+        var cat_id3 = $(".level_3_directory").val();
+
+        if (cat_id2 > 0 ) {
+            var cat_id = cat_id3 > 0 ? cat_id3 : cat_id2 ;
+            var url = DocConfig.server+'/api/export/word_cat&item_id='+item_id+'&cat_id='+cat_id ;
+            window.location.href = url;
+        }else{
+            layer.alert("请选择要导出的目录");
+        }
+    }
+
+    return false;
+});

+ 62 - 0
server/Application/Api/Controller/CatalogController.class.php

@@ -0,0 +1,62 @@
+<?php
+namespace Api\Controller;
+use Think\Controller;
+class CatalogController extends BaseController {
+
+    //获取目录列表
+    public function catList(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d");
+        if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
+            $this->sendError(10303);
+            return ;
+        }
+        if ($item_id > 0 ) {
+            $ret = D("Catalog")->where(" item_id = '$item_id' ")->order(" 's_number', addtime asc  ")->select();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+    //获取二级目录列表
+    public function secondCatList(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d");
+        if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
+            $this->sendError(10303);
+            return ;
+        }
+        if ($item_id > 0 ) {
+            $ret = D("Catalog")->where(" item_id = '$item_id' and level =2  ")->order(" 's_number', addtime asc  ")->select();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+    //获取二级目录的子目录列表,即三级目录列表(如果存在的话)
+    public function childCatList(){
+        $cat_id = I("cat_id/d");
+        if ($cat_id > 0 ) {
+            $ret = D("Catalog")->where(" parent_cat_id = '$cat_id' ")->order(" 's_number', addtime asc  ")->select();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }      
+    }
+
+
+}