ly-front/src/views/contentData/LeftSidebar/index.vue

246 lines
6.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="left-sidebar" :class="{ contracted: isContracted }">
<div class="stats">
<div class="stat-item" v-for="(item, index) in warningDay" :key="index">
<div class="stat-name">{{ item.name }}</div>
<div class="stat-name">{{ item.value }} </div>
</div>
</div>
<div class="drone-list">
<div class="title">
<img src="@/assets/img/uavTitle.png" alt="" />
</div>
<ul>
<li
v-for="(drone, index) in drones"
:key="index"
@click="handleDroneClick(drone)"
>
<div class="top">
<div class="left">
{{ index < 9 ? "0" + (index + 1) : index + 1 }}
</div>
<div class="text">{{ drone.serial_number }}</div>
</div>
<div class="main">
<div class="top_main">
<div class="text">时间:{{ drone.times }}</div>
<div class="text">来源:{{ drone.DeviceName }}</div>
</div>
<div class="top_main">
<div class="text">频段:{{ drone.freq }}</div>
<div class="text">型号:{{ drone.device_type }}</div>
</div>
</div>
</li>
</ul>
</div>
<div class="left-contract" @click="handleContractClick">
<img :src="isContracted ? rightContract : leftContract" alt="" />
</div>
</div>
</template>
<script>
import moment from "moment";
import { mapUavFiex } from "../index.js";
export default {
name: "LeftSidebar",
props: {
homeData: {
type: Object,
default: () => ({})
},
signaData: {
type: Array,
default: () => []
}
},
data() {
return {
leftContract: require("@/assets/img/left-contract.png"),
rightContract: require("@/assets/img/right-contract.png"),
warningDay: [
{
id: "1",
name: "今日预警",
value: 20
},
{
id: "2",
name: "累计预警",
value: 20
},
{
id: "3",
name: "今日处置",
value: 0
},
{
id: "4",
name: "累计处置",
value: 0
}
],
drones: [],
isContracted: false,
homeView: {},
droneTimers: new Map()
};
},
watch: {
homeData: {
handler(newVal) {
this.homeView = newVal;
this.warningDay[0].value = newVal.alarmCount.todaywaring;
this.warningDay[1].value = newVal.alarmCount.totalcount;
this.warningDay[2].value = newVal.alarmCount.todayhandle;
this.warningDay[3].value = newVal.alarmCount.totalhandle;
},
deep: true
},
signaData: {
handler(newVal) {
if (newVal) {
newVal.forEach((newItem) => {
// 如果已经存在相同BatchId的数据重置计时器
if (newItem.BatchId) {
const existingTimer = this.droneTimers.get(newItem.BatchId);
if (existingTimer) {
clearInterval(existingTimer); // 清除旧计时器
}
// 设置15秒初始时间
newItem.currTime = 15000;
// 创建新计时器
const timer = this.startTimer(newItem);
this.droneTimers.set(newItem.BatchId, timer);
// 更新无人机列表
const existingIndex = this.drones.findIndex(
(d) => d.BatchId === newItem.BatchId
);
newItem.times = moment(newItem.CreateTime).format("HH:mm:ss");
if (existingIndex !== -1) {
this.$set(this.drones, existingIndex, { ...newItem });
} else {
this.drones.push({ ...newItem });
}
}
});
if (this.drones) {
mapUavFiex(this.drones);
}
console.log(this.drones, "newVal");
}
},
deep: true
}
},
methods: {
startTimer(item) {
return setInterval(() => {
if (item.currTime > 0) {
item.currTime--;
// 更新显示时间(可选)
const index = this.drones.findIndex(
(d) => d.BatchId === item.BatchId
);
if (index !== -1) {
this.$set(this.drones, index, { ...item });
}
} else {
clearInterval(this.droneTimers.get(item.BatchId));
this.droneTimers.delete(item.BatchId);
this.handleTimerExpiration(item);
}
}, 1000);
},
handleTimerExpiration(item) {
// 从drones数组中移除
// 如果drones也需要同步更新
if (this.drones.length === 1) {
this.drones = [];
} else {
this.drones = this.drones.filter((d) => d.BatchId !== item.BatchId);
}
// 清理地图上的图形
let graphicLayer = window.marsMap.getLayerById("uavFiex");
if (graphicLayer) {
let graphic = graphicLayer.getGraphicById(item.BatchId);
let startPoint = graphicLayer.getGraphicById(item.BatchId + "start");
if (graphic) {
graphic.destroy();
graphicLayer.removeGraphic(graphic);
}
if (startPoint) {
graphicLayer.removeGraphic(startPoint);
}
if (this.drones.length === 0) {
window.marsMap.removeLayer(graphicLayer);
}
}
},
handleContractClick() {
this.isContracted = !this.isContracted; // 切换状态
},
handleDroneClick(value) {
console.log(value, "value");
window.marsMap.setCameraView({
lat: value.drone_lat,
lng: value.drone_lon,
alt: value.height + 800,
pitch: -90
});
if (value.drone_lon == 0 || value.drone_lat == 0) {
console.log("经纬度为0");
} else {
let graphicLayer = window.marsMap.getLayerById("uavFiex");
// let startPoint = graphicLayer.getGraphicById(value.BatchId + "start");
if (graphicLayer) {
graphicLayer.eachGraphic((car) => {
// 取出对应无人机的轨迹列表
//打击之前
if (value.BatchId === car.id) {
// car.openPopup();
console.log(car, "car.polyline");
car.polyline.show = !car.polyline.show; // 轨迹线
// if (car.polyline.show) {
// car.setOptions({
// polyline: {
// width: 2,
// opacity: 1,
// }
// });
// } else {
// car.setOptions({
// polyline: {
// width: 2,
// opacity: 0,
// }
// });
// }
}
});
}
}
}
}
};
</script>
<style lang="scss" scoped>
.left-sidebar {
transition: transform 0.5s;
}
.left-sidebar.contracted {
transform: translateX(-90%);
}
</style>