import { useCallback, useEffect, useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import PullToRefresh from '@dukang/shared-ui/PullToRefresh'; import { request } from '../lib/api'; function formatMoney(n: number) { return n.toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 2 }); } export default function HomePage() { const navigate = useNavigate(); const [dash, setDash] = useState | null>(null); const [open, setOpen] = useState(true); const loadDashboard = useCallback(() => { return request>('SHOP_H5', '/shop/dashboard') .then((d) => { setDash(d); setOpen(String((d.store as Record)?.status) === 'OPEN'); }) .catch(() => {}); }, []); useEffect(() => { void loadDashboard(); }, [loadDashboard]); useEffect(() => { function onResume() { void loadDashboard(); } function onVisibility() { if (document.visibilityState === 'visible') onResume(); } document.addEventListener('visibilitychange', onVisibility); window.addEventListener('pageshow', onResume); window.addEventListener('focus', onResume); return () => { document.removeEventListener('visibilitychange', onVisibility); window.removeEventListener('pageshow', onResume); window.removeEventListener('focus', onResume); }; }, [loadDashboard]); const store = dash?.store as Record | undefined; const recent = (dash?.recentRecords as Array>) || []; const status = String(store?.status || ''); const open = status === 'OPEN'; const hoursParts: string[] = []; if (store?.openTime && store?.closeTime) hoursParts.push(`${store.openTime} - ${store.closeTime}`); if (store?.openTime2 && store?.closeTime2) hoursParts.push(`${store.openTime2} - ${store.closeTime2}`); const hoursText = hoursParts.length ? hoursParts.join(',') : '10:00 - 22:00'; const statusText = status === 'CLOSED' ? '永久关闭' : open ? '当前正在营业中' : '当前临时闭店'; return (

门店管理中心

store

{String(store?.name || '门店')}

今日核销笔数

{Number(dash?.todayCount || 0)}

今日到账金额

¥ {formatMoney(Number(dash?.todayAmount || 0))}

smartphone

手机号核销

schedule

营业状态

{statusText}

营业时间: {hoursText}

核销记录

查看全部 chevron_right
{recent.length === 0 && (

暂无核销记录

)} {recent.map((r) => (

核销时间

{new Date(String(r.createdAt)).toLocaleString('zh-CN')}

¥{formatMoney(Number(r.amount))}

))}
); }