mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-05-09 23:35:17 +08:00
在侧边栏组件中引入运行时间组件,增强页面信息展示,确保用户能够获取站点运行状态。
This commit is contained in:
1
src/assets/svg/other/timer.svg
Normal file
1
src/assets/svg/other/timer.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg t="1747738301352" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8137" width="200" height="200"><path d="M734.485 637.566l-96.168-95.326c-22.612-22.414 0-45.538 0-45.538l103.17-102.268c70.032-69.419 67.162-170.563 67.162-170.563l0.016-131.26L511.999 67 215.334 92.611l0.016 131.26s-2.871 101.144 67.162 170.563l103.17 102.268s22.612 23.124 0 45.538l-96.168 95.326s-74.161 72.923-74.161 189.243c0 116.318-0.016 130.19-0.016 130.19h593.33s-0.018-13.873-0.018-130.19c-0.002-116.319-74.164-189.243-74.164-189.243z" fill="#889FFF" p-id="8138"></path><path d="M368.293 804.902h287.411l-127.74-117.637-0.002-147.045c-0.256-34.087 14.715-55.622 21.475-62.528l66.63-66.042c23.268-23.059 23.675-60.251 23.693-60.411H384.231c-0.009 0.356 0.826 37.738 23.693 60.411l67.353 66.769c6.042 6.18 21.505 27.715 21.248 61.801l-0.4 146.958-127.832 117.724z" fill="#FFFFFF" p-id="8139"></path></svg>
|
||||
|
After Width: | Height: | Size: 928 B |
41
src/components/Sidebar/RunTime/index.tsx
Normal file
41
src/components/Sidebar/RunTime/index.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from 'react';
|
||||
import Image from 'next/image';
|
||||
import Timer from '@/assets/svg/other/timer.svg';
|
||||
|
||||
export default () => {
|
||||
const [time, setTime] = useState(1547647320000);
|
||||
|
||||
const calculateTimeDifference = (startTimestamp: number) => {
|
||||
const startDate = new Date(startTimestamp);
|
||||
const currentDate = new Date();
|
||||
|
||||
let years = currentDate.getFullYear() - startDate.getFullYear();
|
||||
let months = currentDate.getMonth() - startDate.getMonth();
|
||||
let days = currentDate.getDate() - startDate.getDate();
|
||||
|
||||
// 处理月份和天数的进位
|
||||
if (days < 0) {
|
||||
const lastMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);
|
||||
days += lastMonth.getDate();
|
||||
months--;
|
||||
}
|
||||
if (months < 0) {
|
||||
months += 12;
|
||||
years--;
|
||||
}
|
||||
|
||||
return `${years}年 ${months}个月 ${days}天`;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col tw_container bg-white dark:bg-black-b p-4 mb-5 tw_title">
|
||||
<div className="tw_title w-full dark:text-white">
|
||||
<Image src={Timer} alt="站点运行时间" width={33} height={23} /> 站点运行时间
|
||||
</div>
|
||||
|
||||
<div className="mt-2.5">{calculateTimeDifference(time)}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import Author from "./Author"
|
||||
import HotArticle from "./HotArticle"
|
||||
import RandomArticle from "./RandomArticle"
|
||||
import Comment from "./Comment"
|
||||
import RunTime from "./RunTime"
|
||||
import { getConfigDataAPI } from '@/api/project'
|
||||
import { Theme } from "@/types/app/project"
|
||||
|
||||
@@ -14,6 +15,9 @@ export default async () => {
|
||||
<div className={`hidden lg:block ${sidebar.length ? 'lg:w-[29%] xl:w-[24%]' : 'w-0'} rounded-md transition-width sticky top-[70px]`}>
|
||||
{/* 作者介绍 */}
|
||||
{sidebar.includes("author") && <Author/>}
|
||||
{/* 站点已运行 */}
|
||||
{/* {sidebar.includes("runTime") && <RunTime/>} */}
|
||||
<RunTime/>
|
||||
{/* 随机推荐 */}
|
||||
{sidebar.includes("randomArticle") && <RandomArticle/>}
|
||||
{/* 热门文章 */}
|
||||
|
||||
Reference in New Issue
Block a user