- 前后端接入 ESLint 10 扁平配置(typescript-eslint 类型感知检查 + react-hooks/react-refresh),新增 lint / lint:check / lint:fix 脚本并纳入 check 链路 - 清理全部 no-unused-vars 与 no-useless-assignment 警告,修复 floating promises、正则转义等问题 - 删除确认无引用的死代码(markKuaishouCloudBindUrlRefreshFailed、未使用 helper 等)
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Tag } from 'antd'
|
|
import { useEffect, useState } from 'react'
|
|
|
|
export function DeadlineCountdown({
|
|
deadlineAt,
|
|
showExpired: _showExpired = false,
|
|
}: {
|
|
deadlineAt: string
|
|
showExpired?: boolean
|
|
}) {
|
|
const [now, setNow] = useState(() => Date.now())
|
|
|
|
useEffect(() => {
|
|
const timer = window.setInterval(() => setNow(Date.now()), 1000)
|
|
return () => window.clearInterval(timer)
|
|
}, [])
|
|
|
|
const remainingMs = new Date(deadlineAt).getTime() - now
|
|
if (remainingMs <= 0) {
|
|
return <Tag color="red">已超时</Tag>
|
|
}
|
|
const totalSeconds = Math.floor(remainingMs / 1000)
|
|
const minutes = Math.floor(totalSeconds / 60)
|
|
const seconds = totalSeconds % 60
|
|
const label = minutes > 0 ? `${minutes} 分 ${seconds} 秒` : `${seconds} 秒`
|
|
const color = remainingMs < 10 * 60 * 1000 ? 'orange' : 'blue'
|
|
return <Tag color={color}>剩余 {label}</Tag>
|
|
}
|
|
|
|
export function formatTimeoutPolicyLabel(policy?: string) {
|
|
if (policy === 'cancel_release') return '超时取消退押金'
|
|
if (policy === 'cancel_deduct') return '超时取消扣押金'
|
|
return '超时退回大厅'
|
|
}
|