Parcourir la source

When you delete a directory, you delete the pages and subdirectories under it.
删除目录时候会把其下的页面和子目录一并删除

star7th il y a 6 ans
Parent
commit
766e048fce

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

@@ -155,16 +155,9 @@ class CatalogController extends BaseController {
             return;
         }
 
-        if (D("Page")->where(" cat_id = '$cat_id' and is_del = 0")->find() || D("Catalog")->where(" parent_cat_id = '$cat_id' ")->find()) {
-            $return['error_code'] = -1 ;
-            $return['error_message'] = L('no_delete_empty_catalog') ;
-            $this->sendResult($return);
-            return;
-        }
-
         if ($cat_id > 0 ) {
             
-            $ret = D("Catalog")->where(" cat_id = '$cat_id' ")->delete();
+            $ret = D("Catalog")->deleteCat($cat_id);
 
         }
         if ($ret) {

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

@@ -98,5 +98,43 @@ class CatalogModel extends BaseModel {
 
 		return $return ;
 	}
+
+
+	//删除目录以及下面的所有页面/子目录
+	public function deleteCat($cat_id){
+		if (!$cat_id) {
+			return false;
+		}
+		//如果有子目录的话,递归把子目录清了
+		$cat = $this->where(" parent_cat_id = '$cat_id' ")->find();
+		if ($cat) {
+			$this->deleteCat($cat['cat_id']);
+		}
+		//获取当前目录信息
+		$cat = $this->where(" cat_id = '$cat_id' ")->find();
+		$item_id = $cat['item_id'];
+		$all_pages = D("Page")->where("item_id = '$item_id' and is_del = 0 ")->field("page_id,cat_id")->select();
+        $pages = array() ;
+        if ($all_pages) {
+            foreach ($all_pages as $key => $value) {
+                if ($value['cat_id'] == $cat_id) {
+                    $pages[] = $value ;
+                }
+            }
+        }
+        
+        if ($pages) {
+        	foreach ($pages as $key => $value) {
+        		D("Page")->softDeletePage($value['page_id']);
+        	}
+        }
+        $this->where(" cat_id = '$cat_id' ")->delete();
+
+        return true ;
+
+	}
+
+
 	
+
 }

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

@@ -221,7 +221,7 @@ export default {
           var that = this ;
           var url = DocConfig.server+'/api/catalog/delete';
 
-          this.$confirm(that.$t('confirm_delete'), ' ', {
+          this.$confirm(that.$t('confirm_cat_delete'), ' ', {
             confirmButtonText: that.$t('confirm'),
             cancelButtonText: that.$t('cancel'),
             type: 'warning'

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

@@ -258,5 +258,6 @@ exports.default = {
     "file_name":"File name",
     "download":"Download",
     "file_size_tips":"Less than 4MB",
-
+    
+    "confirm_cat_delete" :"Are you sure you want to delete the directory? This action will delete all the pages in this directory. Please be careful.",
 };

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

@@ -265,4 +265,5 @@ exports.default = {
     "download":"下载",
     "file_size_tips":"文件大小在4M内",
     
+    "confirm_cat_delete" :"确认删除目录吗?此操作会把该目录下的所有页面一并删除,请谨慎操作。",
 };