Add login gate, calculation history, and AI markdown download.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-13 09:39:38 +08:00
parent abf78cbbb5
commit 462bec2739
23 changed files with 878 additions and 74 deletions
+32 -1
View File
@@ -23,6 +23,7 @@ import RegionSelect, {
import { calculateBazi, type BaziChart } from "@/lib/calc/bazi";
import type { GuaResult } from "@/lib/calc/hexagram";
import { streamAiCompletion } from "@/lib/ai/client-stream";
import { saveHistoryEntry } from "@/lib/history/storage";
export default function CombinedForm() {
const [birthDate, setBirthDate] = useState(todaySolarYmd());
@@ -114,8 +115,18 @@ export default function CombinedForm() {
setCompletion("");
setIsLoading(true);
const activeChart =
chart ??
calculateBazi({
date: birthDate,
time: unknownHour ? "12:00" : birthTime,
gender,
longitude: birthLocation!.longitude,
unknownHour,
});
try {
await streamAiCompletion(
const text = await streamAiCompletion(
{
mode: "combined",
payload: {
@@ -144,6 +155,19 @@ export default function CombinedForm() {
},
setCompletion,
);
saveHistoryEntry({
mode: "combined",
title: "综合测算解读",
question,
summary: activeChart.lunarDate,
completion: text,
meta: {
出生地域: birthLocation!.name,
当前地域: currentLocation!.name,
: `${calcDate} ${calcTime}`,
六爻: withHexagram && guaData ? guaData.result.guaTitle : "无",
},
});
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
} finally {
@@ -151,6 +175,11 @@ export default function CombinedForm() {
}
}
const downloadPreamble =
completion && birthLocation && currentLocation
? `# 综合测算 AI 解读\n\n- 问事:${question}\n- 出生地域:${birthLocation.name}\n- 当前地域:${currentLocation.name}\n- 测算时间:${calcDate} ${calcTime}\n${chart ? `- 农历:${chart.lunarDate}\n` : ""}${withHexagram && guaData ? `- 六爻:${guaData.result.guaTitle}\n` : ""}`
: undefined;
return (
<ModeWorkspace
aiTitle="综合解读"
@@ -162,6 +191,8 @@ export default function CombinedForm() {
onCompletion={handleAnalyze}
error={error}
emptyHint="填写完整信息后,点击「综合测算」"
downloadFilename={completion ? "综合测算解读.md" : undefined}
downloadPreamble={downloadPreamble}
/>
}
>