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
| <template>
| <div>
| <el-dialog
| title="提示"
| :visible.sync="dialogVisible"
| width="30%"
| :before-close="handleClose">
| <span>这是一段信息</span>
| <span slot="footer" class="dialog-footer">
| <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
| </span>
| </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("任务执行了!");
| // 这里可以触发一个 Vuex 动作、发起一个 HTTP 请求,或者其他操作
| },
| promptToClose() {
| // 提示用户关闭
| alert("请记得在20分钟后关闭任务!");
| }
| },
| beforeDestroy() {
| // 组件销毁时清除定时器
| if (this.timer) {
| clearInterval(this.timer);
| }
| if (this.closeTimeout) {
| clearTimeout(this.closeTimeout);
| }
| }
| }
| </script>
|
| <style scoped>
|
| </style>
|
|