Browse Source

Copy / move pages and directories across items 跨项目复制/移动页面和目录

star7th 4 years ago
parent
commit
53700cdf9b

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

@@ -40,6 +40,54 @@ class CatalogController extends BaseController {
            $this->sendResult(array());
         }
     }
+    
+    
+     //获取目录列表,其中目录名将按层级描述。比如某个目录的名字为“我的项目/用户接口/用户登录”
+     public function catListName(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d");
+        if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
+            $this->sendError(10103);
+            return ;
+        }
+        if ($item_id > 0 ) {
+            $ret = D("Catalog")->getList($item_id,true);
+            $ret = D("Catalog")->filteMemberCat($login_user['uid'] , $ret);
+        }
+        if ($ret) {
+            $return = array() ;
+
+            //匿名递归函数,准备递归改名
+            // uee 指令后面引用参数转递。方便函数内部中使用。
+            $rename = function ($catalog, $p_cat_name) use (&$return , &$rename) {
+               if($catalog){
+                    foreach ($catalog as $key => $value) {
+                        $value['cat_name'] = $p_cat_name .'/'. $value['cat_name'] ;
+                        $sub = $value['sub'] ;
+                        unset($value['sub']);
+                        $return[] = $value ;
+                        if($sub){
+                            $rename($sub , $value['cat_name'] ) ;
+                        }
+                    }
+               }
+            };
+
+            foreach ($ret as $key => $value) {
+                $sub = $value['sub'] ;
+                unset($value['sub']);
+                $return[] = $value ;
+                if($sub){
+                    $rename($sub , $value['cat_name'] ) ;
+                }
+                
+            }
+            $this->sendResult($return);
+        }else{
+           $this->sendResult(array());
+        }
+    }
+
 
     //获取二级目录列表
     public function secondCatList(){
@@ -263,4 +311,29 @@ class CatalogController extends BaseController {
 
     }
 
+    //  复制或移动目录
+    public function copy(){
+        // 参数new_p_cat_id 复制完目录后,挂在哪个父目录下。这里是父目录id。可为0
+        // $to_item_id 要复制到的项目id。可以是同一个项目,可以是跨项目。默认是同一个项目
+        $cat_id = I("cat_id/d");
+        $new_p_cat_id = I("new_p_cat_id/d") ? I("new_p_cat_id/d") : 0;
+        $to_item_id = I("to_item_id/d") ? I("to_item_id/d") : 0 ;
+        $is_del = I("is_del/d") ? I("is_del/d") : 0 ; // 复制完是否删除原目录(相当于移动目录)
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemPermn($login_user['uid'] , $to_item_id)) {
+            $this->sendError(10103);
+            return ;
+        }
+        $old_cat_ary = D("Catalog")->where("cat_id = '$cat_id' ")->find() ;
+        if (!$this->checkItemPermn($login_user['uid'] , $old_cat_ary['item_id'])) {
+            $this->sendError(10103);
+            return ;
+        }
+        $res = D("Catalog")->copy($login_user['uid'] , $cat_id ,$new_p_cat_id , $to_item_id  );
+        if($is_del && $res){
+            D("Catalog")->deleteCat($cat_id) ;
+        }
+        $this->sendResult($res);
+    }
+
 }

+ 40 - 0
server/Application/Api/Model/CatalogModel.class.php

@@ -165,6 +165,46 @@ class CatalogModel extends BaseModel {
 
 		return $catData ;
 	}
+
+	//复制目录
+	// old_cat_id 原目录id
+	// new_p_cat_id 复制完目录后,挂在哪个父目录下。这里是父目录id。可为0。默认使用old_cat_id的父目录id
+	// $to_item_id 要复制到的项目id。可以是同一个项目,可以是跨项目。默认是同一个项目
+	public function copy($uid , $old_cat_id , $new_p_cat_id = 0 , $to_item_id = 0 ){
+		$userInfo = D("User")->userInfo($uid);
+		$old_cat_ary = $this->where("cat_id = '$old_cat_id' ")->find() ;
+		$to_item_id = $to_item_id ? $to_item_id : $cat_ary['item_id'] ;
+	
+		//这里需要读取目录下的页面以及子目录信息
+		$old_cat_data = $this->getCat($old_cat_id) ;
+		$catalogs[] =$old_cat_data ;
+		//获取$level.先初始化$level = 2 ;
+		$level = 2 ;
+		if($new_p_cat_id){
+			$p_cat_ary = $this->where("cat_id = '$new_p_cat_id' ")->find() ;
+			$level = $p_cat_ary['level'] + 1 ;
+		}
+		//插入
+		$res =  $this->insertCat($to_item_id , $catalogs , $userInfo , $new_p_cat_id ,  $level ) ;
+		return $res ;
+	}
+
+	//获取某个目录下的页面和子目录
+	public function getCat($cat_id){
+			$cat_ary = $this->where("cat_id = '$cat_id' ")->find() ;
+			$item_id = $cat_ary['item_id'] ;
+			//获取项目下所有页面信息
+			$all_pages = D("Page")->where("item_id = '$item_id' and is_del = 0 ")->order(" s_number asc , page_id asc ")->field($page_field)->select();
+			//获取项目下所有目录信息
+			$all_catalogs = $this->where(" item_id = '%d' ",array($item_id) )->order(" s_number, cat_id asc  ")->select();
+
+			return D("Item")->getCat($cat_ary , $all_pages , $all_catalogs) ;
+		}
+
+		//插入一个目录下的所有页面和子目录
+	public function insertCat($item_id , $catalogs , $userInfo , $parent_cat_id = 0  ,  $level = 2 ){
+			return D("Item")->insertCat($item_id , $catalogs , $userInfo , $parent_cat_id  ,  $level );
+		}
 	
 
 }

