|
|
|
@ -419,6 +419,11 @@ export default {
|
|
|
|
|
current: 0,
|
|
|
|
|
requestId: "", //请求拍照返回的requestid
|
|
|
|
|
picTime: "", //请求拍照返回的时间
|
|
|
|
|
|
|
|
|
|
pollingTimer: null, // 轮询定时器(使用setTimeout,因此命名为pollingTimer更合适)
|
|
|
|
|
polling: false, // 控制是否正在轮询的标志位
|
|
|
|
|
isPollingStopped: false, // 新增:标记轮询是否已停止
|
|
|
|
|
maxPollingAttempts: 5, // 新增:最大轮询次数
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
@ -810,10 +815,12 @@ export default {
|
|
|
|
|
this.picTime = res.data.taketime; //获取时间 判断获取最新图片
|
|
|
|
|
console.log(this.requestId);
|
|
|
|
|
this.btnpicloading = true;
|
|
|
|
|
this.statusTimer = window.setInterval(() => {
|
|
|
|
|
this.getTakePicStatus(res.data);
|
|
|
|
|
this.statusNum++;
|
|
|
|
|
}, 3000);
|
|
|
|
|
// this.statusTimer = window.setInterval(() => {
|
|
|
|
|
// this.getTakePicStatus(res.data);
|
|
|
|
|
// this.statusNum++;
|
|
|
|
|
// }, 3000);
|
|
|
|
|
this.isPollingStopped = false; // 重置轮询停止标记
|
|
|
|
|
this.startPolling(res.data); // 开始轮询
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err); //代码错误、请求失败捕获
|
|
|
|
@ -828,62 +835,155 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
startPolling(data) {
|
|
|
|
|
if (!this.polling) {
|
|
|
|
|
this.polling = true;
|
|
|
|
|
this.statusNum = 0;
|
|
|
|
|
this.poll(data); // 调用新的poll函数开始第一次轮询
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
poll(data) {
|
|
|
|
|
if (this.isPollingStopped) {
|
|
|
|
|
console.log("轮询已停止,不再调用 getTakePicStatus");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.getTakePicStatus(data)
|
|
|
|
|
.then((shouldContinue) => {
|
|
|
|
|
if (shouldContinue) {
|
|
|
|
|
this.statusNum++;
|
|
|
|
|
if (this.statusNum < this.maxPollingAttempts) {
|
|
|
|
|
// 如果需要继续轮询,则设置下一个定时器
|
|
|
|
|
this.pollingTimer = setTimeout(() => {
|
|
|
|
|
this.poll(data); // 递归调用poll进行下一次轮询
|
|
|
|
|
}, 3000);
|
|
|
|
|
} else {
|
|
|
|
|
// 达到最大轮询次数,停止轮询
|
|
|
|
|
this.stopPolling();
|
|
|
|
|
// this.$message({
|
|
|
|
|
// duration: 1500,
|
|
|
|
|
// showClose: true,
|
|
|
|
|
// message: "下发指令超时,请重试!",
|
|
|
|
|
// type: "warning",
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 根据getTakePicStatus的返回结果,可能在这里就需要停止轮询
|
|
|
|
|
this.stopPolling();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.error("轮询出错:", err);
|
|
|
|
|
this.stopPolling();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
stopPolling() {
|
|
|
|
|
console.log(this.pollingTimer, "清除轮询不");
|
|
|
|
|
if (this.pollingTimer !== null) {
|
|
|
|
|
clearTimeout(this.pollingTimer);
|
|
|
|
|
this.pollingTimer = null;
|
|
|
|
|
}
|
|
|
|
|
this.statusNum = 0;
|
|
|
|
|
this.polling = false;
|
|
|
|
|
this.btnpicloading = false;
|
|
|
|
|
this.btnvideoloading = false;
|
|
|
|
|
this.isPollingStopped = true; // 标记轮询已停止
|
|
|
|
|
},
|
|
|
|
|
//获取装置是否下发状态
|
|
|
|
|
getTakePicStatus(data) {
|
|
|
|
|
console.log(data);
|
|
|
|
|
getTakePicStatusJoggle({
|
|
|
|
|
console.log(data);
|
|
|
|
|
return getTakePicStatusJoggle({
|
|
|
|
|
requestid: data.requestId,
|
|
|
|
|
termId: this.selectRow.termId,
|
|
|
|
|
photoTime: new Date(data.taketime).getTime(),
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
console.log(res);
|
|
|
|
|
//res.data 0 状态未知 1 成功 2失败
|
|
|
|
|
if (
|
|
|
|
|
res.data.cmaStatus == 0 &&
|
|
|
|
|
res.data.picStatus == false &&
|
|
|
|
|
this.statusNum >= 5
|
|
|
|
|
) {
|
|
|
|
|
this.statusNum = 0;
|
|
|
|
|
clearInterval(this.statusTimer);
|
|
|
|
|
this.statusTimer = null;
|
|
|
|
|
this.btnpicloading = false;
|
|
|
|
|
this.btnvideoloading = false;
|
|
|
|
|
this.$message({
|
|
|
|
|
duration: 1500,
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: "下发指令超时,请重试!",
|
|
|
|
|
type: "warning",
|
|
|
|
|
});
|
|
|
|
|
} else if (res.data.cmaStatus == 1 || res.data.picStatus == true) {
|
|
|
|
|
// res.data 0 状态未知 1 成功 2失败
|
|
|
|
|
if (res.data.cmaStatus === 1 || res.data.picStatus === true) {
|
|
|
|
|
this.stopPolling();
|
|
|
|
|
this.$message({
|
|
|
|
|
duration: 1500,
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: "下发指令成功!",
|
|
|
|
|
type: "success",
|
|
|
|
|
});
|
|
|
|
|
this.statusNum = 0;
|
|
|
|
|
clearInterval(this.statusTimer);
|
|
|
|
|
this.statusTimer = null;
|
|
|
|
|
this.timer = window.setInterval(() => {
|
|
|
|
|
this.newPicApi();
|
|
|
|
|
this.i++;
|
|
|
|
|
}, 8000);
|
|
|
|
|
} else if (res.data == 2) {
|
|
|
|
|
this.statusNum = 0;
|
|
|
|
|
clearInterval(this.statusTimer);
|
|
|
|
|
this.statusTimer = null;
|
|
|
|
|
return false; // 停止轮询
|
|
|
|
|
} else if (res.data.cmaStatus === 2) {
|
|
|
|
|
this.stopPolling();
|
|
|
|
|
this.$message({
|
|
|
|
|
duration: 1500,
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: "下发指令失败!",
|
|
|
|
|
type: "error",
|
|
|
|
|
});
|
|
|
|
|
return false; // 停止轮询
|
|
|
|
|
} else {
|
|
|
|
|
return true; // 继续轮询
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err); //代码错误、请求失败捕获
|
|
|
|
|
console.error("获取拍照状态失败:", err);
|
|
|
|
|
this.stopPolling();
|
|
|
|
|
return false; // 停止轮询
|
|
|
|
|
});
|
|
|
|
|
// getTakePicStatusJoggle({
|
|
|
|
|
// requestid: data.requestId,
|
|
|
|
|
// termId: this.selectRow.termId,
|
|
|
|
|
// photoTime: new Date(data.taketime).getTime(),
|
|
|
|
|
// })
|
|
|
|
|
// .then((res) => {
|
|
|
|
|
// console.log(res);
|
|
|
|
|
// //res.data 0 状态未知 1 成功 2失败
|
|
|
|
|
// if (
|
|
|
|
|
// res.data.cmaStatus == 0 &&
|
|
|
|
|
// res.data.picStatus == false &&
|
|
|
|
|
// this.statusNum >= 5
|
|
|
|
|
// ) {
|
|
|
|
|
// this.statusNum = 0;
|
|
|
|
|
// clearInterval(this.statusTimer);
|
|
|
|
|
// this.statusTimer = null;
|
|
|
|
|
// this.btnpicloading = false;
|
|
|
|
|
// this.btnvideoloading = false;
|
|
|
|
|
// this.$message({
|
|
|
|
|
// duration: 1500,
|
|
|
|
|
// showClose: true,
|
|
|
|
|
// message: "下发指令超时,请重试!",
|
|
|
|
|
// type: "warning",
|
|
|
|
|
// });
|
|
|
|
|
// } else if (res.data.cmaStatus == 1 || res.data.picStatus == true) {
|
|
|
|
|
// this.$message({
|
|
|
|
|
// duration: 1500,
|
|
|
|
|
// showClose: true,
|
|
|
|
|
// message: "下发指令成功!",
|
|
|
|
|
// type: "success",
|
|
|
|
|
// });
|
|
|
|
|
// this.statusNum = 0;
|
|
|
|
|
// clearInterval(this.statusTimer);
|
|
|
|
|
// this.statusTimer = null;
|
|
|
|
|
// this.timer = window.setInterval(() => {
|
|
|
|
|
// this.newPicApi();
|
|
|
|
|
// this.i++;
|
|
|
|
|
// }, 8000);
|
|
|
|
|
// } else if (res.data == 2) {
|
|
|
|
|
// this.statusNum = 0;
|
|
|
|
|
// clearInterval(this.statusTimer);
|
|
|
|
|
// this.statusTimer = null;
|
|
|
|
|
// this.$message({
|
|
|
|
|
// duration: 1500,
|
|
|
|
|
// showClose: true,
|
|
|
|
|
// message: "下发指令失败!",
|
|
|
|
|
// type: "error",
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .catch((err) => {
|
|
|
|
|
// console.log(err); //代码错误、请求失败捕获
|
|
|
|
|
// });
|
|
|
|
|
},
|
|
|
|
|
//获取最新图片
|
|
|
|
|
newPicApi() {
|
|
|
|
@ -997,6 +1097,25 @@ export default {
|
|
|
|
|
this.canvasloading = false;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
destroyed() {
|
|
|
|
|
if (this.pollingTimer !== null) {
|
|
|
|
|
clearTimeout(this.pollingTimer);
|
|
|
|
|
this.pollingTimer = null;
|
|
|
|
|
}
|
|
|
|
|
this.cancleFn = false;
|
|
|
|
|
//销毁左侧树状图
|
|
|
|
|
clearInterval(this.treetimer);
|
|
|
|
|
this.treetimer = null;
|
|
|
|
|
this.statusNum = 6;
|
|
|
|
|
//销毁主动拍照
|
|
|
|
|
clearInterval(this.statusTimer);
|
|
|
|
|
this.statusTimer = null;
|
|
|
|
|
if (this.timer) {
|
|
|
|
|
console.log(this.timer);
|
|
|
|
|
clearInterval(this.timer);
|
|
|
|
|
this.timer = null;
|
|
|
|
|
} //利用vue的生命周期函数
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="less">
|
|
|
|
|