lxp
2024-08-07 083bc1030f7dda031f04976c7f02109d31eeff0e
src/view/timer.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,72 @@
<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>