| 186 | |
| 187 | // 格式化过期时间 |
| 188 | function formatExpiredDate(dateStr: string): string { |
| 189 | try { |
| 190 | const date = new Date(dateStr); |
| 191 | // 检查是否是无效的默认日期(0001年) |
| 192 | if (date.getFullYear() <= 1) { |
| 193 | return "未设置"; |
| 194 | } |
| 195 | |
| 196 | const now = new Date(); |
| 197 | const diffTime = date.getTime() - now.getTime(); |
| 198 | const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); |
| 199 | |
| 200 | const dateString = date.toLocaleDateString("zh-CN", { |
| 201 | year: "numeric", |
| 202 | month: "2-digit", |
| 203 | day: "2-digit", |
| 204 | }); |
| 205 | |
| 206 | if (diffDays > 0) { |
| 207 | return `${dateString} (还有 ${diffDays} 天)`; |
| 208 | } else if (diffDays === 0) { |
| 209 | return `${dateString} (今天到期)`; |
| 210 | } else { |
| 211 | return `${dateString} (已过期 ${Math.abs(diffDays)} 天)`; |
| 212 | } |
| 213 | } catch { |
| 214 | return "未知"; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | // HTTP 请求封装 |
| 219 | async function makeRequest(url: string, endpoint: string): Promise<any> { |