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.
 
 
 
 
 
 

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