attachlist.js 16 KB

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