// 台风列表 import { getTaskListData, } from '@/api/task' import PicturesUpload from '../pictures-upload/index.vue' import RightSlide from '@/components/RightSlide.vue' import LeftSlide from '@/components/LeftSlide.vue' import { payloadList, payloadRemove, payloadSave, payloadUpdate, uavRemove, uavList, uavSave, uavUpdate, deviceControlTurnon, deviceControlEndall, } from '@/api/device' let taskListResource = [] export default { name: 'TwinSituation', props: { visible: Boolean, sceneComplete: Boolean, }, components: { PicturesUpload, RightSlide, LeftSlide, }, data() { return { visibleLocale: false, deviceData: [ ], device: { visible: false, title: '', form: { type: 'SAR' }, }, queryForm: { type: 'uav' }, isShowTable: false } }, computed: { deviceTypes() { return [ { label: this.$t('device1Manage.uav'), value: 'uav' }, { label: this.$t('device1Manage.radar'), value: 'payload' }, ] }, deviceMap() { return { payload: this.$t('device1Manage.radar'), uav: this.$t('device1Manage.uav') } }, rules() { return this.device.form.type === 'uav' ? { name1: [{ required: true, message: this.$t('device1Manage.uavNamePlaceholder'), trigger: 'blur' }], ip1: [{ required: true, message: this.$t('device1Manage.uavIpPlaceholder'), trigger: 'blur' }], code: [{ required: true, message: this.$t('device1Manage.uavCodePlaceholder'), trigger: 'blur' }], } : { name2: [{ required: true, message: this.$t('device1Manage.radarNamePlaceholder'), trigger: 'blur' }], ip2: [{ required: true, message: this.$t('device1Manage.ipPlaceholder'), trigger: 'blur' }], } }, }, watch: { visible: { handler: function (nv) { if (nv) { this.visibleLocale = nv } }, immediate: true, }, visibleLocale(nv) { if (!nv) { this.$emit('update:visible', false) } }, 'queryForm.type': { handler: function (nv) { if (nv === 'payload') { this.payloadPage() } else { this.uavPage() } this.isShowTable = false this.$nextTick(() => { this.isShowTable = true }) }, immediate: true, }, }, created() { }, mounted() { }, beforeDestroy() { }, methods: { // 操作雷达 async handleRadar(row, type) { if (type === 1) { deviceControlTurnon({ payloadId: row.ip }).then(res => { if (res.data.code === 200) { this.$message.success(this.$t('device1Manage.radarTurnOnSuccess')) } }) } else if (type === 2) { const bool = await this.$confirm(this.$t('device1Manage.radarEndConfirm'), this.$t('device1Manage.tip'), { customClass: 'confirm-light', confirmButtonText: this.$t('common.confirm'), cancelButtonText: this.$t('common.cancel'), type: 'warning' }) if (!bool) return; deviceControlEndall({ payloadId: row.ip }).then(res => { if (res.data.code === 200) { this.$message.success(this.$t('device1Manage.radarEndSuccess')) } }) } }, payloadPage() { payloadList().then(res => { if (res.data.code === 200) { this.deviceData = res.data.data } else { this.$message.error(res.data.msg || this.$t('common.requestFailed')) } }).catch(err => { this.$message.error(err.msg || this.$t('common.requestFailed')) }) }, uavPage() { uavList().then(res => { if (res.data.code === 200) { this.deviceData = res.data.data } else { this.$message.error(res.data.msg || this.$t('common.requestFailed')) } }).catch(err => { this.$message.error(err.msg || this.$t('common.requestFailed')) }) }, addDevice() { this.device.visible = true this.device.title = this.$t(`device1Manage.add`) + this.deviceMap[this.queryForm.type] if (this.queryForm.type === 'uav') { this.device.form = { id: '', name1: '', code: '', ip1: '' } } else { this.device.form = { id: '', name2: '', type: 'SAR', ip2: '' } } }, editDevice(row) { this.device.visible = true this.device.title = `${this.$t('common.edit')}${this.deviceMap[this.queryForm.type]}` if (this.queryForm.type === 'uav') { this.device.form = { id: row.id, name1: row.name, code: row.code, ip1: row.ip } } else { this.device.form = { id: row.id, name2: row.name, type: row.type, ip2: row.ip } } }, close() { this.$refs.form.resetFields() this.device.visible = false }, async submitDevice() { const valid = await this.$refs.form.validate() if (!valid) return const form = {} if (this.queryForm.type === 'uav') { form.name = this.device.form.name1 form.ip = this.device.form.ip1 form.code = this.device.form.code if (this.device.form.id) { form.id = this.device.form.id uavUpdate(form).then(res => { if (res.data.code === 200) { this.uavPage() this.close() } }) } else { uavSave(form).then(res => { if (res.data.code === 200) { this.uavPage() this.close() } }) } } else { form.name = this.device.form.name2 form.ip = this.device.form.ip2 form.type = this.device.form.type if (this.device.form.id) { form.id = this.device.form.id payloadUpdate(form).then(res => { if (res.data.code === 200) { this.payloadPage() this.close() } }) } else { payloadSave(form).then(res => { if (res.data.code === 200) { this.payloadPage() this.close() } }) } } }, async deleteDevice(row) { const bool = await this.$confirm(`${this.$t('device1Manage.deleteConfirm')}${this.deviceMap[this.queryForm.type]}?`, this.$t('device1Manage.tip'), { customClass: 'confirm-light', confirmButtonText: this.$t('common.confirm'), cancelButtonText: this.$t('common.cancel'), type: 'warning' }) if (!bool) return; if (this.queryForm.type === 'uav') { uavRemove([row.id]).then(res => { this.$message.success(this.$t('common.deleteSuccess')) this.uavPage() }) } else { payloadRemove([row.id]).then(res => { this.$message.success(this.$t('common.deleteSuccess')) this.payloadPage() }) } }, //#region 无人机详情代码 resourceClick(info) { this.detailInfo.visible = false // 直接显示详细信息窗口,跳过中间步骤 this.detailUav.id = info.id this.detailUav.basicsInfo.name = info.name this.detailUav.baseInfo.longitude = info.lon this.detailUav.baseInfo.latitude = info.lat this.detailUav.baseInfo.flyHeight = info.flyHeight this.detailUav.visible = true // TODO 测试 // this.resourceClickTest(info) getTaskListData({ payloadId: info.id }).then(res => { if (res.data.code === 200) { let tasklist = res.data.data this.detailInfo.jobId = undefined if (tasklist.length > 0) { // 有正在执行的任务 // 判断当前任务是否显示 let findIndex = -1 taskListResource.forEach((item, index) => { if (item.status === 1) { item.uavList.forEach(uav => { let find = uav.payloadList.find(payload => payload.payloadId === info.id) if (find) { findIndex = index } }) } }) if (findIndex > -1) { this.detailInfo.jobId = this.taskList.data[findIndex].id if (!this.taskList.data[findIndex].check) { // 打开任务信息 this.toggleTaskSceneShow(this.taskList.data[findIndex], findIndex) } } } else { // 没有正在执行的任务 } this.detailInfo.baseInfo = JSON.parse(JSON.stringify(info)) this.detailInfo.taskList = tasklist let pictureList = [] tasklist.forEach((item, index) => { item.uavList.forEach(child => { child.payloadList.forEach(loader => { if (loader.payloadId === info.id) { loader.imageList.forEach(pic => { pictureList.push(Object.assign({ jobId: item.id, url: window.config.imagePath + pic.relativePath, taskName: item.name, uavName: child.uavName, uavId: child.uavId, payloadId: loader.payloadId, loaderName: loader.payloadName, status: item.status + '', }, pic)) }) } }) }) }) this.detailInfo.pictureList = pictureList //this.detailInfo.visible = true } else { this.$message.error(res.data.message) } }) }, } }