attachlist.js 15 KB

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