You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

637 lines
22 KiB

  1. using Learun.Util;
  2. using Learun.Util.Ueditor;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Web.Mvc;
  9. using Learun.Application.OA;
  10. namespace Learun.Application.Web.Controllers
  11. {
  12. /// <summary>
  13. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  14. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  15. /// 创建人:陈彬彬
  16. /// 日 期:2017.03.07
  17. /// 描 述:通用控制器,处理通用的接口
  18. /// </summary>
  19. [HandlerLogin(FilterMode.Ignore)]
  20. public class UtilityController : MvcControllerBase
  21. {
  22. private NoticeIBLL noticeIBLL = new NoticeBLL();
  23. #region 选择图标
  24. /// <summary>
  25. /// 图标的选择
  26. /// </summary>
  27. /// <returns></returns>
  28. [HttpGet]
  29. [HandlerLogin(FilterMode.Enforce)]
  30. public ActionResult Icon()
  31. {
  32. return View();
  33. }
  34. /// <summary>
  35. /// 移动图标的选择
  36. /// </summary>
  37. /// <returns></returns>
  38. [HttpGet]
  39. [HandlerLogin(FilterMode.Enforce)]
  40. public ActionResult AppIcon()
  41. {
  42. return View();
  43. }
  44. #endregion
  45. #region 百度编辑器的后端接口
  46. /// <summary>
  47. /// 百度编辑器的后端接口
  48. /// </summary>
  49. /// <param name="action">执行动作</param>
  50. /// <returns></returns>
  51. public ActionResult UEditor()
  52. {
  53. string action = Request["action"];
  54. switch (action)
  55. {
  56. case "config":
  57. return Content(UeditorConfig.Items.ToJson());
  58. case "uploadimage":
  59. return UEditorUpload(new UeditorUploadConfig()
  60. {
  61. AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
  62. PathFormat = UeditorConfig.GetString("imagePathFormat"),
  63. SizeLimit = UeditorConfig.GetInt("imageMaxSize"),
  64. UploadFieldName = UeditorConfig.GetString("imageFieldName")
  65. });
  66. case "uploadscrawl":
  67. return UEditorUpload(new UeditorUploadConfig()
  68. {
  69. AllowExtensions = new string[] { ".png" },
  70. PathFormat = UeditorConfig.GetString("scrawlPathFormat"),
  71. SizeLimit = UeditorConfig.GetInt("scrawlMaxSize"),
  72. UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
  73. Base64 = true,
  74. Base64Filename = "scrawl.png"
  75. });
  76. case "uploadvideo":
  77. return UEditorUpload(new UeditorUploadConfig()
  78. {
  79. AllowExtensions = UeditorConfig.GetStringList("videoAllowFiles"),
  80. PathFormat = UeditorConfig.GetString("videoPathFormat"),
  81. SizeLimit = UeditorConfig.GetInt("videoMaxSize"),
  82. UploadFieldName = UeditorConfig.GetString("videoFieldName")
  83. });
  84. case "uploadfile":
  85. return UEditorUpload(new UeditorUploadConfig()
  86. {
  87. AllowExtensions = UeditorConfig.GetStringList("fileAllowFiles"),
  88. PathFormat = UeditorConfig.GetString("filePathFormat"),
  89. SizeLimit = UeditorConfig.GetInt("fileMaxSize"),
  90. UploadFieldName = UeditorConfig.GetString("fileFieldName")
  91. });
  92. case "listimage":
  93. return ListFileManager(UeditorConfig.GetString("imageManagerListPath"), UeditorConfig.GetStringList("imageManagerAllowFiles"));
  94. case "listfile":
  95. return ListFileManager(UeditorConfig.GetString("fileManagerListPath"), UeditorConfig.GetStringList("fileManagerAllowFiles"));
  96. case "catchimage":
  97. //return CrawlerHandler();存在漏洞
  98. return Content(new
  99. {
  100. state = "action 参数为空或者 action 不被支持。"
  101. }.ToJson());
  102. default:
  103. return Content(new
  104. {
  105. state = "action 参数为空或者 action 不被支持。"
  106. }.ToJson());
  107. }
  108. }
  109. /// <summary>
  110. /// 百度编辑器的文件上传
  111. /// </summary>
  112. /// <param name="uploadConfig">上传配置信息</param>
  113. /// <returns></returns>
  114. public ActionResult UEditorUpload(UeditorUploadConfig uploadConfig)
  115. {
  116. UeditorUploadResult result = new UeditorUploadResult() { State = UeditorUploadState.Unknown };
  117. byte[] uploadFileBytes = null;
  118. string uploadFileName = null;
  119. if (uploadConfig.Base64)
  120. {
  121. uploadFileName = uploadConfig.Base64Filename;
  122. uploadFileBytes = Convert.FromBase64String(Request[uploadConfig.UploadFieldName]);
  123. }
  124. else
  125. {
  126. var file = Request.Files[uploadConfig.UploadFieldName];
  127. uploadFileName = file.FileName;
  128. if (!CheckFileType(uploadConfig, uploadFileName))
  129. {
  130. return Content(new
  131. {
  132. state = GetStateMessage(UeditorUploadState.TypeNotAllow)
  133. }.ToJson());
  134. }
  135. if (!CheckFileSize(uploadConfig, file.ContentLength))
  136. {
  137. return Content(new
  138. {
  139. state = GetStateMessage(UeditorUploadState.SizeLimitExceed)
  140. }.ToJson());
  141. }
  142. uploadFileBytes = new byte[file.ContentLength];
  143. try
  144. {
  145. file.InputStream.Read(uploadFileBytes, 0, file.ContentLength);
  146. }
  147. catch (Exception)
  148. {
  149. return Content(new
  150. {
  151. state = GetStateMessage(UeditorUploadState.NetworkError)
  152. }.ToJson());
  153. }
  154. }
  155. result.OriginFileName = uploadFileName;
  156. var savePath = UeditorPathFormatter.Format(uploadFileName, uploadConfig.PathFormat);
  157. var localPath = Server.MapPath(savePath).Replace("\\Utility\\", "\\ueditor\\");// +"/ueditor/net";
  158. try
  159. {
  160. if (!Directory.Exists(Path.GetDirectoryName(localPath)))
  161. {
  162. Directory.CreateDirectory(Path.GetDirectoryName(localPath));
  163. }
  164. System.IO.File.WriteAllBytes(localPath, uploadFileBytes);
  165. result.Url = savePath;
  166. result.State = UeditorUploadState.Success;
  167. }
  168. catch (Exception e)
  169. {
  170. result.State = UeditorUploadState.FileAccessError;
  171. result.ErrorMessage = e.Message;
  172. }
  173. return Content(new
  174. {
  175. state = GetStateMessage(result.State),
  176. url = result.Url,
  177. title = result.OriginFileName,
  178. original = result.OriginFileName,
  179. error = result.ErrorMessage
  180. }.ToJson());
  181. }
  182. /// <summary>
  183. /// 百度编辑器的文件列表管理
  184. /// </summary>
  185. /// <param name="pathToList">文件列表目录</param>
  186. /// <param name="searchExtensions">扩展名</param>
  187. /// <returns></returns>
  188. public ActionResult ListFileManager(string pathToList, string[] searchExtensions)
  189. {
  190. int Start;
  191. int Size;
  192. int Total;
  193. String[] FileList;
  194. String[] SearchExtensions;
  195. SearchExtensions = searchExtensions.Select(x => x.ToLower()).ToArray();
  196. try
  197. {
  198. Start = String.IsNullOrEmpty(Request["start"]) ? 0 : Convert.ToInt32(Request["start"]);
  199. Size = String.IsNullOrEmpty(Request["size"]) ? UeditorConfig.GetInt("imageManagerListSize") : Convert.ToInt32(Request["size"]);
  200. }
  201. catch (FormatException)
  202. {
  203. return Content(new
  204. {
  205. state = "参数不正确",
  206. start = 0,
  207. size = 0,
  208. total = 0
  209. }.ToJson());
  210. }
  211. var buildingList = new List<String>();
  212. try
  213. {
  214. var localPath = Server.MapPath(pathToList).Replace("\\Utility\\", "\\ueditor\\");
  215. buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)
  216. .Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower()))
  217. .Select(x => pathToList + x.Substring(localPath.Length).Replace("\\", "/")));
  218. Total = buildingList.Count;
  219. FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray();
  220. }
  221. catch (UnauthorizedAccessException)
  222. {
  223. return Content(new
  224. {
  225. state = "文件系统权限不足",
  226. start = 0,
  227. size = 0,
  228. total = 0
  229. }.ToJson());
  230. }
  231. catch (DirectoryNotFoundException)
  232. {
  233. return Content(new
  234. {
  235. state = "路径不存在",
  236. start = 0,
  237. size = 0,
  238. total = 0
  239. }.ToJson());
  240. }
  241. catch (IOException)
  242. {
  243. return Content(new
  244. {
  245. state = "文件系统读取错误",
  246. start = 0,
  247. size = 0,
  248. total = 0
  249. }.ToJson());
  250. }
  251. return Content(new
  252. {
  253. state = "SUCCESS",
  254. list = FileList == null ? null : FileList.Select(x => new { url = x }),
  255. start = Start,
  256. size = Size,
  257. total = Total
  258. }.ToJson());
  259. }
  260. //public ActionResult CrawlerHandler()
  261. //{
  262. // string[] sources = Request.Form.GetValues("source[]");
  263. // if (sources == null || sources.Length == 0)
  264. // {
  265. // return Content(new
  266. // {
  267. // state = "参数错误:没有指定抓取源"
  268. // }.ToJson());
  269. // }
  270. // UeditorCrawler[] crawlers = sources.Select(x => new UeditorCrawler(x).Fetch()).ToArray();
  271. // return Content(new
  272. // {
  273. // state = "SUCCESS",
  274. // list = crawlers.Select(x => new
  275. // {
  276. // state = x.State,
  277. // source = x.SourceUrl,
  278. // url = x.ServerUrl
  279. // })
  280. // }.ToJson());
  281. //}
  282. private string GetStateMessage(UeditorUploadState state)
  283. {
  284. switch (state)
  285. {
  286. case UeditorUploadState.Success:
  287. return "SUCCESS";
  288. case UeditorUploadState.FileAccessError:
  289. return "文件访问出错,请检查写入权限";
  290. case UeditorUploadState.SizeLimitExceed:
  291. return "文件大小超出服务器限制";
  292. case UeditorUploadState.TypeNotAllow:
  293. return "不允许的文件格式";
  294. case UeditorUploadState.NetworkError:
  295. return "网络错误";
  296. }
  297. return "未知错误";
  298. }
  299. /// <summary>
  300. /// 检测是否符合上传文件格式
  301. /// </summary>
  302. /// <param name="uploadConfig">配置信息</param>
  303. /// <param name="filename">文件名字</param>
  304. /// <returns></returns>
  305. private bool CheckFileType(UeditorUploadConfig uploadConfig, string filename)
  306. {
  307. var fileExtension = Path.GetExtension(filename).ToLower();
  308. var res = false;
  309. foreach (var item in uploadConfig.AllowExtensions)
  310. {
  311. if (item == fileExtension)
  312. {
  313. res = true;
  314. break;
  315. }
  316. }
  317. return res;
  318. }
  319. /// <summary>
  320. /// 检测是否符合上传文件大小
  321. /// </summary>
  322. /// <param name="uploadConfig">配置信息</param>
  323. /// <param name="size">文件大小</param>
  324. /// <returns></returns>
  325. private bool CheckFileSize(UeditorUploadConfig uploadConfig, int size)
  326. {
  327. return size < uploadConfig.SizeLimit;
  328. }
  329. #endregion
  330. #region 导出Excel
  331. /// <summary>
  332. /// 请选择要导出的字段页面
  333. /// </summary>
  334. /// <returns></returns>
  335. [HttpGet]
  336. [HandlerLogin(FilterMode.Enforce)]
  337. public ActionResult ExcelExportForm()
  338. {
  339. return View();
  340. }
  341. [HttpPost, ValidateInput(false)]
  342. public void ExportExcel(string fileName, string columnJson, string dataJson, string exportField)
  343. {
  344. //设置导出格式
  345. ExcelConfig excelconfig = new ExcelConfig();
  346. excelconfig.Title = Server.UrlDecode(fileName);
  347. excelconfig.TitleFont = "微软雅黑";
  348. excelconfig.TitlePoint = 15;
  349. excelconfig.FileName = Server.UrlDecode(fileName) + ".xls";
  350. excelconfig.IsAllSizeColumn = true;
  351. excelconfig.ColumnEntity = new List<ColumnModel>();
  352. //表头
  353. List<jfGridModel> columnList = columnJson.ToList<jfGridModel>();
  354. //行数据
  355. DataTable rowData = dataJson.ToTable();
  356. //写入Excel表头
  357. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  358. if (!string.IsNullOrEmpty(exportField))
  359. {
  360. string[] exportFields = exportField.Split(',');
  361. foreach (var field in exportFields)
  362. {
  363. if (!exportFieldMap.ContainsKey(field))
  364. {
  365. exportFieldMap.Add(field, "1");
  366. }
  367. }
  368. }
  369. foreach (jfGridModel columnModel in columnList)
  370. {
  371. if (exportFieldMap.ContainsKey(columnModel.name) || string.IsNullOrEmpty(exportField))
  372. {
  373. excelconfig.ColumnEntity.Add(new ColumnModel()
  374. {
  375. Column = columnModel.name,
  376. ExcelColumn = columnModel.label,
  377. Alignment = columnModel.align,
  378. });
  379. }
  380. }
  381. ExcelHelper.ExcelDownload(rowData, excelconfig);
  382. }
  383. #endregion
  384. #region 列表选择弹层
  385. /// <summary>
  386. /// 列表选择弹层
  387. /// </summary>
  388. /// <returns></returns>
  389. [HttpGet]
  390. [HandlerLogin(FilterMode.Enforce)]
  391. public ActionResult GirdSelectIndex()
  392. {
  393. return View();
  394. }
  395. #endregion
  396. #region 树形选择弹层
  397. /// <summary>
  398. /// 列表选择弹层
  399. /// </summary>
  400. /// <returns></returns>
  401. [HttpGet]
  402. [HandlerLogin(FilterMode.Enforce)]
  403. public ActionResult TreeSelectIndex()
  404. {
  405. return View();
  406. }
  407. #endregion
  408. #region 加载js和css文件
  409. /// <summary>
  410. /// 列表选择弹层
  411. /// </summary>
  412. /// <returns></returns>
  413. [HttpGet]
  414. public ActionResult JsCss(string plugins)
  415. {
  416. Dictionary<string,JssCssModel> list = new Dictionary<string,JssCssModel>();
  417. string[] pluginArray = plugins.Split(',');
  418. foreach (var item in pluginArray) {
  419. GetJssCss(item,list);
  420. }
  421. return JsonResult(list);
  422. }
  423. /// <summary>
  424. /// 获取js和css文件值
  425. /// </summary>
  426. /// <param name="name"></param>
  427. /// <param name="list"></param>
  428. private void GetJssCss(string name, Dictionary<string, JssCssModel> list)
  429. {
  430. JssCssModel model = new JssCssModel();
  431. switch (name) {
  432. case "jquery":
  433. model.js = JsCssHelper.Read("/Content/jquery/jquery-1.10.2.min.js");
  434. break;
  435. case "cookie":
  436. model.js = JsCssHelper.Read("/Content/jquery/plugin/jquery.cookie.min.js");
  437. break;
  438. case "md5":
  439. model.js = JsCssHelper.Read("/Content/jquery/jquery.md5.min.js");
  440. break;
  441. case "scrollbar":
  442. model.css = JsCssHelper.Read("/Content/jquery/plugin/scrollbar/jquery.mCustomScrollbar.min.css");
  443. model.js = JsCssHelper.Read("/Content/jquery/plugin/scrollbar/jquery.mCustomScrollbar.concat.min.js");
  444. break;
  445. case "toastr":
  446. model.css = JsCssHelper.Read("/Content/jquery/plugin/toastr/toastr.css");
  447. model.js = JsCssHelper.Read("/Content/jquery/plugin/toastr/toastr.min.js");
  448. break;
  449. case "bootstrap":
  450. model.css = JsCssHelper.Read("/Content/bootstrap/bootstrap.min.css");
  451. model.js = JsCssHelper.Read("/Content/bootstrap/bootstrap.min.js");
  452. break;
  453. case "layer":
  454. model.css = JsCssHelper.Read("/Content/bootstrap/bootstrap.min.css");
  455. model.js = JsCssHelper.Read("/Content/bootstrap/bootstrap.min.js");
  456. break;
  457. case "jqprint":
  458. break;
  459. case "wdatePicker":
  460. break;
  461. case "syntaxhighlighter":
  462. break;
  463. case "fontAwesome":
  464. break;
  465. case "iconfont":
  466. break;
  467. case "common":
  468. break;
  469. case "base":
  470. break;
  471. case "tabs":
  472. break;
  473. case "date":
  474. break;
  475. case "validator-helper":
  476. break;
  477. case "lrlayer":
  478. break;
  479. case "ajax":
  480. break;
  481. case "clientdata":
  482. break;
  483. case "iframe":
  484. break;
  485. case "validator":
  486. break;
  487. case "layout":
  488. break;
  489. case "tree":
  490. break;
  491. case "select":
  492. break;
  493. case "formselect":
  494. break;
  495. case "layerselect":
  496. break;
  497. case "jfgrid":
  498. break;
  499. case "wizard":
  500. break;
  501. case "timeline":
  502. break;
  503. case "datepicker":
  504. break;
  505. case "uploader":
  506. break;
  507. case "excel":
  508. break;
  509. case "authorize":
  510. break;
  511. case "custmerform":
  512. break;
  513. case "workflow":
  514. break;
  515. case "form":
  516. break;
  517. }
  518. }
  519. private class JssCssModel {
  520. /// <summary>
  521. /// js 代码
  522. /// </summary>
  523. public string js { get; set; }
  524. /// <summary>
  525. /// css 代码
  526. /// </summary>
  527. public string css { get; set; }
  528. /// <summary>
  529. /// 版本号
  530. /// </summary>
  531. public string ver { get; set; }
  532. }
  533. #endregion
  534. #region 自定义表单
  535. /// <summary>
  536. /// 表单预览
  537. /// </summary>
  538. /// <returns></returns>
  539. [HttpGet]
  540. public ActionResult PreviewForm()
  541. {
  542. return View();
  543. }
  544. /// <summary>
  545. /// 编辑表格
  546. /// </summary>
  547. /// <returns></returns>
  548. [HttpGet]
  549. public ActionResult EditGridForm()
  550. {
  551. return View();
  552. }
  553. #endregion
  554. #region jfgrid弹层选择
  555. /// <summary>
  556. /// 列表选择弹层
  557. /// </summary>
  558. /// <returns></returns>
  559. [HttpGet]
  560. [HandlerLogin(FilterMode.Enforce)]
  561. public ActionResult JfGirdLayerForm()
  562. {
  563. return View();
  564. }
  565. #endregion
  566. #region 桌面消息列表详情查看
  567. [HttpGet]
  568. public ActionResult ListContentView(string keyValue)
  569. {
  570. var data = noticeIBLL.GetEntity(keyValue);
  571. data.F_NewsContent = WebHelper.HtmlDecode(data.F_NewsContent);
  572. return Content(data.F_NewsContent);
  573. }
  574. /// <summary>
  575. /// 桌面消息列表详情查看
  576. /// </summary>
  577. /// <returns></returns>
  578. [HttpGet]
  579. public ActionResult ListContentIndex()
  580. {
  581. return View();
  582. }
  583. #endregion
  584. #region 开发向导
  585. /// <summary>
  586. /// pc端开发向导
  587. /// </summary>
  588. /// <returns></returns>
  589. [HttpGet]
  590. [HandlerLogin(FilterMode.Enforce)]
  591. public ActionResult PCDevGuideIndex()
  592. {
  593. return View();
  594. }
  595. /// <summary>
  596. /// 移动端开发向导
  597. /// </summary>
  598. /// <returns></returns>
  599. [HttpGet]
  600. [HandlerLogin(FilterMode.Enforce)]
  601. public ActionResult AppDevGuideIndex()
  602. {
  603. return View();
  604. }
  605. #endregion
  606. }
  607. }