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.
 
 
 
 
 
 

468 lines
22 KiB

  1. /*
  2. * 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  3. * Copyright (c) 2013-2017
  4. * 创建人:陈彬彬
  5. * 日 期:2017.06.20
  6. * 描 述:文件管理
  7. */
  8. var refreshGirdData;
  9. var bootstrap = function ($, learun) {
  10. "use strict";
  11. var _url = "/LR_OAModule/ResourceFile/GetListJson";
  12. var fileId = "";
  13. var page = {
  14. init: function () {
  15. page.initleft();
  16. page.initGrid();
  17. page.bind();
  18. },
  19. bind: function () {
  20. // 查询
  21. $('#btn_Search').on('click', function () {
  22. var keyword = $('#txt_Keyword').val();
  23. page.search({ keyword: keyword });
  24. });
  25. // 刷新
  26. $('#lr_refresh').on('click', function () {
  27. location.reload();
  28. });
  29. //返回上一级、返回所有文件
  30. $(".crumb-path span").click(function () {
  31. var value = $(this).attr('data-folderId');
  32. var folderId = $(".crumb-path span:last").attr('data-folderId');
  33. if (value == "back") {
  34. if (folderId == 0) {
  35. $(".crumb-path .back").hide();
  36. }
  37. $.lrSetForm(top.$.rootUrl + _url + '?folderId=' + folderId, function (data) {//
  38. $('#gridTable').jfGridSet('refreshdata', data);
  39. });
  40. $(".crumb-path span:last").remove();
  41. } else {
  42. $.lrSetForm(top.$.rootUrl + _url + '?folderId=0', function (data) {//
  43. $('#gridTable').jfGridSet('refreshdata', data);
  44. });
  45. $(".crumb-path .back").hide();
  46. $(".crumb-path .add").remove();
  47. }
  48. });
  49. //上传文件
  50. $('#lr-uploadify').on('click', function () {
  51. learun.layerForm({
  52. id: 'UploadifyForm',
  53. title: '上传文件',
  54. url: top.$.rootUrl + '/LR_OAModule/ResourceFile/UploadifyForm?folderId=' + fileId,
  55. width: 600,
  56. height: 400,
  57. btn: null,
  58. callBack: function (id) {
  59. return top[id].acceptClick(refreshGirdData);
  60. }
  61. });
  62. });
  63. //新建文件夹
  64. $('#lr-addfolder').on('click', function () {
  65. learun.layerForm({
  66. id: 'FolderForm',
  67. title: '添加文件夹',
  68. url: top.$.rootUrl + '/LR_OAModule/ResourceFile/FolderForm?parentId=' + fileId,
  69. width: 400,
  70. height: 200,
  71. callBack: function (id) {
  72. return top[id].acceptClick(refreshGirdData);
  73. }
  74. });
  75. });
  76. //文件下载
  77. $('#lr-download').on('click', function () {
  78. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  79. var fileType = $("#gridTable").jfGridValue("F_FileType");
  80. if (keyValue) {
  81. if (fileType != 'folder') {
  82. learun.download({ url: top.$.rootUrl + '/LR_OAModule/ResourceFile/DownloadFile', param: { keyValue: keyValue }, method: 'POST' });
  83. } else {
  84. learun.alert.error('目前不支持文件夹下载');
  85. }
  86. } else {
  87. learun.alert.warning('请选择要下载的文件!');
  88. }
  89. });
  90. //文件预览
  91. $('#lr-preview').on('click', function () {
  92. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  93. var fileType = $("#gridTable").jfGridValue("F_FileType");
  94. var rowData = $("#gridTable").jfGridGet('rowdata');
  95. if (keyValue) {
  96. if (fileType != 'folder') {
  97. learun.layerForm({
  98. id: 'PreviewForm',
  99. title: '文件预览',
  100. url: top.$.rootUrl + '/LR_OAModule/ResourceFile/PreviewFile?fileId=' + rowData.F_FileId,
  101. width: 1080,
  102. height: 850,
  103. btn: null,
  104. callBack: function (id) {
  105. return top[id].acceptClick(refreshGirdData);
  106. }
  107. });
  108. } else {
  109. learun.alert.error('请选择文件');
  110. }
  111. } else {
  112. learun.alert.warning('请选择要预览的文件!');
  113. }
  114. });
  115. //文件(夹)删除
  116. $('#lr-delete').on('click', function () {
  117. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  118. var fileType = $("#gridTable").jfGridValue("F_FileType");
  119. if (keyValue) {
  120. learun.layerConfirm("注:您确定要删除此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?可在回收站还原!", function (res) {
  121. if (res) {
  122. learun.deleteForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/RemoveForm', { keyValue: keyValue, fileType: fileType }, function () {
  123. refreshGirdData();
  124. });
  125. }
  126. });
  127. } else {
  128. learun.alert.warning('请选择要删除的文件夹或文件!');
  129. }
  130. });
  131. //文件共享
  132. $('#lr-share').on('click', function () {
  133. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  134. var fileType = $("#gridTable").jfGridValue("F_FileType");
  135. if (keyValue) {
  136. learun.layerConfirm("注:您确定要共享此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?", function (res) {
  137. if (res) {
  138. learun.postForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/ShareFile', { keyValue: keyValue, IsShare: 1, fileType: fileType }, function () {
  139. refreshGirdData();
  140. });
  141. }
  142. });
  143. } else {
  144. learun.alert.warning('请选择要共享的文件夹或文件!');
  145. }
  146. });
  147. //取消共享
  148. $('#lr-cancelshare').on('click', function () {
  149. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  150. var fileType = $("#gridTable").jfGridValue("F_FileType");
  151. if (keyValue) {
  152. learun.layerConfirm("注:您确定要取消共享此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?", function (res) {
  153. if (res) {
  154. learun.deleteForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/ShareFile', { keyValue: keyValue, IsShare: 0, fileType: fileType }, function () {
  155. refreshGirdData();
  156. });
  157. }
  158. });
  159. } else {
  160. learun.alert.warning('请选择要取消共享的文件夹或文件!');
  161. }
  162. });
  163. //文件(夹)重命名
  164. $('#lr-rename').on('click', function () {
  165. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  166. var fileType = $("#gridTable").jfGridValue("F_FileType");
  167. if (keyValue) {
  168. learun.layerForm({
  169. id: (fileType == "folder" ? "FolderForm" : "FileForm"),
  170. title: (fileType == "folder" ? "文件夹" : "文件") + '重命名',
  171. url: top.$.rootUrl + '/LR_OAModule/ResourceFile/' + (fileType == "folder" ? "FolderForm" : "FileForm") + '?keyValue=' + keyValue,
  172. width: 400,
  173. height: 200,
  174. callBack: function (id) {
  175. return top[id].acceptClick(refreshGirdData);
  176. }
  177. });
  178. } else {
  179. learun.alert.warning('请选择要重命名的文件夹或文件!');
  180. }
  181. });
  182. //文件(夹)移动
  183. $('#lr-move').on('click', function () {
  184. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  185. var fileType = $("#gridTable").jfGridValue("F_FileType");
  186. if (keyValue) {
  187. learun.layerForm({
  188. id: 'MoveLocation',
  189. title: (fileType == "folder" ? "文件夹" : "文件") + '移动',
  190. url: top.$.rootUrl + '/LR_OAModule/ResourceFile/MoveForm?keyValue=' + keyValue + "&fileType=" + fileType,
  191. width: 400,
  192. height: 350,
  193. callBack: function (id) {
  194. return top[id].acceptClick(refreshGirdData);
  195. }
  196. });
  197. } else {
  198. learun.alert.warning('请选择要移动的文件夹或文件!');
  199. }
  200. });
  201. //文件(夹)还原
  202. $('#lr-restoreFile').on('click', function () {
  203. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  204. var fileType = $("#gridTable").jfGridValue("F_FileType");
  205. if (keyValue) {
  206. learun.layerConfirm("注:您确定要还原此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?", function (res) {
  207. if (res) {
  208. learun.deleteForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/RestoreFile', { keyValue: keyValue, fileType: fileType }, function () {
  209. refreshGirdData();
  210. });
  211. }
  212. });
  213. } else {
  214. learun.alert.warning('请选择要还原的文件夹或文件!');
  215. }
  216. });
  217. //文件(夹)彻底删除
  218. $('#lr-thoroughDelete').on('click', function () {
  219. var keyValue = $("#gridTable").jfGridValue("F_FileId");
  220. var fileType = $("#gridTable").jfGridValue("F_FileType");
  221. if (keyValue) {
  222. learun.layerConfirm("注:您确定要删除此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?该操作将无法恢复!", function (res) {
  223. if (res) {
  224. learun.deleteForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/ThoroughRemoveForm', { keyValue: keyValue, fileType: fileType }, function () {
  225. refreshGirdData();
  226. });
  227. }
  228. });
  229. } else {
  230. learun.alert.warning('请选择要删除的文件夹或文件!');
  231. }
  232. });
  233. //清空回收站
  234. $('#lr-emptyRecycled').on('click', function () {
  235. learun.layerConfirm("注:您确定要清空回收站吗?该操作将无法恢复!", function (res) {
  236. if (res) {
  237. learun.deleteForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/EmptyRecycledForm', {}, function () {
  238. refreshGirdData();
  239. });
  240. }
  241. });
  242. });
  243. },
  244. initleft: function () {
  245. $('#lr_left_list li').on('click', function () {
  246. $("#txt_Keyword").val('');
  247. $("#lr-uploadify").hide();
  248. $("#lr-addfolder").hide();
  249. $("#lr-download").hide();
  250. $("#lr-delete").hide();
  251. $("#lr-share").hide();
  252. $("#lr-cancelshare").hide();
  253. $("#lr-more").hide();
  254. $("#lr-restoreFile").hide();
  255. $("#lr-thoroughDelete").hide();
  256. $("#lr-emptyRecycled").hide();
  257. $(".crumb-path .back").hide();
  258. $(".crumb-path .add").remove();
  259. var $this = $(this);
  260. var $parent = $this.parent();
  261. $parent.find('.active').removeClass('active');
  262. $this.addClass('active');
  263. var data_value = $this.context.dataset.value;
  264. switch (data_value) {
  265. case "allFile":
  266. _url = "/LR_OAModule/ResourceFile/GetListJson";
  267. $(".crumb-path").find('[data-folderid=allfile]').html('所有文件');
  268. $("#lr-uploadify").show();
  269. $("#lr-addfolder").show();
  270. $("#lr-download").show();
  271. $("#lr-delete").show();
  272. $("#lr-share").show();
  273. $("#lr-more").show();
  274. break;
  275. case "allDocument":
  276. _url = "/LR_OAModule/ResourceFile/GetDocumentListJson";
  277. $(".crumb-path").find('[data-folderid=allfile]').html('所有文档');
  278. $("#lr-download").show();
  279. $("#lr-delete").show();
  280. $("#lr-share").show();
  281. break;
  282. case "allImage":
  283. _url = "/LR_OAModule/ResourceFile/GetImageListJson";
  284. $(".crumb-path").find('[data-folderid=allfile]').html('所有图片');
  285. $("#lr-download").show();
  286. $("#lr-delete").show();
  287. $("#lr-share").show();
  288. break;
  289. case "recycledFile":
  290. _url = "/LR_OAModule/ResourceFile/GetRecycledListJson";
  291. $(".crumb-path").find('[data-folderid=allfile]').html('回收站');
  292. $("#lr-restoreFile").show();
  293. $("#lr-thoroughDelete").show();
  294. $("#lr-emptyRecycled").show();
  295. break;
  296. case "myShare":
  297. _url = "/LR_OAModule/ResourceFile/GetMyShareListJson";
  298. $("#lr-cancelshare").show();
  299. break;
  300. case "othersShare":
  301. _url = "/LR_OAModule/ResourceFile/GetOthersShareListJson";
  302. //$gridTable.setGridParam().showCol("CreateUserName");
  303. $("#lr-download").show();
  304. break;
  305. default:
  306. break;
  307. }
  308. //$gridTable.setGridParam().hideCol("F_CreateUserName");
  309. $.lrSetForm(top.$.rootUrl + _url, function (res) {//
  310. if (res.length != 0) {
  311. $('#gridTable').jfGridSet('refreshdata', res);
  312. }
  313. else {
  314. $('#gridTable').jfGridSet('refreshdata', {});
  315. }
  316. });
  317. });
  318. },
  319. //加载表格
  320. initGrid: function () {
  321. var $gridTable = $("#gridTable");
  322. $('#gridTable').jfGrid({
  323. url: top.$.rootUrl + '/LR_OAModule/ResourceFile/GetListJson',
  324. headData: [
  325. {
  326. label: '文件名', name: 'F_FileName', width: 520, align: 'left',
  327. formatter: function (cellvalue, options, rowObject) {
  328. if (options.length != 0) {
  329. return "<div style='cursor:pointer;'><div style='float: left;'><img src='" + top.$.rootUrl + "/Content/images/filetype/" + options.F_FileType + ".png' style='width:30px;height:30px;padding:5px;margin-left:-5px;margin-right:5px;' /></div><div style='float: left;line-height:35px;'>" + options.F_FileName + "</div></div>";
  330. }
  331. }
  332. },
  333. {
  334. label: '大小', name: 'F_FileSize', index: 'F_FileSize', width: 100, align: 'center',
  335. formatter: function (cellvalue, options, rowObject) {
  336. return page.CountFileSize(cellvalue);
  337. }
  338. },
  339. {
  340. label: "修改时间", name: "F_ModifyDate", index: "F_ModifyDate", width: 120, align: "center",
  341. //formatter: function (cellvalue, options, rowObject) {
  342. // return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
  343. //}
  344. },
  345. {
  346. label: "是否名师资源", name: "teacher", index: "F_ModifyDate", width: 120, align: "center",
  347. formatter: function (val) {
  348. return '是';
  349. }
  350. },
  351. {
  352. label: "是否精品资源", name: "great", index: "F_ModifyDate", width: 120, align: "center",
  353. formatter: function (val) {
  354. return '是';
  355. }
  356. },
  357. ],
  358. mainId: 'F_FileId',
  359. isPage: false,
  360. sidx: 'F_CreatorTime',
  361. dblclick: function (id) {
  362. var rowData = $gridTable.jfGridGet('rowdata');
  363. if (rowData.F_FileType == "folder") {
  364. fileId = rowData.F_FileId;
  365. $.lrSetForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/GetListJson?folderId=' + fileId, function (data) {//
  366. $('#gridTable').jfGridSet('refreshdata', data);
  367. });
  368. $(".crumb-path").append('<span class="path-item add" data-fileId=' + rowData.F_FileId + ' data-folderId=' + rowData.F_FolderId + ' style="cursor:pointer;text-decoration:underline">' + rowData.F_FileName + '</span>');
  369. $(".crumb-path .back").show();
  370. $(".crumb-path span.add").unbind('click');
  371. $(".crumb-path span.add").click(function () {
  372. $(this).nextAll().remove();
  373. $.lrSetForm(top.$.rootUrl + '/LR_OAModule/ResourceFile/GetListJson?folderId=' + $(this).attr('data-fileId'), function (data) {//
  374. $('#gridTable').jfGridSet('refreshdata', data);
  375. });
  376. });
  377. }
  378. else {
  379. //在线预览
  380. learun.layerForm({
  381. id: 'PreviewForm',
  382. title: '文件预览',
  383. url: top.$.rootUrl + '/LR_OAModule/ResourceFile/PreviewFile?fileId=' + rowData.F_FileId,
  384. width: 1080,
  385. height: 850,
  386. btn: null,
  387. callBack: function (id) {
  388. return top[id].acceptClick(refreshGirdData);
  389. }
  390. });
  391. }
  392. }
  393. });
  394. $('#gridTable').jfGridSet('reload', {});
  395. },
  396. search: function (param) {
  397. param = param || {};
  398. $('#gridTable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
  399. },
  400. //初始化页面
  401. InitialPage: function () {
  402. //layout布局
  403. $('#layout').layout({
  404. applyDemoStyles: true,
  405. west__resizable: false,
  406. west__size: 220,
  407. spacing_open: 0,
  408. onresize: function () {
  409. $(window).resize()
  410. }
  411. });
  412. $('.profile-nav').height($(window).height() - 20);
  413. $('.profile-content').height($(window).height() - 20);
  414. //resize重设(表格、树形)宽高
  415. $(window).resize(function (e) {
  416. window.setTimeout(function () {
  417. $('#gridTable').setGridWidth(($('#gridPanel').width() - 15));
  418. $("#gridTable").setGridHeight($(window).height() - 141.5);
  419. $('.profile-nav').height($(window).height() - 20);
  420. $('.profile-content').height($(window).height() - 20);
  421. }, 200);
  422. e.stopPropagation();
  423. });
  424. },
  425. //计算文件大小函数(保留两位小数),Size为字节大小
  426. CountFileSize: function (Size) {
  427. var m_strSize = "";
  428. var FactSize = 0;
  429. FactSize = Size;
  430. if (FactSize < 1024.00)
  431. m_strSize = page.ToDecimal(FactSize) + " 字节";
  432. else if (FactSize >= 1024.00 && FactSize < 1048576)
  433. m_strSize = page.ToDecimal(FactSize / 1024.00) + " KB";
  434. else if (FactSize >= 1048576 && FactSize < 1073741824)
  435. m_strSize = page.ToDecimal(FactSize / 1024.00 / 1024.00) + " MB";
  436. else if (FactSize >= 1073741824)
  437. m_strSize = page.ToDecimal(FactSize / 1024.00 / 1024.00 / 1024.00) + " GB";
  438. return m_strSize;
  439. },
  440. //保留两位小数
  441. //功能:将浮点数四舍五入,取小数点后2位
  442. ToDecimal: function (x) {
  443. var f = parseFloat(x);
  444. if (isNaN(f)) {
  445. return 0;
  446. }
  447. f = Math.round(x * 100) / 100;
  448. return f;
  449. },
  450. };
  451. refreshGirdData = function () {
  452. page.search();
  453. };
  454. page.init();
  455. }