fix: index time set
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<view class="hero">
|
<view class="hero">
|
||||||
<view class="hero-badge">
|
<view class="hero-badge">
|
||||||
<text class="badge-dot">•</text>
|
<text class="badge-dot">•</text>
|
||||||
<text class="badge-text">距春节还有 30 天</text>
|
<text class="badge-text">{{ countdownText }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="hero-title">
|
<view class="hero-title">
|
||||||
<text class="year">2026</text>
|
<text class="year">2026</text>
|
||||||
@@ -77,10 +77,48 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
import { onPullDownRefresh, onShareAppMessage } from "@dcloudio/uni-app";
|
import { onPullDownRefresh, onShareAppMessage } from "@dcloudio/uni-app";
|
||||||
import { getBavBarHeight } from "@/utils/system";
|
import { getBavBarHeight } from "@/utils/system";
|
||||||
|
|
||||||
|
const countdownText = ref("");
|
||||||
|
|
||||||
|
const updateCountdown = () => {
|
||||||
|
const now = new Date();
|
||||||
|
const springFestival = new Date("2026-02-17T00:00:00"); // 2026春节
|
||||||
|
|
||||||
|
// 只比较日期,忽略时分秒
|
||||||
|
now.setHours(0, 0, 0, 0);
|
||||||
|
springFestival.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const diffTime = now.getTime() - springFestival.getTime();
|
||||||
|
const days = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
|
if (days < 0) {
|
||||||
|
countdownText.value = `距春节还有 ${Math.abs(days)} 天`;
|
||||||
|
} else if (days === 0) {
|
||||||
|
countdownText.value = "大年初一";
|
||||||
|
} else {
|
||||||
|
const cnNums = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"];
|
||||||
|
if (days < 10) {
|
||||||
|
countdownText.value = `大年初${cnNums[days]}`;
|
||||||
|
} else if (days < 15) {
|
||||||
|
const sub = days + 1 - 10;
|
||||||
|
const subCn = ["一", "二", "三", "四", "五"][sub - 1];
|
||||||
|
countdownText.value = `正月十${subCn}`;
|
||||||
|
} else if (days === 14) {
|
||||||
|
// days=14是第15天
|
||||||
|
countdownText.value = "元宵节";
|
||||||
|
} else {
|
||||||
|
countdownText.value = "蛇年大吉";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
updateCountdown();
|
||||||
|
});
|
||||||
|
|
||||||
const features = ref([
|
const features = ref([
|
||||||
{
|
{
|
||||||
title: "新春祝福卡片",
|
title: "新春祝福卡片",
|
||||||
|
|||||||
Reference in New Issue
Block a user