feat: 优化首页性能

This commit is contained in:
hzm
2026-02-27 21:01:09 +08:00
parent c740999e90
commit 67ca3ce81d
2 changed files with 49 additions and 30 deletions

View File

@@ -0,0 +1,40 @@
'use client';
import { useEffect, useState } from "react";
import { RefreshIcon } from './Icons';
export default function RefreshButton({ refreshCycleStartRef, refreshMs, manualRefresh, refreshing, fundsLength }) {
// 刷新周期进度 0~1用于环形进度条
const [refreshProgress, setRefreshProgress] = useState(0);
// 刷新进度条:每 100ms 更新一次进度
useEffect(() => {
if (fundsLength === 0 || refreshMs <= 0) return;
const t = setInterval(() => {
const elapsed = Date.now() - refreshCycleStartRef.current;
const p = Math.min(1, elapsed / refreshMs);
setRefreshProgress(p);
}, 100);
return () => clearInterval(t);
}, [fundsLength, refreshMs]);
return (
<div
className="refresh-btn-wrap"
style={{ '--progress': refreshProgress }}
title={`刷新周期 ${Math.round(refreshMs / 1000)}`}
>
<button
className="icon-button"
aria-label="立即刷新"
onClick={manualRefresh}
disabled={refreshing || fundsLength === 0}
aria-busy={refreshing}
title="立即刷新"
>
<RefreshIcon className={refreshing ? 'spin' : ''} width="18" height="18" />
</button>
</div>
);
}

View File

@@ -36,6 +36,7 @@ import TradeModal from "./components/TradeModal";
import TransactionHistoryModal from "./components/TransactionHistoryModal";
import AddHistoryModal from "./components/AddHistoryModal";
import UpdatePromptModal from "./components/UpdatePromptModal";
import RefreshButton from "./components/RefreshButton";
import WeChatModal from "./components/WeChatModal";
import DcaModal from "./components/DcaModal";
import githubImg from "./assets/github.svg";
@@ -311,8 +312,6 @@ export default function HomePage() {
// 全局刷新状态
const [refreshing, setRefreshing] = useState(false);
// 刷新周期进度 0~1用于环形进度条
const [refreshProgress, setRefreshProgress] = useState(0);
// 收起/展开状态
const [collapsedCodes, setCollapsedCodes] = useState(new Set());
@@ -2134,17 +2133,6 @@ export default function HomePage() {
};
}, [funds, refreshMs]);
// 刷新进度条:每 100ms 更新一次进度
useEffect(() => {
if (funds.length === 0 || refreshMs <= 0) return;
const t = setInterval(() => {
const elapsed = Date.now() - refreshCycleStartRef.current;
const p = Math.min(1, elapsed / refreshMs);
setRefreshProgress(p);
}, 100);
return () => clearInterval(t);
}, [funds.length, refreshMs]);
const performSearch = async (val) => {
if (!val.trim()) {
setSearchResults([]);
@@ -3447,22 +3435,13 @@ export default function HomePage() {
</svg>
</button>
)}
<div
className="refresh-btn-wrap"
style={{ '--progress': refreshProgress }}
title={`刷新周期 ${Math.round(refreshMs / 1000)}`}
>
<button
className="icon-button"
aria-label="立即刷新"
onClick={manualRefresh}
disabled={refreshing || funds.length === 0}
aria-busy={refreshing}
title="立即刷新"
>
<RefreshIcon className={refreshing ? 'spin' : ''} width="18" height="18" />
</button>
</div>
<RefreshButton
refreshMs={refreshMs}
manualRefresh={manualRefresh}
refreshing={refreshing}
fundsLength={funds.length}
refreshCycleStartRef={refreshCycleStartRef}
/>
{/*<button*/}
{/* className="icon-button"*/}
{/* aria-label="打开设置"*/}