GLJ.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 'use strict';
  2. var app = angular.module('app', []);
  3. app.controller("GLJCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
  4. var self = this;
  5. var s4 = new SM4Util();
  6. self.userId = $.cookie("GlWorkPlatform-userid");
  7. self.userName = $.cookie("GlWorkPlatform-chineseName");
  8. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  9. self.routeid = sp.getUrlName("routeid");
  10. self.routeinfoid = sp.getUrlName("routeinfoid");
  11. self.copyrightid = sp.getUrlName("copyrightid");
  12. self.directionid = sp.getUrlName("directionid");
  13. self.formeditid = sp.getUrlName("formeditid");
  14. var postCfg = {
  15. headers: {
  16. 'Content-Type': 'application/json',
  17. 'Authorization': "Bearer " + self.get_AccessToken
  18. }
  19. };
  20. var uploadformat = strToJson(s4.decryptData_CBC(apiurljs.uploadformat)).data.map(function (item) {
  21. return item.CNAME
  22. })
  23. self.getGLJ1 = function () {
  24. var data = {
  25. userid: ""
  26. }
  27. $http.post(apiurljs.login + "g2work/routeinfo/queryDataRelatedDocfileType", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  28. .success(function (obj) {
  29. var res = strToJson(s4.decryptData_CBC(obj.data));
  30. self.gljList = res.data;
  31. })
  32. }
  33. self.getGLJ1()
  34. self.newMoBan1 = function (GWZL) {
  35. var data = {
  36. dockind: "D01",
  37. routeinfoid: self.routeinfoid,
  38. gwtype: GWZL,
  39. filekind: "DOCFILE"
  40. }
  41. $http.post(apiurljs.login + "g2app/fawenfilesrelate/newDataFile", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  42. .success(function (obj) {
  43. var res = strToJson(s4.decryptData_CBC(obj.data));
  44. if (res.success) {
  45. window.parent.refreshGLJ(1)
  46. window.parent.sp.layerhide()
  47. } else {
  48. window.top.sp.dialog("创建失败,请联系管理员!")
  49. }
  50. })
  51. }
  52. self.newMoBan2 = function (GWZL) {
  53. var data = {
  54. dockind: "D01",
  55. routeinfoid: self.routeinfoid,
  56. gwtype: GWZL,
  57. filekind: "REDFILE"
  58. }
  59. $http.post(apiurljs.login + "g2app/fawenfilesrelate/newDataFile", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  60. .success(function (obj) {
  61. var res = strToJson(s4.decryptData_CBC(obj.data));
  62. if (res.success) {
  63. window.parent.refreshGLJ(1)
  64. window.parent.sp.layerhide()
  65. } else {
  66. window.top.sp.dialog("创建失败,请联系管理员!");
  67. }
  68. })
  69. }
  70. self.newMoBan3 = function (GWZL) {
  71. $('#fileupload-zw').fileupload({
  72. url: apiurljs.login + 'g2app/fawenfilesrelate/uploadFileWithForm',
  73. dataType: 'json',
  74. beforeSend: function (xhr, data) {
  75. xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken);
  76. xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=FAWEN_FILES_RELATE,routeinfoid=" + self.routeinfoid + ",gwtype=" + GWZL + ",dockind=D01"));
  77. },
  78. add: function (e, data) {
  79. var num = 0;
  80. var acceptFileTypes = eval('/(' + uploadformat.join("|") + ')$/i')
  81. //文件类型判断
  82. $.each(data.originalFiles, function (index, item) {
  83. if (item['type'].length > 0 && !acceptFileTypes.test(item['name'])) {
  84. sp.dialog("您好,请上传" + uploadformat.join("/") + "格式的文件!");
  85. return;
  86. } else {
  87. num++
  88. }
  89. })
  90. if (num == data.originalFiles.length) {
  91. data.submit();
  92. $scope.$apply();
  93. }
  94. },
  95. // 上传完成后的执行逻辑
  96. done: function (e, data) {
  97. window.parent.refreshGLJ(1)
  98. window.parent.sp.layerhide()
  99. }
  100. })
  101. $timeout(function () {
  102. $("#fileupload-zw").trigger("click")
  103. }, 1)
  104. }
  105. }])