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.

Index.js 21 KiB

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