@using System.IO @using System.Text.RegularExpressions; @using Microsoft.AspNetCore.Http @model ZoomLaCMS.Control.C_FileBrower @functions{ // 当前所处的虚拟目录 xxx/xxx public string VDir { get { return CStr(Context.Request.Query["vdir"]).TrimStart('/'); } } // /xxx/xxx/xxx public string VFullDir { get { return Model.BaseDir + VDir; } } public string CStr(object obj) { return DataConverter.CStr(obj); } //目录点开进入下一,文件则预览(暂不实现,可见PLAT) public string ShowLink(DataRow dr) { string reuslt = GetExtIcon(CStr(dr["ExName"]).ToLower()); string name = CStr(dr["Name"]); string vpath = GetVPath(CStr(dr["FullPath"])).TrimStart('/'); switch (CStr(dr["ExName"]).ToLower()) { case "filefolder": return reuslt + "" + name + ""; //case ".htm": //case ".html": //case ".shtml": // return reuslt + "" + name + ""; default: return reuslt + "" + name + ""; } } public string ShowItemOP(DataRow dr) { if (string.IsNullOrEmpty(Model.Tlp_ItemOP)) { return ""; } string vpath = GetVPath(CStr(dr["FullPath"])).TrimStart('/'); string ext = CStr(dr["ExName"]).ToLower().Trim('.'); string ftype = (ext == "filefolder") ? "folder" : "file"; string html = Model.Tlp_ItemOP.Replace("{vpath}", vpath).Replace("{ext}", ext).Replace("{ftype}", ftype); return html; } public string ShowBread() { string breadHtml = ""; if (string.IsNullOrEmpty(VDir)) { return "根目录"; } //----------------------------- string url = AppendQuery(Model.BaseUrl, "vdir="); string[] dirArr = VDir.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); breadHtml += "全部文件"; for (int i = 0; i < dirArr.Length; i++) { //上一级目录链接 url += dirArr[i] + "/"; breadHtml += ""; if (i == (dirArr.Length - 1)) { breadHtml += "" + dirArr[i] + ""; } else { breadHtml += "" + dirArr[i] + ""; } //设置返回上一级 if (dirArr.Length == 1) { breadHtml = "返回上一级 | " + breadHtml; } else if (i == (dirArr.Length - 2)) { breadHtml = "返回上一级 | " + breadHtml; } } return breadHtml; } //物理-->虚拟-->去除模板目录 private string GetVPath(string path) { string _vpath = function.PToV(path); _vpath = Regex.Replace(_vpath, Model.BaseDir, "", RegexOptions.IgnoreCase); return _vpath; } private string GetExtIcon(string ext) { switch (ext.ToLower()) { case "filefolder": return " "; case ".htm": case ".html": case ".shtml": return " "; default: return ""; } } private string AppendQuery(string url, string query) { if (string.IsNullOrEmpty(query)) { return url; } if (url.Contains("?")) { return url + "&" + query; } else { return url + "?" + query; } } } @{ /* {ext}=jpg,{ftype}=file|folder,{vpath}=xxx/xxxx.html */ /* 1.允许JS关联事件 2.根据需要支持预览(Plat方案) 3.支持根目录(指定初始目录) */ string err = ""; DataTable filesDT = new DataTable(); try { if (!Directory.Exists(function.VToP(VFullDir))) { throw new Exception("[" + VFullDir + "]目录不存在"); } if (string.IsNullOrEmpty(Model.BaseUrl)) { Model.BaseUrl = Context.Request.Path.ToString().ToLower(); if (Model.BaseUrl.StartsWith("/manage/")) { Model.BaseUrl = Model.BaseUrl.Replace("/manage/", CustomerPageAction.customPath2); } string query = ""; //参数值为空和vdir不参与 foreach (var item in Context.Request.Query) { string key = item.Key; if (key.ToLower().Equals("vdir")) { continue; } if (string.IsNullOrEmpty(Context.Request.Query[key])) { continue; } query += "&" + key + "=" + Context.Request.Query[key]; } Model.BaseUrl = AppendQuery(Model.BaseUrl, query.TrimStart('&')); } //------------------------------------ filesDT = FileSystemObject.GetDirectoryInfos(function.VToP(VFullDir), FsoMethod.All); //filesDT.DefaultView.RowFilter = "name<>'配置库' and name<>'标签库' and name<>'节点库' and name<>'模型库' and name <>'style' and (name like '%.htm%' OR ExName='FileFolder')"; if (filesDT.Rows.Count > 0) { string f_dir_hide = "", f_ext_show = ""; //隐藏某些目录不显示 foreach (string dir in Model.Dir_Hide.Split('|')) { f_dir_hide += "AND name<>'" + dir + "' "; } f_dir_hide = f_dir_hide.TrimStart("AND".ToCharArray()); //是否仅显示指定的后缀名 if (!string.IsNullOrEmpty(Model.Ext_Show)) { foreach (string ext in Model.Ext_Show.Split('|')) { f_ext_show += "OR name LIKE '%." + ext + "' "; } f_ext_show = f_ext_show.TrimStart("OR".ToCharArray()); //允许文件夹 f_ext_show = "(" + f_ext_show + " OR ExName='FileFolder')"; } string filter = (f_dir_hide + " AND " + f_ext_show).Trim(" AND".ToCharArray()); filesDT.DefaultView.RowFilter = filter; filesDT = filesDT.DefaultView.ToTable(); } } catch (Exception ex) { err = ex.Message; } } @if (!string.IsNullOrEmpty(err)) {
@err
} else {
@MvcHtmlString.Create(ShowBread())
文件名大小修改日期
@foreach (DataRow dr in filesDT.Rows) {
@MvcHtmlString.Create(ShowItemOP(dr)) @MvcHtmlString.Create(ShowLink(dr)) @dr["ExSize"] @dr["LastWriteTime"]
}
@if(string.IsNullOrEmpty(Model.Tlp_ItemOP)) { } }