diff --git a/src/views/vehicle/car.vue b/src/views/vehicle/car.vue index 2c42f26..aabf8fa 100644 --- a/src/views/vehicle/car.vue +++ b/src/views/vehicle/car.vue @@ -244,8 +244,6 @@ export default { marker: null, lineArr: [], vin:null, - carMsg:null, - carMsgTwo:{}, }; }, mounted() { @@ -255,15 +253,12 @@ export default { this.getList() this.listCarType() this.listFence() - this.carMsg = setInterval(this.listRealTime,1000) }, methods: { // 在这里执行后台拉取数据的操作 listRealTime(){ listRealTime(this.vin).then(res=>{ - console.log(res) - this.carMsgTwo = res.data - this.lineArr.push(res.longitude.replace(/"/g, "") +","+res.latitude.replace(/"/g, "")) + }) }, /*重置表单*/ @@ -279,9 +274,11 @@ export default { this.$refs.myForm.resetFields(); // 重置表单验证状态 }, isShowAll(){ + removeRealTime().then(res=>{ + + }) this.isShow = true this.isList = false - // this.map.destroy();//离开页面,销毁掉 location.reload() }, insertCar(){ @@ -310,7 +307,7 @@ export default { realTimeTrajectory(carVin){ this.vin = carVin realTime(this.vin).then(res=>{ - if(res.code!== 200){ + if(res.code !== 200){ this.$message.error("获取实时轨迹失败!") return } diff --git a/src/views/vehicle/record.vue b/src/views/vehicle/record.vue index 88d92cf..9c4ca63 100644 --- a/src/views/vehicle/record.vue +++ b/src/views/vehicle/record.vue @@ -19,16 +19,28 @@ export default { }, arr:[], lineArr:null, - carMsg:[], + recordCarList: [] , // 存储获取到的对象集合 + currentIndex: 0, // 当前展示的对象索引 + currentObject: "" // 当前展示的对象内容 } }, mounted() { - + this.doDo(); }, created() { this.getList() }, methods: { + startDisplay() { + // 启动定时器,每秒展示一个对象 + setInterval(() => { + if (this.currentIndex < this.recordCarList.length) { + // 当前索引小于集合长度时,更新展示的对象内容 + this.currentObject = JSON.stringify(this.recordCarList[this.currentIndex]); + this.currentIndex++; + } + }, 1000); + }, deleteRecord(recordId){ this.recordId = recordId deleteRecord(this.recordId).then(res=>{ @@ -46,13 +58,13 @@ export default { this.recordCar.startTime = recordCar.startTime this.recordCar.endTime = recordCar.endTime historyMap(this.recordCar).then(res=>{ - console.log(res) - this.carMsg = res.data - res.data.forEach(item=>{ - this.arr.push(item.longitude.replace(/"/g, "") +","+item.latitude.replace(/"/g, "")) - this.lineArr = this.arr.map(item => item.trim().replace(/'/g, '').split(',')) - console.log(this.lineArr) - }) + this.recordCarList = res; // 将获取到的对象集合存储到data中 + this.startDisplay(); // 开始展示 + let coordinates = res.data.map(obj => [ + parseFloat(obj.longitude.replace(/"/g, "")), + parseFloat(obj.latitude.replace(/"/g, "")) + ]); + this.lineArr = [coordinates] }) this.initMap() this.startAnimation() @@ -138,54 +150,7 @@ export default {