devAlarm.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. app.controller('devAlarmCtrl', ['$scope', '$http', '$timeout', 'toaster', function ($scope, $http, $timeout, toaster) {
  2. //查询条件
  3. var condition = $scope.condition = {
  4. };
  5. $scope.gridOptions = {
  6. data: 'myData',
  7. showGridFooter: true,
  8. paginationPageSizes: [10, 20, 50, 100],
  9. paginationCurrentPage: 1,
  10. paginationPageSize: 10,
  11. totalItems: 0,
  12. columnDefs: [],
  13. onRegisterApi: function (gridApi) {
  14. $scope.gridApi = gridApi;
  15. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  16. if ($scope.setPagingData) {
  17. $scope.getPagedDataAsync(newPage, pageSize);
  18. }
  19. });
  20. }
  21. };
  22. function setColumnDefs() {
  23. $scope.gridOptions.columnDefs = [
  24. {
  25. field: 'logicalCode',
  26. displayName: '设备',
  27. width: 100,
  28. },
  29. {
  30. field: 'level',
  31. displayName: '事件等级',
  32. width: 100,
  33. cellTemplate: '<div class="temp-row" ng-class="[grid.appScope.levelEnum[row.entity.level].color]">{{grid.appScope.levelEnum[row.entity.level].name}}</div>'
  34. },
  35. {
  36. field: 'status',
  37. displayName: '状态',
  38. width: 100,
  39. cellTemplate: '<div class="temp-row" ng-class="[grid.appScope.getStatusMap(row.entity).color]">{{grid.appScope.getStatusMap(row.entity).name}}</div>'
  40. },
  41. {
  42. field: 'title',
  43. displayName: '标题',
  44. width: 200,
  45. },
  46. {
  47. field: 'description',
  48. displayName: '描述',
  49. width: 300,
  50. },
  51. {
  52. field: 'groupName',
  53. displayName: '地址',
  54. width: 160,
  55. },
  56. {
  57. field: 'createdTime',
  58. displayName: '事件时间',
  59. width: 160,
  60. },
  61. {
  62. field: 'dealedTime',
  63. displayName: '处理时间',
  64. width: 160,
  65. },
  66. {
  67. field: 'dealedDetail',
  68. displayName: '处理详情',
  69. width: 160,
  70. },
  71. ];
  72. let fields = $scope.gridOptions.columnDefs;
  73. for (let index in fields) {
  74. let item = fields[index];
  75. if (item && item['minWidth'] == null) {
  76. item['minWidth'] = 120;
  77. }
  78. }
  79. }
  80. $scope.setPagingData = function (data) {
  81. $scope.myData = data.data.dataList;
  82. $scope.gridOptions.totalItems = data.data.total;
  83. };
  84. $scope.getPagedDataAsync = function (curPage, pageSize) {
  85. let params = {
  86. pageSize: pageSize,
  87. pageIndex: curPage
  88. };
  89. if (condition.searchKey !== "") {
  90. params.searchKey = condition.searchKey
  91. }
  92. $http.get('/device/getAlarmList', {
  93. params: params
  94. }).then(function (data) {
  95. $scope.setPagingData(data.data, curPage, pageSize);
  96. }).catch(function (data) {
  97. toaster.pop("error", "提示", "获取列表失败");
  98. });
  99. };
  100. function initDataGrid() {
  101. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  102. }
  103. setColumnDefs();
  104. initDataGrid();
  105. $scope.levelEnum = {
  106. fatal: {
  107. name: '致命的',
  108. color: 'text-danger'
  109. },
  110. critical: {
  111. name: '严重的',
  112. color: 'text-warning'
  113. },
  114. normal: {
  115. name: '一般的',
  116. color: 'text-info'
  117. }
  118. }
  119. $scope.statusEnum = {
  120. ignored: {
  121. name: '已忽略',
  122. color: ''
  123. },
  124. handled: {
  125. name: '已处理',
  126. color: 'text-success'
  127. },
  128. recovered: {
  129. name: '已经被恢复',
  130. color: 'text-success'
  131. },
  132. init: {
  133. name: '产生未处理',
  134. color: 'text-info'
  135. },
  136. }
  137. $scope.getStatusMap = function (row) {
  138. if (!row.status) {
  139. return {
  140. name: '',
  141. color: ''
  142. }
  143. }
  144. return $scope.statusEnum[row.status]
  145. }
  146. //事件
  147. $scope.event = {
  148. search: function () {
  149. if (condition.searchKey === "") {
  150. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  151. } else {
  152. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  153. }
  154. }
  155. };
  156. $scope.dialogData = {
  157. dealedDetail: '',
  158. status: '',
  159. ids: [],
  160. };
  161. $scope.checkNow = function (entity) {
  162. $http.get('/device/checkAlarm', {
  163. params: {
  164. id: entity.id
  165. }
  166. }).then(function (res) {
  167. $.confirm({
  168. content: res.data.description,
  169. });
  170. }).catch(function (data) {
  171. toaster.pop("error", "提示", "操作失败");
  172. });
  173. }
  174. }]);