修复 时光胶囊显示错误 #101

This commit is contained in:
imsyy 2023-03-10 15:51:18 +08:00
parent 7adf606935
commit faeb0b98fc
2 changed files with 146 additions and 124 deletions

View File

@ -9,7 +9,7 @@
<span>时光胶囊</span> <span>时光胶囊</span>
</div> </div>
<span class="text" <span class="text"
>今日已经度过了&nbsp;{{ timeData.day.start }}&nbsp;小时</span >今日已经度过了&nbsp;{{ timeData.day.elapsed }}&nbsp;小时</span
> >
<el-progress <el-progress
:text-inside="true" :text-inside="true"
@ -17,7 +17,7 @@
:percentage="timeData.day.pass" :percentage="timeData.day.pass"
/> />
<span class="text" <span class="text"
>本周已经度过了&nbsp;{{ timeData.week.start }}&nbsp;</span >本周已经度过了&nbsp;{{ timeData.week.elapsed }}&nbsp;</span
> >
<el-progress <el-progress
:text-inside="true" :text-inside="true"
@ -25,7 +25,7 @@
:percentage="timeData.week.pass" :percentage="timeData.week.pass"
/> />
<span class="text" <span class="text"
>本月已经度过了&nbsp;{{ timeData.month.start }}&nbsp;</span >本月已经度过了&nbsp;{{ timeData.month.elapsed }}&nbsp;</span
> >
<el-progress <el-progress
:text-inside="true" :text-inside="true"
@ -33,7 +33,7 @@
:percentage="timeData.month.pass" :percentage="timeData.month.pass"
/> />
<span class="text" <span class="text"
>今年已经度过了&nbsp;{{ timeData.year.start }}&nbsp;个月</span >今年已经度过了&nbsp;{{ timeData.year.elapsed }}&nbsp;个月</span
> >
<el-progress <el-progress
:text-inside="true" :text-inside="true"
@ -101,4 +101,4 @@ onBeforeUnmount(() => {
font-size: 0.95rem; font-size: 0.95rem;
} }
} }
</style> </style>

View File

