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.userId = $.cookie("GlWorkPlatform-userid");
  8. self.userName = $.cookie("GlWorkPlatform-chineseName");
  9. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  10. self.routeinfoid = sp.getUrlName("routeinfoid");
  11. self.dotype = window.top.sp.getUrlName("dotype");
  12. var width = window.outerWidth;
  13. var height = window.outerHeight;
  14. var postCfg = {
  15. headers: {
  16. 'Content-Type': 'application/json',
  17. 'Authorization': "Bearer " + self.get_AccessToken
  18. }
  19. };
  20. self.getUSER = function () {
  21. var data = {
  22. tablename: "SX_ZDYGZ",
  23. colums: "*",
  24. order: "ID asc",
  25. sqlwhere: { ROUTEINFOID: self.routeinfoid },
  26. sqlinwhere: "",
  27. sqllikewhere: ""
  28. }
  29. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  30. .success(function (obj) {
  31. var res = strToJson(s4.decryptData_CBC(obj.data));
  32. self.USERID = res.data[0].USERID;
  33. self.getData()
  34. })
  35. }
  36. self.getData = function () {
  37. var data = {
  38. tablename: "FILE_ATTACH",
  39. colums: "*",
  40. order: "ID asc",
  41. sqlwhere: { ROUTEINFOID: self.routeinfoid },
  42. sqlinwhere: "",
  43. sqllikewhere: ""
  44. }
  45. $http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  46. .success(function (obj) {
  47. var res = strToJson(s4.decryptData_CBC(obj.data));
  48. self.arrayFile = [];
  49. res.data.forEach(function (item) {
  50. self.arrayFile.push(item)
  51. })
  52. if (sp.getUrlName("page") != "formedit") {
  53. self.browse(self.arrayFile[0])
  54. } else {
  55. self.getGCG()
  56. }
  57. })
  58. }
  59. self.getGCG = function () {
  60. var data = {
  61. dockind: "D01",
  62. routeinfoid: self.routeinfoid
  63. }
  64. $http.post(apiurljs.login + "g2app/fawenfiles/queryDataList", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  65. .success(function (obj) {
  66. var res = strToJson(s4.decryptData_CBC(obj.data));
  67. if (res.data[0].FILENAMES.split(".").length == 1) {
  68. res.data[0].FILENAMES = res.data[0].FILENAMES + "." + res.data[0].FILEEXT
  69. }
  70. if (res.data[0].FILEURL.indexOf("files") > -1) {
  71. //var set_filepath = apiurljs.login + "g2work/files/" + obj.FILEURL.slice(7);
  72. var set_filepath = apiurljs.yzFcscloud + "g2work/files/" + res.data[0].FILEURL.slice(7);
  73. } else {
  74. //var set_filepath = apiurljs.login.split("glwork/")[0] + "glworkweb/" + res.data[0].FILEURL;
  75. var set_filepath = apiurljs.yzFcscloud.split("glwork/")[0] + "glworkweb/" + res.data[0].FILEURL;
  76. }
  77. self.getFileWo(res.data[0].ID, res.data[0].FILENAMES, set_filepath);
  78. })
  79. }
  80. self.getUSER()
  81. $scope.browse = function (obj) {
  82. if (obj.DOCKIND == "D01") {
  83. if (obj.FILEURL.indexOf("files") > -1) {
  84. var set_filepath = apiurljs.yzFcscloud + "g2work" + obj.FILEURL;
  85. self.getFileWo(obj.FILEURL.split("/")[2], obj.FILEURL.split("/")[3], set_filepath);
  86. } else {
  87. var set_filepath = apiurljs.yzFcscloud.split("glwork/")[0] + "glworkweb/" + obj.FILEURL;
  88. self.getFileWo(obj.ID, obj.FILENAMES, set_filepath);
  89. }
  90. } else {
  91. self.browse(obj);
  92. }
  93. }
  94. self.browse = function (obj) {
  95. var n = 0;
  96. self.iframeList.forEach(function (item) {
  97. if (item.title == obj.FILENAMES && item.source == apiurljs.login + "g2work/files2/inline/" + obj.FILEURL.slice(7)) {
  98. n++
  99. }
  100. })
  101. if (n == 0) {;
  102. ///20230324---zyg ---永中转换-----start
  103. var set_convertType = 0;
  104. if (obj.FILEEXT == "doc") {
  105. set_convertType = 0;
  106. } else if (obj.FILEEXT == "pdf") {
  107. set_convertType = 20;
  108. } else if (obj.FILEEXT == "ofd") {
  109. set_convertType = 570;
  110. } else if (/(png|jpg|jpeg|gif|bmp|jfif|svg|tif|tiff)$/i.test(obj.FILEEXT) == true) {
  111. set_convertType = 23;
  112. } else {
  113. set_convertType = 0;
  114. }
  115. let postData = {
  116. convertType: set_convertType,
  117. fileUrl: apiurljs.yzFcscloud + "g2work/files2/inline/" + obj.FILEURL.slice(7)
  118. };
  119. var postCfg_transfer = {
  120. headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  121. transformRequest: function (data) {
  122. return $.param(data);
  123. }
  124. };
  125. $http.post(apiurljs.login.split("glwork/")[0] + "fcscloud/composite/httpfile", postData, postCfg_transfer)
  126. .success(function (res) {
  127. if (res.errorcode === 0) {
  128. let rst = res.data;
  129. 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) })
  130. self.add()
  131. } else {
  132. sp.dialog(res.message);
  133. }
  134. });
  135. ///20230324---zyg ---永中转换-----end
  136. }
  137. }
  138. self.getFileWo = function (fileid, filename, filepath) {
  139. var n = 0;
  140. self.iframeList.forEach(function (item) {
  141. if (item.title == filename && item.source == filepath) {
  142. n++
  143. }
  144. })
  145. if (n == 0) {
  146. if (filepath.indexOf("files") > -1) {
  147. fileid = filepath.split("/")[2];
  148. }
  149. var data = {
  150. method: 1,
  151. params: {
  152. userId: self.userName,//用户名称
  153. fileId: fileid,//文件id
  154. fileName: filename,//文件标题
  155. filePath: filepath,//apiurljs.yzFcscloud+"glworkweb/" + res.data[0].FILEURL
  156. userRight: self.USERID != self.userId ? 1 : 0,// 用户权限 编辑:UserRightEdit = 0; 只读:UserRightReadonly = 1; 临时只读:UserRightTempReadonly = 2;此时页面上编辑—临时只读按钮,打开只能临时只读,不打开可以进行编辑
  157. //saveFlag: true, /// true:自动保存文档 false:不自动保存文档 (默认为true)
  158. //callbackUrl: apiurljs.login + "g2app/fawenfiles/uploadFile?fileUrl=" + fileurl//回调函数——window.location.origin + "/glwork/"
  159. callbackUrl: filepath.indexOf("files") > -1 ? apiurljs.login + "g2app/attachfiles/uploadFileAttach" : apiurljs.login + "g2app/fawenfiles/uploadFile"
  160. }
  161. };
  162. $.ajax({
  163. url: apiurljs.yzFileWo + "api.do",
  164. data: {
  165. jsonParams: encodeURIComponent(JSON.stringify(data))
  166. },
  167. type: "POST",
  168. dataType: "json",
  169. general: false,
  170. async: false,
  171. success: function (data) {
  172. if (data) {
  173. if (data.errorCode === "0") {
  174. let rst = data.result;
  175. if (rst && rst.urls) {
  176. var get_urls = rst.urls;
  177. if (typeof (get_urls) === "string") {
  178. self.iframeList.push({ id: self.iframeList.length + 1, title: filename, url: $sce.trustAsResourceUrl(sp.ipChange(get_urls)), source: filepath, wo: true })
  179. self.add()
  180. $scope.$apply();
  181. } else {
  182. console.warn("无效的urls:" + get_urls);
  183. }
  184. } else {
  185. console.warn("ajax响应内容data.result有问题:" + rst);
  186. }
  187. } else {
  188. alert(data.errorMessage);
  189. }
  190. } else {
  191. console.warn("ajax响应内容为空!");
  192. }
  193. },
  194. });
  195. }
  196. }
  197. $scope.addGJL = function (name, url) {
  198. self.addGJL(name, url);
  199. }
  200. self.addGJL = function (name, url) {
  201. var n = 0;
  202. self.iframeList.forEach(function (item) {
  203. if (item.title == name && item.source == url) {
  204. n++
  205. }
  206. })
  207. if (n == 0) {
  208. self.iframeList.push({ id: self.iframeList.length + 1, title: name, url: $sce.trustAsResourceUrl(url), source: url })
  209. self.add()
  210. $scope.$apply();
  211. }
  212. }
  213. self.iframeList = []//[{ id: 1, url: "../../index/img-new/background3.png", source: "../../index/img-new/background3.png", boxWidth: { width: 1200 }, iframeWidth: { width: 1190 } }]
  214. self.add = 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) {
  220. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  221. item.iframeWidth = { width: item.boxWidth.width - 10 }
  222. })
  223. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  224. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  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. var leftbox = document.getElementsByClassName("iframe-item")[n - 1];
  247. var rightbox = document.getElementsByClassName("iframe-item")[n];
  248. var line = document.getElementsByClassName("iframe-border-right")[n - 1];
  249. document.getElementsByClassName("iframe-border-right")[n - 1].addEventListener("mousedown", function (event) {
  250. $(".mousemove").show()
  251. var leftboxW = leftbox.style.width.slice(0, leftbox.style.width.length - 2);
  252. var rightboxW = rightbox.style.width.slice(0, rightbox.style.width.length - 2);
  253. var x = event.pageX - line.offsetLeft;
  254. document.addEventListener("mousemove", boxMove)
  255. function boxMove(event) {
  256. if (leftboxW * 1 + (event.pageX - x) * 1 <= 200) {
  257. //document.removeEventListener("mousemove", boxMove)
  258. } else if (rightboxW * 1 - (event.pageX - x) * 1 <= 200) {
  259. //document.removeEventListener("mousemove", boxMove)
  260. } else {
  261. leftbox.style.width = leftboxW * 1 + (event.pageX - x) * 1 + "px";
  262. //leftbox.getElementsByClassName("iframe-title")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  263. leftbox.getElementsByTagName("iframe")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
  264. self.iframeList[n - 1].boxWidth.width = leftboxW * 1 + (event.pageX - x) * 1;
  265. self.iframeList[n - 1].iframeWidth.width = leftboxW * 1 + (event.pageX - x) * 1 - 10;
  266. rightbox.style.width = rightboxW * 1 - (event.pageX - x) * 1 + "px";
  267. //rightbox.getElementsByClassName("iframe-title")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  268. rightbox.getElementsByTagName("iframe")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
  269. self.iframeList[n].boxWidth.width = rightboxW * 1 - (event.pageX - x) * 1;
  270. self.iframeList[n].iframeWidth.width = rightboxW * 1 - (event.pageX - x) * 1 - 10;
  271. }
  272. }
  273. document.addEventListener("mouseup", function () {
  274. $(".mousemove").hide()
  275. document.removeEventListener("mousemove", boxMove)
  276. })
  277. })
  278. }
  279. $(function () {
  280. $(window).resize(function () {
  281. if (self.iframeList.length > 0) {
  282. $("#iframeList").css("height", $(window).height())
  283. $(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height())
  284. if (self.iframeList.length == 1) {
  285. self.iframeList[0].boxWidth = { width: $(".col-md-12").width() }
  286. self.iframeList[0].iframeWidth = { width: $(".col-md-12").width() - 10 }
  287. } else {
  288. self.iframeList.forEach(function (item) {
  289. item.boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
  290. item.iframeWidth = { width: item.boxWidth.width - 10 }
  291. })
  292. self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-12").width() / 4 * 2) - 10 }
  293. self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
  294. }
  295. $scope.$apply();
  296. }
  297. })
  298. })
  299. }])
  300. app.directive("repeatFinish", function () {
  301. return {
  302. link: function (scope) {
  303. if (scope.$last == true) {
  304. $("#iframeList").css("height", $(window).height())
  305. $(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height())
  306. }
  307. }
  308. };
  309. });
  310. function openFile(obj) {
  311. angular.element(document.getElementById('app')).scope().browse(obj);
  312. }
  313. function openTool(url, name) {
  314. angular.element(document.getElementById('app')).scope().addGJL(name, url);
  315. }