From 3af9250443f7ee4aeb01390a41be2f157f7796a6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Fri, 17 Jul 2020 18:08:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=A2=9E=E5=8A=A0=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E9=99=84=E4=BB=B6=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Core/Models/APIModels.cs | 25 +++++++ .../AdminCP/Controllers/AttachController.cs | 45 ++++++++++- .../AdminCP/Views/Attach/AttachList.cshtml | 75 +++++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Attach/AttachList.cshtml diff --git a/COMCMS.Core/Models/APIModels.cs b/COMCMS.Core/Models/APIModels.cs index 267cbe2..b0a9aae 100644 --- a/COMCMS.Core/Models/APIModels.cs +++ b/COMCMS.Core/Models/APIModels.cs @@ -38,4 +38,29 @@ namespace COMCMS.Core.Models public int qty { get; set; } = 1; } #endregion + + #region 系统文件目录信息列表 + /// + /// 系统文件目录信息 + /// + public class DirInfo + { + /// + /// 目录名称 + /// + public string name { get; set; } + /// + /// 目录 + /// + public string path { get; set; } + /// + /// 目录详情 + /// + public string fullPath { get; set; } + /// + /// 子目录 + /// + public List subList { get; set; } + } + #endregion } diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/AttachController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/AttachController.cs index 3e775e6..5afc9e3 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/AttachController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/AttachController.cs @@ -37,7 +37,13 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers [MyAuthorize("viewlist", "attach")] public IActionResult AttachList() { + List all = getAllAttach(""); + string allJson = JsonConvert.SerializeObject(all); + //string basePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";//基础目录 + + //string[] arrDirs = Directory.GetDirectories(basePath); return View(); + //return Content(JsonConvert.SerializeObject(allJson)); } #endregion @@ -46,7 +52,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers [MyAuthorize("viewlist", "attach","JSON")] public IActionResult GetDirList(string subdir) { - string attachPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}"; + //string attachPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}"; @@ -54,5 +60,42 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Json(tip); } #endregion + + #region 获取附件目录和所有子目录树 + /// + /// 所有所有附件目录树 + /// + /// 子目录,需要完整,如:images/2020 + /// + public List getAllAttach(string subdir) + { + List list = new List(); + string basePath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}";//基础目录 + if (!string.IsNullOrEmpty(subdir)) + { + basePath += subdir.Replace("/", Path.DirectorySeparatorChar.ToString()); + } + + string[] arrDirs = Directory.GetDirectories(basePath); + + if (arrDirs !=null && arrDirs.Length > 0) + { + foreach (var item in arrDirs) + { + string nextSubDir = subdir + "/" + item.Substring(item.LastIndexOf(Path.DirectorySeparatorChar)+1); + var tpmList = getAllAttach(nextSubDir); + list.Add(new DirInfo() + { + name = item.Substring(item.LastIndexOf(Path.DirectorySeparatorChar)+1), + path = nextSubDir, + //fullPath = item, + subList = tpmList + }); + } + } + + return list; + } + #endregion } } diff --git a/COMCMS.Web/Areas/AdminCP/Views/Attach/AttachList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Attach/AttachList.cshtml new file mode 100644 index 0000000..601e84a --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/Attach/AttachList.cshtml @@ -0,0 +1,75 @@ +@{ + ViewBag.title = "附件管理"; +} + +
+
+
+
+
+
+
显示:
+ 所有 + 文档 + 视频 + 图片 +
+ +
+
文件夹
+ +
标签
+ +
+
+
+
+
+
+ +
+