attachlist.js 14 KB

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