<template>
|
<div>
|
<el-dialog
|
title="提示"
|
:visible.sync="dialogVisible"
|
:close-on-click-modal="false"
|
:close-on-press-escape="false"
|
:show-close="false"
|
width="30%">
|
<div style="display: flex;align-items: center;"><i class="el-icon-warning" style="color: red;font-size: 40px;margin-right: 20px;"></i><span>代码正在部署,请30分钟后重新进入系统!</span></div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
export default {
|
data(){
|
return{
|
timer:null,
|
closeTimeout:null,
|
dialogVisible:false,
|
}
|
},
|
mounted() {
|
this.startScheduler();
|
},
|
methods: {
|
startScheduler() {
|
this.checkTime();
|
// 每分钟检查一次
|
this.timer = setInterval(this.checkTime, 60 * 1000);
|
},
|
checkTime() {
|
const now = new Date();
|
const hours = now.getHours();
|
const minutes = now.getMinutes();
|
|
if (hours === 20 && minutes === 0) {
|
this.performTask();
|
// 设置20分钟后提示关闭
|
this.closeTimeout = setTimeout(() => {
|
this.promptToClose();
|
}, 20 * 60 * 1000); // 20分钟
|
}
|
},
|
performTask() {
|
// 在这里执行你想要的定时任务
|
console.log("任务执行了!");
|
this.dialogVisible = true;
|
// 这里可以触发一个 Vuex 动作、发起一个 HTTP 请求,或者其他操作
|
},
|
promptToClose() {
|
// 提示用户关闭
|
// alert("请记得在20分钟后关闭任务!");
|
this.dialogVisible = true;
|
}
|
},
|
beforeDestroy() {
|
// 组件销毁时清除定时器
|
if (this.timer) {
|
clearInterval(this.timer);
|
}
|
if (this.closeTimeout) {
|
clearTimeout(this.closeTimeout);
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|