app.controller('devAlarmCtrl', ['$scope', '$http', '$timeout', 'toaster', function ($scope, $http, $timeout, toaster) {
//查询条件
var condition = $scope.condition = {
};
$scope.gridOptions = {
data: 'myData',
showGridFooter: true,
paginationPageSizes: [10, 20, 50, 100],
paginationCurrentPage: 1,
paginationPageSize: 10,
totalItems: 0,
columnDefs: [],
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
if ($scope.setPagingData) {
$scope.getPagedDataAsync(newPage, pageSize);
}
});
}
};
function setColumnDefs() {
$scope.gridOptions.columnDefs = [
{
field: 'logicalCode',
displayName: '设备',
width: 100,
},
{
field: 'level',
displayName: '事件等级',
width: 100,
cellTemplate: '
{{grid.appScope.levelEnum[row.entity.level].name}}
'
},
{
field: 'status',
displayName: '状态',
width: 100,
cellTemplate: '{{grid.appScope.getStatusMap(row.entity).name}}
'
},
{
field: 'title',
displayName: '标题',
width: 200,
},
{
field: 'description',
displayName: '描述',
width: 300,
},
{
field: 'groupName',
displayName: '地址',
width: 160,
},
{
field: 'createdTime',
displayName: '事件时间',
width: 160,
},
{
field: 'dealedTime',
displayName: '处理时间',
width: 160,
},
{
field: 'dealedDetail',
displayName: '处理详情',
width: 160,
},
];
let fields = $scope.gridOptions.columnDefs;
for (let index in fields) {
let item = fields[index];
if (item && item['minWidth'] == null) {
item['minWidth'] = 120;
}
}
}
$scope.setPagingData = function (data) {
$scope.myData = data.data.dataList;
$scope.gridOptions.totalItems = data.data.total;
};
$scope.getPagedDataAsync = function (curPage, pageSize) {
let params = {
pageSize: pageSize,
pageIndex: curPage
};
if (condition.searchKey !== "") {
params.searchKey = condition.searchKey
}
$http.get('/device/getAlarmList', {
params: params
}).then(function (data) {
$scope.setPagingData(data.data, curPage, pageSize);
}).catch(function (data) {
toaster.pop("error", "提示", "获取列表失败");
});
};
function initDataGrid() {
$scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
}
setColumnDefs();
initDataGrid();
$scope.levelEnum = {
fatal: {
name: '致命的',
color: 'text-danger'
},
critical: {
name: '严重的',
color: 'text-warning'
},
normal: {
name: '一般的',
color: 'text-info'
}
}
$scope.statusEnum = {
ignored: {
name: '已忽略',
color: ''
},
handled: {
name: '已处理',
color: 'text-success'
},
recovered: {
name: '已经被恢复',
color: 'text-success'
},
init: {
name: '产生未处理',
color: 'text-info'
},
}
$scope.getStatusMap = function (row) {
if (!row.status) {
return {
name: '',
color: ''
}
}
return $scope.statusEnum[row.status]
}
//事件
$scope.event = {
search: function () {
if (condition.searchKey === "") {
$scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
} else {
$scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
}
}
};
$scope.dialogData = {
dealedDetail: '',
status: '',
ids: [],
};
$scope.checkNow = function (entity) {
$http.get('/device/checkAlarm', {
params: {
id: entity.id
}
}).then(function (res) {
$.confirm({
content: res.data.description,
});
}).catch(function (data) {
toaster.pop("error", "提示", "操作失败");
});
}
}]);