import { HttpClient } from '@angular/common/http'; import { Component, OnInit, AfterViewInit, ViewChild, ViewContainerRef } from '@angular/core'; import { TreeService } from 'src/app/service/tree.service'; import { NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions } from 'ng-zorro-antd/tree'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { NzModalService } from 'ng-zorro-antd/modal'; import { NzMessageService } from 'ng-zorro-antd/message'; import { AddhostComponent } from './addhost/addhost.component'; import { AddcameraComponent } from './addcamera/addcamera.component'; import { EdithostComponent } from './edithost/edithost.component'; @Component({ selector: 'app-analysis-of-the-host', templateUrl: './analysis-of-the-host.component.html', styleUrls: ['./analysis-of-the-host.component.scss'] }) export class AnalysisOfTheHostComponent implements OnInit { constructor(private fb: FormBuilder, private http: HttpClient, private toTree: TreeService, private modal: NzModalService, private message: NzMessageService, private viewContainerRef: ViewContainerRef) { } ngOnInit(): void { this.getAllOrganization() } //获取所有组织机构 searchValue = ''; nzExpandAll = false; totalCount: string getAllOrganization() { this.http.get('/api/services/app/Organization/GetAll').subscribe((data: any) => { this.totalCount = data.result.totalCount data.result.items.forEach(element => { element.key = element.id element.title = element.displayName element.selectable = false }); this.nodes = [...this.toTree.toTree(data.result.items)] this.defaultExpandedKeys = [...this.defaultExpandedKeys] }) } @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; defaultExpandedKeys = []; nodes: any[] = [] nzSelectedKeys: any[] = [] selectedOilStation: any nzClick(event: NzFormatEmitEvent): void { console.log(event.node.origin); if (event.node.origin.isGasStation) {//如果点击的是加油站才生效 this.nzSelectedKeys[0] = event.node.origin.id this.nzSelectedKeys = [...this.nzSelectedKeys] this.selectedOilStation = event.node.origin this.getHost() } else { this.message.info('只有加油站才可以增加主机'); } } //获得加油站的主机 listOfData: any[] = []; getHost() { this.http.get('/api/services/app/EdgeDevice/GetAll', { params: { organizationUnitId: this.selectedOilStation.id } }).subscribe((data: any) => { console.log('主机列表', data.result.items) this.listOfData = data.result.items }) } //获得加油站摄像头 listOfDataCamera: any[] = []; getCamera() { this.http.get('/api/services/app/Camera/GetAll', { params: { organizationUnitId: this.selectedOilStation.id } }).subscribe((data: any) => { console.log('摄像头列表', data) this.listOfDataCamera = data }) } ngAfterViewInit(): void { } //新增分析主机 addHost() { console.log(this.selectedOilStation) const modal = this.modal.create({ nzTitle: '新增加油站主机', nzContent: AddhostComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 288, nzComponentParams: {}, nzOnOk: async () => { if (instance.validateForm.valid) { await new Promise(resolve => { console.log('表单信息', instance.validateForm) let body = { hostIPAddress: instance.validateForm.value.ip, organizationUnitId: this.selectedOilStation.id } this.http.post('/api/services/app/EdgeDevice/Create', body).subscribe(data => { resolve(data) this.message.create('success', '创建成功!'); this.getHost() return true }) }) } else { this.message.create('warning', '请填写完整!'); return false } } }); const instance = modal.getContentComponent(); } edit(data) { console.log(data) const modal = this.modal.create({ nzTitle: '编辑加油站主机', nzContent: EdithostComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 288, nzComponentParams: { ip: data.hostIPAddress }, nzOnOk: async () => { if (instance.validateForm.valid) { await new Promise(resolve => { console.log('表单信息', instance.validateForm) data.hostIPAddress = instance.validateForm.value.ip, this.http.put('/api/services/app/EdgeDevice/Update', data).subscribe(data => { resolve(data) this.message.create('success', '修改成功!'); this.getHost() return true }) }) } else { this.message.create('warning', '请填写完整!'); return false } } }); const instance = modal.getContentComponent(); } delete(item) { console.log(item) this.modal.confirm({ nzTitle: `确定要删除${item.name}这个主机吗?`, nzOkText: '确定', nzOkType: 'danger', nzOnOk: () => { this.http.delete('/api/services/app/EdgeDevice/Delete', { params: { Id: item.id } }).subscribe(data => { this.message.create('success', '删除成功!'); this.getHost() }) }, nzCancelText: '取消' }); } //摄像头 addCamera() { console.log(this.selectedOilStation) const modal = this.modal.create({ nzTitle: '新增加油站摄像头', nzContent: AddcameraComponent, nzViewContainerRef: this.viewContainerRef, nzWidth: 288, nzComponentParams: {}, nzOnOk: async () => { if (instance.validateForm.valid) { await new Promise(resolve => { console.log('表单信息', instance.validateForm) let body = { organizationUnitId: this.selectedOilStation.id, code: instance.validateForm.value.code, name: instance.validateForm.value.name, description: "", } this.http.post('/api/services/app/Camera/Create', body).subscribe(data => { resolve(data) this.message.create('success', '创建成功!'); this.getCamera() return true }, err => { return false }) }) } else { this.message.create('warning', '请填写完整!'); return false } } }); const instance = modal.getContentComponent(); } editCamera(data) { } deleteCamera(data) { } }