main
fwb 3 months ago
parent 2b7075db80
commit 217a087d64
  1. BIN
      public/year.mp4
  2. 2
      src/App.vue
  3. 74
      src/views/calendar/component/CountDown.vue
  4. 55
      src/views/calendar/index.vue

Binary file not shown.

@ -2,7 +2,7 @@
<index/>
</template>
<script setup lang="ts">
import Index from "@/views/ref-parent/index.vue";
import Index from "@/views/calendar/index.vue";
</script>
<style scoped>

@ -0,0 +1,74 @@
<template>
<div class="countdown">
<h2 v-if="targetTime">距离除夕还剩:</h2>
<div v-if="targetTime">
<span>{{ days }}</span>
<span>{{ hours }}</span> 小时
<span>{{ minutes }}</span> 分钟
<span>{{ seconds }}</span>
</div>
<div v-else>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, onUnmounted,watch } from 'vue';
const props = defineProps({
targetTime: {
type: String,
required: true
}
});
let intervalId;
const days = ref(0);
const hours = ref(0);
const minutes = ref(0);
const seconds = ref(0);
const calculateTimeLeft = () => {
if (!props.targetTime) return;
const now = new Date().getTime();
const target = new Date(props.targetTime).getTime();
const difference = target - now;
if (difference > 0) {
days.value = Math.floor(difference / (1000 * 60 * 60 * 24));
hours.value = Math.floor((difference / (1000 * 60 * 60)) % 24);
minutes.value = Math.floor((difference / 1000 / 60) % 60);
seconds.value = Math.floor((difference / 1000) % 60);
} else {
days.value = 0;
hours.value = 0;
minutes.value = 0;
seconds.value = 0;
clearInterval(intervalId); //
}
};
onMounted(() => {
calculateTimeLeft(); //
intervalId = setInterval(calculateTimeLeft, 1000); //
});
onUnmounted(() => {
clearInterval(intervalId); //
});
watch(() => props.targetTime, () => {
calculateTimeLeft(); //
});
</script>
<style scoped>
.countdown {
background-image: linear-gradient(60deg,lightgrey,white,darkslateblue);
width: 370px;
height: 140px;
text-align: center;
font-size: 2rem;
}
</style>

@ -0,0 +1,55 @@
<template>
<div class="box">
<video autoplay loop muted playsinline class="background-video">
<source src="../../../public/year.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<el-date-picker
v-model="targetTime"
type="date"
placeholder="请选择一个时间"
size="large"
style="width: 100%;margin-bottom: 20px"
/>
<hr>
<CountDown :targetTime="formattedTargetTime" />
</div>
</template>
<script setup>
import {ref,computed,onMounted} from 'vue'
// import {Calendar} from "@element-plus/icons-vue";
import CountDown from "./component/CountDown.vue";
//
const targetTime = ref();
// //
// onMounted(() => {
// targetTime.value = new Date();
// });
// ISO
const formattedTargetTime = computed(() => {
return targetTime.value ? targetTime.value.toISOString() : null;
});
</script>
<style>
.box{
position: absolute;
text-align: center;
color: #2c3e50;
margin-top: -400px;
margin-left: -200px;
/*background-image: linear-gradient(60deg,powderblue,pink,purple);*/
padding: 10px;
height:700px;
overflow: hidden;
}
.background-video {
position: absolute;
top: 0;
left: 0;
height:700px;
object-fit: cover;
z-index: -1;
}
</style>
Loading…
Cancel
Save