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.
 
 
 
 
 
 

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