feat(annual): the start overlay is two steps in one fixed card and can be closed (BUG-2047)
Independent Staging Quality Gate / validate-frontend (push) Successful in 5m35s
Independent Staging Quality Gate / validate-python (push) Successful in 7m1s
Independent Staging Quality Gate / publish (push) Successful in 3m3s

Step one: range, notes, 下一步. Step two: the optional inputs in two columns,
上一步 / 跳过,直接开始 / 开始写年运 and the price lines. Outside click, Esc and a
close button put the overlay away; what was picked and filled stays. The request
body is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
This commit is contained in:
2026-11-20 00:58:39 +08:00
co-authored by Claude Fable 5.2
parent 93d28db0f9
commit 2b956f8294
6 changed files with 505 additions and 116 deletions
+12
View File
@@ -27503,3 +27503,15 @@
- 验证与防复发:新增 `tests/consultation-run-status-2048.test.tsx`(每个领域都有中英句子、事件到文字的顺序、10 秒前不显示用时、完成摘要与步骤、重新载入不显示、样式没有边线、事件只收注册表领域);`consultation-steps-footer-20261105`、`consultation-smalltalk-ui`、`chat-stream-motion-20261116` 按新设计改写并注明原值 / 新值 / 原因。
- 关联记录:BUG-1074、BUG-1145、BUG-2041、BUG-2045;产品负责人 2026-11-20 走查第 4 条。
- 修复版本:`claude/qa-run-status-2048`,待 staging。
## BUG-2047 | 年运开始弹窗:补充项展开后又长又乱,点空白处也关不掉
- 状态:fixed-pending-verify(待测试环境真机确认)。
- 首次发现 / 最近更新:2026-11-20 / 2026-11-20。
- 触发与现象:年运开始页点开「补充现在的情况(可以不填)」,弹窗被撑得很长,整张卡片出现滚动,开始按钮被挤到最下面;弹窗只能点「开始写年运」离开,点空白处没有反应。
- 触发条件:任何用户打开年运并展开补充项。
- 根因:补充项是塞在同一张卡片里的一个折叠块,卡片高度随内容走;遮罩当初按「只有开始一条路」做,没有关闭的办法。
- 修复:同一张卡片分两步,大小固定。第一步选范围、看说明,「下一步」;第二步是补充项,四组标签两栏排开,底部「上一步」「跳过,直接开始」「开始写年运」和扣点说明。卡片头和底部固定,窗口矮时只有中间滚动。加关闭按钮,点卡片外面或按 Esc 收起,收起后页面上留一枚「开始写年运」重新打开,选过和填过的内容保留。发给服务端的请求不变,「跳过」发的是空的补充项,和以前什么都不填一样。
- 验证与防复发:`frontend/tests/annual-two-step-2047.test.tsx` 覆盖两步切换、焦点、跳过与开始、前后往返和关闭重开后内容保留、点外面和 Esc 关闭、请求体不变、卡片尺寸和两栏样式;`annual-report.test.tsx` 里钉住旧版式的断言按原值、新值、原因更新。用产品的样式表把两步渲染成静态页面,在桌面和手机宽度下看过截图并量过滚动高度;登录后的真实页面本机起不来,没有在真实页面上看过。
- 关联记录:BUG-1637、BUG-1650、BUG-2037、BUG-2044。
- 修复版本:`claude/annual-two-step-2047`。
+1
View File
@@ -1439,6 +1439,7 @@ Yogini 还在取时,右栏用和 Chara 相同的轨道等待(`OrbitWaiting`
- **年运研究回归(#269,BUG-1885):** 正文月相回归块内默认折叠具名候选表。打开后用既有可横向滚动的表格显示每个候选、当地时刻、两种年长和用途。附录「几种回归的完整数据」先显示第一条,展开时再挂载其余行。Markdown 同时导出正文表和附录。
- **入口**:「我的报告」最上面两个横条并排(手机上下排,2026-11-03 方案 A,见 Personal report centre):「年运」横条是 `Sun` 图标方块、标题、一行「这一年每段怎么安排,几个要留意的时间点」,右边描边按钮「打开年运」(手机「打开」),直接打开 `/reports/annual`。没有单独的入口页。个人报告横条上不写份数。
- **地址**:`/reports/annual`(`?report=<id>` 打开某一份),放在 `/reports` 下,侧栏仍亮「我的报告」。沿用二级页外壳,标题「年运」,标题旁是人物切换。正文一栏 `min(720px, 100%)` 居中。
- **遮罩分两步(2026-11-20,BUG-2047,产品走查后的原型 C):** 同一张卡片、同一个大小(`min(640px, 100%)` 宽、`min(760px, 100%)` 高),标题下一行灰色小字写「第 1 步,共 2 步」「第 2 步,可以不填」。第一步是三种范围、三条说明、出生时间那一句,底部左边是扣点说明、右边实心「下一步」。第二步标题「开始前可以补充几句」,四组标签排成两栏,「已有的计划」和「今年住在哪个城市」并排,地点下拉横跨两栏,不再用折叠三角;底部左边「上一步」、右边「跳过,直接开始」和实心「开始写年运」,下面是扣点说明、写过一份的说明和报错。卡片头和底部不动,窗口比卡片矮时只有中间滚动。右上角关闭按钮,点卡片外面或按 Esc 也收起;收起后页面上方留一枚「开始写年运」重新打开,选过和填过的内容都在。手机上单栏,实心按钮整行在上、两个文字按钮在下,标题靠左让开关闭按钮。
- **遮罩**:报告的章节骨架在后面虚着(灰标题 + 两条微光条),上面一层 `--color-canvas` 72% 半透明 + 6px 模糊,正中一张卡片(`min(520px, 100%)`、圆角 20px、细边、`--shadow-elevated`,超出时卡内滚动):范围小字「YYYY-MM-DD 到 YYYY-MM-DD」,衬线标题「某人的这一年」;三个胶囊切换「生日年度 / 公历年 / 未来十二个月」(`ToggleGroup`,选中描边 `--color-action-strong`、文字 `--color-action`);三条注意事项(主色勾);出生时间没确认时一行浅底提示,本人和别人都带「先做生时校正」链接(#160 起可以给档案里的其他人做校正);「补充现在的情况(可以不填)」折叠,展开后是关系状态、工作 / 学习、最关心的(最多三项)、已有的计划(一行输入)、不想看的;居中实心按钮「开始写年运」(最小 220×52,手机占满宽),下面一行「本次消耗 N 点,写到一半断掉不扣」。价格读不到时这一行写「计费配置不可用」,按钮不可点。没有别的提示小字。
- **写作中**:点了以后遮罩淡出(200ms),写好的那一节上浮淡入(320ms),下一节标题下一行主色小字「正在写这一节……」,其余仍是骨架。已经写过的这一年直接打开,不出遮罩。没写完时一行「这一次没写完,没有扣点。」和描边按钮「重新开始」。
- **报告**:各节标题 18px;领域节里「回看 / 换年盘后 / 例外窗口 / 年尾」是小标题。「这一年怎么走」(方案 B,BUG-1636)是一条时间轴:顶上一条按天数分段的细条(偏顺主色、偏紧和平稳灰色);下面每个阶段一行:日期、走势胶囊(偏顺主色浅底、偏紧灰底、平稳描边)、「现在」,一句粗体的事情和一句怎么安排;转折点作为「要留意的几天」小卡挂在它开始的那个阶段下,只显示日期、状态(已过 / 进行中)、主题和怎么做,「为什么、另一面、盘面依据」折叠。卡片随内容撑开,不在卡内滚动;已经过去的阶段里的转折点收在「已经过去的时间点(n)」里。BUG-1636 之前写好的报告仍是旧版:两列卡片(不再固定高度)加不换行表格。末尾「计算依据」折叠。
+41 -13
View File
@@ -88,8 +88,7 @@
.annual-remember-line b { color: var(--color-ink); font-weight: 500; }
.annual-evidence, .annual-timing { color: var(--color-ink-secondary); font-size: var(--type-body-sm); }
.annual-evidence b, .annual-timing b { color: var(--color-ink); font-weight: 500; }
.annual-current-city { display: grid; gap: var(--space-2); }
.annual-situation-hint { margin: 0 0 var(--space-2); color: var(--color-ink-secondary); font-size: var(--type-body-sm); }
.annual-situation-hint { margin: 0; color: var(--color-ink-secondary); font-size: var(--type-body-sm); }
.annual-remember { margin: 0; padding-left: 1.25em; display: grid; gap: var(--space-2); }
.annual-when { display: inline-flex; align-items: center; gap: var(--space-2); margin-right: var(--space-2); color: var(--color-action); font-size: var(--type-caption); font-variant-numeric: tabular-nums; white-space: nowrap; }
.annual-candidate { padding: 0 6px; border: 1px solid var(--color-border); border-radius: 999px; color: var(--color-ink-tertiary); font-size: var(--type-overline); }
@@ -117,8 +116,7 @@
.annual-window dl { grid-template-columns: minmax(0, 1fr); }
}
.annual-basis summary,
.annual-appendix summary,
.annual-situation summary { cursor: pointer; color: var(--color-ink-secondary); font-size: var(--type-body-sm); }
.annual-appendix summary { cursor: pointer; color: var(--color-ink-secondary); font-size: var(--type-body-sm); }
.annual-basis ul,
.annual-appendix ul { margin: var(--space-2) 0 0; padding-left: 1.1em; color: var(--color-ink-secondary); font-size: var(--type-caption); }
@@ -215,10 +213,15 @@
backdrop-filter: blur(6px);
animation: annual-fade 200ms ease-out both;
}
/* BUG-2047: two steps in one card. The card keeps one size for both steps (was
520px wide, as tall as its content, scrolling as a whole once the optional
block was opened); the head and the buttons stay put and only the middle
scrolls when the window is shorter than the card. */
.annual-veil-card {
width: min(520px, 100%);
width: min(640px, 100%);
height: min(760px, 100%);
max-height: 100%;
overflow-y: auto;
overflow: hidden;
box-sizing: border-box;
display: flex;
flex-direction: column;
@@ -230,7 +233,16 @@
box-shadow: var(--shadow-elevated);
animation: annual-card-in 280ms cubic-bezier(.22, 1, .36, 1) both;
}
.annual-veil-head { display: flex; flex-direction: column; gap: 6px; text-align: center; }
.annual-veil-head { position: relative; flex: none; display: flex; flex-direction: column; gap: 6px; text-align: center; }
.annual-veil-head h2:focus { outline: none; }
.annual-veil-step { color: var(--color-ink-tertiary); font-size: var(--type-caption); }
.annual-veil-close { position: absolute; top: calc(-1 * var(--space-4)); right: calc(-1 * var(--space-4)); color: var(--color-ink-secondary); }
.annual-veil-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-5); }
.annual-veil-foot { flex: none; display: flex; flex-direction: column; gap: var(--space-3); }
.annual-veil-actions { display: flex; align-items: center; gap: var(--space-3); }
.annual-veil-actions .annual-veil-actions-lead { margin-right: auto; }
.annual-veil-actions .annual-start-button { min-width: 168px; }
.annual-reopen { width: min(720px, 100%); margin: 0 auto var(--space-6); display: flex; justify-content: center; }
/* Option B (2026-11-05): the range is three single-choice cards. */
.annual-kind-field { display: flex; flex-direction: column; gap: var(--space-2); }
.annual-kind-legend { color: var(--color-ink-secondary); font-size: 13px; }
@@ -291,12 +303,19 @@
.annual-notice { margin: 0; padding: var(--space-3) 14px; border-radius: var(--radius-lg); background: var(--color-action-soft); color: var(--color-ink-strong); font-size: var(--type-body-sm); line-height: 1.7; }
.annual-notice a,
.annual-error a { color: var(--color-action); }
.annual-situation { display: flex; flex-direction: column; gap: var(--space-3); }
.annual-situation[open] { padding-bottom: var(--space-1); }
.annual-situation-group { margin: var(--space-3) 0 0; padding: 0; border: 0; min-width: 0; }
/* Second step (BUG-2047): chip groups in two columns, the plan line and the city across both. */
.annual-situation { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4) var(--space-6); align-items: start; }
.annual-situation-group { margin: 0; padding: 0; border: 0; min-width: 0; }
/* The city question sits beside 「已有的计划」; its selects run across both columns. */
.annual-situation .annual-current-city { display: contents; }
.annual-current-city-head { min-width: 0; display: grid; gap: var(--space-2); align-content: start; }
.annual-situation-legend { color: var(--color-ink-tertiary); font-size: var(--type-caption); }
.annual-current-city-picker { grid-column: 1 / -1; min-width: 0; display: grid; gap: var(--space-2); justify-items: start; }
.annual-current-city-picker .birth-place-picker { width: 100%; }
.annual-situation .birth-place-levels { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.annual-situation-group legend { margin-bottom: var(--space-2); color: var(--color-ink-tertiary); font-size: var(--type-caption); }
.annual-situation-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.annual-situation-plans { display: grid; gap: var(--space-2); margin-top: var(--space-3); color: var(--color-ink-tertiary); font-size: var(--type-caption); }
.annual-situation-plans { display: grid; gap: var(--space-2); color: var(--color-ink-tertiary); font-size: var(--type-caption); }
.annual-situation-plans input { min-height: 40px; padding: 0 var(--space-3); border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); background: var(--color-canvas); color: var(--color-ink); font: inherit; font-size: var(--type-body-sm); }
.annual-start { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.annual-start-button { min-width: 220px; min-height: 52px; font-size: var(--type-body-md); }
@@ -305,8 +324,17 @@
.annual-failed { width: min(720px, 100%); margin: var(--space-6) auto 0; display: flex; align-items: center; gap: var(--space-3); color: var(--color-ink-secondary); }
@media (max-width: 720px) {
.annual-veil { padding: var(--space-4); }
.annual-veil-card { padding: var(--space-6) var(--space-5); gap: var(--space-4); }
.annual-start-button { width: 100%; }
.annual-veil-card { height: 100%; padding: var(--space-6) var(--space-5); gap: var(--space-4); }
.annual-veil-close { top: calc(-1 * var(--space-3)); right: calc(-1 * var(--space-3)); }
/* The close button takes the top right corner; on a phone the title starts at the left edge and stops short of it. */
.annual-veil-head { padding-right: var(--space-10); text-align: left; }
.annual-situation { grid-template-columns: minmax(0, 1fr); }
.annual-situation .birth-place-levels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* Phone: the main button first at full width, the two quiet ones under it. */
.annual-veil-actions { flex-wrap: wrap; justify-content: center; }
.annual-veil-actions .annual-start-button { order: -1; flex: 1 0 100%; width: 100%; }
.annual-veil-actions .annual-veil-actions-lead { margin-right: 0; }
.annual-veil-actions p.annual-veil-actions-lead { order: 1; flex: 1 0 100%; text-align: center; }
}
@keyframes annual-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@@ -5,9 +5,14 @@
* 报告页本身,章节骨架在后面虚着,上面一层遮罩写范围、三条注意事项、出生
* 时间提示和「开始写年运」。点了以后遮罩淡出,写好一节出现一节;这一年
* 已经写过的直接打开,不出遮罩。
*
* BUG-2047(产品 2026-11-20 走查):遮罩分两步,同一个卡片、同一个大小。第一步
* 选范围、看说明;第二步是可以不填的补充项,两栏排开,不再用折叠三角。点空白、
* 按 Esc 或点关闭都能收起,填过的内容留在页面状态里。
*/
import { useCallback, useEffect, useRef, useState } from "react";
import { X } from "lucide-react";
import { AppLink } from "@/components/app-link";
import { BirthPlacePicker } from "@/components/birth-place-picker";
@@ -318,14 +323,17 @@ const DOMAIN_OPTIONS = Object.fromEntries(ANNUAL_DOMAINS.map((domain) => [domain
export function SituationForm(props: Readonly<{ value: AnnualSituation; onChange: (next: AnnualSituation) => void }>) {
const { value, onChange } = props;
return (
<details className="annual-situation">
<summary>补充现在的情况(可以不填)</summary>
// BUG-2047: was a <details> with a disclosure triangle inside the one-step
// overlay; now the whole second step, chip groups in two columns.
<div className="annual-situation">
<Chips legend="关系状态" options={RELATIONSHIP_STATES} value={value.relationship ? [value.relationship] : []}
onChange={(next) => onChange({ ...value, relationship: next[0] ?? null })} />
<Chips legend="工作 / 学习" options={WORK_STATES} value={value.work ? [value.work] : []}
onChange={(next) => onChange({ ...value, work: next[0] ?? null })} />
<Chips legend="最关心的(最多三项)" options={DOMAIN_OPTIONS} value={value.concerns} multiple max={3}
onChange={(next) => onChange({ ...value, concerns: next, avoid: value.avoid.filter((item) => !next.includes(item)) })} />
<Chips legend="不想看的" options={DOMAIN_OPTIONS} value={value.avoid} multiple max={ANNUAL_DOMAINS.length - 1}
onChange={(next) => onChange({ ...value, avoid: next, concerns: value.concerns.filter((item) => !next.includes(item)) })} />
<label className="annual-situation-plans">
<span>已有的计划</span>
<input
@@ -336,10 +344,8 @@ export function SituationForm(props: Readonly<{ value: AnnualSituation; onChange
onChange={(event) => onChange({ ...value, plans: event.target.value })}
/>
</label>
<Chips legend="不想看的" options={DOMAIN_OPTIONS} value={value.avoid} multiple max={ANNUAL_DOMAINS.length - 1}
onChange={(next) => onChange({ ...value, avoid: next, concerns: value.concerns.filter((item) => !next.includes(item)) })} />
<CurrentCityField value={value} onChange={onChange} />
</details>
</div>
);
}
@@ -353,44 +359,57 @@ function CurrentCityField(props: Readonly<{ value: AnnualSituation; onChange: (n
const city = value.currentCity ?? null;
const today = new Date().toISOString().slice(0, 10);
return (
<fieldset className="annual-situation-group annual-current-city">
<legend>今年住在哪个城市</legend>
<p className="annual-situation-hint">年盘按这一年所在的城市起盘;不填就按出生地起,报告里会写明。</p>
<BirthPlacePicker
value={{
countryCode: city?.countryCode || "CN",
provinceCode: city?.provinceCode ?? "",
cityCode: city?.cityCode ?? "",
districtCode: city?.districtCode ?? "",
timezoneId: city?.timezoneId ?? "",
timezoneOffset: city?.timezoneOffset ?? null,
}}
birthDate={today}
birthTime="12:00"
onChange={(selection) => onChange({
...value,
currentCity: {
label: selection.label.slice(0, 80),
latitude: selection.latitude,
longitude: selection.longitude,
timezoneId: selection.timezoneId,
timezoneOffset: selection.timezoneOffset,
countryCode: selection.countryCode,
provinceCode: selection.provinceCode,
cityCode: selection.cityCode,
districtCode: selection.districtCode,
},
})}
/>
{city ? (
<Button type="button" variant="ghost" size="sm" onClick={() => onChange({ ...value, currentCity: null })}>
不用{city.label},改回出生地
</Button>
) : null}
</fieldset>
// BUG-2047: a group, not a fieldset, so its two parts can sit in the second
// step's grid: the question next to 「已有的计划」, the selects across both columns.
<div className="annual-situation-group annual-current-city" role="group" aria-labelledby="annual-current-city-legend">
<div className="annual-current-city-head">
<span className="annual-situation-legend" id="annual-current-city-legend">今年住在哪个城市</span>
<p className="annual-situation-hint">年盘按这一年所在的城市起盘;不填就按出生地起,报告里会写明。</p>
</div>
<div className="annual-current-city-picker">
<BirthPlacePicker
value={{
countryCode: city?.countryCode || "CN",
provinceCode: city?.provinceCode ?? "",
cityCode: city?.cityCode ?? "",
districtCode: city?.districtCode ?? "",
timezoneId: city?.timezoneId ?? "",
timezoneOffset: city?.timezoneOffset ?? null,
}}
birthDate={today}
birthTime="12:00"
onChange={(selection) => onChange({
...value,
currentCity: {
label: selection.label.slice(0, 80),
latitude: selection.latitude,
longitude: selection.longitude,
timezoneId: selection.timezoneId,
timezoneOffset: selection.timezoneOffset,
countryCode: selection.countryCode,
provinceCode: selection.provinceCode,
cityCode: selection.cityCode,
districtCode: selection.districtCode,
},
})}
/>
{city ? (
<Button type="button" variant="ghost" size="sm" onClick={() => onChange({ ...value, currentCity: null })}>
不用{city.label},改回出生地
</Button>
) : null}
</div>
</div>
);
}
/** The request the start button sends; the second step only changes how `situation` is collected. */
export function annualStartBody(subjectId: string, kind: AnnualRangeKind, situation: AnnualSituation) {
return { reportType: "annual_full" as const, subject: subjectId, rangeKind: kind, situation };
}
export const ANNUAL_STEP_TWO_TITLE = "开始前可以补充几句";
export function AnnualOverlay(props: Readonly<{
overview: AnnualOverview;
kind: AnnualRangeKind;
@@ -400,70 +419,117 @@ export function AnnualOverlay(props: Readonly<{
onKind: (kind: AnnualRangeKind) => void;
onSituation: (next: AnnualSituation) => void;
onStart: () => void;
/** 「跳过,直接开始」: start with no optional inputs. Without it the second step has no skip. */
onSkip?: () => void;
/** Outside click, Esc and the close button. Without it the overlay cannot be dismissed. */
onClose?: () => void;
initialStep?: 1 | 2;
}>) {
const { overview } = props;
const { overview, onClose } = props;
const notice = birthNotice(overview.subject);
const [step, setStep] = useState<1 | 2>(props.initialStep ?? 1);
const heading = useRef<HTMLHeadingElement>(null);
// Each step starts at its heading, so a keyboard or screen-reader user lands on
// the new content and Esc reaches the card.
useEffect(() => { heading.current?.focus(); }, [step]);
const blocked = props.starting || overview.creditCost === null;
return (
<div className="annual-veil">
<section className="annual-veil-card" aria-labelledby="annual-veil-title">
<div
className="annual-veil"
onMouseDown={(event) => { if (onClose && event.target === event.currentTarget) onClose(); }}
onKeyDown={(event) => { if (onClose && event.key === "Escape") onClose(); }}
>
<section className="annual-veil-card" aria-labelledby="annual-veil-title" data-step={step}>
<div className="annual-veil-head">
<h2 id="annual-veil-title">{overview.subject.name}的这一年</h2>
</div>
{/* Option B (2026-11-05, product: 「这三个看起来不像是选项」): three
single-choice cards, each with a dot, its name and one line; the
picked one carries its dates. */}
<div className="annual-kind-field">
<span className="annual-kind-legend" id="annual-kind-legend">按哪种「一年」来写</span>
<ToggleGroup
className="annual-kind"
aria-labelledby="annual-kind-legend"
value={[props.kind]}
onValueChange={(next) => {
const picked = next.at(-1) as AnnualRangeKind | undefined;
if (picked) props.onKind(picked);
}}
>
{ANNUAL_RANGE_KINDS.map((kind) => (
<ToggleGroupItem key={kind} value={kind} className="annual-kind-option">
<span className="annual-kind-dot" aria-hidden="true" />
<span className="annual-kind-text">
<span className="annual-kind-label">{ANNUAL_RANGE_LABELS[kind]}</span>
<span className="annual-kind-hint">{ANNUAL_RANGE_HINTS[kind]}</span>
</span>
{kind === props.kind ? (
<span className="annual-range annual-kind-range">{overview.range.start} 到 {overview.range.end}</span>
) : null}
</ToggleGroupItem>
))}
</ToggleGroup>
</div>
<ul className="annual-notes">
{overview.notes.map((note) => <li key={note}>{note}</li>)}
</ul>
{notice ? (
<p className="annual-notice">
{notice.text}
</p>
) : null}
<SituationForm value={props.situation} onChange={props.onSituation} />
<div className="annual-start">
<Button type="button" className="annual-start-button" disabled={props.starting || overview.creditCost === null} onClick={props.onStart}>
{props.starting ? "正在开始…" : "开始写年运"}
</Button>
<p className="annual-price">{priceLine(overview.creditCost)}</p>
{overview.existing?.status === "ready" ? (
<p className="annual-price">
{againLine(overview.creditCost)}
{" "}<AppLink href={`/reports/annual?report=${encodeURIComponent(overview.existing.id)}`}>看上次那份</AppLink>
</p>
) : null}
{props.error ? (
<p className="annual-error" role="alert">
{props.error.message}
{props.error.billing ? <> <a href={accountDialogHref("billing")}>去补点数</a></> : null}
</p>
<h2 id="annual-veil-title" ref={heading} tabIndex={-1}>
{step === 1 ? `${overview.subject.name}的这一年` : ANNUAL_STEP_TWO_TITLE}
</h2>
<span className="annual-veil-step">{step === 1 ? "第 1 步,共 2 步" : "第 2 步,可以不填"}</span>
{onClose ? (
<Button className="dialog-close annual-veil-close" aria-label="关闭" type="button" variant="ghost" size="icon-sm" onClick={onClose}>
<X aria-hidden="true" />
</Button>
) : null}
</div>
{step === 1 ? (
<div className="annual-veil-body">
{/* Option B (2026-11-05, product: 「这三个看起来不像是选项」): three
single-choice cards, each with a dot, its name and one line; the
picked one carries its dates. */}
<div className="annual-kind-field">
<span className="annual-kind-legend" id="annual-kind-legend">按哪种「一年」来写</span>
<ToggleGroup
className="annual-kind"
aria-labelledby="annual-kind-legend"
value={[props.kind]}
onValueChange={(next) => {
const picked = next.at(-1) as AnnualRangeKind | undefined;
if (picked) props.onKind(picked);
}}
>
{ANNUAL_RANGE_KINDS.map((kind) => (
<ToggleGroupItem key={kind} value={kind} className="annual-kind-option">
<span className="annual-kind-dot" aria-hidden="true" />
<span className="annual-kind-text">
<span className="annual-kind-label">{ANNUAL_RANGE_LABELS[kind]}</span>
<span className="annual-kind-hint">{ANNUAL_RANGE_HINTS[kind]}</span>
</span>
{kind === props.kind ? (
<span className="annual-range annual-kind-range">{overview.range.start} 到 {overview.range.end}</span>
) : null}
</ToggleGroupItem>
))}
</ToggleGroup>
</div>
<ul className="annual-notes">
{overview.notes.map((note) => <li key={note}>{note}</li>)}
</ul>
{notice ? (
<p className="annual-notice">
{notice.text}
</p>
) : null}
</div>
) : (
<div className="annual-veil-body">
<SituationForm value={props.situation} onChange={props.onSituation} />
</div>
)}
{step === 1 ? (
<div className="annual-veil-foot">
<div className="annual-veil-actions">
<p className="annual-price annual-veil-actions-lead">{priceLine(overview.creditCost)}</p>
<Button type="button" className="annual-start-button" onClick={() => setStep(2)}>下一步</Button>
</div>
</div>
) : (
<div className="annual-veil-foot">
<div className="annual-veil-actions">
<Button type="button" variant="ghost" className="annual-veil-actions-lead" disabled={props.starting} onClick={() => setStep(1)}>上一步</Button>
{props.onSkip ? (
<Button type="button" variant="ghost" disabled={blocked} onClick={props.onSkip}>跳过,直接开始</Button>
) : null}
<Button type="button" className="annual-start-button" disabled={blocked} onClick={props.onStart}>
{props.starting ? "正在开始…" : "开始写年运"}
</Button>
</div>
<div className="annual-start">
<p className="annual-price">{priceLine(overview.creditCost)}</p>
{overview.existing?.status === "ready" ? (
<p className="annual-price">
{againLine(overview.creditCost)}
{" "}<AppLink href={`/reports/annual?report=${encodeURIComponent(overview.existing.id)}`}>看上次那份</AppLink>
</p>
) : null}
{props.error ? (
<p className="annual-error" role="alert">
{props.error.message}
{props.error.billing ? <> <a href={accountDialogHref("billing")}>去补点数</a></> : null}
</p>
) : null}
</div>
</div>
)}
</section>
</div>
);
@@ -799,6 +865,8 @@ export function AnnualReportPage({ initialReportId = null }: Readonly<{ initialR
const [situation, setSituation] = useState<AnnualSituation>(EMPTY_ANNUAL_SITUATION);
const [starting, setStarting] = useState(false);
const [startError, setStartError] = useState<{ message: string; billing?: boolean } | null>(null);
// BUG-2047: the overlay can be put away; what was picked and filled stays in this page's state.
const [veilClosed, setVeilClosed] = useState(false);
const fromLink = useRef(initialReportId !== null);
useEffect(() => {
@@ -857,7 +925,7 @@ export function AnnualReportPage({ initialReportId = null }: Readonly<{ initialR
onPoll: () => { if (reportId) void loadReport(reportId); },
});
const start = useCallback(async () => {
const start = useCallback(async (given?: AnnualSituation) => {
if (!overview || starting) return;
setStarting(true);
setStartError(null);
@@ -866,7 +934,7 @@ export function AnnualReportPage({ initialReportId = null }: Readonly<{ initialR
method: "POST",
credentials: "same-origin",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify({ reportType: "annual_full", subject: overview.subject.id, rangeKind: kind, situation }),
body: JSON.stringify(annualStartBody(overview.subject.id, kind, given ?? situation)),
});
const json = record(await response.json().catch(() => null));
const id = str(record(json.report).id);
@@ -883,7 +951,8 @@ export function AnnualReportPage({ initialReportId = null }: Readonly<{ initialR
}
}, [kind, overview, situation, starting]);
const showVeil = Boolean(overview) && !reportId;
const canStart = Boolean(overview) && !reportId;
const showVeil = canStart && !veilClosed;
const failed = report?.status === "failed";
const writing = Boolean(reportId) && report !== null && report.status === "generating";
const now = useNow(writing);
@@ -901,6 +970,11 @@ export function AnnualReportPage({ initialReportId = null }: Readonly<{ initialR
<AnnualProgress phase={report.phase} snapshot={report.annual} createdAt={report.createdAt} now={now} queueLine={report.queueLine} />
</div>
) : null}
{canStart && veilClosed ? (
<div className="annual-reopen">
<Button type="button" className="annual-start-button" onClick={() => setVeilClosed(false)}>开始写年运</Button>
</div>
) : null}
{/* A failed run keeps what it already wrote (BUG-1611): the snapshot is
saved after every section, so only the unwritten ones are missing. */}
{report?.annual ? (
@@ -924,6 +998,8 @@ export function AnnualReportPage({ initialReportId = null }: Readonly<{ initialR
onKind={setKind}
onSituation={setSituation}
onStart={() => void start()}
onSkip={() => void start(EMPTY_ANNUAL_SITUATION)}
onClose={() => setVeilClosed(true)}
/>
) : null}
</div>
+13 -2
View File
@@ -328,9 +328,20 @@ test("the overlay matches the approved prototype", () => {
// 原因:产品 2026-11-06「不管做不做生时校正都用同样的算法……误差就用用户初始化选择的」(BUG-1650)
assert.match(html, /出生时间按你填的误差(早 15 分钟到晚 15 分钟)两头都算过/);
assert.doesNotMatch(html, /先做生时纠正|还没确认/);
assert.match(html, />开始写年运</);
// 原值:同一屏里有「开始写年运」和折叠的补充项(关系状态、工作 / 学习、最关心的、已有的计划、不想看的)
// 新值:第一步只有范围、说明和「下一步」;补充项和「开始写年运」在第二步
// 原因:BUG-2047,产品 2026-11-20 走查:补充项展开后弹窗很难看,改成同一个弹窗里的两步
assert.match(html, />下一步</);
assert.doesNotMatch(html, />开始写年运</);
assert.match(html, /本次消耗 20 点,写到一半断掉不扣/);
for (const label of ["关系状态", "工作 / 学习", "最关心的", "已有的计划", "不想看的"]) assert.ok(html.includes(label), label);
for (const label of ["关系状态", "工作 / 学习", "最关心的", "已有的计划", "不想看的"]) assert.ok(!html.includes(label), label);
const second = renderToStaticMarkup(createElement(AnnualOverlay, {
overview, kind: "birthday_year", situation: EMPTY_ANNUAL_SITUATION, starting: false, error: null, initialStep: 2,
onKind: () => undefined, onSituation: () => undefined, onStart: () => undefined,
}));
assert.match(second, />开始写年运</);
assert.match(second, /本次消耗 20 点,写到一半断掉不扣/);
for (const label of ["关系状态", "工作 / 学习", "最关心的", "已有的计划", "不想看的"]) assert.ok(second.includes(label), label);
// 原值:没确认带「先做生时纠正」链接,已确认(含校正后采用)不提示
// 新值:按误差范围说明;没填误差直说日期不确定;准确到分钟不提示;校正与否不影响
// 原因:BUG-1650(占星师 2026-11-06 第 11 条;产品 2026-11-06)
@@ -0,0 +1,261 @@
import "./install-test-document";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import React, { createElement, useState } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import {
ANNUAL_STEP_TWO_TITLE,
AnnualOverlay,
annualStartBody,
type AnnualOverview,
} from "../src/components/annual/annual-report-page.tsx";
import {
EMPTY_ANNUAL_SITUATION,
annualOverlayNotes,
annualSituationSchema,
type AnnualSituation,
} from "../src/lib/annual-report-shared.ts";
import { createClientLifecycleHarness } from "./react-client-lifecycle-test-support.ts";
Object.assign(globalThis, { React });
/**
* BUG-2047 (owner walkthrough 2026-11-20): the annual start overlay is two steps
* in one card. These run the real component in React (state and effects are
* React's own); the host DOM is the lifecycle harness, so handlers are invoked
* directly and nothing here measures layout.
*/
const overview: AnnualOverview = {
subject: { id: "self", name: "小林", isSelf: true, birthTime: { known: true, beforeMinutes: 15, afterMinutes: 15, rectification: "none" } as never },
range: { kind: "birthday_year", key: "annual:birthday_year:2026", start: "2026-06-15", end: "2027-06-15", crossesBirthday: false, birthdays: [] },
notes: annualOverlayNotes("birthday_year"),
creditCost: 50,
existing: { id: "report-1", status: "ready" },
};
type Harness = ReturnType<typeof createClientLifecycleHarness>;
type Node = ReturnType<Harness["elements"]>[number];
function textOf(node: Node): string {
const own = typeof node.props?.children === "string" ? node.props.children : "";
return own || node.childNodes.map((child) => textOf(child)).join("");
}
function button(harness: Harness, label: string): Node {
const found = harness.elements().find((node) => node.tagName === "BUTTON" && textOf(node).trim() === label);
assert.ok(found, `button ${label}`);
return found;
}
function hasButton(harness: Harness, label: string): boolean {
return harness.elements().some((node) => node.tagName === "BUTTON" && textOf(node).trim() === label);
}
function byClass(harness: Harness, name: string): Node {
const found = harness.elements().find((node) => (node.getAttribute("class") ?? "").split(/\s+/).includes(name));
assert.ok(found, `.${name}`);
return found;
}
type Calls = { start: number; skip: number; close: number; situations: AnnualSituation[] };
type Recorder = Readonly<{
calls: Calls;
start: () => void;
skip: () => void;
close: () => void;
situation: (next: AnnualSituation) => void;
}>;
function recorder(): Recorder {
const calls: Calls = { start: 0, skip: 0, close: 0, situations: [] };
return {
calls,
start: () => { calls.start += 1; },
skip: () => { calls.skip += 1; },
close: () => { calls.close += 1; },
situation: (next) => { calls.situations.push(next); },
};
}
/** What the page does around the overlay: it owns the situation and the open state. */
function Host({ on, initial }: Readonly<{ on: Recorder; initial: AnnualSituation }>) {
const [situation, setSituation] = useState(initial);
const [open, setOpen] = useState(true);
if (!open) return createElement("button", { type: "button", onClick: () => setOpen(true) }, "重新打开");
return createElement(AnnualOverlay, {
overview, kind: "birthday_year", situation, starting: false, error: null,
onKind: () => undefined,
onSituation: (next: AnnualSituation) => { on.situation(next); setSituation(next); },
onStart: on.start,
onSkip: on.skip,
onClose: () => { on.close(); setOpen(false); },
});
}
test("step one has the range, the notes and 下一步; step two has the optional inputs and the start buttons", async () => {
const harness = createClientLifecycleHarness();
const on = recorder();
try {
await harness.render(createElement(Host, { on, initial: EMPTY_ANNUAL_SITUATION }));
assert.equal(byClass(harness, "annual-veil-card").getAttribute("data-step"), "1");
assert.equal(textOf(byClass(harness, "annual-veil-step")), "第 1 步,共 2 步");
assert.ok(hasButton(harness, "下一步"));
for (const label of ["上一步", "跳过,直接开始", "开始写年运"]) assert.equal(hasButton(harness, label), false, label);
await harness.event(button(harness, "下一步"));
assert.equal(byClass(harness, "annual-veil-card").getAttribute("data-step"), "2");
assert.equal(textOf(harness.elements().find((node) => node.tagName === "H2")!), ANNUAL_STEP_TWO_TITLE);
assert.equal(textOf(byClass(harness, "annual-veil-step")), "第 2 步,可以不填");
for (const label of ["上一步", "跳过,直接开始", "开始写年运"]) assert.ok(hasButton(harness, label), label);
assert.equal(hasButton(harness, "下一步"), false);
// The same card for both steps: the step changes inside it, the shell does not remount.
const card = byClass(harness, "annual-veil-card");
await harness.event(button(harness, "上一步"));
assert.equal(byClass(harness, "annual-veil-card"), card);
assert.equal(card.getAttribute("data-step"), "1");
assert.deepEqual(harness.errors, []);
} finally {
await harness.close();
}
});
test("each step moves focus to its heading", async () => {
const harness = createClientLifecycleHarness();
try {
await harness.render(createElement(Host, { on: recorder(), initial: EMPTY_ANNUAL_SITUATION }));
const heading = () => harness.elements().find((node) => node.tagName === "H2")!;
assert.equal(harness.document.activeElement, heading());
await harness.event(button(harness, "下一步"));
assert.equal(harness.document.activeElement, heading());
assert.equal(heading().getAttribute("tabindex"), "-1");
} finally {
await harness.close();
}
});
test("跳过 calls the skip handler and 开始写年运 the start handler; neither touches what was filled", async () => {
const harness = createClientLifecycleHarness();
const on = recorder();
const { calls } = on;
const filled: AnnualSituation = { ...EMPTY_ANNUAL_SITUATION, relationship: "dating", concerns: ["career"], plans: "明年想换城市" };
try {
await harness.render(createElement(Host, { on, initial: filled }));
await harness.event(button(harness, "下一步"));
await harness.event(button(harness, "跳过,直接开始"));
assert.deepEqual([calls.skip, calls.start], [1, 0]);
await harness.event(button(harness, "开始写年运"));
assert.deepEqual([calls.skip, calls.start], [1, 1]);
assert.deepEqual(calls.situations, [], "starting or skipping does not rewrite the form");
const plans = harness.elements().find((node) => node.tagName === "INPUT" && node.getAttribute("placeholder") === "比如:明年想换城市");
assert.equal(plans?.props.value, "明年想换城市");
} finally {
await harness.close();
}
});
test("values stay when going back and forth and when the overlay is closed and reopened", async () => {
const harness = createClientLifecycleHarness();
const on = recorder();
const { calls } = on;
const plansInput = () => harness.elements().find((node) => node.tagName === "INPUT" && node.getAttribute("placeholder") === "比如:明年想换城市");
try {
await harness.render(createElement(Host, { on, initial: EMPTY_ANNUAL_SITUATION }));
await harness.event(button(harness, "下一步"));
await harness.event(plansInput()!, "onChange", { target: { value: "想换工作" } });
assert.equal(calls.situations.at(-1)?.plans, "想换工作");
await harness.event(button(harness, "上一步"));
await harness.event(button(harness, "下一步"));
assert.equal(plansInput()?.props.value, "想换工作");
const close = harness.elements().find((node) => node.tagName === "BUTTON" && node.getAttribute("aria-label") === "关闭");
assert.ok(close, "close button");
await harness.event(close);
assert.equal(calls.close, 1);
assert.equal(harness.elements().some((node) => (node.getAttribute("class") ?? "").includes("annual-veil")), false);
await harness.event(button(harness, "重新打开"));
assert.equal(byClass(harness, "annual-veil-card").getAttribute("data-step"), "1", "a reopened overlay starts at the first step");
await harness.event(button(harness, "下一步"));
assert.equal(plansInput()?.props.value, "想换工作");
} finally {
await harness.close();
}
});
test("outside click and Esc close; a click inside the card does not", async () => {
const harness = createClientLifecycleHarness();
const on = recorder();
const { calls } = on;
try {
await harness.render(createElement(Host, { on, initial: EMPTY_ANNUAL_SITUATION }));
const veil = byClass(harness, "annual-veil");
const card = byClass(harness, "annual-veil-card");
await harness.event(veil, "onMouseDown", { target: card, currentTarget: veil });
assert.equal(calls.close, 0, "a press that starts inside the card is not an outside click");
await harness.event(veil, "onKeyDown", { key: "Enter" });
assert.equal(calls.close, 0);
await harness.event(veil, "onMouseDown", { target: veil, currentTarget: veil });
assert.equal(calls.close, 1);
await harness.event(button(harness, "重新打开"));
await harness.event(byClass(harness, "annual-veil"), "onKeyDown", { key: "Escape" });
assert.equal(calls.close, 2);
} finally {
await harness.close();
}
});
test("without onClose and onSkip the overlay offers neither (the old one-way overlay still renders)", () => {
const props = {
overview, kind: "birthday_year" as const, situation: EMPTY_ANNUAL_SITUATION, starting: false, error: null,
onKind: () => undefined, onSituation: () => undefined, onStart: () => undefined,
};
const first = renderToStaticMarkup(createElement(AnnualOverlay, props));
assert.doesNotMatch(first, /aria-label="关闭"/);
const second = renderToStaticMarkup(createElement(AnnualOverlay, { ...props, initialStep: 2 }));
assert.doesNotMatch(second, /跳过,直接开始/);
assert.match(second, />上一步</);
// No disclosure triangle any more.
assert.doesNotMatch(second, /<details|<summary|补充现在的情况/);
// The price lines sit under the start button on the second step.
assert.match(second, /本次消耗 50 点,写到一半断掉不扣/);
assert.match(second, /这一年已经写过一份,再写一份会另扣 50 点。/);
assert.match(second, /看上次那份/);
const withError = renderToStaticMarkup(createElement(AnnualOverlay, { ...props, initialStep: 2, error: { message: "点数不够。", billing: true } }));
assert.match(withError, /role="alert"[^>]*>点数不够。/);
assert.doesNotMatch(renderToStaticMarkup(createElement(AnnualOverlay, { ...props, error: { message: "点数不够。", billing: true } })), /点数不够/);
});
test("the request is what it was before: same keys, and 跳过 sends the empty situation", () => {
const filled: AnnualSituation = { ...EMPTY_ANNUAL_SITUATION, relationship: "married", work: "employed", concerns: ["career", "wealth"], avoid: ["home"], plans: "明年想换城市" };
// 原值(页面里的字面量): { reportType: "annual_full", subject, rangeKind, situation }
assert.deepEqual(annualStartBody("self", "calendar_year", filled), { reportType: "annual_full", subject: "self", rangeKind: "calendar_year", situation: filled });
assert.deepEqual(Object.keys(annualStartBody("self", "birthday_year", EMPTY_ANNUAL_SITUATION)), ["reportType", "subject", "rangeKind", "situation"]);
assert.equal(annualSituationSchema.safeParse(annualStartBody("self", "birthday_year", EMPTY_ANNUAL_SITUATION).situation).success, true);
// 最关心的 still stops at three.
assert.equal(annualSituationSchema.safeParse({ ...EMPTY_ANNUAL_SITUATION, concerns: ["career", "wealth", "home", "energy"] }).success, false);
const page = readFileSync(new URL("../src/components/annual/annual-report-page.tsx", import.meta.url), "utf8");
assert.match(page, /body: JSON\.stringify\(annualStartBody\(overview\.subject\.id, kind, given \?\? situation\)\)/);
assert.match(page, /onSkip=\{\(\) => void start\(EMPTY_ANNUAL_SITUATION\)\}/);
assert.match(page, /onClose=\{\(\) => setVeilClosed\(true\)\}/);
// The route still reads the same body.
const route = readFileSync(new URL("../src/app/api/reports/route.ts", import.meta.url), "utf8");
assert.match(route, /reportType === "annual_full"/);
});
test("one card size for both steps; only the middle scrolls; no left accent bar", () => {
const css = readFileSync(new URL("../src/app/annual-report.css", import.meta.url), "utf8");
const card = /\.annual-veil-card \{([^}]*)\}/.exec(css)?.[1] ?? "";
assert.match(card, /width: min\(640px, 100%\)/);
assert.match(card, /height: min\(760px, 100%\)/);
assert.match(card, /overflow: hidden/);
assert.match(css, /\.annual-veil-body \{[^}]*overflow-y: auto/);
assert.match(css, /\.annual-situation \{[^}]*grid-template-columns: repeat\(2, minmax\(0, 1fr\)\)/);
assert.match(css, /@media \(max-width: 720px\) \{[\s\S]*\.annual-situation \{ grid-template-columns: minmax\(0, 1fr\); \}/);
assert.doesNotMatch(css, /\.annual-situation summary|\.annual-situation\[open\]/);
for (const rule of css.match(/\.annual-(?:veil|situation|current-city|reopen)[^{]*\{[^}]*\}/g) ?? []) {
assert.doesNotMatch(rule, /border-left/, rule);
}
});