attachlist.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. 'use strict';
  2. var app = angular.module('app', [
  3. ]);
  4. app.controller("formeditCtrl", ["$scope", "$http", "$sce", function ($scope, $http, $sce) {
  5. var self = this;
  6. var s4 = new SM4Util();
  7. self.userName = $.cookie("GlWorkPlatform-chineseName");
  8. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  9. self.routeinfoid = sp.getUrlName("routeinfoid");
  10. self.dotype = window.top.sp.getUrlName("dotype");
  11. var width = window.outerWidth;
  12. var height = window.outerHeight;
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. };
  19. self.getData = function () {
  20. var data = {
  21. tablename: "FILE_ATTACH",
  22. colums: "*",
  23. order: "ID asc",
  24. sqlwhere: { ROUTEINFOID: self.routeinfoid },
  25. sqlinwhere: "",
  26. sqllikewhere: ""
  27. }
  28. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  29. .success(function (obj) {
  30. var res = strToJson(s4.decryptData_CBC(obj.data));
  31. self.arrayFile = [];
  32. res.data.forEach(function (item) {
  33. self.arrayFile.push(item)
  34. })
  35. if (sp.getUrlName("page") != "formedit") {
  36. self.browse(self.arrayFile[0])
  37. } else {
  38. self.getGCG()
  39. }
  40. })
  41. }
  42. self.getGCG = function () {
  43. var data = {
  44. dockind: "D01",
  45. routeinfoid: self.routeinfoid
  46. }
  47. $http.post(apiurljs.login + "g2app/fawenfiles/queryDataList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  48. .success(function (obj) {
  49. var res = strToJson(s4.decryptData_CBC(obj.data));
  50. if (res.data[0].FILENAMES.split(".").length == 1) {
  51. res.data[0].FILENAMES = res.data[0].FILENAMES + "." + res.data[0].FILEEXT
  52. }
  53. if (res.data[0].FILEURL.indexOf("files") > -1) {
  54. var set_filepath = apiurljs.yzFcscloud + "g2work/files/" + res.data[0].FILEURL.slice(7);
  55. } else {
  56. var set_filepath = apiurljs.yzFcscloud.split("glwork/")[0] + "glworkweb/" + res.data[0].FILEURL;
  57. }
  58. self.getFileWo(res.data[0].ID, res.data[0].FILENAMES, set_filepath);
  59. })
  60. }
  61. self.getData()
  62. $scope.browse = function (obj) {
  63. if (obj.DOCKIND == "D01") {
  64. if (obj.FILEURL.indexOf("files") > -1) {
  65. var set_filepath = apiurljs.yzFcscloud + "g2work/files/" + obj.FILEURL.slice(7);
  66. } else {
  67. var set_filepath = apiurljs.yzFcscloud.split("glwork/")[0] + "glworkweb/" + obj.FILEURL;
  68. }
  69. self.getFileWo(obj.ID, obj.FILENAMES, set_filepath);
  70. } else {
  71. self.browse(obj);
  72. }
  73. }
  74. self.browse = function (obj) {
  75. var n = 0;
  76. self.iframeList.forEach(function (item) {
  77. if (item.title == obj.FILENAMES && item.source == apiurljs.login + "g2work/files2/inline/" + obj.FILEURL.slice(7)) {
  78. n++
  79. }
  80. })
  81. if (n == 0) {;
  82. ///20230324---zyg ---永中转换-----start
  83. var set_convertType = 0;
  84. if (obj.FILEEXT == "doc") {
  85. set_convertType = 0;
  86. } else if (obj.FILEEXT == "pdf") {
  87. set_convertType = 20;
  88. } else if (obj.FILEEXT == "ofd") {
  89. set_convertType = 570;
  90. } else if (/(png|jpg|jpeg|gif|bmp|jfif|svg|tif|tiff)$/i.test(obj.FILEEXT) == true) {
  91. set_convertType = 23;
  92. } else {
  93. set_convertType = 0;
  94. }
  95. let postData = {
  96. convertType: set_convertType,
  97. fileUrl: apiurljs.yzFcscloud + "g2work/files2/inline/" + obj.FILEURL.slice(7)
  98. };
  99. var postCfg_transfer = {
  100. headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  101. transformRequest: function (data) {
  102. return $.param(data);
  103. }
  104. };
  105. $http.post(apiurljs.login.split("glwork/")[0] + "fcscloud/composite/httpfile", postData, postCfg_transfer)
  106. .success(function (res) {
  107. if (res.errorcode === 0) {
  108. let rst = res.data;
  109. self.iframeList.push({ id: self.iframeList.length + 1, title: obj.FILENAMES, url: $sce.trustAsResourceUrl(sp.ipChange(rst.viewUrl)), source: apiurljs.login + "g2work/files2/inline/" + obj.FILEURL.slice(7) })
  110. self.add()
  111. } else {
  112. sp.dialog(res.message);
  113. }
  114. });
  115. ///20230324---zyg ---永中转换-----end
  116. }
  117. }
  118. $scope.editFile = function (obj) {
  119. //if (obj.FILEURL.indexOf("files") > -1) {
  120. // var set_filepath = apiurljs.yzFcscloud + "g2work/files/" + obj.FILEURL.slice(7);
  121. //} else {
  122. // var set_filepath = apiurljs.yzFcscloud.split("glwork/")[0] + "glworkweb/" + obj.FILEURL;
  123. //}
  124. console.log(obj)
  125. var set_filename = obj.FILEURL.split("/")[obj.FILEURL.split("/").length - 1];
  126. var set_filepath = apiurljs.yzFcscloud + "g2work" + obj.FILEURL;
  127. //self.getFileWo(obj.ID, obj.FILENAMES, set_filepath);
  128. self.getFileWo(obj.FILEID, set_filename, set_filepath);
  129. }
  130. self.getFileWo = function (fileid, filename, filepath) {
  131. var n = 0;
  132. self.iframeList.forEach(function (item) {
  133. if (item.title == filename && item.source == filepath) {
  134. n++
  135. }
  136. })
  137. if (n == 0) {
  138. if (filepath.indexOf("files") > -1) {
  139. fileid = filepath.split("/")[6];
  140. }
  141. var data = {
  142. method: 1,
  143. params: {
  144. userId: self.userName,
  145. fileId: fileid,
  146. fileName: filename,
  147. filePath: filepath,
  148. userRight: self.dotype == 1 ? 0 : 1,// 用户权限 编辑:UserRightEdit = 0; 只读:UserRightReadonly = 1; 临时只读:UserRightTempReadonly = 2;此时页面上编辑—临时只读按钮,打开只能临时只读,不打开可以进行编辑
  149. //saveFlag: true, /// true:自动保存文档 false:不自动保存文档 (默认为true)
  150. callbackUrl: filepath.indexOf("files") > -1 ? apiurljs.login + "g2app/attachfiles/uploadFileAttach" : apiurljs.login + "g2app/fawenfiles/uploadFile"
  151. }
  152. };
  153. $.ajax({
  154. url: apiurljs.yzFileWo + "api.do",
  155. data: {
  156. jsonParams: encodeURIComponent(JSON.stringify(data))
  157. },
  158. type: "POST",
  159. dataType: "json",
  160. general: false,
  161. async: false,
  162. success: function (data) {
  163. if (data) {
  164. if (data.errorCode === "0") {
  165. let rst = data.result;
  166. if (rst && rst.urls) {
  167. var get_urls = rst.urls;
  168. if (typeof (get_urls) === "string") {
  169. self.iframeList.push({ id: self.iframeList.length + 1, title: filename, url: $sce.trustAsResourceUrl(sp.ipChange(get_urls)), source: filepath, wo: true })
  170. self.add()
  171. $scope.$apply();
  172. } else {
  173. console.warn("无效的urls:" + get_urls);
  174. }
  175. } else {
  176. console.warn("ajax响应内容data.result有问题:" + rst);
  177. }
  178. } else {
  179. alert(data.errorMessage);
  180. }
  181. } else {
  182. console.warn("ajax响应内容为空!");
  183. }
  184. },
  185. });
  186. }
  187. }
  188. $scope.addGJL = function (name, url) {
  189. self.addGJL(name, url);
  190. }
  191. self.addGJL = function (name, url) {
  192. var n = 0;
  193. self.iframeList.forEach(function (item) {
  194. if (item.title == name && item.source == url) {
  195. n++
  196. }
  197. })
  198. if (n == 0) {
  199. self.iframeList.push({ id: self.iframeList.length + 1, title: name, url: $sce.trustAsResourceUrl(url), source: url })
  200. self.add()
  201. $scope.$apply();
  202. }
  203. }
  204. self.iframeList = []//[{ id: 1, url: "../../index/img-new/background3.png", source: "../../index/img-new/background3.png", boxWidth: { width: 1200 }, iframeWidth: { width: 1190 } }]
  205. self.add = function () {
  206. if (self.iframeList.length == 1) {
  207. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  208. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  209. } else {
  210. self.iframeList.forEach(function (item) {
  211. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  212. item.iframeWidth = { width: item.boxWidth.width - 10 }
  213. })
  214. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  215. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  216. }
  217. }
  218. self.openItem = function (obj) {
  219. window.open(obj.url, obj.title, 'width=' + width + ',height=' + height + ',toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
  220. }
  221. self.closeItem = function (n) {
  222. self.iframeList.splice(n, 1)
  223. if (self.iframeList.length == 0) {
  224. } else if (self.iframeList.length == 1) {
  225. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  226. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  227. } else {
  228. self.iframeList.forEach(function (item) {
  229. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  230. item.iframeWidth = { width: item.boxWidth.width - 10 }
  231. })
  232. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  233. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  234. }
  235. }
  236. self.reSize = function (n) {
  237. var leftbox = document.getElementsByClassName("iframe-item")[n - 1];
  238. var rightbox = document.getElementsByClassName("iframe-item")[n];
  239. var line = document.getElementsByClassName("iframe-border-right")[n - 1];
  240. document.getElementsByClassName("iframe-border-right")[n - 1].addEventListener("mousedown", function (event) {
  241. $(".mousemove").show()
  242. var leftboxW = leftbox.style.width.slice(0, leftbox.style.width.length - 2);
  243. var rightboxW = rightbox.style.width.slice(0, rightbox.style.width.length - 2);
  244. var x = event.pageX - line.offsetLeft;
  245. document.addEventListener("mousemove", boxMove)
  246. function boxMove(event) {
  247. if (leftboxW * 1 + (event.pageX - x) * 1 <= 200) {
  248. //document.removeEventListener("mousemove", boxMove)
  249. } else if (rightboxW * 1 - (event.pageX - x) * 1 <= 200) {
  250. //document.removeEventListener("mousemove", boxMove)
  251. } else {
  252. leftbox.style.width = leftboxW * 1 + (event.pageX - x) * 1 + "px";
  253. //leftbox.getElementsByClassName("iframe-title")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  254. leftbox.getElementsByTagName("iframe")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  255. self.iframeList[n - 1].boxWidth.width = leftboxW * 1 + (event.pageX - x) * 1;
  256. self.iframeList[n - 1].iframeWidth.width = leftboxW * 1 + (event.pageX - x) * 1 - 10;
  257. rightbox.style.width = rightboxW * 1 - (event.pageX - x) * 1 + "px";
  258. //rightbox.getElementsByClassName("iframe-title")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  259. rightbox.getElementsByTagName("iframe")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  260. self.iframeList[n].boxWidth.width = rightboxW * 1 - (event.pageX - x) * 1;
  261. self.iframeList[n].iframeWidth.width = rightboxW * 1 - (event.pageX - x) * 1 - 10;
  262. }
  263. }
  264. document.addEventListener("mouseup", function () {
  265. $(".mousemove").hide()
  266. document.removeEventListener("mousemove", boxMove)
  267. })
  268. })
  269. }
  270. $(function () {
  271. $(window).resize(function () {
  272. if (self.iframeList.length > 0) {
  273. $("#iframeList").css("height", $(window).height())
  274. $(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height())
  275. if (self.iframeList.length == 1) {
  276. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  277. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  278. } else {
  279. self.iframeList.forEach(function (item) {
  280. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  281. item.iframeWidth = { width: item.boxWidth.width - 10 }
  282. })
  283. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  284. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  285. }
  286. $scope.$apply();
  287. }
  288. })
  289. })
  290. }])
  291. app.directive("repeatFinish", function () {
  292. return {
  293. link: function (scope) {
  294. if (scope.$last == true) {
  295. $("#iframeList").css("height", $(window).height())
  296. $(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height())
  297. }
  298. }
  299. };
  300. });
  301. function openFile(obj) {
  302. angular.element(document.getElementById('app')).scope().browse(obj);
  303. }
  304. function editFile(obj) {
  305. angular.element(document.getElementById('app')).scope().editFile(obj);
  306. }
  307. function openTool(url, name) {
  308. angular.element(document.getElementById('app')).scope().addGJL(name, url);
  309. }