forked from huangdaju/cloud-ui
肖凡4.8提交
parent
3eab588178
commit
1e9f7abf01
|
@ -55,7 +55,7 @@ service.interceptors.request.use(config => {
|
||||||
const s_url = sessionObj.url; // 请求地址
|
const s_url = sessionObj.url; // 请求地址
|
||||||
const s_data = sessionObj.data; // 请求数据
|
const s_data = sessionObj.data; // 请求数据
|
||||||
const s_time = sessionObj.time; // 请求时间
|
const s_time = sessionObj.time; // 请求时间
|
||||||
const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交
|
const interval = 500; // 间隔时间(ms),小于此时间视为重复提交
|
||||||
if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
|
if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
|
||||||
const message = '数据正在处理,请勿重复提交';
|
const message = '数据正在处理,请勿重复提交';
|
||||||
console.warn(`[${s_url}]: ` + message)
|
console.warn(`[${s_url}]: ` + message)
|
||||||
|
|
|
@ -163,7 +163,7 @@
|
||||||
<el-button
|
<el-button
|
||||||
size="mini"
|
size="mini"
|
||||||
type="text"
|
type="text"
|
||||||
icon="el-icon-delete"
|
icon="el-icon-eleme"
|
||||||
@click="$router.push({
|
@click="$router.push({
|
||||||
path:'track',
|
path:'track',
|
||||||
query:{
|
query:{
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="container"></div>
|
<div>
|
||||||
|
<div id="container" style="width: 25%; height: 250px;"></div>
|
||||||
|
<div>
|
||||||
|
{{carData}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import AMapLoader from "@amap/amap-jsapi-loader";
|
import AMapLoader from "@amap/amap-jsapi-loader";
|
||||||
import {getRealTimeData} from "@/api/system/car";
|
|
||||||
import {getRealTimeDataTwo} from "@/api/system/car";
|
import {getRealTimeDataTwo} from "@/api/system/car";
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,21 +20,23 @@ export default {
|
||||||
return {
|
return {
|
||||||
carPosition: ["116.397428", "39.90923"], // 初始化小汽车位置
|
carPosition: ["116.397428", "39.90923"], // 初始化小汽车位置
|
||||||
carMarker: null, // 存储小汽车Marker
|
carMarker: null, // 存储小汽车Marker
|
||||||
animationInterval:null//存储动画定时器
|
animationInterval:null,//存储动画定时器
|
||||||
|
lastUpdateTime:0,//上次更新时间
|
||||||
|
animationFramId:null,//存储动画帧的ID
|
||||||
|
carData:[],//小汽车经纬度
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initAMap();
|
this.initAMap()
|
||||||
|
// this.getRealTimeDataAndUpdatePosition(this.$route.query.carVin); // 添加此行
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
clearInterval(this.animationInterval);//清除定时器
|
clearInterval(this.animationInterval);//清除定时器
|
||||||
this.map?.destroy();
|
this.map?.destroy();
|
||||||
|
cancelAnimationFrame(this.animationFramId);//取消动画帧请求
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
initAMap() {
|
initAMap() {
|
||||||
AMapLoader.load({
|
AMapLoader.load({
|
||||||
key: "e7398786b61ee782417e1749de1f2b39", // 申请好的Web端开发者Key,首次调用 load 时必填
|
key: "e7398786b61ee782417e1749de1f2b39", // 申请好的Web端开发者Key,首次调用 load 时必填
|
||||||
|
@ -57,53 +66,44 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
startCarAnimation() {
|
startCarAnimation() {
|
||||||
this.animationInterval = setInterval(() => {
|
// this.animationInterval = setInterval(() => {
|
||||||
let vin=this.$route.query.carVin;
|
// let vin = this.$route.query.carVin;
|
||||||
|
// this.getRealTimeDataAndUpdatePosition(vin);
|
||||||
|
// }, 1000);
|
||||||
|
const animate = () => {
|
||||||
|
const currentTime = Date.now();
|
||||||
|
const deltaTime = currentTime - this.lastUpdateTime;
|
||||||
|
|
||||||
|
if (deltaTime > 1000) {
|
||||||
|
//每秒更新一次位置
|
||||||
|
this.lastUpdateTime = currentTime;
|
||||||
|
let vin = this.$route.query.carVin;
|
||||||
this.getRealTimeDataAndUpdatePosition(vin);
|
this.getRealTimeDataAndUpdatePosition(vin);
|
||||||
}, 1000);
|
}
|
||||||
|
this.animationFramId = requestAnimationFrame(animate);
|
||||||
|
};
|
||||||
|
this.animationFramId = requestAnimationFrame(animate);
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
getRealTimeDataAndUpdatePosition(vin){
|
getRealTimeDataAndUpdatePosition(vin) {
|
||||||
// getRealTimeData().then(response=>{
|
|
||||||
// // 假设实时数据的格式为 { longitude: ..., latitude: ... }
|
|
||||||
// const realTimeData = response.data; // 假设实时数据在 response.data 中
|
|
||||||
// this.$message.success('Real-time data:',response.data)
|
|
||||||
// // 更新小汽车位置
|
|
||||||
// this.carPosition = [realTimeData.longitude, realTimeData.latitude];
|
|
||||||
// // 更新小汽车Marker的位置
|
|
||||||
// this.carMarker.setPosition(this.carPosition);
|
|
||||||
// })
|
|
||||||
// .catch((error)=>{
|
|
||||||
// console.error("Error fetching real-time data:",error);
|
|
||||||
// })
|
|
||||||
getRealTimeDataTwo(vin)
|
getRealTimeDataTwo(vin)
|
||||||
.then(response=>{
|
.then(response => {
|
||||||
// debugger
|
console.log('Response from getRealTimeDataTwo:', response);
|
||||||
// 假设实时数据的格式为 { longitude: ..., latitude: ... }
|
// this.$message.success('Real-time data:',response);
|
||||||
this.$message.success('Real-time data:',response);
|
this.carData = response
|
||||||
let carData=response
|
|
||||||
//更新小汽车位置
|
//更新小汽车位置
|
||||||
this.carPosition=[carData.longitude,carData.latitude];
|
this.carPosition = [this.carData.longitude, this.carData.latitude];
|
||||||
// debugger
|
|
||||||
//更新小汽车Marker的位置
|
//更新小汽车Marker的位置
|
||||||
this.carMarker.setPosition(this.carPosition);
|
this.carMarker.setPosition(this.carPosition);
|
||||||
|
//显示实时数据
|
||||||
|
|
||||||
})
|
})
|
||||||
// .catch(error=>{
|
},
|
||||||
// console.error("Error fetching real-time data:",error)
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
#container {
|
|
||||||
width: 25%;
|
|
||||||
height: 250px;
|
|
||||||
}
|
|
||||||
.amap-marker-icon {
|
|
||||||
border: none !important; /* 移除Marker的边框 */
|
|
||||||
box-shadow: none !important; /* 移除Marker的阴影 */
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue