中化项目-边缘主机维护-前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
2.5 KiB

import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd/message';
import { ConfigFormDataService } from 'src/app/service/configFormData.service';
@Component({
selector: 'app-config-form',
templateUrl: './config-form.component.html',
styleUrls: ['./config-form.component.scss']
})
export class ConfigFormComponent implements OnInit {
constructor(public configFormData: ConfigFormDataService, private http: HttpClient, private route: ActivatedRoute, private message: NzMessageService) { }
config1: string
config2: string
config3: string
config4: string
hostId//主机id
orId//加油站id
ngOnInit(): void {
this.hostId = this.route.snapshot.queryParams.hostId
this.orId = this.route.snapshot.queryParams.orId
this.config1 = sessionStorage.getItem('config1')
this.config2 = sessionStorage.getItem('config2')
this.config3 = sessionStorage.getItem('config3')
this.config4 = sessionStorage.getItem('config4')
}
goback() {
history.go(-1)
}
putConfig() {
let body = {
configFiles: [
{ name: 'config_nvdsanalytics.txt', content: this.config1 },
{ name: 'config.yaml', content: this.config2 },
{ name: 'producer.yaml', content: this.config3 },
{ name: 'source.yaml', content: this.config4 }
]
}
this.http.put(`/api/EdgeDevices/${this.hostId}`, body).subscribe({
next: (data) => {
this.message.create('success', `文件保存成功`);
let promiseArr = []
body.configFiles.forEach(element => {
let params = {
edgeDeviceId: this.hostId,
fileName: element.name
}
promiseArr.push(
new Promise((resolve, reject) => {
this.http.put('/api/EdgeDevices/Commands/PushFile', '', { params: params }).subscribe({
next: (data) => {
resolve('成功了')
},
error: err => {
reject('失败了')
}
})
})
)
});
Promise.all(promiseArr).then((result) => {
this.message.create('success', `发送文件名成功`);
}).catch((error) => {
this.message.create('error', `发送文件名失败`);
console.log('发送文件名失败', error)
})
},
error: (err) => {
this.message.create('error', `文件保存失败`);
}
})
}
}