diff --git a/docs/prototype/buddy-switch-prototype.html b/docs/prototype/buddy-switch-prototype.html index ec2eac42..ede0d919 100644 --- a/docs/prototype/buddy-switch-prototype.html +++ b/docs/prototype/buddy-switch-prototype.html @@ -3695,20 +3695,25 @@

确认

/* ── 剩余时长的展示粒度(与产品 `lib/credit-expiry.ts::remainingSpan` 同规则)── * - * ≤ 48 小时说小时(向上取整、≥1):25 小时与 47 小时都能各自说准; - * > 48 小时才折算成天(向上取整,宁可说晚不说早 —— 49 小时算「3 天」)。 - * ⚠️ 别在调用点另写 `<= 48` 的边界:产品侧就因为「徽章改了、表格没改」出过 + * < 1 小时说分钟(向下取整):最后一小时里「1 小时」会停滞,看不出还剩多少; + * 1 分钟以内向下取整到 0 分钟(刻意不设秒档 —— 0 分钟就是「马上到期」); + * ≤ 48 小时说小时(向下取整):25 小时与 47 小时都能各自说准; + * > 48 小时才折算成天(向上取整 —— 49 小时算「3 天」,宁可说晚不说早)。 + * ⚠️ 别在调用点另写边界:产品侧就因为「徽章改了、表格没改」出过 * 「2 小时 / 1 天」同屏两句话(#189 后的回归,2026-11-09 修)。 */ const expirySpan = (ms) => { + const MINUTE = 60000; const HOUR = 3600000; const DAY = 86400000; + if (ms < HOUR) return { value: Math.max(0, Math.floor(ms / MINUTE)), unit: "minutes" }; return ms <= 48 * HOUR - ? { value: Math.max(1, Math.ceil(ms / HOUR)), unit: "hours" } + ? { value: Math.max(1, Math.floor(ms / HOUR)), unit: "hours" } : { value: Math.max(1, Math.ceil(ms / DAY)), unit: "days" }; }; -const spanUnitText = (unit) => (unit === "hours" ? "小时" : "天"); +const spanUnitText = (unit) => + unit === "minutes" ? "分钟" : unit === "hours" ? "小时" : "天"; -/** 卡片徽章:「最近到期 {N天|N小时} · {金额} 积分」—— 数值与金额同批(`soonestExpire`)。 */ +/** 卡片徽章:「最近到期 {N分钟|N小时|N天} · {金额} 积分」—— 数值与金额同批(`soonestExpire`)。 */ function expiringChipText(a) { if (!a.soonestExpire) return ""; const span = expirySpan(a.soonestExpire.ms - Date.now()); diff --git a/docs/prototype/demo-app.js b/docs/prototype/demo-app.js index 54be0fb1..22b26e8b 100644 --- a/docs/prototype/demo-app.js +++ b/docs/prototype/demo-app.js @@ -185,20 +185,25 @@ const fmtTok = (n) => (n >= 1e6 ? (n / 1e6).toFixed(1) + "M" : n >= 1e3 ? (n / 1 /* ── 剩余时长的展示粒度(与产品 `lib/credit-expiry.ts::remainingSpan` 同规则)── * - * ≤ 48 小时说小时(向上取整、≥1):25 小时与 47 小时都能各自说准; - * > 48 小时才折算成天(向上取整,宁可说晚不说早 —— 49 小时算「3 天」)。 - * ⚠️ 别在调用点另写 `<= 48` 的边界:产品侧就因为「徽章改了、表格没改」出过 + * < 1 小时说分钟(向下取整):最后一小时里「1 小时」会停滞,看不出还剩多少; + * 1 分钟以内向下取整到 0 分钟(刻意不设秒档 —— 0 分钟就是「马上到期」); + * ≤ 48 小时说小时(向下取整):25 小时与 47 小时都能各自说准; + * > 48 小时才折算成天(向上取整 —— 49 小时算「3 天」,宁可说晚不说早)。 + * ⚠️ 别在调用点另写边界:产品侧就因为「徽章改了、表格没改」出过 * 「2 小时 / 1 天」同屏两句话(#189 后的回归,2026-11-09 修)。 */ const expirySpan = (ms) => { + const MINUTE = 60000; const HOUR = 3600000; const DAY = 86400000; + if (ms < HOUR) return { value: Math.max(0, Math.floor(ms / MINUTE)), unit: "minutes" }; return ms <= 48 * HOUR - ? { value: Math.max(1, Math.ceil(ms / HOUR)), unit: "hours" } + ? { value: Math.max(1, Math.floor(ms / HOUR)), unit: "hours" } : { value: Math.max(1, Math.ceil(ms / DAY)), unit: "days" }; }; -const spanUnitText = (unit) => (unit === "hours" ? "小时" : "天"); +const spanUnitText = (unit) => + unit === "minutes" ? "分钟" : unit === "hours" ? "小时" : "天"; -/** 卡片徽章:「最近到期 {N天|N小时} · {金额} 积分」—— 数值与金额同批(`soonestExpire`)。 */ +/** 卡片徽章:「最近到期 {N分钟|N小时|N天} · {金额} 积分」—— 数值与金额同批(`soonestExpire`)。 */ function expiringChipText(a) { if (!a.soonestExpire) return ""; const span = expirySpan(a.soonestExpire.ms - Date.now()); diff --git a/docs/specs/DECISIONS.md b/docs/specs/DECISIONS.md index 22a9e338..ffcb4f95 100644 --- a/docs/specs/DECISIONS.md +++ b/docs/specs/DECISIONS.md @@ -960,10 +960,15 @@ webview 里属 HTTPS 页面发起的回环 HTTP 请求 —— 依赖平台把 lo Trae 从 7 放宽到 14(理由:多数人一周才开一次工具,7 天窗口常在下一次打开前滑过)。 那条理由单独看仍成立,但它**只在 Trae 一侧生效**,代价是口径分裂 —— 本次判定 **同口径优先于单平台的宽松度**。要改就三处一起改,别再单边放宽。 -- **徽章只报最快那一批**:`最近到期 {N天|N小时} · {金额} 积分`,时间与金额同批(`batches[0]`); - ≤ 48 小时说小时(25 小时与 47 小时不能都说成「1 天」),超过 48 小时才折算成天、 - 向上取整(宁可说晚不说早)。粒度判据只有一处:`credit-expiry.ts::remainingSpan` - (卡片徽章与账号表格列共用;2026-11-09 修过一次「徽章说 2 小时、表格说 1 天」)。 +- **徽章只报最快那一批**:`最近到期 {N分钟|N小时|N天} · {金额} 积分`,时间与金额同批(`batches[0]`); + **< 1 小时说分钟**(最后一小时里「1 小时」会停滞,看不出还剩多少),≤ 48 小时说小时 + (25 小时与 47 小时不能都说成「1 天」),超过 48 小时才折算成天;分钟与小时档向下取整 + (61 秒显示「1分钟」),天档仍向上取整(49 小时显示「3天」,宁可说晚不说早)。 + **不设秒档**:1 分钟以内向下取整为「0分钟」—— 那是「马上到期」的读数,允许出现。 + 分钟值是**渲染时快照**,随积分数据刷新或组件重渲染更新;不做秒级倒计时,也不为它增设定时器。 + 粒度判据只有一处:`credit-expiry.ts::remainingSpan` + (卡片徽章与账号表格列共用;2026-11-09 修过一次「徽章说 2 小时、表格说 1 天」, + 2026-11-17 补了「分钟」档)。 - **余额改可用口径**:后端 `totalRemaining` / `totalCapacity` 剔除已过期包,浪费量由 `expiredRemaining` 单独报告;WB 抽屉 / 聚合详情的资源包明细同步剔过期, Trae / Qoder 的抽屉**仍保留**过期包(它们的账号级余额口径没改,不能一刀切)。 diff --git a/docs/specs/P4-ARCH.md b/docs/specs/P4-ARCH.md index 84a75f36..214b1e8a 100644 --- a/docs/specs/P4-ARCH.md +++ b/docs/specs/P4-ARCH.md @@ -181,7 +181,9 @@ export interface DetailPack { > Trae `trae/credits.rs::EXPIRING_SOON_SECS`、前端两个镜像常量(`TRAE_EXPIRING_SOON_MS` / > `EXPIRING_SOON_MS`)四处必须相等 —— 跨语言不能共享常量,由 `check-credit-packs.mjs` 钉住。 > 同一文件还钉住「剩余时长的粒度」只有一处判据 `credit-expiry.ts::remainingSpan` -> (≤ 48 小时说小时;卡片徽章与账号表格列共用,别再长出只到天的第二个函数)。 +> (< 1 小时说分钟、≤ 48 小时说小时;分钟与小时档向下取整,天档向上取整; +> **不设秒档**,1 分钟以内显示「0 分钟」;分钟值是渲染时快照,随数据刷新或重渲染更新, +> 不做秒级倒计时;卡片徽章与账号表格列共用,别再长出只到天的第二个函数)。 > > ★ **余额是可用口径**(同 D57):`credit_result` 的 `totalRemaining` / `totalCapacity` > **剔除已过期包**,浪费量走 `expiredRemaining`;因此 WB 侧的资源包明细也必须剔过期包 diff --git a/scripts/check-credit-packs.mjs b/scripts/check-credit-packs.mjs index 40367ac0..1b029f14 100644 --- a/scripts/check-credit-packs.mjs +++ b/scripts/check-credit-packs.mjs @@ -299,31 +299,89 @@ check("★ 临期窗口只剩两档:后端标记,或镜像后端的 7 天常 * 仍用只到天的 `daysUntil()` ⇒ 2 小时后到期的批在徽章上「2小时」、在同一行的表格里 * 「1 天」。这类分叉不会被 tsc 抓(两个函数都合法),只能靠行为断言把「同源」钉住。 * + * 2026-11-17:补 **< 1 小时 ⇒ 分钟**,分钟与小时档改为向下取整;天档继续向上取整 + * (宁可说晚不说早)。**不设秒档**:1 分钟以内显示 0 分钟(「马上到期」的读数)。 + * * 可证伪点: - * ① 边界:48 小时(含等号)仍算小时,49 小时才是 3 天(向上取整、宁可说晚); + * ① 边界:59.5 秒向下取整到 0 分钟(不足 1 分钟即 0);60 秒正好 1 分钟; + * 59.5 分钟向下取整到 59 分钟;60 分钟(含等号)说 1 小时;48 小时(含等号)仍算小时, + * 49 小时按天向上取整成 3 天; * ② 同源:`summarizeExpiring().soonestUnit` 必须等于 `remainingSpan()` 对同一剩余时长的 * 结论 —— 变异:把 summarizeExpiring 里的 `remainingSpan(remaining).unit` 换回 * 内联三元 ⇒ 这一组仍可能过,所以还要 ③; - * ③ 用法:表格列读 `remainingSpan`,且 `daysUntil` 这个「只到天」的旧出口已删除 - * (留着它,下一个人一定会再用一次)。 + * ③ 用法:表格列读 `remainingSpan`;四个展示点(三张卡片 + 表格列)都接了「分钟」档 + * (漏接时 tsc 不报,界面会把 20 分钟渲染成「1小时」); + * `daysUntil` 这个「只到天」的旧出口已删除(留着它,下一个人一定会再用一次)。 */ check("★ 剩余时长粒度只有一处判据(remainingSpan):徽章与表格列同源", () => { + const MINUTE = 60_000; const HOUR = 3_600_000; + eq(remainingSpan(999), { unit: "minutes", value: 0 }, "不足 1 分钟显示 0 分钟(不设秒档)"); + eq(remainingSpan(45 * 1_000), { unit: "minutes", value: 0 }, "45 秒是 0 分钟"); + eq(remainingSpan(59_500), { unit: "minutes", value: 0 }, "59.5 秒向下取整到 0 分钟"); + eq(remainingSpan(MINUTE), { unit: "minutes", value: 1 }, "正好 60 秒是 1 分钟"); + eq(remainingSpan(20 * MINUTE), { unit: "minutes", value: 20 }, "20 分钟"); + eq(remainingSpan(59 * MINUTE), { unit: "minutes", value: 59 }, "59 分钟"); + eq(remainingSpan(59 * MINUTE + 30_000), { unit: "minutes", value: 59 }, "59.5 分钟向下取整到 59 分钟"); + eq(remainingSpan(HOUR), { unit: "hours", value: 1 }, "正好 60 分钟不再算分钟档,进入小时档"); eq(remainingSpan(2 * HOUR), { unit: "hours", value: 2 }, "2 小时"); eq(remainingSpan(48 * HOUR), { unit: "hours", value: 48 }, "48 小时(边界含等号)"); - eq(remainingSpan(49 * HOUR), { unit: "days", value: 3 }, "49 小时应向上取整成 3 天"); + eq(remainingSpan(48 * HOUR + 1), { unit: "days", value: 3 }, "48 小时 + 1 毫秒进入天档(向上取整)"); + eq(remainingSpan(49 * HOUR), { unit: "days", value: 3 }, "49 小时向上取整成 3 天"); + eq(remainingSpan(72 * HOUR), { unit: "days", value: 3 }, "72 小时正好 3 天"); eq(remainingSpan(3 * DAY), { unit: "days", value: 3 }, "3 天"); const only = (hours) => [ { expireAt: NOW + hours * HOUR, remaining: 10, expired: false, expiringSoon: true }, ]; - for (const hours of [1, 47, 48, 49, 72]) { + for (const hours of [0.5, 1, 47, 48, 49, 72]) { const summary = summarizeExpiring(only(hours), { now: NOW }); eq(summary.soonestUnit, remainingSpan(hours * HOUR).unit, `${hours} 小时后徽章的单位`); } + eq(summarizeExpiring(only(0.5), { now: NOW }).soonestMinutes, 30, "半小时徽章要拿到 30 分钟"); + eq(summarizeExpiring(only(49), { now: NOW }).soonestDays, 3, "49 小时徽章要拿到 3 天"); + eq( + summarizeExpiring( + [{ expireAt: NOW + 30_000, remaining: 10, expired: false, expiringSoon: true }], + { now: NOW }, + ).soonestMinutes, + 0, + "不足 1 分钟徽章要拿到 0 分钟", + ); const page = readFileSync(path.join(root, "src/pages/AccountsPage.tsx"), "utf8"); if (!/remainingSpan\(/.test(page)) { throw new Error("AccountsPage 的「积分到期」列没读 remainingSpan —— 会与卡片徽章的粒度分叉"); } + /* 漏接「分钟」档不会报编译错误,只会把 20 分钟渲染成「1小时」。 */ + const displays = { + "src/pages/AccountsPage.tsx": { + key: "wbAccounts.table.creditExpiryMinutes", + branch: /span\.unit\s*===\s*["']minutes["']/, + }, + "src/components/account-card.tsx": { + key: "wbAccounts.card.expiringChipMinutes", + branch: /expiring\.soonestUnit\s*===\s*["']minutes["']/, + }, + "src/components/trae-account-card.tsx": { + key: "trae.comp.card.chip.expiringMinutes", + branch: /expiring\.soonestUnit\s*===\s*["']minutes["']/, + }, + "src/components/qoder/qoder-account-card.tsx": { + key: "qoder.page.accounts.metric.expiringChipMinutes", + branch: /expiring\.soonestUnit\s*===\s*["']minutes["']/, + }, + }; + for (const [rel, { key, branch }] of Object.entries(displays)) { + const code = readFileSync(path.join(root, rel), "utf8") + .split("\n") + .filter((line) => !/^\s*(\*|\/\/|\/\*)/.test(line)) + .join("\n"); + const keyPattern = new RegExp( + `["']${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}["']`, + ); + if (!branch.test(code) || !keyPattern.test(code)) { + throw new Error(`${rel} 没有真正接「分钟」档(缺分钟分支或 ${key})`); + } + } const pageCode = page .split("\n") .filter((line) => !/^\s*(\*|\/\/|\/\*)/.test(line)) diff --git a/src/components/account-card.tsx b/src/components/account-card.tsx index 62a42546..e5d5f144 100644 --- a/src/components/account-card.tsx +++ b/src/components/account-card.tsx @@ -684,31 +684,37 @@ const isCurrentAccount = programSlots.some((slot) => slot.active); ); /** - * 「最近到期 {N天|N小时} · {金额} 积分」——原型 `.acct-chips` 的第三条 + * 「最近到期 {N分钟|N小时|N天} · {金额} 积分」——原型 `.acct-chips` 的第三条 * (`demo-app.js` 的 `expiringChipText()`;徽章只在**最快那批**存在时渲染)。 * * ★ 2026-11-09 **口径修正**:徽章只报**最快到期的那一批** —— 天数与金额同批 * (`summarizeExpiring` 的 `soonestDays` / `soonestAmount`)。 * 此前「金额 = 全部临期之和」配「天数 = 最晚那一刻」会让徽章说成「2 天内过期」, * 而实际上明天就有一批要作废。逐批明细(最快排第一、绝对时刻)放进 tooltip。 - * ★ 粒度(≤48 小时说小时)由 `remainingSpan` 唯一决定,卡片与账号表格列同源。 + * ★ 粒度(<1 小时用分钟、≤48 小时用小时)由 `remainingSpan` 唯一决定, + * 卡片与账号表格列同源。1 分钟以内显示 0 分钟(刻意:不设秒档)。 * * ⚠️ 窗口不再是前端自设的 3 天,而是**后端的 `expiringSoon`(7 天)**——统计页 / 总览页 * 读的就是同一口径(`expiringSoonRemaining`),卡片若另设窗口,同一件事会出现两个数字。 * 拿不到临期批次 ⇒ **整条不渲染**(绝不写一个猜出来的「N 天」标签)。 */ const expiring = credit?.ok ? summarizeExpiring(metricResources, { now: expiryNow }) : null; - /* 徽章文案:≤ 48 小时用小时,超过才用天(与 `summarizeExpiring.soonestUnit` 同源)。 */ + /* 徽章文案:<1 小时用分钟、≤ 48 小时用小时,超过才用天(与 `summarizeExpiring.soonestUnit` 同源)。 */ const expiringChipText = expiring - ? expiring.soonestUnit === "hours" - ? t("wbAccounts.card.expiringChipHours", { + ? expiring.soonestUnit === "minutes" + ? t("wbAccounts.card.expiringChipMinutes", { amount: formatCredits(expiring.soonestAmount), - hours: expiring.soonestHours, - }) - : t("wbAccounts.card.expiringChip", { - amount: formatCredits(expiring.soonestAmount), - days: expiring.soonestDays, + minutes: expiring.soonestMinutes, }) + : expiring.soonestUnit === "hours" + ? t("wbAccounts.card.expiringChipHours", { + amount: formatCredits(expiring.soonestAmount), + hours: expiring.soonestHours, + }) + : t("wbAccounts.card.expiringChip", { + amount: formatCredits(expiring.soonestAmount), + days: expiring.soonestDays, + }) : ""; const expiringChip = expiring ? ( diff --git a/src/components/qoder/qoder-account-card.tsx b/src/components/qoder/qoder-account-card.tsx index eb010ca5..775a6100 100644 --- a/src/components/qoder/qoder-account-card.tsx +++ b/src/components/qoder/qoder-account-card.tsx @@ -556,17 +556,23 @@ export function QoderAccountCard({ ); - /* 徽章文案:≤ 48 小时用小时,超过才用天(与 `summarizeExpiring.soonestUnit` 同源)。 */ + /* 徽章文案:<1 小时用分钟、≤ 48 小时用小时,超过才用天 + (与 `summarizeExpiring.soonestUnit` 同源)。 */ const expiringChipText = expiring - ? expiring.soonestUnit === "hours" - ? t("qoder.page.accounts.metric.expiringChipHours", { + ? expiring.soonestUnit === "minutes" + ? t("qoder.page.accounts.metric.expiringChipMinutes", { amount: formatCredits(expiring.soonestAmount), - hours: expiring.soonestHours, - }) - : t("qoder.page.accounts.metric.expiringChip", { - amount: formatCredits(expiring.soonestAmount), - days: expiring.soonestDays, + minutes: expiring.soonestMinutes, }) + : expiring.soonestUnit === "hours" + ? t("qoder.page.accounts.metric.expiringChipHours", { + amount: formatCredits(expiring.soonestAmount), + hours: expiring.soonestHours, + }) + : t("qoder.page.accounts.metric.expiringChip", { + amount: formatCredits(expiring.soonestAmount), + days: expiring.soonestDays, + }) : ""; const expiryChip = expiring ? ( diff --git a/src/components/trae-account-card.tsx b/src/components/trae-account-card.tsx index 3c2e8f21..7b232166 100644 --- a/src/components/trae-account-card.tsx +++ b/src/components/trae-account-card.tsx @@ -424,17 +424,23 @@ export function TraeAccountCard({ ); - /* 徽章文案:≤ 48 小时用小时,超过才用天(与 `summarizeExpiring.soonestUnit` 同源)。 */ + /* 徽章文案:<1 小时用分钟、≤ 48 小时用小时,超过才用天 + (与 `summarizeExpiring.soonestUnit` 同源)。 */ const expiringChipText = expiring - ? expiring.soonestUnit === "hours" - ? t("trae.comp.card.chip.expiringHours", { + ? expiring.soonestUnit === "minutes" + ? t("trae.comp.card.chip.expiringMinutes", { amount: formatCredits(expiring.soonestAmount), - hours: expiring.soonestHours, - }) - : t("trae.comp.card.chip.expiring", { - amount: formatCredits(expiring.soonestAmount), - days: expiring.soonestDays, + minutes: expiring.soonestMinutes, }) + : expiring.soonestUnit === "hours" + ? t("trae.comp.card.chip.expiringHours", { + amount: formatCredits(expiring.soonestAmount), + hours: expiring.soonestHours, + }) + : t("trae.comp.card.chip.expiring", { + amount: formatCredits(expiring.soonestAmount), + days: expiring.soonestDays, + }) : ""; const expiringChip = expiring ? ( diff --git a/src/lib/credit-expiry.ts b/src/lib/credit-expiry.ts index 296d7ff5..6db146c5 100644 --- a/src/lib/credit-expiry.ts +++ b/src/lib/credit-expiry.ts @@ -15,11 +15,13 @@ * 窗口内的**总量**仍是真实有用的数(抽屉副文本「7 天内到期 X 积分」、聚合页 / 统计页 * 的 `expiringSoonRemaining` 都读它),所以保留在 `total` 字段,只是**不进徽章**。 * - * ## 时间单位:≤ 48 小时用「小时」 + * ## 时间单位:< 1 小时用「分钟」,≤ 48 小时用「小时」,再往上用「天」 * - * 徽章的时间单位由最快那批的剩余时长决定:**≤ 48 小时 ⇒ 小时**(`最近到期 47小时`), - * 超过 48 小时才折算成**天**(`最近到期 3天`)。用小时是为了不让「25 小时」和「47 小时」 - * 都被说成「1 天」;天档向上取整,宁可说晚不说早。 + * 徽章的时间单位由最快那批的剩余时长决定:**< 1 小时 ⇒ 分钟**(`最近到期 25分钟`), + * **≤ 48 小时 ⇒ 小时**(`最近到期 47小时`),超过 48 小时才折算成**天**(`最近到期 3天`)。 + * 越短的区间给越细的刻度:最后一小时里「1 小时」会一动不动,用户没法判断要不要现在动手用掉。 + * 分钟与小时档向下取整;天档仍向上取整(宁可说晚不说早)。**1 分钟以内显示「0 分钟」** + * —— 这是刻意的:不再给秒档,`0 分钟` 就是「马上到期」的读数。 * * ## 明细放 tooltip,用绝对时刻 * @@ -39,6 +41,8 @@ * {@link TRAE_EXPIRING_SOON_MS} —— 它是后端窗口的**镜像**,不是第二个口径。 */ +/** 一分钟的毫秒数(徽章最后一小时用「分钟」)。 */ +const MINUTE_MS = 60_000; /** 一小时的毫秒数(徽章短区间用「小时」)。 */ const HOUR_MS = 3_600_000; /** 一天的毫秒数。 */ @@ -73,14 +77,17 @@ export interface ExpiringSummary { /** 窗口内全部临期剩余积分之和(抽屉副文本 / 聚合页读它;**不进徽章**)。 */ total: number; /** - * 徽章的**单位**:最快那批剩余 ≤ 48 小时 ⇒ `"hours"`,否则 `"days"`。 - * 短区间用小时是因为「1 天」会把 25 小时和 47 小时说成同一个数。 + * 徽章的**单位**:最快那批剩余 < 1 小时 ⇒ `"minutes"`,≤ 48 小时 ⇒ `"hours"`, + * 否则 `"days"`。短区间用更细的刻度:「1 天」会把 25 小时和 47 小时说成同一个数, + * 「1 小时」会让最后一段看起来停滞。1 分钟以内归入分钟档,向下取整得 0。 */ - soonestUnit: "hours" | "days"; - /** 最快那批距今天数,向上取整、≥1 —— 仅 `soonestUnit === "days"` 时使用。 */ + soonestUnit: "minutes" | "hours" | "days"; + /** 最快那批距今天数,向上取整 —— 仅 `soonestUnit === "days"` 时使用。 */ soonestDays: number; - /** 最快那批距今小时数,向上取整、≥1 —— 仅 `soonestUnit === "hours"` 时使用。 */ + /** 最快那批距今小时数,向下取整 —— 仅 `soonestUnit === "hours"` 时使用。 */ soonestHours: number; + /** 最快那批距今分钟数,向下取整、可为 0 —— 仅 `soonestUnit === "minutes"` 时使用。 */ + soonestMinutes: number; /** 最快那批(`batches[0]`)的剩余积分 —— 徽章的金额,与上面的数值同批。 */ soonestAmount: number; /** 按到期时刻升序的逐批明细(最快的那批排第一)。 */ @@ -140,16 +147,22 @@ export function summarizeExpiring( if (total <= 0) return null; /* 徽章只看最快那批:单位、数值、金额必须来自同一批(见模块头)。 - 单位(小时 / 天)与数值一律取自 {@link remainingSpan},不在本函数里再算一遍 —— - 账号页表格的「积分到期」列也读它,两处判据分叉就会回到 - 「徽章说 2 小时、表格说 1 天」的老样子。 */ + 当前单位的数值直接取自 {@link remainingSpan};其余单位的冗余字段为兼容现有 + 调用方保留,不参与当前展示 —— 账号页表格的「积分到期」列也读它,两处判据 + 分叉就会回到「徽章说 2 小时、表格说 1 天」的老样子。 */ const soonest = batches[0]; - const remaining = soonest.expireAt - now; + const span = remainingSpan(soonest.expireAt - now); return { total, - soonestUnit: remainingSpan(remaining).unit, - soonestDays: Math.max(1, Math.ceil(remaining / DAY_MS)), - soonestHours: Math.max(1, Math.ceil(remaining / HOUR_MS)), + soonestUnit: span.unit, + soonestDays: + span.unit === "days" ? span.value : Math.max(1, Math.ceil((soonest.expireAt - now) / DAY_MS)), + soonestHours: + span.unit === "hours" ? span.value : Math.max(1, Math.floor((soonest.expireAt - now) / HOUR_MS)), + soonestMinutes: + span.unit === "minutes" + ? span.value + : Math.max(0, Math.floor((soonest.expireAt - now) / MINUTE_MS)), soonestAmount: soonest.amount, batches, }; @@ -158,8 +171,13 @@ export function summarizeExpiring( /** * 一段**剩余时长**的展示粒度 —— 全仓唯一出口。 * - * - `≤ 48 小时` ⇒ 小时(向上取整、≥1):25 小时与 47 小时都能各自说准; - * - `> 48 小时` ⇒ 天(向上取整、≥1):宁可说晚不说早 —— 49 小时算「3 天」。 + * - `< 1 小时` ⇒ 分钟(向下取整):最后一小时要给到分钟刻度,否则「1 小时」 + * 会一直挂到过期;1 分钟以内显示 0 分钟(刻意:不设秒档,0 分钟就是「马上到期」); + * - `≤ 48 小时` ⇒ 小时(向下取整):25 小时与 47 小时都能各自说准; + * - `> 48 小时` ⇒ 天(向上取整):49 小时算「3 天」,宁可说晚不说早。 + * + * 恰好 60 分钟仍是「1 小时」:边界含等号,沿用到上一档; + * 恰好 48 小时仍是「48 小时」,再多 1 毫秒才进入天档。 * * ## 谁在读它 * @@ -171,11 +189,14 @@ export function summarizeExpiring( * ⚠️ 别在调用点重写 `<= 48` 这个边界:那正是这次要根除的「同一规则两处实现」。 */ export function remainingSpan(remainingMs: number): { - unit: "hours" | "days"; + unit: "minutes" | "hours" | "days"; value: number; } { + if (remainingMs < HOUR_MS) { + return { unit: "minutes", value: Math.max(0, Math.floor(remainingMs / MINUTE_MS)) }; + } if (remainingMs <= HOUR_DISPLAY_LIMIT_MS) { - return { unit: "hours", value: Math.max(1, Math.ceil(remainingMs / HOUR_MS)) }; + return { unit: "hours", value: Math.max(1, Math.floor(remainingMs / HOUR_MS)) }; } return { unit: "days", value: Math.max(1, Math.ceil(remainingMs / DAY_MS)) }; } @@ -277,10 +298,10 @@ export function nearestExpiringBatch( return upcomingExpiries(items, options)[0] ?? null; } -/* 曾有一个 `daysUntil(expireAt)` 只返回「向上取整的天数」,WB 表格的「积分到期」列用它 —— - 2 小时后到期的批被说成「1 天」,与本模块 {@link remainingSpan} 的「≤48 小时用小时」 - 直接矛盾。2026-11-09 已删:需要天数就 `remainingSpan(剩余毫秒).value`, - 判据只有一处,别再长出第二个只到天的函数。 */ +/* 曾有一个 `daysUntil(expireAt)` 只返回取整后的天数,WB 表格的「积分到期」列用它 —— + 2 小时后到期的批被说成「1 天」,与本模块 {@link remainingSpan} 的「<1 小时用分钟、 + ≤48 小时用小时」直接矛盾。2026-11-09 已删:需要天数就 + `remainingSpan(剩余毫秒).value`,判据只有一处,别再长出第二个只到天的函数。 */ /* ══════════════════════ 渲染约束 ══════════════════════ */ diff --git a/src/lib/qoder-packs.ts b/src/lib/qoder-packs.ts index 19307970..b60ee3dd 100644 --- a/src/lib/qoder-packs.ts +++ b/src/lib/qoder-packs.ts @@ -85,7 +85,7 @@ export function packSourceLabel( * * ## 与 WorkBuddy 的口径关系 * - * WB 卡的黄徽章(`最近到期 {N天|N小时} · {金额} 积分`)用**后端 `expiringSoon`**;Qoder 的逐包响应里 + * WB 卡的黄徽章(`最近到期 {N分钟|N小时|N天} · {金额} 积分`)用**后端 `expiringSoon`**;Qoder 的逐包响应里 * **没有这个标记**,所以这里用 `EXPIRING_SOON_MS`(7 天)自己判 —— 它是后端窗口的 * 镜像常量,不是第二个口径(`packState()` 判每行状态用的就是它)。 * diff --git a/src/locales/domains/qoderPages.en.ts b/src/locales/domains/qoderPages.en.ts index aea31614..44416c2a 100644 --- a/src/locales/domains/qoderPages.en.ts +++ b/src/locales/domains/qoderPages.en.ts @@ -208,6 +208,8 @@ export const en = { // Expiry badge (issue #166): warning = expiring soon (7-day window, same as WB / Trae). // Badge reports the **closest-expiring batch only**; per-batch absolute timestamps go in the tooltip. "qoder.page.accounts.metric.expiringChip": "Closest expiry in {days} days · {amount} credits", + /* Under an hour the badge speaks in minutes, so the last hour keeps moving. */ + "qoder.page.accounts.metric.expiringChipMinutes": "Closest expiry in {minutes} min · {amount} credits", /* Within 48 hours the badge speaks in hours, so 25h and 47h stay distinguishable. */ "qoder.page.accounts.metric.expiringChipHours": "Closest expiry in {hours} hrs · {amount} credits", "qoder.page.accounts.metric.expiringTipTitle": "Expiring batches ({n})", diff --git a/src/locales/domains/qoderPages.zh.ts b/src/locales/domains/qoderPages.zh.ts index ebf35ed8..ebc59624 100644 --- a/src/locales/domains/qoderPages.zh.ts +++ b/src/locales/domains/qoderPages.zh.ts @@ -218,6 +218,9 @@ export const zh = { // 到期徽章(issue #166):黄=临期警告(7 天窗口,与 WB / Trae 同口径)。 // 只报**最快到期的那一批**:天数与该批金额同批;逐批明细(绝对时刻)在 tooltip。 "qoder.page.accounts.metric.expiringChip": "最近到期 {days}天 · {amount} 积分", + /* < 1 小时说分钟:与 `summarizeExpiring.soonestUnit` 同源; + 1 分钟以内向下取整到 0 分钟(刻意不设秒档)。 */ + "qoder.page.accounts.metric.expiringChipMinutes": "最近到期 {minutes}分钟 · {amount} 积分", /* ≤ 48 小时用小时:与 `summarizeExpiring.soonestUnit` 同源。 */ "qoder.page.accounts.metric.expiringChipHours": "最近到期 {hours}小时 · {amount} 积分", "qoder.page.accounts.metric.expiringTipTitle": "按到期时间分批(共 {n} 批)", diff --git a/src/locales/domains/traeComponents.en.ts b/src/locales/domains/traeComponents.en.ts index fb047c75..80ea53e5 100644 --- a/src/locales/domains/traeComponents.en.ts +++ b/src/locales/domains/traeComponents.en.ts @@ -61,6 +61,8 @@ export const en = { "trae.comp.card.chip.expired": "Credentials expired", "trae.comp.card.chip.needRelogin": "Needs re-login", "trae.comp.card.chip.expiring": "Closest expiry in {days} days · {amount} credits", + /* Under an hour the badge speaks in minutes, so the last hour keeps moving. */ + "trae.comp.card.chip.expiringMinutes": "Closest expiry in {minutes} min · {amount} credits", /* Within 48 hours the badge speaks in hours, so 25h and 47h stay distinguishable. */ "trae.comp.card.chip.expiringHours": "Closest expiry in {hours} hrs · {amount} credits", /* Badge tooltip detail — same shape as WB / Qoder (one line per batch, merge by expiry, diff --git a/src/locales/domains/traeComponents.zh.ts b/src/locales/domains/traeComponents.zh.ts index fc868547..2604e399 100644 --- a/src/locales/domains/traeComponents.zh.ts +++ b/src/locales/domains/traeComponents.zh.ts @@ -94,6 +94,9 @@ export const zh = { // 「最近到期 {days}天 · {amount} 积分」—— 天数与金额都取**最快到期的那一批**。 // 不把窗口总量和某一批的天数拼在一起:那是两批积分,怎么拼都有半句假话。 "trae.comp.card.chip.expiring": "最近到期 {days}天 · {amount} 积分", + /* < 1 小时说分钟:与 `summarizeExpiring.soonestUnit` 同源; + 1 分钟以内向下取整到 0 分钟(刻意不设秒档)。 */ + "trae.comp.card.chip.expiringMinutes": "最近到期 {minutes}分钟 · {amount} 积分", /* ≤ 48 小时用小时:与 `summarizeExpiring.soonestUnit` 同源。 */ "trae.comp.card.chip.expiringHours": "最近到期 {hours}小时 · {amount} 积分", /* 徽章浮层的逐批明细 —— **与 WB / Qoder 同一形状**(一行一批、按到期时刻合并、不带包名)。 diff --git a/src/locales/domains/wbAccounts.en.ts b/src/locales/domains/wbAccounts.en.ts index 7e499ba8..b56701ac 100644 --- a/src/locales/domains/wbAccounts.en.ts +++ b/src/locales/domains/wbAccounts.en.ts @@ -101,6 +101,8 @@ export const en = { "wbAccounts.card.priority": "Priority", "wbAccounts.card.priorityTip": "Recommended priority", "wbAccounts.card.expiringChip": "Closest expiry in {days} days · {amount} credits", + /* Under an hour the badge speaks in minutes, so the last hour keeps moving. */ + "wbAccounts.card.expiringChipMinutes": "Closest expiry in {minutes} min · {amount} credits", /* Within 48 hours the badge speaks in hours, so 25h and 47h stay distinguishable. */ "wbAccounts.card.expiringChipHours": "Closest expiry in {hours} hrs · {amount} credits", "wbAccounts.card.expiringTipTitle": "Expiring batches ({n})", @@ -399,6 +401,7 @@ export const en = { "wbAccounts.table.creditExpiry": "Credit expiry", "wbAccounts.table.creditExpiryDays": "{value} days", "wbAccounts.table.creditExpiryHours": "{value} hrs", + "wbAccounts.table.creditExpiryMinutes": "{value} min", "wbAccounts.table.tokenExpiry": "Token expiry", "wbAccounts.table.programs": "Programs", "wbAccounts.table.current": "Current", diff --git a/src/locales/domains/wbAccounts.zh.ts b/src/locales/domains/wbAccounts.zh.ts index d8b1b106..7fe93ab4 100644 --- a/src/locales/domains/wbAccounts.zh.ts +++ b/src/locales/domains/wbAccounts.zh.ts @@ -117,6 +117,9 @@ export const zh = { // ★ 2026-11-09:徽章只报**最快到期的那一批** —— 天数与该批金额同批(`batches[0]`), // 不再把「窗口内总量」和某一批的天数拼在一起(那是两批积分,怎么拼都有半句假话)。 "wbAccounts.card.expiringChip": "最近到期 {days}天 · {amount} 积分", + /* < 1 小时说分钟:最后一小时里「1 小时」会停滞,用户看不出还剩多少; + 1 分钟以内向下取整到 0 分钟(刻意不设秒档)。 */ + "wbAccounts.card.expiringChipMinutes": "最近到期 {minutes}分钟 · {amount} 积分", /* ≤ 48 小时用小时:25 小时与 47 小时各自说准,不被都写成「1 天」。 */ "wbAccounts.card.expiringChipHours": "最近到期 {hours}小时 · {amount} 积分", "wbAccounts.card.expiringTipTitle": "按到期时间分批(共 {n} 批)", @@ -447,6 +450,7 @@ export const zh = { "wbAccounts.table.creditExpiry": "积分到期", "wbAccounts.table.creditExpiryDays": "{value} 天", "wbAccounts.table.creditExpiryHours": "{value} 小时", + "wbAccounts.table.creditExpiryMinutes": "{value} 分钟", "wbAccounts.table.tokenExpiry": "Token 到期", "wbAccounts.table.programs": "程序位", "wbAccounts.table.current": "当前", diff --git a/src/pages/AccountsPage.tsx b/src/pages/AccountsPage.tsx index f327ae97..f3692a6b 100644 --- a/src/pages/AccountsPage.tsx +++ b/src/pages/AccountsPage.tsx @@ -1790,9 +1790,9 @@ function RegionPanel({ region }: { region: Region }) { /** * 「积分到期」列(issue #69):**积分**最近到期,tooltip 给绝对时刻与金额。 * - * 粒度走 `remainingSpan()` —— 与卡片徽章**同一个判据**(≤ 48 小时说小时)。 - * 此前这里用只到天的 `daysUntil()`:2 小时后到期显示「1 天」,而同一行的卡片 - * 徽章说「2小时」—— 同一批积分在同一页两句话(2026-11-09 修)。 + * 粒度走 `remainingSpan()` —— 与卡片徽章**同一个判据**(<1 小时说分钟、 + * ≤ 48 小时说小时)。此前这里用只到天的 `daysUntil()`:2 小时后到期显示「1 天」, + * 而同一行的卡片徽章说「2小时」—— 同一批积分在同一页两句话(2026-11-09 修)。 * * ⚠️ 与下一列「Token 到期」是**两件事**:那列是 Token 有效期(所有账号差不多), * 这列才是用户要的「先用哪个账号」。同名会让用户以为看错了。 @@ -1808,9 +1808,11 @@ function RegionPanel({ region }: { region: Region }) { {t( - span.unit === "hours" - ? "wbAccounts.table.creditExpiryHours" - : "wbAccounts.table.creditExpiryDays", + span.unit === "minutes" + ? "wbAccounts.table.creditExpiryMinutes" + : span.unit === "hours" + ? "wbAccounts.table.creditExpiryHours" + : "wbAccounts.table.creditExpiryDays", { value: span.value }, )}