aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/site/src/components/Left.vue
blob: 672ba363ee9fef739521cadb038217bd9cde45c8 (plain) (blame)
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
81
82
83
84
<script lang="ts">
export default {
  data(){
    return{
      day:0,
      hour:0,
      min:0,
      sec:0,
      timer:0
    }
  },
  props:{
    msg:{
      type:String,
      require:true
    },
    date:{
      type:Date,
      default:new Date('2024-07-14T12:00:00Z')
    }
  },
  methods:{
    getTime(){
      this.timer=window.setTimeout(()=>{
        const date1 = new Date();
        const date2 = new Date(this.date);
        const timeDiff = Math.abs(date2.getTime() - date1.getTime());
        this.day = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
        this.hour = Math.floor(timeDiff / (1000 * 60 * 60)%24);
        this.min = Math.floor((timeDiff / (1000 * 60)) % 60);
        this.sec = Math.floor((timeDiff / 1000) % 60);
        this.getTime()
      },1000)
    }
  },
  beforeMount() {
    this.getTime()
  }

}
</script>

<template>
  <div class="greetings">
    <h1 class="green">{{ msg }}</h1>
    <h3>
      距离水系公测还有
    </h3>
    <h2>
      {{ day }} 天 {{ hour }} 时 {{ min }} 分 {{ sec }} 秒
    </h2>
  </div>
</template>

<style scoped>
h1 {
  font-weight: 500;
  font-size: 2.6rem;
  position: relative;
  top: -10px;
}

h3 {
  font-size: 1.2rem;
}

.greetings h1,
.greetings h2 {
  text-align: center;
}
.greetings h3 {
  text-align: center;
}

@media (min-width: 1024px) {
  .greetings h1,
  .greetings h2 {
    text-align: left;
  }
  .greetings h3 {
    text-align: left;
  }
}
</style>