|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
import { HttpClient } from '@angular/common/http'; |
|
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
|
|
|
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message'; |
|
|
|
|
import { TreeService } from 'src/app/service/tree.service'; |
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-condition-monitoring', |
|
|
|
|
templateUrl: './condition-monitoring.component.html', |
|
|
|
@ -8,24 +10,77 @@ import { Component, OnInit } from '@angular/core';
|
|
|
|
|
}) |
|
|
|
|
export class ConditionMonitoringComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient) { } |
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient, private fb: FormBuilder, private toTree: TreeService, private message: NzMessageService) { } |
|
|
|
|
validateForm!: FormGroup; |
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
organization: [null] |
|
|
|
|
}); |
|
|
|
|
this.getAllOrganization() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//获取所有组织机构
|
|
|
|
|
nodes: any = [] |
|
|
|
|
defaultOrId: string |
|
|
|
|
defaultExpandedKeys = []; |
|
|
|
|
getAllOrganization() { |
|
|
|
|
let params = { |
|
|
|
|
ContainsChildren: true, |
|
|
|
|
pageSize: 9999 |
|
|
|
|
} |
|
|
|
|
this.http.get('/api/Organizations', { |
|
|
|
|
params: params |
|
|
|
|
}).subscribe((data: any) => { |
|
|
|
|
console.log('组织机构列表', data) |
|
|
|
|
data.items.forEach(element => { |
|
|
|
|
element.key = element.id |
|
|
|
|
element.title = element.name |
|
|
|
|
// element.selectable = false
|
|
|
|
|
}); |
|
|
|
|
this.nodes = [...this.toTree.toTree(data.items)] |
|
|
|
|
this.defaultOrId = this.nodes[0].id |
|
|
|
|
this.validateForm.value.organization = this.defaultOrId |
|
|
|
|
this.getConditionMonitoring() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
submitForm(): void { |
|
|
|
|
for (const i in this.validateForm.controls) { |
|
|
|
|
this.validateForm.controls[i].markAsDirty(); |
|
|
|
|
this.validateForm.controls[i].updateValueAndValidity(); |
|
|
|
|
} |
|
|
|
|
this.getConditionMonitoring() |
|
|
|
|
} |
|
|
|
|
resetForm(e: MouseEvent): void { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
this.validateForm.reset(); |
|
|
|
|
for (const key in this.validateForm.controls) { |
|
|
|
|
this.validateForm.controls[key].markAsPristine(); |
|
|
|
|
this.validateForm.controls[key].updateValueAndValidity(); |
|
|
|
|
} |
|
|
|
|
this.validateForm.patchValue({ |
|
|
|
|
organization: this.nodes[0].id, |
|
|
|
|
}); |
|
|
|
|
this.PageNumber = 1 |
|
|
|
|
this.getConditionMonitoring() |
|
|
|
|
} |
|
|
|
|
listOfData: any |
|
|
|
|
num: string |
|
|
|
|
PageNumber: number = 1 |
|
|
|
|
isLoading = false |
|
|
|
|
//获取盒子状态
|
|
|
|
|
getConditionMonitoring() { |
|
|
|
|
let params = { |
|
|
|
|
ContainsChildren: true, |
|
|
|
|
OrganizationId: this.defaultOrId, |
|
|
|
|
PageNumber: this.PageNumber, |
|
|
|
|
PageSize: 10 |
|
|
|
|
} |
|
|
|
|
this.isLoading = true |
|
|
|
|
this.http.get('/api/EdgeDevices/Statuses', { params: params }).subscribe( |
|
|
|
|
(data: any) => { |
|
|
|
|
console.log(data) |
|
|
|
|
this.isLoading = false |
|
|
|
|
this.listOfData = data.items |
|
|
|
|
this.num = data.totalCount |
|
|
|
|
}, err => { |
|
|
|
@ -37,4 +92,68 @@ export class ConditionMonitoringComponent implements OnInit {
|
|
|
|
|
this.PageNumber = $event |
|
|
|
|
this.getConditionMonitoring() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checked = false; |
|
|
|
|
loading = false; |
|
|
|
|
indeterminate = false; |
|
|
|
|
listOfCurrentPageData: readonly any[] = []; |
|
|
|
|
setOfCheckedId = new Set<number>(); |
|
|
|
|
updateCheckedSet(id: number, checked: boolean): void { |
|
|
|
|
if (checked) { |
|
|
|
|
this.setOfCheckedId.add(id); |
|
|
|
|
} else { |
|
|
|
|
this.setOfCheckedId.delete(id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onCurrentPageDataChange(listOfCurrentPageData: readonly any[]): void { |
|
|
|
|
this.listOfCurrentPageData = listOfCurrentPageData; |
|
|
|
|
this.refreshCheckedStatus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
refreshCheckedStatus(): void { |
|
|
|
|
const listOfEnabledData = this.listOfCurrentPageData.filter(({ disabled }) => !disabled); |
|
|
|
|
this.checked = listOfEnabledData.every(({ id }) => this.setOfCheckedId.has(id)); |
|
|
|
|
this.indeterminate = listOfEnabledData.some(({ id }) => this.setOfCheckedId.has(id)) && !this.checked; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onItemChecked(id: number, checked: boolean): void { |
|
|
|
|
this.updateCheckedSet(id, checked); |
|
|
|
|
this.refreshCheckedStatus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onAllChecked(checked: boolean): void { |
|
|
|
|
this.listOfCurrentPageData |
|
|
|
|
.filter(({ disabled }) => !disabled) |
|
|
|
|
.forEach(({ id }) => this.updateCheckedSet(id, checked)); |
|
|
|
|
this.refreshCheckedStatus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sendRequest(): void { |
|
|
|
|
this.loading = true; |
|
|
|
|
const requestData = this.listOfData.filter(data => this.setOfCheckedId.has(data.id)); |
|
|
|
|
console.log(requestData); |
|
|
|
|
let strArr = [] |
|
|
|
|
requestData.forEach(element => { |
|
|
|
|
strArr.push(element.id) |
|
|
|
|
}); |
|
|
|
|
let params = { |
|
|
|
|
edgeDeviceIds: strArr |
|
|
|
|
} |
|
|
|
|
this.http.put('/api/EdgeDevices/Commands/UpdateStates', '', { params: params }).subscribe({ |
|
|
|
|
next: (data) => { |
|
|
|
|
this.message.create('success', '通知边缘盒子成功,请过一段时间手动刷新尝试!'); |
|
|
|
|
this.setOfCheckedId.clear(); |
|
|
|
|
this.refreshCheckedStatus(); |
|
|
|
|
this.loading = false; |
|
|
|
|
}, |
|
|
|
|
error: (err) => { |
|
|
|
|
this.loading = false; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
|
|
|
|
|
// }, 1000);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|