attachlist.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. 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. self.iframeList.push({ id: self.iframeList.length + 1, title: filename, url: $sce.trustAsResourceUrl(sp.ipChange(get_urls)), source: filepath, wo: true })
  158. self.add()
  159. $scope.$apply();
  160. } else {
  161. console.warn("无效的urls:" + get_urls);
  162. }
  163. } else {
  164. console.warn("ajax响应内容data.result有问题:" + rst);
  165. }
  166. } else {
  167. alert(data.errorMessage);
  168. }
  169. } else {
  170. console.warn("ajax响应内容为空!");
  171. }
  172. },
  173. });
  174. }
  175. }
  176. $scope.addGJL = function (name, url) {
  177. self.addGJL(name, url);
  178. }
  179. self.addGJL = function (name, url) {
  180. var n = 0;
  181. self.iframeList.forEach(function (item) {
  182. if (item.title == name && item.source == url) {
  183. n++
  184. }
  185. })
  186. if (n == 0) {
  187. self.iframeList.push({ id: self.iframeList.length + 1, title: name, url: $sce.trustAsResourceUrl(url), source: url })
  188. self.add()
  189. $scope.$apply();
  190. }
  191. }
  192. self.iframeList = []//[{ id: 1, url: "../../index/img-new/background3.png", source: "../../index/img-new/background3.png", boxWidth: { width: 1200 }, iframeWidth: { width: 1190 } }]
  193. self.add = function () {
  194. if (self.iframeList.length == 1) {
  195. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  196. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  197. } else {
  198. self.iframeList.forEach(function (item) {
  199. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  200. item.iframeWidth = { width: item.boxWidth.width - 10 }
  201. })
  202. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  203. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  204. }
  205. }
  206. self.openItem = function (obj) {
  207. window.open(obj.url, obj.title, 'width=' + width + ',height=' + height + ',toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
  208. }
  209. self.closeItem = function (n) {
  210. self.iframeList.splice(n, 1)
  211. if (self.iframeList.length == 0) {
  212. } else 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) {
  217. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  218. item.iframeWidth = { width: item.boxWidth.width - 10 }
  219. })
  220. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  221. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  222. }
  223. }
  224. self.reSize = function (n) {
  225. var leftbox = document.getElementsByClassName("iframe-item")[n - 1];
  226. var rightbox = document.getElementsByClassName("iframe-item")[n];
  227. var line = document.getElementsByClassName("iframe-border-right")[n - 1];
  228. document.getElementsByClassName("iframe-border-right")[n - 1].addEventListener("mousedown", function (event) {
  229. $(".mousemove").show()
  230. var leftboxW = leftbox.style.width.slice(0, leftbox.style.width.length - 2);
  231. var rightboxW = rightbox.style.width.slice(0, rightbox.style.width.length - 2);
  232. var x = event.pageX - line.offsetLeft;
  233. document.addEventListener("mousemove", boxMove)
  234. function boxMove(event) {
  235. if (leftboxW * 1 + (event.pageX - x) * 1 <= 200) {
  236. //document.removeEventListener("mousemove", boxMove)
  237. } else if (rightboxW * 1 - (event.pageX - x) * 1 <= 200) {
  238. //document.removeEventListener("mousemove", boxMove)
  239. } else {
  240. leftbox.style.width = leftboxW * 1 + (event.pageX - x) * 1 + "px";
  241. //leftbox.getElementsByClassName("iframe-title")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  242. leftbox.getElementsByTagName("iframe")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  243. self.iframeList[n - 1].boxWidth.width = leftboxW * 1 + (event.pageX - x) * 1;
  244. self.iframeList[n - 1].iframeWidth.width = leftboxW * 1 + (event.pageX - x) * 1 - 10;
  245. rightbox.style.width = rightboxW * 1 - (event.pageX - x) * 1 + "px";
  246. //rightbox.getElementsByClassName("iframe-title")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  247. rightbox.getElementsByTagName("iframe")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  248. self.iframeList[n].boxWidth.width = rightboxW * 1 - (event.pageX - x) * 1;
  249. self.iframeList[n].iframeWidth.width = rightboxW * 1 - (event.pageX - x) * 1 - 10;
  250. }
  251. }
  252. document.addEventListener("mouseup", function () {
  253. $(".mousemove").hide()
  254. document.removeEventListener("mousemove", boxMove)
  255. })
  256. })
  257. }
  258. $(function () {
  259. $(window).resize(function () {
  260. if (self.iframeList.length > 0) {
  261. $("#iframeList").css("height", $(window).height())
  262. $(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height())
  263. if (self.iframeList.length == 1) {
  264. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  265. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  266. } else {
  267. self.iframeList.forEach(function (item) {
  268. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  269. item.iframeWidth = { width: item.boxWidth.width - 10 }
  270. })
  271. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  272. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  273. }
  274. $scope.$apply();
  275. }
  276. })
  277. })
  278. }])
  279. app.directive("repeatFinish", function () {
  280. return {
  281. link: function (scope) {
  282. if (scope.$last == true) {
  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. }
  286. }
  287. };
  288. });
  289. function openFile(obj) {
  290. angular.element(document.getElementById('app')).scope().browse(obj);
  291. }
  292. function openTool(url, name) {
  293. angular.element(document.getElementById('app')).scope().addGJL(name, url);
  294. }