Files
katelyatv/src/components/HubNotice.tsx
T
3970260761 54fdea4f84
Docker Build & Test / build (push) Canceled after 0s
Docker Build & Test / test (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/amd64) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm/v7) (push) Canceled after 0s
Build & Push Docker image / build-and-push (linux/arm64) (push) Canceled after 0s
Build & Push Docker image / merge-images (push) Canceled after 0s
Release / release (push) Canceled after 0s
Release / docker (push) Canceled after 0s
fixed73: 通知切授权公告+右上角版本号全页显示
- 首页旧公告弹窗彻底拆除(page.tsx: 删JSX/useSite/showAnnouncement/handleCloseAnnouncement残留)
- layout授权覆盖顺序修复: 先getConfig再hub.getNotice覆盖, 授权公告优先
- HubBell只发open-hub-notice事件, 不再清hasSeenAnnouncement/跳首页
- HubNotice支持铃铛手动打开: 公告/首条/版本兜底, 空指针修复
- 版本号三处补齐: TopRightButtons bar+float, MobileHeader移动端, 对齐fixed73
2026-11-08 00:19:48 +08:00

143 lines
4.9 KiB
TypeScript

'use client';
import { useEffect, useState } from 'react';
interface LicenseData {
version: string;
latest: string;
update_available: boolean;
changelog: string;
announcement: { id: number; title: string; content: string } | null;
}
export default function HubNotice() {
const [data, setData] = useState<LicenseData | null>(null);
const [visible, setVisible] = useState(false);
const [mode, setMode] = useState<'ann' | 'upd'>('ann');
useEffect(() => {
const openHandler = () => {
// 铃铛手动打开:有授权公告就显示公告,无公告则显示版本信息兜底
fetch('/api/license-config', { cache: 'no-store' })
.then((r) => r.json())
.then((j) => {
if (!j || j.code !== 200 || !j.data) return;
const d = j.data as LicenseData;
setData(d);
if (d.announcement) {
setMode('ann');
setVisible(true);
} else if (Array.isArray((d as any).announcements) && (d as any).announcements.length) {
const first = (d as any).announcements[0];
setData({ ...d, announcement: first });
setMode('ann');
setVisible(true);
} else {
setMode('upd');
setVisible(true);
}
})
.catch(() => {});
};
window.addEventListener('open-hub-notice', openHandler);
const t = setTimeout(() => {
fetch('/api/license-config', { cache: 'no-store' })
.then((r) => r.json())
.then((j) => {
if (!j || j.code !== 200 || !j.data) return;
const d = j.data as LicenseData;
setData(d);
let ann = null;
try {
const seen = JSON.parse(localStorage.getItem('hub_seen') || '{}');
if (d.announcement && !seen['a' + d.announcement.id]) ann = d.announcement;
} catch {}
let upd = null;
try {
upd =
d.update_available &&
localStorage.getItem('hub_ver_dismiss') !== String(d.latest || '')
? d
: null;
} catch {}
if (!ann && !upd) return;
setMode(ann ? 'ann' : 'upd');
setVisible(true);
})
.catch(() => {});
}, 1500);
return () => {
clearTimeout(t);
window.removeEventListener('open-hub-notice', openHandler);
};
}, []);
if (!visible || !data) return null;
const title =
mode === 'ann' && data.announcement
? String(data.announcement.title || '📢 公告')
: data.latest
? '发现新版本 v' + String(data.latest || '')
: '米视TV v' + String(data.version || '');
const body =
mode === 'ann' && data.announcement
? String(data.announcement.content || '')
: String(data.changelog || '当前已是最新版本,暂无授权中心公告。').slice(0, 600);
const close = (dismissVer = false) => {
try {
if (mode === 'ann' && data.announcement) {
const s = JSON.parse(localStorage.getItem('hub_seen') || '{}');
s['a' + data.announcement.id] = 1;
localStorage.setItem('hub_seen', JSON.stringify(s));
}
if (dismissVer && mode === 'upd') {
localStorage.setItem('hub_ver_dismiss', String(data.latest || ''));
}
} catch {}
setVisible(false);
};
return (
<div
className='fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 p-4'
style={{ backdropFilter: 'blur(4px)' }}
>
<div className='bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full max-h-[80vh] flex flex-col overflow-hidden'>
<div className='flex items-center justify-between px-6 pt-5 pb-3'>
<h3 className='text-base font-bold text-gray-900 dark:text-gray-100 truncate mr-2'>
{title}
</h3>
<button
className='text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-lg leading-none flex-shrink-0'
onClick={() => close(true)}
>
✕
</button>
</div>
<div className='px-6 pb-2 overflow-y-auto text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap'>
{body}
<div className='mt-3 text-xs text-gray-400 dark:text-gray-500'>
当前版本 v{String(data.version || '')}
</div>
</div>
<div className='px-6 py-4 bg-gray-50 dark:bg-gray-700/50 flex items-center justify-end gap-2'>
<button
className='px-3 py-1.5 rounded-lg text-xs font-medium text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600'
onClick={() => close(false)}
>
我知道了
</button>
<button
className='px-3 py-1.5 rounded-lg text-xs font-medium text-purple-600 dark:text-purple-400 hover:bg-purple-500/10'
onClick={() => close(true)}
>
不再提醒
</button>
</div>
</div>
</div>
);
}