+ 13 - 2
server/Application/Api/Model/ItemModel.class.php

@@ -89,6 +89,7 @@ class ItemModel extends BaseModel {
         if (!$catalogs) {
             return ;
         }
+        $cat_id = 0 ;
         foreach ($catalogs as $key => $value) {
             $catalog_data = array(
                 "cat_name" => $this->_htmlspecialchars($value['cat_name']) ,
@@ -126,9 +127,14 @@ class ItemModel extends BaseModel {
                 $this->_insertCat($item_id , $value['catalogs'] , $userInfo , $cat_id,  $level + 1  ) ;
             }
         }
-
+        return $cat_id ;
     }
 
+	//插入一个目录下的所有页面和子目录
+    public function insertCat($item_id , $catalogs , $userInfo , $parent_cat_id = 0  ,  $level = 2 ){
+		return $this->_insertCat($item_id , $catalogs , $userInfo , $parent_cat_id  ,  $level );
+	}
+
     public function copy($item_id,$uid,$item_name= '',$item_description= '',$item_password = '',$item_domain=''){
         return $this->import($this->export($item_id),$uid,$item_name,$item_description,$item_password,$item_domain);
     }
@@ -142,7 +148,7 @@ class ItemModel extends BaseModel {
     }
 
     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 , page_id asc  ")->field($page_field)->select();
             $pages = array() ;
             if ($all_pages) {
@@ -211,6 +217,11 @@ class ItemModel extends BaseModel {
         return $pages;
     }
 
+    //获取某个目录下的页面和子目录
+    public function getCat($catalog_data ,  & $all_pages , & $all_catalogs){
+        return $this->_getCat($catalog_data ,  $all_pages , $all_catalogs) ;
+    }
+
     //获取某个目录下的所有子目录
     private function _getCatByCatId($cat_id ,$all_catalogs){
         $cats = array() ;

+ 108 - 0
web_src/src/components/catalog/Copy.vue

@@ -0,0 +1,108 @@
+<template>
+  <el-dialog :visible="true" :close-on-click-modal="false" width="350px">
+    <el-form>
+      <el-form-item label class="text-left">
+        <el-select
+          style="width:100%;"
+          v-model="is_del"
+          :placeholder="$t('please_choose')"
+          @change="selectItem"
+        >
+          <el-option key="0" :label="$t('copy_to')" value="0"></el-option>
+          <el-option key="1" :label="$t('move_to')" value="1"></el-option>
+        </el-select>
+      </el-form-item>
+      <el-form-item label class="text-left">
+        <el-select
+          style="width:100%;"
+          v-model="to_item_id"
+          :placeholder="$t('please_choose')"
+          @change="selectItem"
+        >
+          <el-option
+            v-for="item in itemList"
+            :key="item.item_id"
+            :label="item.item_name"
+            :value="item.item_id"
+          ></el-option>
+        </el-select>
+      </el-form-item>
+
+      <el-form-item label class="text-left">
+        <el-select style="width:100%;" v-model="new_p_cat_id" :placeholder="$t('please_choose')">
+          <el-option
+            v-for="item in catalogs"
+            :key="item.cat_id"
+            :label="item.cat_name"
+            :value="item.cat_id"
+          ></el-option>
+        </el-select>
+      </el-form-item>
+    </el-form>
+    <div slot="footer" class="dialog-footer">
+      <el-button @click="closeDialog">{{$t('cancel')}}</el-button>
+      <el-button type="primary" @click="copy">{{$t('confirm')}}</el-button>
+    </div>
+  </el-dialog>
+</template>
+<script>
+export default {
+  props: ['cat_id', 'item_id', 'callback'],
+  data() {
+    return {
+      itemList: [],
+      to_item_id: '0',
+      is_del: '0',
+      catalogs: [{ cat_id: '0', cat_name: '/' }],
+      new_p_cat_id: '0'
+    }
+  },
+  methods: {
+    getItemList() {
+      this.request('/api/item/myList', {
+      }).then((data) => {
+        this.itemList = data.data
+        this.to_item_id = this.item_id
+      })
+    },
+    selectItem(item_id) {
+      this.get_catalog(item_id)
+    },
+    get_catalog(item_id) {
+      var that = this
+      that.request('/api/catalog/catListName', {
+        item_id: item_id
+      })
+      .then(data => {
+        this.new_p_cat_id = '0'
+        var Info = data.data
+        Info.unshift({ cat_id: '0', cat_name: '/' })
+        that.catalogs = Info
+      })
+    },
+    copy() {
+      var that = this
+      that.request('/api/catalog/copy', {
+        cat_id: this.cat_id,
+        new_p_cat_id: this.new_p_cat_id,
+        to_item_id: this.to_item_id,
+        is_del: this.is_del
+      })
+      .then(data => {
+        this.closeDialog()
+      })
+    },
+    closeDialog() {
+      if (this.callback) this.callback()
+    }
+  },
+  mounted() {
+    this.getItemList()
+    this.get_catalog(this.item_id)
+  }
+}
+</script>
+<style scoped>
+
+
+</style>

+ 24 - 1
web_src/src/components/catalog/Index.vue

@@ -23,6 +23,7 @@
               <el-button
                 type="text"
                 size="mini"
+                :title="$t('edit')"
                 class="el-icon-edit"
                 @click.stop="edit(node, data)"
               ></el-button>
@@ -30,14 +31,23 @@
                 type="text"
                 size="mini"
                 class="el-icon-plus"
+                :title="$t('add_cat')"
                 @click.stop="add_cat(node, data)"
               ></el-button>
               <el-button
                 type="text"
                 size="mini"
                 class="el-icon-document"
+                :title="$t('sort_pages')"
                 @click.stop="showSortPage(node, data)"
               ></el-button>
+              <el-button
+                type="text"
+                size="mini"
+                class="el-icon-copy-document"
+                :title="$t('copy_or_mv_cat')"
+                @click.stop="copyCat(node, data)"
+              ></el-button>
               <el-button
                 type="text"
                 size="mini"
@@ -80,16 +90,20 @@
       ref="SortPage"
     ></SortPage>
 
+    <Copy v-if="copyFormVisible" :item_id="item_id" :cat_id="curl_cat_id" :callback="copyCallback"></Copy>
+
     <Footer></Footer>
   </div>
 </template>
 
 <script>
 import SortPage from '@/components/page/edit/SortPage'
+import Copy from './Copy'
 export default {
   name: 'Login',
   components: {
-    SortPage
+    SortPage,
+    Copy
   },
   data() {
     return {
@@ -101,6 +115,7 @@ export default {
       },
       catalogs: [],
       dialogFormVisible: false,
+      copyFormVisible: false,
       treeData: [],
       defaultProps: {
         children: 'children',
@@ -274,6 +289,14 @@ export default {
       this.curl_cat_id = data.id
       let childRef = this.$refs.SortPage // 获取子组件
       childRef.show()
+    },
+    copyCat(node, data) {
+      this.curl_cat_id = data.id
+      this.copyFormVisible = true
+    },
+    copyCallback() {
+      this.copyFormVisible = false
+      this.get_catalog()
     }
   },
 

+ 1 - 1
web_src/src/components/item/show/show_regular_item/OpBar.vue

@@ -127,7 +127,7 @@
           </el-tooltip>
 
           <span v-if="item_info.ItemCreator">
-            <el-tooltip class="item" effect="dark" :content="$t('item_setting')" placement="top">
+            <el-tooltip class="item" effect="dark" :content="$t('item_setting')" placement="left">
               <router-link :to="'/item/setting/'+item_info.item_id" v-if="item_info.ItemCreator">
                 <i class="el-icon-setting"></i>
               </router-link>

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

@@ -416,6 +416,10 @@ exports.default = {
 
   from_file_gub: 'From FileHub',
   file_gub: 'FileHub',
-  select: 'select'
+  select: 'select',
+
+  copy_or_mv_cat: 'Copy or move catalog',
+  copy_to: 'Copy To',
+  move_to: 'Move To'
 
 }

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

@@ -406,5 +406,9 @@ exports.default = {
 
   from_file_gub: '从文件库选择',
   file_gub: '文件库',
-  select: '选择'
+  select: '选择',
+
+  copy_or_mv_cat: '复制或移动目录',
+  copy_to: '复制到',
+  move_to: '移动到'
 }