licp
2024-12-23 8bfc9743f7f2c02c0e2c6de139dca17b2dde5cb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!--
 * @Author: licp lichunping@guanfang.com.cn
 * @Date: 2024-08-20 09:31:20
 * @LastEditors: licp lichunping@guanfang.com.cn
 * @LastEditTime: 2024-12-19 09:57:53
 * @FilePath: \tx-lims-before\src\view\timer.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<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 === 22 && 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>