初步增加后台附件管理功能

This commit is contained in:
2020-07-17 18:08:54 +08:00
parent b92d40b623
commit 36fbe99831
3 changed files with 144 additions and 1 deletions
@@ -37,7 +37,13 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
[MyAuthorize("viewlist", "attach")]
public IActionResult AttachList()
{
List<DirInfo> 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 获取附件目录和所有子目录树
/// <summary>
/// 所有所有附件目录树
/// </summary>
/// <param name="subdir">子目录,需要完整,如:images/2020</param>
/// <returns></returns>
public List<DirInfo> getAllAttach(string subdir)
{
List<DirInfo> list = new List<DirInfo>();
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
}
}