list.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("listCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
  6. var self = this;
  7. var s4 = new SM4Util();
  8. self.userId = $.cookie("GlWorkPlatform-userid");
  9. self.userName = $.cookie("GlWorkPlatform-chineseName");
  10. self.userType = $.cookie("GlWorkPlatform-userType");
  11. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  12. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. }
  19. self.search = {
  20. TITLE: "",
  21. LOGTYPE: ""
  22. }
  23. self.CrossPage = window.parent.CrossPage;
  24. self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
  25. self.list = [];
  26. self.pageno = 1;
  27. self.total_count = 0;
  28. self.itemsPerPage = 10;
  29. self.pageOptions = [10, 20, 30, 40];
  30. //安全管理员看系统管理员的日志,系统管理员看普通用户的日志,审计看安全管理员和系统管理员的日志
  31. self.getData = function (pageno) {
  32. self.pageno = pageno;
  33. $scope.__default__currentPage = self.pageno; //设置页面样式在第几页
  34. self.list = [];
  35. var data = {
  36. tablename: "SYS_CLICKLOG",
  37. sqlwhere: {},
  38. sqlorwhere: {},
  39. sqlinwhere: {},
  40. sqllikewhere: {
  41. TITLE: self.search.TITLE
  42. },
  43. colums: "ID,TITLE,REQUESTURL,LOGTYPE,USERTYPE,CLIENTIP,PCNAME,BROWSERNAME,TO_CHAR(CTIME,'YYYY-mm-dd hh24:mi:ss.ff3') AS CTIME1,TO_CHAR(RESPONSETIME,'YYYY-mm-dd hh24:mi:ss.ff3') AS RESPONSETIME1",
  44. order: "ID",
  45. pagesize: self.itemsPerPage,
  46. pageno: self.pageno
  47. }
  48. if (self.search.LOGTYPE != "") {
  49. data.sqlwhere.LOGTYPE = self.search.LOGTYPE
  50. }
  51. if (self.userType == "安全管理员") {
  52. data.sqlwhere.USERTYPE = "系统管理员"
  53. }
  54. if (self.userType == "系统管理员") {
  55. data.sqlwhere.USERTYPE = "普通用户"
  56. }
  57. if (self.userType == "审计管理员") {
  58. data.sqlinwhere.USERTYPE = "'安全管理员','系统管理员'"
  59. }
  60. $http.post(apiurljs.login + "g2app/DangJian/queryDataByColWithPage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  61. .success(function (obj) {
  62. var res = strToJson(s4.decryptData_CBC(obj.data));
  63. if (res.data == null || res.data == undefined || res.data == "") {
  64. self.noDataTip = 0;
  65. } else {
  66. self.noDataTip = 1;
  67. self.list = res.data;
  68. self.total_count = res.totalCount;
  69. self.list.forEach(function (item) {
  70. item.CTIME2 = item.CTIME1.split(".")[0];
  71. item.RESPONSETIME2 = minS(new Date(item.RESPONSETIME1).getTime() - new Date(item.CTIME1).getTime());
  72. if (item.REQUESTURL == "") {
  73. item.REQUESTURL = "/g2workweb/index.html/#menu-list"
  74. }
  75. })
  76. }
  77. if (self.CrossPage.type == 0) {
  78. self.journalRecord(self.CrossPage.ctime, sp.getLocalDate1(), "", "接入日志", window.location.pathname)
  79. }
  80. })
  81. }
  82. self.load = function () {
  83. if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
  84. self.getData(self.pageno);
  85. } else {
  86. self.getData(self.get_lastReturnPageno);
  87. }
  88. }
  89. self.load();
  90. self.refresh = function () {
  91. self.CrossPage.type = null;
  92. self.getData(self.pageno);
  93. }
  94. self.openSearchLayer = function () {
  95. var time1 = sp.getLocalDate1();
  96. self.journalRecord(time1, sp.getLocalDate1(), "查询", "查询日志", "/g2app/DangJian/queryDataByColWithPage")
  97. self.CrossPage.type = 1;
  98. sp.layer("#layer_search");
  99. }
  100. self.doSearch = function () {
  101. sp.closeCenter('.sp-layer');
  102. self.getData(1);
  103. }
  104. self.closeSeach = function () {
  105. self.search = {
  106. TITLE: "",
  107. LOGTYPE: ""
  108. }
  109. sp.layerhide();
  110. self.getData(1);
  111. };
  112. //记录日志
  113. self.journalRecord = function (time1, time2, title, func, url) {
  114. if (!self.CrossPage.cname) { return; }
  115. var data = {
  116. tablename: "SYS_CLICKLOG",
  117. data: {
  118. CTIME: time1 == null ? sp.getLocalDate1() : time1,
  119. TITLE: (title != "" ? self.CrossPage.cname + "/" + title : self.CrossPage.cname),
  120. REQUESTURL: url,
  121. REQUESTHEADERURL: window.location.origin,
  122. LOGTYPE: func,
  123. USERTYPE: $.cookie("GlWorkPlatform-userType"),
  124. ADMIN: $.cookie("GlWorkPlatform-userTypeEng"),
  125. CLIENTIP: sp.myIP(),
  126. PCNAME: sp.detectOS(),
  127. BROWSERNAME: sp.browser(),
  128. RESPONSETIME: time2 == null ? sp.getLocalDate1() : time2,
  129. USERID: self.userId,
  130. USERNAME: self.userName
  131. }
  132. }
  133. $http.post(apiurljs.login + "g2app/DangJian/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  134. .success(function (res) {
  135. self.CrossPage.type = 1;
  136. })
  137. }
  138. }])
  139. function minS(str) {
  140. var time = "";
  141. if (str < 1000) {
  142. time = str + "毫秒";
  143. }
  144. if (str >= 1000 && str < 60000) {
  145. time = str / 1000 + "秒";
  146. }
  147. if (str >= 60000 && str < 3600000) {
  148. time = Math.floor(str / 60000) + "分" + (str - 60000 * Math.floor(str / 60000)) / 1000 + "秒";
  149. }
  150. if (str >= 3600000) {
  151. time = Math.floor(str / 3600000) + "小时" + Math.floor((str - 3600000 * Math.floor(str / 3600000)) / 60000) + "分" + (str - 60000 * Math.floor(str / 60000)) / 1000 + "秒";
  152. }
  153. return time;
  154. }