@ -1,134 +1,156 @@
import { import { h } from "vue";
h import { SpaCandle } from "@icon-park/vue-next";
} from "vue";
import {
SpaCandle
} from "@icon-park/vue-next";
// 时钟 // 时钟
export const getCurrentTime = () => { export const getCurrentTime = () => {
let time = new Date(); let time = new Date();
let year = time.getFullYear(); let year = time.getFullYear();
let month = time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1; let month =
let day = time.getDate() < 10 ? '0' + time.getDate() : time.getDate(); time.getMonth() + 1 < 10
let hour = time.getHours() < 10 ? '0' + time.getHours() : time.getHours(); ? "0" + (time.getMonth() + 1)
let minute = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes(); : time.getMonth() + 1;
let second = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds(); let day = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
let weekday = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; let hour = time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
let currentTime = { let minute =
year, time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
month, let second =
day, time.getSeconds() < 10 ? "0" + time.getSeconds() : time.getSeconds();
hour, let weekday = [
minute, "星期日",
second, "星期一",
weekday: weekday[time.getDay()], "星期二",
} "星期三",
return currentTime; "星期四",
} "星期五",
"星期六",
];
let currentTime = {
year,
month,
day,
hour,
minute,
second,
weekday: weekday[time.getDay()],
};
return currentTime;
};
// 时光胶囊 // 时光胶囊
export const getTimeCapsule = () => { export const getTimeCapsule = () => {
// 日进度 // 日进度
let todayStartDate = new Date(new Date().toLocaleDateString()).getTime(); const todayStartDate = new Date(new Date().toLocaleDateString()).getTime();
let todayPassHours = (new Date() - todayStartDate) / 1000 / 60 / 60; const todayPassHours = (new Date() - todayStartDate) / 1000 / 60 / 60;
let todayPassHoursPercent = (todayPassHours / 24) * 100; const todayPassHoursPercent = (todayPassHours / 24) * 100;
// 周进度
let weeks = [7, 1, 2, 3, 4, 5, 6]; // 周进度
let weekDay = weeks[new Date().getDay()]; const weeks = [7, 1, 2, 3, 4, 5, 6];
let weekDayPassPercent = (weekDay / 7) * 100; const weekDay = weeks[new Date().getDay()];
// 月进度 const weekDayPassPercent = (weekDay / 7) * 100;
let year = new Date().getFullYear();
let date = new Date().getDate(); // 月进度
let month = new Date().getMonth() + 1; const year = new Date().getFullYear();
let monthAll = new Date(year, month, 0).getDate(); const date = new Date().getDate();
let monthPassPercent = (date / monthAll) * 100; const month = new Date().getMonth() + 1;
// 年进度 const monthAll = new Date(year, month, 0).getDate();
let yearPass = (month / 12) * 100; const monthPassPercent = (date / monthAll) * 100;
return {
day: { // 年进度
start: parseInt(todayPassHours), const yearStartDate = new Date(year, 0, 1).getTime();
pass: parseInt(todayPassHoursPercent), const yearEndDate = new Date(year + 1, 0, 1).getTime();
}, const yearPassHours = (new Date() - yearStartDate) / 1000 / 60 / 60;
week: { const yearTotalHours = (yearEndDate - yearStartDate) / 1000 / 60 / 60;
start: weekDay, const yearPassPercent = (yearPassHours / yearTotalHours) * 100;
pass: parseInt(weekDayPassPercent),
}, return {
month: { day: {
start: date, elapsed: Math.floor(todayPassHours),
pass: parseInt(monthPassPercent), pass: Math.floor(todayPassHoursPercent),
}, },
year: { week: {
start: month == 0 ? month : month - 1, elapsed: weekDay,
pass: parseInt(yearPass), pass: Math.floor(weekDayPassPercent),
} },
} month: {
} elapsed: date,
pass: Math.floor(monthPassPercent),
},
year: {
elapsed: month - 1,
pass: Math.floor(yearPassPercent),
},
};
};
// 欢迎提示 // 欢迎提示
export const helloInit = () => { export const helloInit = () => {
let hour = new Date().getHours(); const hour = new Date().getHours();
let hello = null; let hello = null;
if (hour < 6) { if (hour < 6) {
hello = "凌晨好"; hello = "凌晨好";
} else if (hour < 9) { } else if (hour < 9) {
hello = "早上好"; hello = "早上好";
} else if (hour < 12) { } else if (hour < 12) {
hello = "上午好"; hello = "上午好";
} else if (hour < 14) { } else if (hour < 14) {
hello = "中午好"; hello = "中午好";
} else if (hour < 17) { } else if (hour < 17) {
hello = "下午好"; hello = "下午好";
} else if (hour < 19) { } else if (hour < 19) {
hello = "傍晚好"; hello = "傍晚好";
} else if (hour < 22) { } else if (hour < 22) {
hello = "晚上好"; hello = "晚上好";
} else { } else {
hello = "夜深了"; hello = "夜深了";
} }
ElMessage({ ElMessage({
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,
message: `<strong>${hello}</strong> 欢迎来到我的主页`, message: `<strong>${hello}</strong> 欢迎来到我的主页`,
}); });
} };
// 默哀模式 // 默哀模式
const anniversaries = {
4.4: "清明节",
5.12: "汶川大地震纪念日",
7.7: "中国人民抗日战争纪念日",
9.18: "九·一八事变纪念日",
12.13: "南京大屠杀死难者国家公祭日",
};
export const checkDays = () => { export const checkDays = () => {
let myDate = new Date; const myDate = new Date();
let mon = myDate.getMonth() + 1; const mon = myDate.getMonth() + 1;
let date = myDate.getDate(); const date = myDate.getDate();
let days = ['4.4', '5.12', '7.7', '9.9', '9.18', '12.13']; const key = `${mon}.${date}`;
for (let day of days) { if (anniversaries.hasOwnProperty(key)) {
let d = day.split('.'); console.log(`今天是${anniversaries[key]}`);
if (mon == d[0] && date == d[1]) { const gray = document.createElement("style");
console.log("今天是纪念日"); gray.innerHTML = "html{filter: grayscale(100%)}";
let gray = document.createElement("style"); document.head.appendChild(gray);
document.body.appendChild(gray); ElMessage({
gray.innerHTML = "html{-webkit-filter:grayscale(100%);-moz-filter:grayscale(100%);-ms-filter:grayscale(100%);-o-filter:grayscale(100%);filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);_filter:none}"; message: `今天是${anniversaries[key]}`,
ElMessage({ duration: 14000,
message: "今天是中国国家纪念日", icon: h(SpaCandle, { theme: "filled", fill: "#efefef" }),
duration: 14000, });
icon: h(SpaCandle, { }
theme: "filled", };
fill: "#efefef",
}),
});
}
}
}
// 建站日期统计 // 建站日期统计
export const siteDateStatistics = (startDate) => { export const siteDateStatistics = (startDate) => {
const currentDate = new Date(); const currentDate = new Date();
const differenceInTime = currentDate.getTime() - startDate.getTime(); const differenceInTime = currentDate.getTime() - startDate.getTime();
const differenceInDays = differenceInTime / (1000 * 3600 * 24); const differenceInDays = differenceInTime / (1000 * 3600 * 24);
const differenceInMonths = differenceInDays / 30; const differenceInMonths = differenceInDays / 30;
const differenceInYears = differenceInMonths / 12; const differenceInYears = differenceInMonths / 12;
if (differenceInYears >= 1) { if (differenceInYears >= 1) {
return `本站已经苟活了 ${Math.floor(differenceInYears)}${Math.floor(differenceInMonths % 12)}${Math.round(differenceInDays % 30)}`; return `本站已经苟活了 ${Math.floor(differenceInYears)}${Math.floor(
} else if (differenceInMonths >= 1) { differenceInMonths % 12
return `本站已经苟活了 ${Math.floor(differenceInMonths)}${Math.round(differenceInDays % 30)}`; )} ${Math.round(differenceInDays % 30)} `;
} else { } else if (differenceInMonths >= 1) {
return `本站已经苟活了 ${Math.round(differenceInDays)}`; return `本站已经苟活了 ${Math.floor(differenceInMonths)}${Math.round(
} differenceInDays % 30
} )} `;
} else {
return `本站已经苟活了 ${Math.round(differenceInDays)}`;
}
};