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.
 
 
 
 
 
 

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