attachlist.js 14 KB

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