fileList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. // 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("fileListCtrl", ["$http", "$scope", "$timeout", function ($http, $scope, $timeout) {
  6. var self = this;
  7. var s4 = new SM4Util();
  8. self.userId = $.cookie("GlWorkPlatform-userid");
  9. self.userName = $.cookie("GlWorkPlatform-username");
  10. self.userChineseName = $.cookie("GlWorkPlatform-chineseName");
  11. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  12. self.CrossPage = window.parent.CrossPage;
  13. //声明
  14. self.noDataTip = 1;
  15. self.rows = []; //声明空数组
  16. self.pageno = 1; // 初始化 当前页为 1
  17. self.total_count = 0;
  18. self.itemsPerPage = 10;
  19. self.pageOptions = [10, 15, 20, 25, 30];
  20. var postCfgJson = {
  21. headers: {
  22. 'Content-Type': 'application/json',
  23. 'Authorization': "Bearer " + self.get_AccessToken
  24. }
  25. };
  26. //文件上传用到的变量
  27. self.finishUploadArray = [];
  28. self.uploadTypeName = "";
  29. self.uploadTypeCode = "";
  30. self.uploadTypeList = [];
  31. //搜索参数
  32. self.search = {
  33. FILESNAME: "",
  34. TYPECODE: sp.getUrlName("CODE") || ""
  35. }
  36. //打开上传弹出层
  37. self.openUploadLayer = function () {
  38. var time1 = sp.getLocalDate1();
  39. self.journalRecord(time1, sp.getLocalDate1(), "上传", "接入日志", window.location.pathname)
  40. self.finishUploadArray = [];
  41. if (self.uploadTypeList.length == 0) {
  42. self.getResourceType();
  43. } else {
  44. self.uploadTypeName = self.uploadTypeList[0].CNAME;
  45. self.uploadTypeCode = self.uploadTypeList[0].CODE;
  46. }
  47. $(".warninfo").html("");
  48. $(".uploadBtn").val("");
  49. $(".fileList tbody").html("");
  50. $(".noFileWarning").show();
  51. sp.layer("#layer_uploadFile");
  52. }
  53. //部署文件上传服务
  54. self.setFileUpload = function () {
  55. var $form = null;
  56. var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
  57. var collection = {};
  58. var fileaddr = ""; //标记文件地址
  59. $('#fileupload').fileupload({
  60. dataType: 'json',
  61. maxChunkSize: 10000000,
  62. autoUpload: false,
  63. limitConcurrentUploads: 1,
  64. sequentialUploads: true,
  65. url: apiurljs.login + "g2work/files/upLoad",
  66. complete: function (e, data) {
  67. console.log(e);
  68. if (e.responseJSON.files[0].size > 0) {
  69. var itemFile = {
  70. ID: "0",
  71. ROUTEINFOID: "0",
  72. SORTID: "0",
  73. SUBMAN: self.userChineseName,
  74. SUNMANUSERID: self.userId,
  75. PREFIX: e.responseJSON.files[0].prefix,
  76. FILESNAME: e.responseJSON.files[0].name,
  77. FILESIZE: self.formatFileSize(e.responseJSON.files[0].size),
  78. FILEURL: e.responseJSON.files[0].url,
  79. FILESID: e.responseJSON.files[0].fileid
  80. }
  81. self.finishUploadArray.push(itemFile);
  82. }
  83. },
  84. beforeSend: function (xhr, data) {
  85. xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken);
  86. data.files.forEach(function (file) {
  87. //console.log("fileid=" + collection[file.name + file.size]);
  88. xhr.setRequestHeader('X-File-Identifier', fileid);
  89. //xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  90. })
  91. }
  92. }).bind('fileuploadadd', function (e, data) {
  93. data.files.forEach(function (file) {
  94. chunkSize = 10000000;
  95. fileid = "";
  96. frOnload = function (e) {
  97. fileid = SparkMD5.ArrayBuffer.hash(e.target.result);
  98. collection[file.name + file.size] = fileid;
  99. var filetype = file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length).toLowerCase();
  100. }
  101. function loadFile() {
  102. var fileReader = new FileReader();
  103. fileReader.onload = frOnload;
  104. var start = 0,
  105. end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
  106. fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
  107. };
  108. loadFile();
  109. });
  110. })
  111. }
  112. //格式化文件大小的函数
  113. self.formatFileSize = function (bytes) {
  114. if (typeof bytes !== 'number') {
  115. return '';
  116. }
  117. if (bytes >= 1000000000) {
  118. return (bytes / 1000000000).toFixed(2) + 'GB';
  119. }
  120. if (bytes >= 1000000) {
  121. return (bytes / 1000000).toFixed(2) + 'MB';
  122. }
  123. return (bytes / 1000).toFixed(2) + 'KB';
  124. }
  125. //格式化文件类型的函数
  126. self.formatFileExt = function (fileName) {
  127. var LastIndex = fileName.lastIndexOf(".");
  128. return fileName.substring(LastIndex + 1, fileName.length);
  129. }
  130. //格式化文件名称的函数
  131. self.formatFileName = function (fileName) {
  132. var LastIndex = fileName.lastIndexOf(".");
  133. return fileName.substring(0, LastIndex);
  134. }
  135. //加载文件分类
  136. self.getResourceType = function () {
  137. self.uploadTypeList = [];
  138. self.uploadTypeName = "";
  139. self.uploadTypeCode = "";
  140. var postData = {
  141. tablename: "CODESHAREFILESTYPE"
  142. }
  143. $http.post(apiurljs.login + "g2app/share/queryCode", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfgJson)
  144. .success(function (obj) {
  145. var res = strToJson(s4.decryptData_CBC(obj.data));
  146. console.log(res);
  147. self.uploadTypeList = res.data;
  148. self.uploadTypeName = res.data[0].CNAME;
  149. self.uploadTypeCode = res.data[0].CODE;
  150. })
  151. }
  152. //改变文件分类
  153. self.changeResourceType = function () {
  154. self.uploadTypeList.forEach(function (item) {
  155. if (self.uploadTypeCode == item.CODE) {
  156. self.uploadTypeName = item.CNAME;
  157. }
  158. })
  159. }
  160. //保存上传文件的记录
  161. self.saveUploadFile = function () {
  162. var uploadNum = $(".fileList .template-upload").length;
  163. var downloadNum = $(".fileList .template-download").length;
  164. if (downloadNum == 0 && uploadNum == 0) {
  165. self.addWarning("未选择上传文件");
  166. } else if (downloadNum == 0 && uploadNum != 0 || downloadNum != 0 && uploadNum != 0) {
  167. self.addWarning("存在未上传文件");
  168. } else {
  169. self.finishUploadArray.forEach(function (item) {
  170. item.TYPECODE = self.uploadTypeCode;
  171. item.TYPENAME = self.uploadTypeName;
  172. item.UPTIMES = sp.dateFtt("yyyy-MM-dd hh:mm:ss", new Date())
  173. })
  174. var postData = JSON.stringify(self.finishUploadArray);
  175. $http.post(apiurljs.login + "g2app/share/shareInsert", { data: s4.encryptData_CBC(postData) }, postCfgJson)
  176. .success(function (obj) {
  177. var res = strToJson(s4.decryptData_CBC(obj.data));
  178. if (res.success) {
  179. sp.closeCenter('.sp-layer');
  180. self.pageno = 1; // 初始化 当前页为 1
  181. self.getData(self.pageno);
  182. sp.dialog("保存成功!");
  183. self.finishUploadArray.forEach(function (item) {
  184. item.FILENAMES = item.FILESNAME;
  185. item.FILEEXT = item.PREFIX;
  186. item.FILESIZE = item.FILESIZE;
  187. item.FILEURL = item.FILEURL;
  188. item.FILEID = item.FILESID;
  189. })
  190. sp.transmit2("FILEMANAGER_SHENQING", "行政", "", self.finishUploadArray, "0", "KNOWLEDGEATTACHLIST")
  191. } else {
  192. self.addWarning("保存失败!");
  193. }
  194. })
  195. }
  196. }
  197. //去除警告
  198. self.removeWarning = function () {
  199. $(".warninfo").html("").hide();
  200. }
  201. //给上传弹出层添加警告
  202. self.addWarning = function (content) {
  203. $(".warninfo").html("<i class=\"fa fa-exclamation sp-mr-5\"></i>" + content).show();
  204. }
  205. //关闭wps刷新
  206. $scope.WpsClose = function () {
  207. self.getData(self.pageno);
  208. }
  209. //获取加载数据
  210. self.getData = function (pageno) {
  211. self.pageno = pageno;
  212. $scope.__default__currentPage = self.pageno; //设置页面样式在第几页
  213. var data = {
  214. pageSize: self.itemsPerPage,
  215. pageno: pageno,
  216. filesname: self.search.FILESNAME,
  217. typecode: self.search.TYPECODE
  218. }
  219. $http.post(apiurljs.login + "g2app/share/queryDataWithPage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfgJson)
  220. .success(function (obj) {
  221. var res = strToJson(s4.decryptData_CBC(obj.data));
  222. if (sp.isval(res.data)) {
  223. res.data.forEach(function (item) {
  224. item.UPTIMES = item.UPTIMES == null ? "" : sp.dateFtt("yyyy-MM-dd hh:mm", new Date(item.UPTIMES));
  225. item.FILEURL = apiurljs.login + "g2work" + item.FILEURL;
  226. item.FILESIZE = item.FILESIZE == "" || item.FILESIZE.indexOf("B") > -1 ? item.FILESIZE : self.formatFileSize(parseFloat(item.FILESIZE));
  227. })
  228. self.noDataTip = 1;
  229. self.rows = res.data;
  230. self.total_count = res.totalCount;
  231. } else {
  232. self.rows = [];
  233. self.total_count = 0;
  234. self.noDataTip = 0;
  235. }
  236. if (self.CrossPage.type == 0) {
  237. self.journalRecord(self.CrossPage.ctime, sp.getLocalDate1(), "", "接入日志", window.location.pathname)
  238. }
  239. console.log(self.rows);
  240. }).error(function (err) {
  241. sp.dialog(JSON.stringify(err));
  242. });
  243. }
  244. self.goUrl = function (obj) {
  245. if (obj.PREFIX == "wps" || obj.PREFIX == "doc" || obj.PREFIX == "docx" || obj.PREFIX == "") {
  246. sp.toggleWps(true)
  247. if (obj.FILESID == "") {
  248. newDoc(apiurljs.wpspath + "/g2app/abase/saveUploadFileNameshare?Authorization=Bearer " + self.get_AccessToken + "&file-argument=" + encodeURIComponent(s4.encryptData_CBC("tablename=SHAREFILES,id=" + obj.ID + ",routeinfoid=" + obj.ID + ",typename=" + obj.TYPENAME + ",typecode=" + obj.TYPECODE)), obj.FILESNAME)
  249. } else {
  250. onlineEditOfficialDocument(apiurljs.wpspath + "/g2work/wpsfiles/" + obj.FILEURL.slice(14), apiurljs.wpspath + "/g2app/abase/saveUploadFileNameshare?Authorization=Bearer " + self.get_AccessToken + "&file-argument=" + encodeURIComponent(s4.encryptData_CBC("tablename=SHAREFILES,id=" + obj.ID + ",routeinfoid=" + obj.ID + ",typename=" + obj.TYPENAME + ",typecode=" + obj.TYPECODE)), "")
  251. }
  252. } else if (obj.PREFIX == "ofd" || obj.PREFIX == "pdf") {
  253. window.open("../../iframeDemo.html?data=" + encodeURIComponent(s4.encryptData_CBC("type=0&file=" + obj.FILEURL.slice(14) + "&tablename=SHAREFILES&routeinfoid=" + obj.ID)))
  254. } else if (obj.FILEEXT == null || obj.FILEEXT == undefined) {
  255. return;
  256. } else {
  257. window.open(apiurljs.wpspath + "/g2work/files2/inline/" + obj.FILEURL.slice(14))
  258. }
  259. }
  260. //下载
  261. self.downLoad = function (href) {
  262. window.location.href = href;
  263. var time1 = sp.getLocalDate1();
  264. self.journalRecord(time1, sp.getLocalDate1(), "下载", "接入日志", window.location.pathname)
  265. }
  266. //删除
  267. self.btnDelete = function (item) {
  268. var time1 = sp.getLocalDate1();
  269. self.journalRecord(time1, sp.getLocalDate1(), "上传", "修改日志", window.location.pathname)
  270. var getDelID = item.ID;
  271. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  272. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  273. var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='dialog_btnConfirm' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  274. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  275. sp.openCenter(".sp-dialog");
  276. ///取消按钮
  277. $('.sp-closeDialog').click(function (event) {
  278. sp.dialoghide();
  279. event.preventDefault();
  280. event.stopPropagation();
  281. });
  282. //post消息的id
  283. $("#dialog_btnConfirm").click(function () {
  284. var getid = $(this).attr("data-id");
  285. var data = {
  286. ID: getid
  287. }
  288. $http.post(apiurljs.login + "g2app/share/del", data, postCfgJson)
  289. .success(function (obj) {
  290. var res = strToJson(s4.decryptData_CBC(obj.data));
  291. sp.dialoghide();
  292. if (res.success) {
  293. self.getData(self.pageno);
  294. sp.deltransmit(item.FILESID)
  295. } else {
  296. sp.dialog("删除失败,请联系管理员!");
  297. }
  298. })
  299. });
  300. }
  301. //弹出筛选框
  302. self.openSearchLayer = function () {
  303. self.search.TYPECODE = self.uploadTypeList[0].code;
  304. sp.layer("#layer_search");
  305. var time1 = sp.getLocalDate1();
  306. self.journalRecord(time1, sp.getLocalDate1(), "查询", "查询日志", "/g2app/share/queryDataWithPage")
  307. }
  308. self.doSearch = function () {
  309. sp.closeCenter('.sp-layer');
  310. self.pageno = 1; // 初始化 当前页为 1
  311. self.getData(self.pageno);
  312. }
  313. self.closeSeach = function () {
  314. self.search = {
  315. FILESNAME: "",
  316. TYPECODE: sp.getUrlName("CODE") || ""
  317. };
  318. sp.layerhide();
  319. self.getData(1);
  320. };
  321. //刷新
  322. self.btnRefresh = function () {
  323. self.getData(self.pageno);
  324. };
  325. self.openAddFile = function () {
  326. self.add = {
  327. FILESNAME: "",
  328. TYPECODE: "C04",
  329. TYPENAME: ""
  330. }
  331. self.uploadTypeList.forEach(function (item) {
  332. if (item.CODE == "C04") {
  333. self.add.TYPENAME = item.CNAME;
  334. }
  335. })
  336. sp.layer("#layer_addwps")
  337. }
  338. self.addWpsType = function () {
  339. self.uploadTypeList.forEach(function (item) {
  340. if (self.add.TYPECODE == item.CODE) {
  341. self.add.TYPENAME = item.CNAME;
  342. }
  343. })
  344. }
  345. self.btnAddWps = function () {
  346. var data = [{
  347. ID: "0",
  348. ROUTEINFOID: "0",
  349. SORTID: "0",
  350. SUBMAN: self.userChineseName,
  351. SUNMANUSERID: self.userId,
  352. PREFIX: "",
  353. FILESNAME: self.add.FILESNAME + ".wps",
  354. FILESIZE: "",
  355. FILEURL: "",
  356. FILESID: "",
  357. UPTIMES: "",
  358. TYPECODE: self.add.TYPECODE,
  359. TYPENAME: self.add.TYPENAME
  360. }]
  361. $http.post(apiurljs.login + "g2app/share/shareInsert", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfgJson)
  362. .success(function (obj) {
  363. var res = strToJson(s4.decryptData_CBC(obj.data));
  364. sp.layerhide()
  365. if (res.success == true) {
  366. self.getData(1)
  367. } else {
  368. sp.dialeg(res.message)
  369. }
  370. })
  371. }
  372. $("#fileupload").attr("data-url", apiurljs.login + "g2work/files/upLoad");
  373. self.setFileUpload();
  374. self.getResourceType();
  375. self.getData(self.pageno);
  376. //记录日志
  377. self.journalRecord = function (time1, time2, title, func, url) {
  378. if (!self.CrossPage.cname) { return; }
  379. var data = {
  380. tablename: "SYS_CLICKLOG",
  381. data: {
  382. CTIME: time1 == null ? sp.getLocalDate1() : time1,
  383. TITLE: (title != "" ? self.CrossPage.cname + "/" + title : self.CrossPage.cname),
  384. REQUESTURL: url,
  385. REQUESTHEADERURL: window.location.origin,
  386. LOGTYPE: func,
  387. USERTYPE: $.cookie("GlWorkPlatform-userType"),
  388. ADMIN: $.cookie("GlWorkPlatform-userTypeEng"),
  389. CLIENTIP: sp.myIP(),
  390. PCNAME: sp.detectOS(),
  391. BROWSERNAME: sp.browser(),
  392. RESPONSETIME: time2 == null ? sp.getLocalDate1() : time2,
  393. USERID: self.userId,
  394. USERNAME: self.userChineseName
  395. }
  396. }
  397. $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfgJson)
  398. .success(function (res) {
  399. self.CrossPage.type = 1;
  400. })
  401. }
  402. }]);