Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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