attachlist.js 14 KB

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