import { useState } from 'react' import { useQuery } from '@tanstack/react-query' import { FileText, AlertCircle, Check, RefreshCw, Calendar, Briefcase, Clock } from 'lucide-react' import api from '../../lib/api' import Card from '../../components/ui/Card' import Button from '../../components/ui/Button' import EmptyState from '../../components/ui/EmptyState' /** 金额格式化:保留两位小数 + 千分位 */ const fmt = (n: number) => (n || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) const portalApi = api.create({ baseURL: '/api/v1/portal' }) portalApi.interceptors.request.use((config: any) => { const token = localStorage.getItem('portalToken') if (token) config.headers.Authorization = `Bearer ${token}` return config }) export default function MyContract() { const [resending, setResending] = useState(false) const [resendMsg, setResendMsg] = useState('') const { data, isLoading } = useQuery({ queryKey: ['my-contract'], queryFn: async () => { const res = await portalApi.get('/contract') as any return res.data?.data ?? null }, }) const contract = data const daysToExpire = contract?.endDate ? Math.floor((new Date(contract.endDate).getTime() - Date.now()) / (1000 * 60 * 60 * 24)) : null const isConfirmed = contract?.attachmentName?.startsWith('confirmed:') const handleResend = async () => { setResending(true) setResendMsg('') try { const res = await portalApi.post('/contract-confirm/resend', { contractId: contract?.id }) as any setResendMsg(res.data?.data?.message || '重发成功') } catch (err: any) { setResendMsg(err.response?.data?.error?.message || '重发失败') } finally { setResending(false) } } return (
{/* 页面标题 */}

我的劳动合同

{isLoading ? (
) : !contract ? ( ) : ( <> {/* 到期提醒横幅 */} {daysToExpire !== null && daysToExpire <= 30 && daysToExpire >= 0 && (
您的合同还有 {daysToExpire} 天到期,请关注续签事宜
)} {/* 合同概览卡片 */}
{contract.contractType === 'FIXED' ? '固定期限劳动合同' : contract.contractType === 'UNFIXED' ? '无固定期限劳动合同' : '未签订'}
{contract.signMethod === 'PAPER' ? '纸质合同' : '电子合同'}
{contract.endDate && ( )} {contract.contractYears > 0 && ( )} {contract.signDate && ( )} {contract.probationMonths > 0 && ( )} {contract.probationSalary > 0 && ( )}
{/* 签署确认记录 */}

签署确认

{isConfirmed ? (
已确认签署
{new Date(contract.attachmentName.slice(10).split('|')[0]).toLocaleString()}
) : (
合同尚未确认签署
{resendMsg &&
{resendMsg}
}
)}
)}
) } function InfoRow({ icon: Icon, label, value }: { icon: any; label: string; value: string }) { return (
{label}
{value}
) }