Index.cshtml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. @{
  2. ViewBag.Title = "文件管理";
  3. Layout = "~/Views/Shared/_LayoutIndex.cshtml";
  4. }
  5. <script>
  6. $(function () {
  7. InitialPage();
  8. GetGrid();
  9. });
  10. //初始化页面
  11. function InitialPage() {
  12. //layout布局
  13. $('#layout').layout({
  14. applyDemoStyles: true,
  15. west__resizable: false,
  16. west__size: 220,
  17. spacing_open: 0,
  18. onresize: function () {
  19. $(window).resize()
  20. }
  21. });
  22. $('.profile-nav').height($(window).height() - 20);
  23. $('.profile-content').height($(window).height() - 20);
  24. //resize重设(表格、树形)宽高
  25. $(window).resize(function (e) {
  26. window.setTimeout(function () {
  27. $('#gridTable').setGridWidth(($('#gridPanel').width() - 15));
  28. $("#gridTable").setGridHeight($(window).height() - 141.5);
  29. $('.profile-nav').height($(window).height() - 20);
  30. $('.profile-content').height($(window).height() - 20);
  31. }, 200);
  32. e.stopPropagation();
  33. });
  34. }
  35. //计算文件大小函数(保留两位小数),Size为字节大小
  36. function CountFileSize(Size) {
  37. var m_strSize = "";
  38. var FactSize = 0;
  39. FactSize = Size;
  40. if (FactSize < 1024.00)
  41. m_strSize = ToDecimal(FactSize) + " 字节";
  42. else if (FactSize >= 1024.00 && FactSize < 1048576)
  43. m_strSize = ToDecimal(FactSize / 1024.00) + " KB";
  44. else if (FactSize >= 1048576 && FactSize < 1073741824)
  45. m_strSize = ToDecimal(FactSize / 1024.00 / 1024.00) + " MB";
  46. else if (FactSize >= 1073741824)
  47. m_strSize = ToDecimal(FactSize / 1024.00 / 1024.00 / 1024.00) + " GB";
  48. return m_strSize;
  49. }
  50. //保留两位小数
  51. //功能:将浮点数四舍五入,取小数点后2位
  52. function ToDecimal(x) {
  53. var f = parseFloat(x);
  54. if (isNaN(f)) {
  55. return 0;
  56. }
  57. f = Math.round(x * 100) / 100;
  58. return f;
  59. }
  60. //加载表格
  61. var fileId = "";
  62. function GetGrid() {
  63. var $gridTable = $("#gridTable");
  64. $gridTable.jqGrid({
  65. url: "../../PublicInfoManage/ResourceFile/GetListJson",
  66. datatype: "json",
  67. height: $(window).height() - 141.5,
  68. autowidth: true,
  69. colModel: [
  70. { label: '主键', name: 'FileId', hidden: true },
  71. { label: 'FolderId', name: 'FolderId', hidden: true },
  72. { label: 'FileType', name: 'FileType', hidden: true },
  73. { label: 'FileName', name: 'FileName', hidden: true },
  74. {
  75. label: '文件名', width: $(".profile-content").width() - 350, align: 'left',
  76. formatter: function (cellvalue, options, rowObject) {
  77. return "<div style='cursor:pointer;'><div style='float: left;'><img src='" + top.contentPath + "/Content/images/filetype/" + rowObject.FileType + ".png' style='width:35px;height:35px;padding:5px;margin-left:-7px;margin-right:5px;' /></div><div style='float: left;line-height:35px;'>" + rowObject.FileName + "</div></div>";
  78. }
  79. },
  80. {
  81. label: '大小', name: 'FileSize', index: 'FileSize', width: 100, align: 'center',
  82. formatter: function (cellvalue, options, rowObject) {
  83. return CountFileSize(cellvalue);
  84. }
  85. },
  86. {
  87. label: "修改时间", name: "ModifyDate", index: "ModifyDate", width: 120, align: "center",
  88. formatter: function (cellvalue, options, rowObject) {
  89. return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
  90. }
  91. },
  92. { label: '共享用户', name: 'CreateUserName', index: 'CreateUserName', hidden: true }
  93. ],
  94. pager: false,
  95. rowNum: "1000",
  96. rownumbers: true,
  97. shrinkToFit: false,
  98. gridview: true,
  99. ondblClickRow: function (id) {
  100. var rowData = $gridTable.getRowData(id);
  101. if (rowData.FileType == "folder") {
  102. fileId = rowData.FileId;
  103. $gridTable.jqGrid('setGridParam', {
  104. postData: { folderId: fileId },
  105. }).trigger('reloadGrid');
  106. $(".crumb-path").append('<span class="path-item add" data-fileId=' + rowData.FileId + ' data-folderId=' + rowData.FolderId + '>' + rowData.FileName + '</span>');
  107. $(".crumb-path .back").show();
  108. $(".crumb-path span.add").unbind('click');
  109. $(".crumb-path span.add").click(function () {
  110. $(this).nextAll().remove();
  111. $gridTable.jqGrid('setGridParam', {
  112. postData: { folderId: $(this).attr('data-fileId') },
  113. }).trigger('reloadGrid');
  114. });
  115. }
  116. }
  117. });
  118. //返回上一级、返回所有文件
  119. $(".crumb-path span").click(function () {
  120. var value = $(this).attr('data-folderId');
  121. var folderId = $(".crumb-path span:last").attr('data-folderId');
  122. if (value == "back") {
  123. if (folderId == 0) {
  124. $(".crumb-path .back").hide();
  125. }
  126. $gridTable.jqGrid('setGridParam', {
  127. postData: { folderId: folderId },
  128. }).trigger('reloadGrid');
  129. $(".crumb-path span:last").remove()
  130. } else {
  131. $gridTable.jqGrid('setGridParam', {
  132. postData: { folderId: 0 },
  133. }).trigger('reloadGrid');
  134. $(".crumb-path .back").hide();
  135. $(".crumb-path .add").remove()
  136. }
  137. });
  138. //文件left导航事件(所有文件、文档、图片、回收站、我的共享、他人共享)
  139. $("#nav_email li").click(function () {
  140. $gridTable.setGridParam().hideCol("CreateUserName");
  141. $("#txt_Keyword").val('');
  142. $("#lr-uploadify").hide();
  143. $("#lr-addfolder").hide();
  144. $("#lr-download").hide();
  145. $("#lr-delete").hide();
  146. $("#lr-share").hide();
  147. $("#lr-cancelshare").hide();
  148. $("#lr-more").hide();
  149. $("#lr-restoreFile").hide();
  150. $("#lr-thoroughDelete").hide();
  151. $("#lr-emptyRecycled").hide();
  152. $(".crumb-path .back").hide();
  153. $(".crumb-path .add").remove();
  154. var _url = "";
  155. var id = $(this).attr('id');
  156. switch (id) {
  157. case "allFile":
  158. _url = "../../PublicInfoManage/ResourceFile/GetListJson";
  159. $(".crumb-path").find('[data-folderid=allfile]').html('所有文件');
  160. $("#lr-uploadify").show();
  161. $("#lr-addfolder").show();
  162. $("#lr-download").show();
  163. $("#lr-delete").show();
  164. $("#lr-share").show();
  165. $("#lr-more").show();
  166. break;
  167. case "allDocument":
  168. _url = "../../PublicInfoManage/ResourceFile/GetDocumentListJson";
  169. $(".crumb-path").find('[data-folderid=allfile]').html('所有文档');
  170. $("#lr-download").show();
  171. $("#lr-delete").show();
  172. $("#lr-share").show();
  173. break;
  174. case "allImage":
  175. _url = "../../PublicInfoManage/ResourceFile/GetImageListJson";
  176. $(".crumb-path").find('[data-folderid=allfile]').html('所有图片');
  177. $("#lr-download").show();
  178. $("#lr-delete").show();
  179. $("#lr-share").show();
  180. break;
  181. case "recycledFile":
  182. _url = "../../PublicInfoManage/ResourceFile/GetRecycledListJson";
  183. $(".crumb-path").find('[data-folderid=allfile]').html('回收站');
  184. $("#lr-restoreFile").show();
  185. $("#lr-thoroughDelete").show();
  186. $("#lr-emptyRecycled").show();
  187. break;
  188. case "myShare":
  189. _url = "../../PublicInfoManage/ResourceFile/GetMyShareListJson";
  190. $("#lr-cancelshare").show();
  191. break;
  192. case "othersShare":
  193. _url = "../../PublicInfoManage/ResourceFile/GetOthersShareListJson";
  194. $gridTable.setGridParam().showCol("CreateUserName");
  195. $("#lr-download").show();
  196. break;
  197. default:
  198. break;
  199. }
  200. $gridTable.jqGrid('setGridParam', {
  201. url: _url,
  202. postData: { folderId: "" },
  203. }).trigger('reloadGrid');
  204. });
  205. }
  206. //上传文件
  207. function btn_uploadify() {
  208. dialogOpen({
  209. id: "UploadifyForm",
  210. title: '上传文件',
  211. url: '/PublicInfoManage/ResourceFile/UploadifyForm?folderId=' + fileId,
  212. width: "600px",
  213. height: "400px",
  214. btn: null
  215. });
  216. }
  217. //新建文件夹
  218. function btn_add_folder() {
  219. dialogOpen({
  220. id: "FolderForm",
  221. title: '添加文件夹',
  222. url: '/PublicInfoManage/ResourceFile/FolderForm?parentId=' + fileId,
  223. width: "400px",
  224. height: "200px",
  225. callBack: function (iframeId) {
  226. top.frames[iframeId].AcceptClick();
  227. }
  228. });
  229. }
  230. //文件下载
  231. function btn_download() {
  232. var keyValue = $("#gridTable").jqGridRowValue("FileId");
  233. var fileType = $("#gridTable").jqGridRowValue("FileType");
  234. if (keyValue) {
  235. if (fileType != 'folder') {
  236. $.download("../../PublicInfoManage/ResourceFile/DownloadFile", "keyValue=" + keyValue, 'post');
  237. } else {
  238. top.dialogTop('目前不支持文件夹下载', 'error');
  239. }
  240. } else {
  241. dialogMsg('请选择要下载的文件!', 0);
  242. }
  243. }
  244. //文件(夹)删除
  245. function btn_delete() {
  246. var keyValue = $("#gridTable").jqGridRowValue("FileId");
  247. var fileType = $("#gridTable").jqGridRowValue("FileType");
  248. if (keyValue) {
  249. $.RemoveForm({
  250. msg: "注:您确定要删除此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?可在回收站还原!",
  251. url: "../../PublicInfoManage/ResourceFile/RemoveForm",
  252. param: { keyValue: keyValue, fileType: fileType },
  253. success: function (data) {
  254. $("#gridTable").trigger("reloadGrid");
  255. }
  256. })
  257. } else {
  258. dialogMsg('请选择要删除的文件夹或文件!', 0);
  259. }
  260. }
  261. //文件(夹)重命名
  262. function btn_rename() {
  263. var keyValue = $("#gridTable").jqGridRowValue("FileId");
  264. var fileType = $("#gridTable").jqGridRowValue("FileType");
  265. if (keyValue) {
  266. dialogOpen({
  267. id: (fileType == "folder" ? "FolderForm" : "FileForm"),
  268. title: (fileType == "folder" ? "文件夹" : "文件") + '重命名',
  269. url: '/PublicInfoManage/ResourceFile/' + (fileType == "folder" ? "FolderForm" : "FileForm") + '?keyValue=' + keyValue,
  270. width: "400px",
  271. height: "200px",
  272. callBack: function (iframeId) {
  273. top.frames[iframeId].AcceptClick();
  274. }
  275. });
  276. } else {
  277. dialogMsg('请选择要重命名的文件夹或文件!', 0);
  278. }
  279. }
  280. //文件(夹)移动
  281. function btn_move() {
  282. var keyValue = $("#gridTable").jqGridRowValue("FileId");
  283. var fileType = $("#gridTable").jqGridRowValue("FileType");
  284. if (keyValue) {
  285. dialogOpen({
  286. id: "MoveLocation",
  287. title: (fileType == "folder" ? "文件夹" : "文件") + '移动',
  288. url: '/PublicInfoManage/ResourceFile/MoveForm?keyValue=' + keyValue + "&fileType=" + fileType,
  289. width: "500px",
  290. height: "400px",
  291. callBack: function (iframeId) {
  292. top.frames[iframeId].AcceptClick();
  293. }
  294. });
  295. } else {
  296. dialogMsg('请选择要移动的文件夹或文件!', 0);
  297. }
  298. }
  299. //文件(夹)还原
  300. function btn_restorefile() {
  301. var keyValue = $("#gridTable").jqGridRowValue("FileId");
  302. var fileType = $("#gridTable").jqGridRowValue("FileType");
  303. if (keyValue) {
  304. $.ConfirmAjax({
  305. msg: "注:您确定要还原此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?",
  306. url: "../../PublicInfoManage/ResourceFile/RestoreFile",
  307. param: { keyValue: keyValue, fileType: fileType },
  308. success: function (data) {
  309. $("#gridTable").trigger("reloadGrid");
  310. }
  311. })
  312. } else {
  313. dialogMsg('请选择要还原的文件夹或文件!', 0);
  314. }
  315. }
  316. //文件(夹)彻底删除
  317. function btn_thoroughdelete() {
  318. var keyValue = $("#gridTable").jqGridRowValue("FileId");
  319. var fileType = $("#gridTable").jqGridRowValue("FileType");
  320. if (keyValue) {
  321. $.RemoveForm({
  322. msg: "注:您确定要删除此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?该操作将无法恢复!",
  323. url: "../../PublicInfoManage/ResourceFile/ThoroughRemoveForm",
  324. param: { keyValue: keyValue, fileType: fileType },
  325. success: function (data) {
  326. $("#gridTable").trigger("reloadGrid");
  327. }
  328. })
  329. } else {
  330. dialogMsg('请选择要删除的文件夹或文件!', 0);
  331. }
  332. }
  333. //文件共享(取消共享)
  334. function btn_share(isshare) {
  335. var keyValue = $("#gridTable").jqGridRowValue("FileId");
  336. var fileType = $("#gridTable").jqGridRowValue("FileType");
  337. if (keyValue) {
  338. $.ConfirmAjax({
  339. msg: "注:您确定要共享此" + (fileType == "folder" ? "文件夹" : "文件") + "吗?",
  340. url: "../../PublicInfoManage/ResourceFile/ShareFile",
  341. param: { keyValue: keyValue, IsShare: isshare, fileType: fileType },
  342. success: function (data) {
  343. $("#gridTable").trigger("reloadGrid");
  344. }
  345. })
  346. } else {
  347. dialogMsg('请选择要共享的文件夹或文件!', 0);
  348. }
  349. }
  350. </script>
  351. <div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
  352. <div class="ui-layout-west">
  353. <div class="west-Panel" style="border-right: none;">
  354. <div class="profile-nav" style="overflow: auto;">
  355. <ul id="nav_email" style="padding-top: 10px;">
  356. <li id="allFile" class="active"><i class="fa fa-folder-open" style="vertical-align: middle; margin-top: -2px; margin-right: 8px; font-size: 14px; color: #666666; opacity: 0.9; width: 16px;"></i>所有文件</li>
  357. <li id="allDocument"><i class="fa fa-newspaper-o" style="vertical-align: middle; margin-top: -2px; margin-right: 8px; margin-top: -2px; font-size: 14px; color: #666666; opacity: 0.9; width: 16px;"></i>文档</li>
  358. <li id="allImage"><i class="fa fa-picture-o" style="vertical-align: middle; margin-top: -2px; margin-right: 8px; font-size: 14px; color: #666666; opacity: 0.9; width: 16px;"></i>图片</li>
  359. <li id="recycledFile"><i class="fa fa-trash-o" style="vertical-align: middle; margin-top: -3px; margin-right: 8px; font-size: 14px; color: #666666; opacity: 0.9; width: 16px;"></i>回收站</li>
  360. <div class="divide"></div>
  361. <li id="myShare"><i class="fa fa-thumbs-up" style="vertical-align: middle; margin-top: -2px; margin-right: 8px; font-size: 14px; color: #666666; opacity: 0.9; width: 16px;"></i>我的共享</li>
  362. <li id="othersShare"><i class="fa fa-share-alt" style="vertical-align: middle; margin-top: -2px; margin-right: 8px; font-size: 14px; color: #666666; opacity: 0.9; width: 16px;"></i>他人共享</li>
  363. </ul>
  364. </div>
  365. </div>
  366. </div>
  367. <div class="ui-layout-center">
  368. <div class="center-Panel">
  369. <div class="profile-content" style="background: #fff; padding: 0px;">
  370. <div class="titlePanel">
  371. <div class="title-search">
  372. <table>
  373. <tr>
  374. <td>
  375. <input id="txt_Keyword" type="text" class="form-control" placeholder="搜索我的文件" style="width: 200px;" />
  376. </td>
  377. <td style="padding-left: 5px;">
  378. <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
  379. </td>
  380. </tr>
  381. </table>
  382. </div>
  383. <div class="toolbar">
  384. <div class="btn-group">
  385. <a id="lr-uploadify" class="btn btn-success" onclick="btn_uploadify()"><i class="fa fa-upload" style="color: #fff;"></i>&nbsp;上传文件</a>
  386. </div>
  387. <div class="btn-group">
  388. <a id="lr-addfolder" class="btn btn-default" onclick="btn_add_folder()"><i class="fa fa-plus"></i>&nbsp;新建文件夹</a>
  389. </div>
  390. <div class="btn-group">
  391. <a id="lr-download" class="btn btn-default" onclick="btn_download()"><i class="fa fa-download"></i>&nbsp;下载</a>
  392. <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
  393. <a id="lr-share" class="btn btn-default" onclick="btn_share(1)"><i class="fa fa-share-alt"></i>&nbsp;共享</a>
  394. <a id="lr-cancelshare" class="btn btn-default" style="display: none;" onclick="btn_share(0)"><i class="fa fa-share-alt"></i>&nbsp;取消共享</a>
  395. <a id="lr-more" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-reorder"></i>&nbsp;更多<span class="caret"></span></a>
  396. <ul class="dropdown-menu pull-right">
  397. <li id="lr-rename"><a onclick="btn_rename()">&nbsp;重命名</a></li>
  398. <li id="lr-move"><a onclick="btn_move()">&nbsp;移动</a></li>
  399. </ul>
  400. </div>
  401. <div class="btn-group">
  402. <a id="lr-restoreFile" style="display: none;" class="btn btn-default" onclick="btn_restorefile()"><i class="fa fa-rotate-left"></i>&nbsp;还原文件</a>
  403. <a id="lr-thoroughDelete" style="display: none;" class="btn btn-default" onclick="btn_thoroughdelete()"><i class="fa fa-trash-o"></i>&nbsp;彻底删除</a>
  404. <a id="lr-emptyRecycled" style="display: none;" class="btn btn-default" onclick=""><i class="fa fa-eraser"></i>&nbsp;清空回收站</a>
  405. </div>
  406. <script>$('.toolbar').authorizeButton()</script>
  407. </div>
  408. </div>
  409. <div style="height: 30px; padding-left: 16px;">
  410. <div class="crumb-path">
  411. <span class="back" data-folderid="back" style="display: none;">返回上一级</span>
  412. <span class="path-item" data-folderid="allfile">所有文件</span>
  413. </div>
  414. </div>
  415. <div id="gridPanel" style="padding-left: 15px; padding-right: 15px;">
  416. <table id="gridTable"></table>
  417. <div id="gridPager"></div>
  418. </div>
  419. </div>
  420. </div>
  421. </div>
  422. </div>
  423. <style>
  424. .ui-jqgrid-htable th.ui-th-column {
  425. background-color: #F7F7F7;
  426. }
  427. </style>