attachlist.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. console.log(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(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. self.getFileWo = function (fileid, filename, filepath) {
  119. var n = 0;
  120. self.iframeList.forEach(function (item) {
  121. if (item.title == filename && item.source == filepath) {
  122. n++
  123. }
  124. })
  125. if (n == 0) {
  126. var data = {
  127. method: 1,
  128. params: {
  129. userId: self.userName,
  130. fileId: fileid,
  131. fileName: filename,
  132. filePath: filepath,
  133. userRight: 0,// 用户权限 编辑:UserRightEdit = 0; 只读:UserRightReadonly = 1; 临时只读:UserRightTempReadonly = 2;此时页面上编辑—临时只读按钮,打开只能临时只读,不打开可以进行编辑
  134. //saveFlag: true, /// true:自动保存文档 false:不自动保存文档 (默认为true)
  135. callbackUrl: apiurljs.login + "g2app/fawenfiles/uploadFile"
  136. }
  137. };
  138. $.ajax({
  139. url: apiurljs.yzFileWo + "api.do",
  140. data: {
  141. jsonParams: encodeURIComponent(JSON.stringify(data))
  142. },
  143. type: "POST",
  144. dataType: "json",
  145. general: false,
  146. async: false,
  147. success: function (data) {
  148. if (data) {
  149. if (data.errorCode === "0") {
  150. let rst = data.result;
  151. if (rst && rst.urls) {
  152. var get_urls = rst.urls;
  153. if (typeof (get_urls) === "string") {
  154. if(self.iframeList.length>0&&self.iframeList[0].type=='zw'){
  155. self.closeItem(0)
  156. $scope.$apply();
  157. self.iframeList.unshift({type:'zw', id: self.iframeList.length + 1, title: filename, url: $sce.trustAsResourceUrl(get_urls), source: filepath, wo: true })
  158. }else if(self.iframeList.length>0&&self.iframeList[0].type!='zw'){
  159. self.iframeList.unshift({type:'zw', id: self.iframeList.length + 1, title: filename, url: $sce.trustAsResourceUrl(get_urls), source: filepath, wo: true })
  160. }else{
  161. self.iframeList.push({type:'zw', id: self.iframeList.length + 1, title: filename, url: $sce.trustAsResourceUrl(get_urls), source: filepath, wo: true })
  162. }
  163. self.addZW()
  164. $scope.$apply();
  165. } else {
  166. console.warn("无效的urls:" + get_urls);
  167. }
  168. } else {
  169. console.warn("ajax响应内容data.result有问题:" + rst);
  170. }
  171. } else {
  172. alert(data.errorMessage);
  173. }
  174. } else {
  175. console.warn("ajax响应内容为空!");
  176. }
  177. },
  178. });
  179. }
  180. }
  181. $scope.addGJL = function (name, url) {
  182. self.addGJL(name, url);
  183. }
  184. self.addGJL = function (name, url) {
  185. var n = 0;
  186. self.iframeList.forEach(function (item) {
  187. if (item.title == name && item.source == url) {
  188. n++
  189. }
  190. })
  191. if (n == 0) {
  192. self.iframeList.push({ id: self.iframeList.length + 1, title: name, url: $sce.trustAsResourceUrl(url), source: url })
  193. self.add()
  194. $scope.$apply();
  195. }
  196. }
  197. self.iframeList = []//[{ id: 1, url: "../../index/img-new/background3.png", source: "../../index/img-new/background3.png", boxWidth: { width: 1200 }, iframeWidth: { width: 1190 } }]
  198. self.add = function () {
  199. if (self.iframeList.length == 1) {
  200. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  201. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  202. } else {
  203. self.iframeList.forEach(function (item) {
  204. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  205. item.iframeWidth = { width: item.boxWidth.width - 10 }
  206. })
  207. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  208. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  209. }
  210. }
  211. self.addZW = function () {
  212. if (self.iframeList.length == 1) {
  213. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  214. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  215. } else {
  216. self.iframeList.forEach(function (item,index) {
  217. if(index == 0){
  218. self.iframeList[0].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  219. self.iframeList[0].iframeWidth = { width: self.iframeList[0].boxWidth.width - 10 }
  220. }else{
  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. })
  225. }
  226. }
  227. self.openItem = function (obj) {
  228. window.open(obj.url, obj.title, 'width=' + width + ',height=' + height + ',toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
  229. }
  230. self.closeItem = function (n) {
  231. self.iframeList.splice(n, 1)
  232. if (self.iframeList.length == 0) {
  233. } else if (self.iframeList.length == 1) {
  234. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  235. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  236. } else {
  237. self.iframeList.forEach(function (item) {
  238. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  239. item.iframeWidth = { width: item.boxWidth.width - 10 }
  240. })
  241. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  242. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  243. }
  244. }
  245. self.reSize = function (n) {
  246. console.log('n',n)
  247. var leftbox = document.getElementsByClassName("iframe-item")[n - 1];
  248. var rightbox = document.getElementsByClassName("iframe-item")[n];
  249. var line = document.getElementsByClassName("iframe-border-right")[n - 1];
  250. document.getElementsByClassName("iframe-border-right")[n - 1].addEventListener("mousedown", function (event) {
  251. $(".mousemove").show()
  252. var leftboxW = leftbox.style.width.slice(0, leftbox.style.width.length - 2);
  253. var rightboxW = rightbox.style.width.slice(0, rightbox.style.width.length - 2);
  254. var x = event.pageX - line.offsetLeft;
  255. document.addEventListener("mousemove", boxMove)
  256. function boxMove(event) {
  257. if (leftboxW * 1 + (event.pageX - x) * 1 <= 200) {
  258. //document.removeEventListener("mousemove", boxMove)
  259. } else if (rightboxW * 1 - (event.pageX - x) * 1 <= 200) {
  260. //document.removeEventListener("mousemove", boxMove)
  261. } else {
  262. leftbox.style.width = leftboxW * 1 + (event.pageX - x) * 1 + "px";
  263. //leftbox.getElementsByClassName("iframe-title")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  264. leftbox.getElementsByTagName("iframe")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  265. self.iframeList[n - 1].boxWidth.width = leftboxW * 1 + (event.pageX - x) * 1;
  266. self.iframeList[n - 1].iframeWidth.width = leftboxW * 1 + (event.pageX - x) * 1 - 10;
  267. rightbox.style.width = rightboxW * 1 - (event.pageX - x) * 1 + "px";
  268. //rightbox.getElementsByClassName("iframe-title")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  269. rightbox.getElementsByTagName("iframe")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  270. self.iframeList[n].boxWidth.width = rightboxW * 1 - (event.pageX - x) * 1;
  271. self.iframeList[n].iframeWidth.width = rightboxW * 1 - (event.pageX - x) * 1 - 10;
  272. }
  273. }
  274. document.addEventListener("mouseup", function () {
  275. $(".mousemove").hide()
  276. document.removeEventListener("mousemove", boxMove)
  277. })
  278. })
  279. }
  280. $(function () {
  281. $(window).resize(function () {
  282. if (self.iframeList.length > 0) {
  283. $("#iframeList").css("height", $(window).height())
  284. $(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height())
  285. if (self.iframeList.length == 1) {
  286. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  287. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  288. } else {
  289. self.iframeList.forEach(function (item) {
  290. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  291. item.iframeWidth = { width: item.boxWidth.width - 10 }
  292. })
  293. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  294. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  295. }
  296. $scope.$apply();
  297. }
  298. })
  299. })
  300. }])
  301. app.directive("repeatFinish", function () {
  302. return {
  303. link: function (scope) {
  304. if (scope.$last == true) {
  305. $("#iframeList").css("height", $(window).height())
  306. $(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height())
  307. }
  308. }
  309. };
  310. });
  311. function openFile(obj) {
  312. angular.element(document.getElementById('app')).scope().browse(obj);
  313. }
  314. function openTool(url, name) {
  315. angular.element(document.getElementById('app')).scope().addGJL(name, url);
  316. }