feat:完善版本更新检查逻辑

This commit is contained in:
hzm
2026-02-07 16:03:33 +08:00
parent 374b34fcf5
commit 8a62e7383d

View File

@@ -1856,12 +1856,12 @@ export default function HomePage() {
// 检查更新 // 检查更新
const [hasUpdate, setHasUpdate] = useState(false); const [hasUpdate, setHasUpdate] = useState(false);
const [latestVersion, setLatestVersion] = useState(''); const [latestVersion, setLatestVersion] = useState('');
const [updateContent, setUpdateContent] = useState('');
useEffect(() => { useEffect(() => {
const checkUpdate = async () => { const checkUpdate = async () => {
try { try {
const res = await fetch('https://api.github.com/repos/hzm0321/real-time-fund/releases/latest'); const res = await fetch('https://api.github.com/repos/hzm0321/real-time-fund/releases/latest');
console.log(packageJson.version)
if (!res.ok) return; if (!res.ok) return;
const data = await res.json(); const data = await res.json();
if (data.tag_name) { if (data.tag_name) {
@@ -1869,6 +1869,7 @@ export default function HomePage() {
if (remoteVersion !== packageJson.version) { if (remoteVersion !== packageJson.version) {
setHasUpdate(true); setHasUpdate(true);
setLatestVersion(remoteVersion); setLatestVersion(remoteVersion);
setUpdateContent(data.body || '');
} }
} }
} catch (e) { } catch (e) {
@@ -3579,10 +3580,9 @@ export default function HomePage() {
<span>基估宝</span> <span>基估宝</span>
</div> </div>
<div className="actions"> <div className="actions">
<img alt="项目Github地址" src={githubImg.src} style={{ width: '30px', height: '30px', cursor: 'pointer' }} onClick={() => window.open("https://github.com/hzm0321/real-time-fund")} />
{hasUpdate && ( {hasUpdate && (
<div <div
className="badge" className="badge"
title={`发现新版本 ${latestVersion},点击前往下载`} title={`发现新版本 ${latestVersion},点击前往下载`}
style={{ cursor: 'pointer', borderColor: 'var(--success)', color: 'var(--success)' }} style={{ cursor: 'pointer', borderColor: 'var(--success)', color: 'var(--success)' }}
onClick={() => setUpdateModalOpen(true)} onClick={() => setUpdateModalOpen(true)}
@@ -3590,6 +3590,7 @@ export default function HomePage() {
<UpdateIcon width="14" height="14" /> <UpdateIcon width="14" height="14" />
</div> </div>
)} )}
<img alt="项目Github地址" src={githubImg.src} style={{ width: '30px', height: '30px', cursor: 'pointer' }} onClick={() => window.open("https://github.com/hzm0321/real-time-fund")} />
<div className="badge" title="当前刷新频率"> <div className="badge" title="当前刷新频率">
<span>刷新</span> <span>刷新</span>
<strong>{Math.round(refreshMs / 1000)}</strong> <strong>{Math.round(refreshMs / 1000)}</strong>
@@ -4837,9 +4838,28 @@ export default function HomePage() {
<UpdateIcon width="20" height="20" style={{color: 'var(--success)'}} /> <UpdateIcon width="20" height="20" style={{color: 'var(--success)'}} />
<span>更新提示</span> <span>更新提示</span>
</div> </div>
<p className="muted" style={{ marginBottom: 24, fontSize: '14px', lineHeight: '1.6' }}> <div style={{ marginBottom: 24 }}>
检测到新版本是否刷新浏览器以更新 <p className="muted" style={{ fontSize: '14px', lineHeight: '1.6', marginBottom: 12 }}>
</p> 检测到新版本是否刷新浏览器以更新
<br/>
更新内容如下
</p>
{updateContent && (
<div style={{
background: 'rgba(0,0,0,0.2)',
padding: '12px',
borderRadius: '8px',
fontSize: '13px',
lineHeight: '1.5',
maxHeight: '200px',
overflowY: 'auto',
whiteSpace: 'pre-wrap',
border: '1px solid rgba(255,255,255,0.1)'
}}>
{updateContent}
</div>
)}
</div>
<div className="row" style={{ gap: 12 }}> <div className="row" style={{ gap: 12 }}>
<button <button
className="button secondary" className="button secondary"