Implement three divination modes, learn pages, and PM2 deploy on port 3130.
Add liuyao/bazi/combined flows with shared calc and AI infrastructure, 64-gua learn routes, and update Ubuntu PM2 deployment docs for port 3130. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+2
-2
@@ -13,8 +13,8 @@ OPENAI_BASE_URL=https://op.bz121.com/v1
|
||||
# AI 模型
|
||||
OPENAI_MODEL=huihui_ai/gemma-4-abliterated:e4b
|
||||
|
||||
# 服务端口
|
||||
PORT=3000
|
||||
# 服务端口(生产 PM2 默认 3130;本地 dev 仍用 3000)
|
||||
PORT=3130
|
||||
|
||||
# 运行环境
|
||||
NODE_ENV=production
|
||||
|
||||
@@ -38,18 +38,23 @@ cp .env.example .env.local
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
访问 http://localhost:3000
|
||||
访问 http://localhost:3000(`pnpm run dev` 默认端口;生产 PM2 为 **3130**)
|
||||
|
||||
## 生产部署(摘要)
|
||||
|
||||
```bash
|
||||
cd /opt/zhimingge
|
||||
cp .env.example .env.local && nano .env.local # 填写 OPENAI_API_KEY,PORT=3130
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm run build
|
||||
pm2 start ecosystem.config.cjs
|
||||
pm2 save && pm2 startup
|
||||
```
|
||||
|
||||
服务监听 **3130** 端口:`http://服务器IP:3130`
|
||||
|
||||
日常更新:`bash scripts/deploy.sh`
|
||||
|
||||
完整步骤见 [docs/DEPLOY.md](./docs/DEPLOY.md)。
|
||||
|
||||
## 目录说明
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
"use server";
|
||||
|
||||
import { streamAIResponse } from "@/lib/ai/stream";
|
||||
import {
|
||||
calculateBazi,
|
||||
formatBaziForPrompt,
|
||||
type BaziInput,
|
||||
} from "@/lib/calc/bazi";
|
||||
import { BAZI_SYSTEM_PROMPT } from "@/lib/prompts";
|
||||
|
||||
export async function getBaziAnswer(
|
||||
input: BaziInput,
|
||||
question: string,
|
||||
birthPlaceName: string,
|
||||
) {
|
||||
const chart = calculateBazi(input);
|
||||
const chartText = formatBaziForPrompt(chart);
|
||||
|
||||
return streamAIResponse(
|
||||
BAZI_SYSTEM_PROMPT,
|
||||
`【出生时空】
|
||||
出生地:${birthPlaceName}
|
||||
|
||||
【排盘信息】
|
||||
${chartText}
|
||||
|
||||
【问事】
|
||||
${question}`,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
"use server";
|
||||
|
||||
import { streamAIResponse } from "@/lib/ai/stream";
|
||||
import {
|
||||
calculateBazi,
|
||||
formatBaziForPrompt,
|
||||
type BaziInput,
|
||||
} from "@/lib/calc/bazi";
|
||||
import {
|
||||
formatTimingForPrompt,
|
||||
getTimingInfoWithLongitude,
|
||||
} from "@/lib/calc/timing";
|
||||
import { COMBINED_SYSTEM_PROMPT } from "@/lib/prompts";
|
||||
import {
|
||||
extractChangeDetails,
|
||||
extractZhangMingRen,
|
||||
readGuaMarkdown,
|
||||
} from "@/lib/content/zhouyi";
|
||||
|
||||
export interface CombinedInput {
|
||||
birth: BaziInput;
|
||||
birthPlaceName: string;
|
||||
currentPlaceName: string;
|
||||
currentLongitude: number;
|
||||
calcDate: string;
|
||||
calcTime: string;
|
||||
question: string;
|
||||
hexagram?: {
|
||||
guaMark: string;
|
||||
guaTitle: string;
|
||||
guaResult: string;
|
||||
guaChange: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function getCombinedAnswer(input: CombinedInput) {
|
||||
const chart = calculateBazi(input.birth);
|
||||
const chartText = formatBaziForPrompt(chart);
|
||||
const { timing, trueSolarTime } = getTimingInfoWithLongitude(
|
||||
input.calcDate,
|
||||
input.calcTime,
|
||||
input.currentLongitude,
|
||||
);
|
||||
const timingText = [
|
||||
formatTimingForPrompt(timing, input.currentPlaceName, input.currentLongitude),
|
||||
`真太阳时:${trueSolarTime}`,
|
||||
].join("\n");
|
||||
|
||||
let hexagramText = "";
|
||||
if (input.hexagram) {
|
||||
const { guaMark, guaTitle, guaResult, guaChange } = input.hexagram;
|
||||
try {
|
||||
const guaDetail = await readGuaMarkdown(guaMark);
|
||||
const explain = extractZhangMingRen(guaDetail) ?? "";
|
||||
const changeList = extractChangeDetails(guaDetail, guaChange, guaTitle);
|
||||
hexagramText = [
|
||||
"",
|
||||
"【卦象 · 可选六爻】",
|
||||
`${guaTitle} ${guaResult} ${guaChange}`,
|
||||
explain,
|
||||
changeList.join("\n"),
|
||||
].join("\n");
|
||||
} catch {
|
||||
hexagramText = [
|
||||
"",
|
||||
"【卦象 · 可选六爻】",
|
||||
`${input.hexagram.guaTitle} ${input.hexagram.guaResult} ${input.hexagram.guaChange}`,
|
||||
].join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return streamAIResponse(
|
||||
COMBINED_SYSTEM_PROMPT,
|
||||
`【人和 · 八字排盘】
|
||||
出生地:${input.birthPlaceName}
|
||||
${chartText}
|
||||
|
||||
${timingText}
|
||||
${hexagramText}
|
||||
|
||||
【问事】
|
||||
${input.question}`,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
"use server";
|
||||
|
||||
import { streamAIResponse } from "@/lib/ai/stream";
|
||||
import {
|
||||
formatLiuyaoTimingForPrompt,
|
||||
getTimingInfoWithLongitude,
|
||||
} from "@/lib/calc/timing";
|
||||
import {
|
||||
extractChangeDetails,
|
||||
extractZhangMingRen,
|
||||
readGuaMarkdown,
|
||||
} from "@/lib/content/zhouyi";
|
||||
import { LIUYAO_SYSTEM_PROMPT } from "@/lib/prompts";
|
||||
|
||||
export interface LiuyaoInput {
|
||||
question: string;
|
||||
calcDate: string;
|
||||
calcTime: string;
|
||||
locationName: string;
|
||||
longitude: number;
|
||||
guaMark: string;
|
||||
guaTitle: string;
|
||||
guaResult: string;
|
||||
guaChange: string;
|
||||
}
|
||||
|
||||
export async function getLiuyaoAnswer(input: LiuyaoInput) {
|
||||
const { timing, trueSolarTime } = getTimingInfoWithLongitude(
|
||||
input.calcDate,
|
||||
input.calcTime,
|
||||
input.longitude,
|
||||
);
|
||||
const timingText = formatLiuyaoTimingForPrompt(
|
||||
timing,
|
||||
trueSolarTime,
|
||||
input.locationName,
|
||||
input.longitude,
|
||||
);
|
||||
|
||||
let guaDetailText = "";
|
||||
try {
|
||||
const guaDetail = await readGuaMarkdown(input.guaMark);
|
||||
const explain = extractZhangMingRen(guaDetail) ?? "";
|
||||
const changeList = extractChangeDetails(
|
||||
guaDetail,
|
||||
input.guaChange,
|
||||
input.guaTitle,
|
||||
);
|
||||
guaDetailText = [explain, changeList.join("\n")].filter(Boolean).join("\n");
|
||||
} catch {
|
||||
guaDetailText = "";
|
||||
}
|
||||
|
||||
return streamAIResponse(
|
||||
LIUYAO_SYSTEM_PROMPT,
|
||||
`${timingText}
|
||||
|
||||
【卦象】
|
||||
${input.guaTitle} ${input.guaResult} ${input.guaChange}
|
||||
|
||||
【问事】
|
||||
${input.question}
|
||||
|
||||
${guaDetailText}`,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import PageShell from "@/components/page-shell";
|
||||
import BaziForm from "@/components/modes/bazi-form";
|
||||
|
||||
export default function BaziPage() {
|
||||
return (
|
||||
<PageShell>
|
||||
<div className="px-4 pt-6 text-center">
|
||||
<h1 className="text-xl font-bold">生辰八字</h1>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
四柱排盘 · 十神大运 · AI 命理解读
|
||||
</p>
|
||||
</div>
|
||||
<BaziForm />
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import PageShell from "@/components/page-shell";
|
||||
import CombinedForm from "@/components/modes/combined-form";
|
||||
|
||||
export default function CombinedPage() {
|
||||
return (
|
||||
<PageShell>
|
||||
<div className="px-4 pt-6 text-center">
|
||||
<h1 className="text-xl font-bold">综合测算</h1>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
天时 · 地利 · 人和 · 六爻可选
|
||||
</p>
|
||||
</div>
|
||||
<CombinedForm />
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
+3
-3
@@ -5,11 +5,11 @@ import Umami from "@/components/umami";
|
||||
import { ThemeProvider } from "next-themes";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "AI 算卦 - 在线卜卦 GPT4 解读",
|
||||
title: "知命阁 - 易经学习 · 六爻算卦 · 生辰八字",
|
||||
description:
|
||||
"AI 算卦 - 通过进行六次硬币的随机卜筮,生成卦象,并使用 AI 对卦象进行分析|AI 算命、在线算命、在线算卦、周易易经64卦",
|
||||
"知命阁 — 融合周易智慧与人工智能,提供易经学习、六爻算卦、生辰八字排盘、综合测算等服务",
|
||||
appleWebApp: {
|
||||
title: "AI 算卦",
|
||||
title: "知命阁",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import PageShell from "@/components/page-shell";
|
||||
import GuaFooter from "@/components/learn/gua-footer";
|
||||
import MarkdownContent from "@/components/learn/markdown-content";
|
||||
import {
|
||||
getGuaName,
|
||||
getGuaNumber,
|
||||
listGuaMarks,
|
||||
readLearnMarkdown,
|
||||
stripFrontmatter,
|
||||
} from "@/lib/content/zhouyi";
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const marks = await listGuaMarks("traditional");
|
||||
return marks.map((guaMark) => ({ guaMark }));
|
||||
}
|
||||
|
||||
export default async function GuaDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ guaMark: string }>;
|
||||
}) {
|
||||
const { guaMark } = await params;
|
||||
const marks = await listGuaMarks("traditional");
|
||||
if (!marks.includes(guaMark)) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const raw = await readLearnMarkdown(guaMark, "traditional");
|
||||
const content = stripFrontmatter(raw);
|
||||
|
||||
return (
|
||||
<PageShell className="max-w-3xl px-4 py-8">
|
||||
<div className="mb-6 text-sm text-muted-foreground">
|
||||
<Link href="/learn" className="hover:text-foreground">
|
||||
← 返回总览
|
||||
</Link>
|
||||
</div>
|
||||
<div className="mb-4 text-sm text-muted-foreground">
|
||||
第 {getGuaNumber(guaMark)} 卦 · {getGuaName(guaMark)}
|
||||
</div>
|
||||
<MarkdownContent content={content} variant="traditional" />
|
||||
<GuaFooter guaMark={guaMark} />
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import PageShell from "@/components/page-shell";
|
||||
import GuaFooter from "@/components/learn/gua-footer";
|
||||
import MarkdownContent from "@/components/learn/markdown-content";
|
||||
import {
|
||||
getGuaName,
|
||||
getGuaNumber,
|
||||
listGuaMarks,
|
||||
readLearnMarkdown,
|
||||
stripFrontmatter,
|
||||
} from "@/lib/content/zhouyi";
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const marks = await listGuaMarks("simplified");
|
||||
return marks.map((guaMark) => ({ guaMark }));
|
||||
}
|
||||
|
||||
export default async function GuaOtherDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ guaMark: string }>;
|
||||
}) {
|
||||
const { guaMark } = await params;
|
||||
const marks = await listGuaMarks("simplified");
|
||||
if (!marks.includes(guaMark)) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const raw = await readLearnMarkdown(guaMark, "simplified");
|
||||
const content = stripFrontmatter(raw);
|
||||
|
||||
return (
|
||||
<PageShell className="max-w-3xl px-4 py-8">
|
||||
<div className="mb-6 text-sm text-muted-foreground">
|
||||
<Link href="/learn/other" className="hover:text-foreground">
|
||||
← 返回简体总览
|
||||
</Link>
|
||||
</div>
|
||||
<div className="mb-4 text-sm text-muted-foreground">
|
||||
第 {getGuaNumber(guaMark)} 卦 · {getGuaName(guaMark)}
|
||||
</div>
|
||||
<MarkdownContent content={content} variant="simplified" />
|
||||
<GuaFooter guaMark={guaMark} />
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import Link from "next/link";
|
||||
import PageShell from "@/components/page-shell";
|
||||
import {
|
||||
getGuaName,
|
||||
getGuaNumber,
|
||||
listGuaMarks,
|
||||
} from "@/lib/content/zhouyi";
|
||||
|
||||
export default async function LearnOtherPage() {
|
||||
const guaMarks = await listGuaMarks("simplified");
|
||||
|
||||
return (
|
||||
<PageShell className="max-w-3xl px-4 py-8">
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-bold">易经学习 · 简体图文版</h1>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
含互卦、错卦、综卦及更多注释(部分卦象图片待补全)
|
||||
</p>
|
||||
<Link
|
||||
href="/learn"
|
||||
className="mt-2 inline-block text-sm text-primary underline underline-offset-4"
|
||||
>
|
||||
← 返回繁体精简版
|
||||
</Link>
|
||||
</div>
|
||||
<div className="overflow-x-auto rounded-lg border">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-muted/50">
|
||||
<tr>
|
||||
<th className="px-4 py-2 text-left font-medium">序号</th>
|
||||
<th className="px-4 py-2 text-left font-medium">卦名</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{guaMarks.map((mark) => (
|
||||
<tr key={mark} className="border-t">
|
||||
<td className="px-4 py-2 font-mono text-muted-foreground">
|
||||
{getGuaNumber(mark)}
|
||||
</td>
|
||||
<td className="px-4 py-2">
|
||||
<Link
|
||||
href={`/learn/other/${encodeURIComponent(mark)}`}
|
||||
className="text-primary underline-offset-4 hover:underline"
|
||||
>
|
||||
{getGuaName(mark)}
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import Link from "next/link";
|
||||
import PageShell from "@/components/page-shell";
|
||||
import {
|
||||
getGuaName,
|
||||
getGuaNumber,
|
||||
listGuaMarks,
|
||||
} from "@/lib/content/zhouyi";
|
||||
|
||||
export default async function LearnPage() {
|
||||
const guaMarks = await listGuaMarks("traditional");
|
||||
|
||||
return (
|
||||
<PageShell className="max-w-3xl px-4 py-8">
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-bold">易经学习</h1>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
周易六十四卦原文详解(繁体精简版)
|
||||
</p>
|
||||
<Link
|
||||
href="/learn/other"
|
||||
className="mt-2 inline-block text-sm text-primary underline underline-offset-4"
|
||||
>
|
||||
切换到简体图文版 →
|
||||
</Link>
|
||||
</div>
|
||||
<div className="overflow-x-auto rounded-lg border">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-muted/50">
|
||||
<tr>
|
||||
<th className="px-4 py-2 text-left font-medium">序号</th>
|
||||
<th className="px-4 py-2 text-left font-medium">卦名</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{guaMarks.map((mark) => (
|
||||
<tr key={mark} className="border-t">
|
||||
<td className="px-4 py-2 font-mono text-muted-foreground">
|
||||
{getGuaNumber(mark)}
|
||||
</td>
|
||||
<td className="px-4 py-2">
|
||||
<Link
|
||||
href={`/learn/${encodeURIComponent(mark)}`}
|
||||
className="text-primary underline-offset-4 hover:underline"
|
||||
>
|
||||
{getGuaName(mark)}
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import PageShell from "@/components/page-shell";
|
||||
import LiuyaoForm from "@/components/modes/liuyao-form";
|
||||
|
||||
export default function LiuyaoPage() {
|
||||
return (
|
||||
<PageShell>
|
||||
<div className="px-4 pt-6 text-center">
|
||||
<h1 className="text-xl font-bold">六爻算卦</h1>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
问事 · 起卦时空 · 线上 / 线下六爻
|
||||
</p>
|
||||
</div>
|
||||
<LiuyaoForm />
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
+53
-8
@@ -1,13 +1,58 @@
|
||||
import Header from "@/components/header";
|
||||
import Divination from "@/components/divination";
|
||||
import Footer from "@/components/footer";
|
||||
import Link from "next/link";
|
||||
import PageShell from "@/components/page-shell";
|
||||
import { BookOpen, BrainCircuit, Compass, Sparkles } from "lucide-react";
|
||||
|
||||
const MODULES = [
|
||||
{
|
||||
href: "/learn",
|
||||
title: "易经学习",
|
||||
description: "64 卦原文阅读,繁体精简版与简体图文版",
|
||||
icon: BookOpen,
|
||||
},
|
||||
{
|
||||
href: "/liuyao",
|
||||
title: "六爻算卦",
|
||||
description: "三钱法起卦,结合卦辞 AI 智能解读",
|
||||
icon: Sparkles,
|
||||
},
|
||||
{
|
||||
href: "/bazi",
|
||||
title: "生辰八字",
|
||||
description: "四柱排盘,十神大运流年,AI 命理解读",
|
||||
icon: BrainCircuit,
|
||||
},
|
||||
{
|
||||
href: "/combined",
|
||||
title: "综合测算",
|
||||
description: "天时地利人和融合分析,六爻可选",
|
||||
icon: Compass,
|
||||
},
|
||||
];
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<Divination />
|
||||
<Footer />
|
||||
</>
|
||||
<PageShell className="max-w-2xl px-4 py-8">
|
||||
<div className="mb-8 text-center">
|
||||
<h1 className="text-2xl font-bold tracking-tight">知命阁</h1>
|
||||
<p className="mt-2 text-muted-foreground">
|
||||
融合周易智慧与人工智能
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
{MODULES.map(({ href, title, description, icon: Icon }) => (
|
||||
<Link
|
||||
key={href}
|
||||
href={href}
|
||||
className="group rounded-lg border bg-card p-5 shadow-sm transition-colors hover:border-primary/40 hover:bg-accent/30"
|
||||
>
|
||||
<div className="mb-3 flex items-center gap-2">
|
||||
<Icon size={20} className="text-primary" />
|
||||
<span className="font-medium">{title}</span>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">{description}</p>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
+16
-88
@@ -1,23 +1,8 @@
|
||||
"use server";
|
||||
import { streamText } from "ai";
|
||||
import { createOpenAI } from "@ai-sdk/openai";
|
||||
import { createStreamableValue } from "ai/rsc";
|
||||
import { ERROR_PREFIX } from "@/lib/constant";
|
||||
import {
|
||||
extractChangeDetails,
|
||||
extractZhangMingRen,
|
||||
readGuaMarkdown,
|
||||
} from "@/lib/content/zhouyi";
|
||||
|
||||
const model =
|
||||
process.env.OPENAI_MODEL ?? "huihui_ai/gemma-4-abliterated:e4b";
|
||||
const openai = createOpenAI({
|
||||
baseURL: process.env.OPENAI_BASE_URL ?? "https://op.bz121.com/v1",
|
||||
});
|
||||
|
||||
const STREAM_INTERVAL = 60;
|
||||
const MAX_SIZE = 6;
|
||||
import { getLiuyaoAnswer } from "@/app/actions/liuyao";
|
||||
|
||||
/** 兼容旧版 divination 组件签名 */
|
||||
export async function getAnswer(
|
||||
prompt: string,
|
||||
guaMark: string,
|
||||
@@ -25,76 +10,19 @@ export async function getAnswer(
|
||||
guaResult: string,
|
||||
guaChange: string,
|
||||
) {
|
||||
console.log(prompt, guaTitle, guaResult, guaChange);
|
||||
const stream = createStreamableValue();
|
||||
try {
|
||||
const guaDetail = await readGuaMarkdown(guaMark);
|
||||
const explain = extractZhangMingRen(guaDetail) ?? "";
|
||||
const changeList = extractChangeDetails(guaDetail, guaChange, guaTitle);
|
||||
const now = new Date();
|
||||
const calcDate = now.toISOString().slice(0, 10);
|
||||
const calcTime = `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}`;
|
||||
|
||||
const { fullStream } = streamText({
|
||||
temperature: 0.5,
|
||||
model: openai(model),
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: `你是一位精通《周易》的AI助手,根据用户提供的卦象和问题,提供准确的卦象解读和实用建议
|
||||
任务要求:逻辑清晰,语气得当
|
||||
1. 解读卦象:分析主卦、变爻及变卦,解读整体趋势和吉凶
|
||||
2. 关联问题:针对用户问题,结合卦象信息,提供具体分析
|
||||
3. 提供建议:根据卦象启示,给出切实可行的建议,帮助用户解决实际问题`,
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: `我摇到的卦象:${guaTitle} ${guaResult} ${guaChange}
|
||||
我的问题:${prompt}
|
||||
|
||||
${explain}
|
||||
${changeList.join("\n")}`,
|
||||
},
|
||||
],
|
||||
maxRetries: 0,
|
||||
});
|
||||
|
||||
let buffer = "";
|
||||
let done = false;
|
||||
const intervalId = setInterval(() => {
|
||||
if (done && buffer.length === 0) {
|
||||
clearInterval(intervalId);
|
||||
stream.done();
|
||||
return;
|
||||
}
|
||||
if (buffer.length <= MAX_SIZE) {
|
||||
stream.update(buffer);
|
||||
buffer = "";
|
||||
} else {
|
||||
const chunk = buffer.slice(0, MAX_SIZE);
|
||||
buffer = buffer.slice(MAX_SIZE);
|
||||
stream.update(chunk);
|
||||
}
|
||||
}, STREAM_INTERVAL);
|
||||
|
||||
(async () => {
|
||||
for await (const part of fullStream) {
|
||||
switch (part.type) {
|
||||
case "text-delta":
|
||||
buffer += part.textDelta;
|
||||
break;
|
||||
case "error":
|
||||
const err = part.error as any;
|
||||
stream.update(ERROR_PREFIX + (err.message ?? err.toString()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
})()
|
||||
.catch(console.error)
|
||||
.finally(() => {
|
||||
done = true;
|
||||
});
|
||||
|
||||
return { data: stream.value };
|
||||
} catch (err: any) {
|
||||
stream.done();
|
||||
return { error: err.message ?? err };
|
||||
}
|
||||
return getLiuyaoAnswer({
|
||||
question: prompt,
|
||||
calcDate,
|
||||
calcTime,
|
||||
locationName: "未指定",
|
||||
longitude: 120,
|
||||
guaMark,
|
||||
guaTitle,
|
||||
guaResult,
|
||||
guaChange,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,256 +0,0 @@
|
||||
"use client";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import Coin from "@/components/coin";
|
||||
import Hexagram, { HexagramObj } from "@/components/hexagram";
|
||||
import { bool } from "aimless.js";
|
||||
import Result, { ResultObj } from "@/components/result";
|
||||
import Question from "@/components/question";
|
||||
import ResultAI from "@/components/result-ai";
|
||||
import { animateChildren } from "@/lib/animate";
|
||||
import guaIndexData from "@/lib/data/gua-index.json";
|
||||
import guaListData from "@/lib/data/gua-list.json";
|
||||
import { getAnswer } from "@/app/server";
|
||||
import { readStreamableValue } from "ai/rsc";
|
||||
import { Button } from "./ui/button";
|
||||
import { BrainCircuit, ListRestart } from "lucide-react";
|
||||
import { ERROR_PREFIX } from "@/lib/constant";
|
||||
|
||||
const AUTO_DELAY = 600;
|
||||
|
||||
function Divination() {
|
||||
const [error, setError] = useState<string>("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [completion, setCompletion] = useState<string>("");
|
||||
|
||||
async function onCompletion() {
|
||||
setError("");
|
||||
setCompletion("");
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const { data, error } = await getAnswer(
|
||||
question,
|
||||
resultObj!.guaMark,
|
||||
resultObj!.guaTitle,
|
||||
resultObj!.guaResult,
|
||||
resultObj!.guaChange,
|
||||
);
|
||||
if (error) {
|
||||
setError(error);
|
||||
return;
|
||||
}
|
||||
if (data) {
|
||||
let ret = "";
|
||||
for await (const delta of readStreamableValue(data)) {
|
||||
if (delta.startsWith(ERROR_PREFIX)) {
|
||||
setError(delta.slice(ERROR_PREFIX.length));
|
||||
return;
|
||||
}
|
||||
ret += delta;
|
||||
setCompletion(ret);
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
setError(err.message ?? err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
const [frontList, setFrontList] = useState([true, true, true]);
|
||||
const [rotation, setRotation] = useState(false);
|
||||
|
||||
const [hexagramList, setHexagramList] = useState<HexagramObj[]>([]);
|
||||
|
||||
const [resultObj, setResultObj] = useState<ResultObj | null>(null);
|
||||
const [question, setQuestion] = useState("");
|
||||
|
||||
const [resultAi, setResultAi] = useState(false);
|
||||
|
||||
const flexRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const [count, setCount] = useState(0);
|
||||
|
||||
// 自动卜筮
|
||||
useEffect(() => {
|
||||
if (rotation || resultObj || count >= 6 || !question) {
|
||||
return;
|
||||
}
|
||||
setTimeout(startClick, AUTO_DELAY);
|
||||
}, [question, rotation]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!flexRef.current) {
|
||||
return;
|
||||
}
|
||||
const observer = animateChildren(flexRef.current);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
function onTransitionEnd() {
|
||||
setRotation(false);
|
||||
let frontCount = frontList.reduce((acc, val) => (val ? acc + 1 : acc), 0);
|
||||
setHexagramList((list) => {
|
||||
const newList = [
|
||||
...list,
|
||||
{
|
||||
change: frontCount == 0 || frontCount == 3 || null,
|
||||
yang: frontCount >= 2,
|
||||
separate: list.length == 3,
|
||||
},
|
||||
];
|
||||
setResult(newList);
|
||||
return newList;
|
||||
});
|
||||
}
|
||||
|
||||
function startClick() {
|
||||
if (rotation) {
|
||||
return;
|
||||
}
|
||||
if (hexagramList.length >= 6) {
|
||||
setHexagramList([]);
|
||||
}
|
||||
setFrontList([bool(), bool(), bool()]);
|
||||
setRotation(true);
|
||||
setCount(count + 1);
|
||||
}
|
||||
|
||||
async function testClick() {
|
||||
for (let i = 0; i < 6; i++) {
|
||||
onTransitionEnd();
|
||||
}
|
||||
}
|
||||
|
||||
function restartClick() {
|
||||
setResultObj(null);
|
||||
setHexagramList([]);
|
||||
setQuestion("");
|
||||
setResultAi(false);
|
||||
setCount(0);
|
||||
stop();
|
||||
}
|
||||
|
||||
function aiClick() {
|
||||
setResultAi(true);
|
||||
onCompletion();
|
||||
}
|
||||
|
||||
function setResult(list: HexagramObj[]) {
|
||||
if (list.length != 6) {
|
||||
return;
|
||||
}
|
||||
const guaDict1 = ["坤", "震", "坎", "兑", "艮", "离", "巽", "乾"];
|
||||
const guaDict2 = ["地", "雷", "水", "泽", "山", "火", "风", "天"];
|
||||
|
||||
const changeYang = ["初九", "九二", "九三", "九四", "九五", "上九"];
|
||||
const changeYin = ["初六", "六二", "六三", "六四", "六五", "上六"];
|
||||
|
||||
const changeList: String[] = [];
|
||||
list.forEach((value, index) => {
|
||||
if (!value.change) {
|
||||
return;
|
||||
}
|
||||
changeList.push(value.yang ? changeYang[index] : changeYin[index]);
|
||||
});
|
||||
|
||||
// 卦的结果: 第X卦 X卦 XX卦 X上X下
|
||||
// 计算卦的索引,111对应乾卦,000对应坤卦,索引转为10进制。
|
||||
const upIndex =
|
||||
(list[5].yang ? 4 : 0) + (list[4].yang ? 2 : 0) + (list[3].yang ? 1 : 0);
|
||||
const downIndex =
|
||||
(list[2].yang ? 4 : 0) + (list[1].yang ? 2 : 0) + (list[0].yang ? 1 : 0);
|
||||
|
||||
const guaIndex = guaIndexData[upIndex][downIndex] - 1;
|
||||
const guaName1 = guaListData[guaIndex];
|
||||
|
||||
let guaName2;
|
||||
if (upIndex === downIndex) {
|
||||
// 上下卦相同,格式为X为X
|
||||
guaName2 = guaDict1[upIndex] + "为" + guaDict2[upIndex];
|
||||
} else {
|
||||
guaName2 = guaDict2[upIndex] + guaDict2[downIndex] + guaName1;
|
||||
}
|
||||
|
||||
const guaDesc = guaDict1[upIndex] + "上" + guaDict1[downIndex] + "下";
|
||||
|
||||
setResultObj({
|
||||
// 例:26.山天大畜
|
||||
guaMark: `${(guaIndex + 1).toString().padStart(2, "0")}.${guaName2}`,
|
||||
guaTitle: `周易第${guaIndex + 1}卦`,
|
||||
// 例:大畜卦(山天大畜)_艮上乾下
|
||||
guaResult: `${guaName1}卦(${guaName2})_${guaDesc}`,
|
||||
guaChange:
|
||||
changeList.length === 0 ? "无变爻" : `变爻: ${changeList.toString()}`,
|
||||
});
|
||||
}
|
||||
|
||||
const showResult = resultObj !== null;
|
||||
const inputQuestion = question === "";
|
||||
return (
|
||||
<main
|
||||
ref={flexRef}
|
||||
className="gap mx-auto flex h-0 w-[90%] flex-1 flex-col flex-nowrap items-center"
|
||||
>
|
||||
<Question question={question} setQuestion={setQuestion} />
|
||||
|
||||
{!resultAi && !inputQuestion && (
|
||||
<Coin
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
frontList={frontList}
|
||||
rotation={rotation}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!inputQuestion && !showResult && (
|
||||
<div className="relative">
|
||||
<span className="pl-2 text-lg font-medium">
|
||||
🎲 第{" "}
|
||||
<span className="font-mono text-xl font-bold text-orange-500">
|
||||
{count === 0 ? "-/-" : `${count}/6`}
|
||||
</span>{" "}
|
||||
次卜筮
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!inputQuestion && hexagramList.length != 0 && (
|
||||
<div className="flex max-w-md gap-2">
|
||||
<Hexagram list={hexagramList} />
|
||||
{showResult && (
|
||||
<div className="flex flex-col justify-around">
|
||||
<Result {...resultObj} />
|
||||
<div className="flex flex-col gap-2 sm:px-6">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={restartClick}
|
||||
disabled={rotation}
|
||||
>
|
||||
<ListRestart size={18} className="mr-1" />
|
||||
重来
|
||||
</Button>
|
||||
{resultAi ? null : (
|
||||
<Button size="sm" onClick={aiClick} disabled={rotation}>
|
||||
<BrainCircuit size={16} className="mr-1" />
|
||||
AI 解读
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{resultAi && (
|
||||
<ResultAI
|
||||
completion={completion}
|
||||
isLoading={isLoading}
|
||||
onCompletion={onCompletion}
|
||||
error={error}
|
||||
/>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export default Divination;
|
||||
+43
-5
@@ -1,15 +1,53 @@
|
||||
"use client";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { ChatGPT } from "@/components/svg";
|
||||
import { ModeToggle } from "@/components/mode-toggle";
|
||||
|
||||
const NAV_ITEMS = [
|
||||
{ href: "/learn", label: "易经学习" },
|
||||
{ href: "/liuyao", label: "六爻算卦" },
|
||||
{ href: "/bazi", label: "生辰八字" },
|
||||
{ href: "/combined", label: "综合测算" },
|
||||
];
|
||||
|
||||
function NavLink({ href, label }: { href: string; label: string }) {
|
||||
const pathname = usePathname();
|
||||
const active =
|
||||
href === "/"
|
||||
? pathname === "/"
|
||||
: pathname === href || pathname.startsWith(`${href}/`);
|
||||
|
||||
return (
|
||||
<Link
|
||||
href={href}
|
||||
className={`whitespace-nowrap text-sm transition-colors ${
|
||||
active
|
||||
? "font-medium text-foreground"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
{label}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Header() {
|
||||
return (
|
||||
<header className="h-14 bg-secondary py-2 shadow">
|
||||
<div className="mx-auto flex h-full w-full items-center justify-center sm:max-w-md sm:justify-between md:max-w-2xl">
|
||||
<div className="flex gap-2">
|
||||
<header className="bg-secondary py-2 shadow">
|
||||
<div className="mx-auto flex w-full max-w-4xl flex-col gap-2 px-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<Link href="/" className="flex items-center justify-center gap-2 sm:justify-start">
|
||||
<ChatGPT />
|
||||
<span>知命阁</span>
|
||||
<span className="font-medium">知命阁</span>
|
||||
</Link>
|
||||
<nav className="flex flex-wrap items-center justify-center gap-x-4 gap-y-1">
|
||||
{NAV_ITEMS.map((item) => (
|
||||
<NavLink key={item.href} {...item} />
|
||||
))}
|
||||
</nav>
|
||||
<div className="flex justify-center sm:justify-end">
|
||||
<ModeToggle />
|
||||
</div>
|
||||
<ModeToggle />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Sparkles } from "lucide-react";
|
||||
|
||||
export default function GuaFooter({ guaMark }: { guaMark: string }) {
|
||||
return (
|
||||
<div className="mt-8 flex flex-wrap gap-3 border-t pt-6">
|
||||
<Button asChild size="sm">
|
||||
<Link href={`/liuyao?gua=${encodeURIComponent(guaMark)}`}>
|
||||
<Sparkles size={16} className="mr-1" />
|
||||
以此卦起卦
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import Link from "next/link";
|
||||
import Markdown from "react-markdown";
|
||||
import type { LearnVariant } from "@/lib/content/zhouyi";
|
||||
|
||||
function resolveLearnHref(
|
||||
href: string | undefined,
|
||||
variant: LearnVariant,
|
||||
): string | undefined {
|
||||
if (!href) {
|
||||
return href;
|
||||
}
|
||||
if (href.startsWith("http://") || href.startsWith("https://")) {
|
||||
return href;
|
||||
}
|
||||
|
||||
const base = variant === "traditional" ? "/learn" : "/learn/other";
|
||||
|
||||
if (href === "index.md" || href === "./index.md") {
|
||||
return base;
|
||||
}
|
||||
if (href === "other/index.md") {
|
||||
return "/learn/other";
|
||||
}
|
||||
if (href.endsWith("/index.md")) {
|
||||
const mark = href.replace(/\/index\.md$/, "").replace(/^\.\//, "");
|
||||
if (mark.startsWith("other/")) {
|
||||
return `/learn/other/${mark.slice("other/".length)}`;
|
||||
}
|
||||
return `${base}/${mark}`;
|
||||
}
|
||||
return href;
|
||||
}
|
||||
|
||||
export default function MarkdownContent({
|
||||
content,
|
||||
variant = "traditional",
|
||||
}: {
|
||||
content: string;
|
||||
variant?: LearnVariant;
|
||||
}) {
|
||||
return (
|
||||
<Markdown
|
||||
className="prose max-w-none dark:prose-invert prose-headings:scroll-mt-20 prose-a:text-primary"
|
||||
components={{
|
||||
a: ({ href, children, ...props }) => {
|
||||
const resolved = resolveLearnHref(href, variant);
|
||||
if (resolved?.startsWith("/")) {
|
||||
return (
|
||||
<Link href={resolved} {...props}>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<a href={resolved} {...props}>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
},
|
||||
img: ({ src, alt, ...props }) => {
|
||||
if (typeof src === "string" && !src.startsWith("http")) {
|
||||
return (
|
||||
<span className="my-2 block rounded border border-dashed p-4 text-center text-sm text-muted-foreground">
|
||||
[{alt || "卦象图片"}]
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return <img src={src} alt={alt} {...props} />;
|
||||
},
|
||||
}}
|
||||
>
|
||||
{content}
|
||||
</Markdown>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { BaziChart, PillarInfo } from "@/lib/calc/bazi";
|
||||
|
||||
function PillarRow({ label, pillar }: { label: string; pillar: PillarInfo }) {
|
||||
return (
|
||||
<tr className="border-t">
|
||||
<td className="px-3 py-2 font-medium">{label}</td>
|
||||
<td className="px-3 py-2 font-mono">{pillar.ganZhi}</td>
|
||||
<td className="px-3 py-2">{pillar.shiShenGan}</td>
|
||||
<td className="px-3 py-2 text-sm">
|
||||
{pillar.shiShenZhi.join("、") || "—"}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-sm">{pillar.naYin}</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
export default function BaziChartDisplay({ chart }: { chart: BaziChart }) {
|
||||
return (
|
||||
<div className="space-y-4 rounded-lg border bg-card p-4 text-sm">
|
||||
<div className="grid gap-1 text-muted-foreground sm:grid-cols-2">
|
||||
<span>出生:{chart.birthTime}</span>
|
||||
<span>真太阳时:{chart.trueSolarTime}</span>
|
||||
<span className="sm:col-span-2">农历:{chart.lunarDate}</span>
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full">
|
||||
<thead className="bg-muted/50 text-left">
|
||||
<tr>
|
||||
<th className="px-3 py-2">柱</th>
|
||||
<th className="px-3 py-2">干支</th>
|
||||
<th className="px-3 py-2">天干十神</th>
|
||||
<th className="px-3 py-2">地支十神</th>
|
||||
<th className="px-3 py-2">纳音</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<PillarRow label="年柱" pillar={chart.pillars.year} />
|
||||
<PillarRow label="月柱" pillar={chart.pillars.month} />
|
||||
<PillarRow label="日柱" pillar={chart.pillars.day} />
|
||||
<PillarRow label="时柱" pillar={chart.pillars.time} />
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="mb-1 font-medium">大运</div>
|
||||
<p className="text-muted-foreground">
|
||||
起运 {chart.daYun.startYear} 年 {chart.daYun.startMonth} 月{" "}
|
||||
{chart.daYun.startDay} 天 ·{" "}
|
||||
{chart.daYun.items.map((d) => `${d.startAge}岁 ${d.ganZhi}`).join(" → ")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="mb-1 font-medium">流年</div>
|
||||
<p className="text-muted-foreground">
|
||||
{chart.liuNian.map((l) => `${l.year}(${l.ganZhi})`).join("、")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="mb-1 font-medium">神煞</div>
|
||||
<p className="text-muted-foreground">
|
||||
吉神:{chart.shenSha.ji.join("、") || "无"}
|
||||
<br />
|
||||
凶煞:{chart.shenSha.xiong.join("、") || "无"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { readStreamableValue } from "ai/rsc";
|
||||
import { BrainCircuit } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import ResultAI from "@/components/result-ai";
|
||||
import BaziChartDisplay from "@/components/modes/bazi-chart";
|
||||
import DateTimePicker, { nowDateString } from "@/components/shared/datetime-picker";
|
||||
import RegionSelect, {
|
||||
useRegionLocation,
|
||||
} from "@/components/shared/region-select";
|
||||
import { calculateBazi, type BaziChart } from "@/lib/calc/bazi";
|
||||
import { getBaziAnswer } from "@/app/actions/bazi";
|
||||
import { ERROR_PREFIX } from "@/lib/constant";
|
||||
|
||||
export default function BaziForm() {
|
||||
const [date, setDate] = useState(nowDateString());
|
||||
const [time, setTime] = useState("12:00");
|
||||
const [unknownHour, setUnknownHour] = useState(false);
|
||||
const [gender, setGender] = useState<"male" | "female">("male");
|
||||
const [provinceCode, setProvinceCode] = useState("");
|
||||
const [cityCode, setCityCode] = useState("");
|
||||
const [question, setQuestion] = useState("");
|
||||
const [chart, setChart] = useState<BaziChart | null>(null);
|
||||
const [completion, setCompletion] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [showAi, setShowAi] = useState(false);
|
||||
|
||||
const location = useRegionLocation(provinceCode, cityCode);
|
||||
|
||||
function buildInput() {
|
||||
if (!location) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
date,
|
||||
time: unknownHour ? "12:00" : time,
|
||||
gender,
|
||||
longitude: location.longitude,
|
||||
unknownHour,
|
||||
};
|
||||
}
|
||||
|
||||
function handleCalculate() {
|
||||
const input = buildInput();
|
||||
if (!input) {
|
||||
setError("请选择出生地域");
|
||||
return;
|
||||
}
|
||||
if (!question.trim()) {
|
||||
setError("请输入问事");
|
||||
return;
|
||||
}
|
||||
setError("");
|
||||
setChart(calculateBazi(input));
|
||||
setShowAi(false);
|
||||
setCompletion("");
|
||||
}
|
||||
|
||||
async function handleAnalyze() {
|
||||
const input = buildInput();
|
||||
if (!input || !chart) {
|
||||
return;
|
||||
}
|
||||
setError("");
|
||||
setCompletion("");
|
||||
setIsLoading(true);
|
||||
setShowAi(true);
|
||||
try {
|
||||
const { data, error: apiError } = await getBaziAnswer(
|
||||
input,
|
||||
question,
|
||||
location!.name,
|
||||
);
|
||||
if (apiError) {
|
||||
setError(apiError);
|
||||
return;
|
||||
}
|
||||
if (data) {
|
||||
let ret = "";
|
||||
for await (const delta of readStreamableValue(data)) {
|
||||
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
|
||||
setError(delta.slice(ERROR_PREFIX.length));
|
||||
return;
|
||||
}
|
||||
ret += delta ?? "";
|
||||
setCompletion(ret);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col gap-4 px-4 py-6">
|
||||
<div className="mx-auto w-full max-w-lg space-y-4">
|
||||
<DateTimePicker
|
||||
label="出生日期 / 时间"
|
||||
date={date}
|
||||
time={time}
|
||||
timeDisabled={unknownHour}
|
||||
onDateChange={setDate}
|
||||
onTimeChange={setTime}
|
||||
/>
|
||||
<label className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={unknownHour}
|
||||
onChange={(e) => setUnknownHour(e.target.checked)}
|
||||
/>
|
||||
时辰不详
|
||||
</label>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label className="text-sm font-medium">性别</label>
|
||||
<div className="flex gap-4">
|
||||
{(["male", "female"] as const).map((g) => (
|
||||
<label key={g} className="flex items-center gap-2 text-sm">
|
||||
<input
|
||||
type="radio"
|
||||
name="gender"
|
||||
checked={gender === g}
|
||||
onChange={() => setGender(g)}
|
||||
/>
|
||||
{g === "male" ? "男" : "女"}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<RegionSelect
|
||||
label="出生地域"
|
||||
provinceCode={provinceCode}
|
||||
cityCode={cityCode}
|
||||
onProvinceChange={setProvinceCode}
|
||||
onCityChange={setCityCode}
|
||||
/>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label className="text-sm font-medium">问事</label>
|
||||
<Textarea
|
||||
placeholder="事业、婚姻、健康等..."
|
||||
value={question}
|
||||
onChange={(e) => setQuestion(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && !showAi && (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
)}
|
||||
|
||||
<Button onClick={handleCalculate} className="w-full">
|
||||
排盘
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{chart && (
|
||||
<div className="mx-auto w-full max-w-lg space-y-4">
|
||||
<BaziChartDisplay chart={chart} />
|
||||
{!showAi && (
|
||||
<Button onClick={handleAnalyze} className="w-full">
|
||||
<BrainCircuit size={16} className="mr-1" />
|
||||
测算
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showAi && (
|
||||
<div className="mx-auto h-96 w-full max-w-lg flex-1">
|
||||
<ResultAI
|
||||
completion={completion}
|
||||
isLoading={isLoading}
|
||||
onCompletion={handleAnalyze}
|
||||
error={error}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { readStreamableValue } from "ai/rsc";
|
||||
import { Compass } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import Result from "@/components/result";
|
||||
import ResultAI from "@/components/result-ai";
|
||||
import BaziChartDisplay from "@/components/modes/bazi-chart";
|
||||
import DateTimePicker, {
|
||||
nowDateString,
|
||||
nowTimeString,
|
||||
} from "@/components/shared/datetime-picker";
|
||||
import HexagramInput from "@/components/shared/hexagram-input";
|
||||
import RegionSelect, {
|
||||
useRegionLocation,
|
||||
} from "@/components/shared/region-select";
|
||||
import { calculateBazi, type BaziChart } from "@/lib/calc/bazi";
|
||||
import type { GuaResult } from "@/lib/calc/hexagram";
|
||||
import { getCombinedAnswer } from "@/app/actions/combined";
|
||||
import { ERROR_PREFIX } from "@/lib/constant";
|
||||
|
||||
export default function CombinedForm() {
|
||||
const [birthDate, setBirthDate] = useState("1990-01-01");
|
||||
const [birthTime, setBirthTime] = useState("12:00");
|
||||
const [unknownHour, setUnknownHour] = useState(false);
|
||||
const [gender, setGender] = useState<"male" | "female">("male");
|
||||
const [birthProvince, setBirthProvince] = useState("");
|
||||
const [birthCity, setBirthCity] = useState("");
|
||||
const [currentProvince, setCurrentProvince] = useState("");
|
||||
const [currentCity, setCurrentCity] = useState("");
|
||||
const [calcDate, setCalcDate] = useState(nowDateString);
|
||||
const [calcTime, setCalcTime] = useState(nowTimeString);
|
||||
const [question, setQuestion] = useState("");
|
||||
const [withHexagram, setWithHexagram] = useState(false);
|
||||
const [castMode, setCastMode] = useState<"online" | "offline">("online");
|
||||
const [guaData, setGuaData] = useState<GuaResult | null>(null);
|
||||
|
||||
const [chart, setChart] = useState<BaziChart | null>(null);
|
||||
const [completion, setCompletion] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [showAi, setShowAi] = useState(false);
|
||||
|
||||
const birthLocation = useRegionLocation(birthProvince, birthCity);
|
||||
const currentLocation = useRegionLocation(currentProvince, currentCity);
|
||||
const hexagramReady =
|
||||
!withHexagram ||
|
||||
(question.trim() !== "" && currentLocation !== null && guaData !== null);
|
||||
|
||||
function validate(): string | null {
|
||||
if (!birthLocation) {
|
||||
return "请选择出生地域";
|
||||
}
|
||||
if (!currentLocation) {
|
||||
return "请选择当前所在地域";
|
||||
}
|
||||
if (!question.trim()) {
|
||||
return "请输入问事内容";
|
||||
}
|
||||
if (withHexagram && !guaData) {
|
||||
return "请完成六爻起卦,或取消附加六爻";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function handlePreview() {
|
||||
const err = validate();
|
||||
if (err) {
|
||||
setError(err);
|
||||
return;
|
||||
}
|
||||
setError("");
|
||||
setChart(
|
||||
calculateBazi({
|
||||
date: birthDate,
|
||||
time: unknownHour ? "12:00" : birthTime,
|
||||
gender,
|
||||
longitude: birthLocation!.longitude,
|
||||
unknownHour,
|
||||
}),
|
||||
);
|
||||
setShowAi(false);
|
||||
setCompletion("");
|
||||
}
|
||||
|
||||
async function handleAnalyze() {
|
||||
const err = validate();
|
||||
if (err) {
|
||||
setError(err);
|
||||
return;
|
||||
}
|
||||
if (!chart) {
|
||||
setChart(
|
||||
calculateBazi({
|
||||
date: birthDate,
|
||||
time: unknownHour ? "12:00" : birthTime,
|
||||
gender,
|
||||
longitude: birthLocation!.longitude,
|
||||
unknownHour,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
setError("");
|
||||
setCompletion("");
|
||||
setIsLoading(true);
|
||||
setShowAi(true);
|
||||
|
||||
try {
|
||||
const { data, error: apiError } = await getCombinedAnswer({
|
||||
birth: {
|
||||
date: birthDate,
|
||||
time: unknownHour ? "12:00" : birthTime,
|
||||
gender,
|
||||
longitude: birthLocation!.longitude,
|
||||
unknownHour,
|
||||
},
|
||||
birthPlaceName: birthLocation!.name,
|
||||
currentPlaceName: currentLocation!.name,
|
||||
currentLongitude: currentLocation!.longitude,
|
||||
calcDate,
|
||||
calcTime,
|
||||
question,
|
||||
hexagram: withHexagram && guaData
|
||||
? {
|
||||
guaMark: guaData.result.guaMark,
|
||||
guaTitle: guaData.result.guaTitle,
|
||||
guaResult: guaData.result.guaResult,
|
||||
guaChange: guaData.result.guaChange,
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
if (apiError) {
|
||||
setError(apiError);
|
||||
return;
|
||||
}
|
||||
if (data) {
|
||||
let ret = "";
|
||||
for await (const delta of readStreamableValue(data)) {
|
||||
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
|
||||
setError(delta.slice(ERROR_PREFIX.length));
|
||||
return;
|
||||
}
|
||||
ret += delta ?? "";
|
||||
setCompletion(ret);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : String(e));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col gap-4 px-4 py-6">
|
||||
<div className="mx-auto w-full max-w-lg space-y-6">
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-sm font-semibold text-primary">人和 · 生辰八字</h2>
|
||||
<DateTimePicker
|
||||
label="出生日期 / 时间"
|
||||
date={birthDate}
|
||||
time={birthTime}
|
||||
timeDisabled={unknownHour}
|
||||
onDateChange={setBirthDate}
|
||||
onTimeChange={setBirthTime}
|
||||
/>
|
||||
<label className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={unknownHour}
|
||||
onChange={(e) => setUnknownHour(e.target.checked)}
|
||||
/>
|
||||
时辰不详
|
||||
</label>
|
||||
<div className="flex gap-4">
|
||||
{(["male", "female"] as const).map((g) => (
|
||||
<label key={g} className="flex items-center gap-2 text-sm">
|
||||
<input
|
||||
type="radio"
|
||||
name="combined-gender"
|
||||
checked={gender === g}
|
||||
onChange={() => setGender(g)}
|
||||
/>
|
||||
{g === "male" ? "男" : "女"}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<RegionSelect
|
||||
label="出生地域"
|
||||
provinceCode={birthProvince}
|
||||
cityCode={birthCity}
|
||||
onProvinceChange={setBirthProvince}
|
||||
onCityChange={setBirthCity}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-sm font-semibold text-primary">地利 · 当前位置</h2>
|
||||
<RegionSelect
|
||||
label="所在地域"
|
||||
provinceCode={currentProvince}
|
||||
cityCode={currentCity}
|
||||
onProvinceChange={setCurrentProvince}
|
||||
onCityChange={setCurrentCity}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-sm font-semibold text-primary">天时 · 测算时刻</h2>
|
||||
<DateTimePicker
|
||||
label="日期 / 时间"
|
||||
date={calcDate}
|
||||
time={calcTime}
|
||||
onDateChange={setCalcDate}
|
||||
onTimeChange={setCalcTime}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-sm font-semibold text-primary">问事</h2>
|
||||
<Textarea
|
||||
placeholder="具体所求..."
|
||||
value={question}
|
||||
onChange={(e) => setQuestion(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section className="space-y-3">
|
||||
<label className="flex items-center gap-2 text-sm font-medium">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={withHexagram}
|
||||
onChange={(e) => {
|
||||
setWithHexagram(e.target.checked);
|
||||
setGuaData(null);
|
||||
setShowAi(false);
|
||||
}}
|
||||
/>
|
||||
附加六爻(可选)
|
||||
</label>
|
||||
{withHexagram && (
|
||||
<div className="space-y-3 rounded-md border p-3">
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={castMode === "online" ? "default" : "outline"}
|
||||
onClick={() => {
|
||||
setCastMode("online");
|
||||
setGuaData(null);
|
||||
}}
|
||||
>
|
||||
线上摇卦
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={castMode === "offline" ? "default" : "outline"}
|
||||
onClick={() => {
|
||||
setCastMode("offline");
|
||||
setGuaData(null);
|
||||
}}
|
||||
>
|
||||
线下录入
|
||||
</Button>
|
||||
</div>
|
||||
<HexagramInput
|
||||
key={castMode}
|
||||
mode={castMode}
|
||||
enabled={question.trim() !== "" && currentLocation !== null}
|
||||
onResult={setGuaData}
|
||||
onClear={() => setGuaData(null)}
|
||||
/>
|
||||
{guaData && (
|
||||
<div className="rounded-md border bg-card p-3">
|
||||
<Result {...guaData.result} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{error && !showAi && (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={handlePreview} className="flex-1">
|
||||
预览排盘
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleAnalyze}
|
||||
disabled={withHexagram && !hexagramReady}
|
||||
className="flex-1"
|
||||
>
|
||||
<Compass size={16} className="mr-1" />
|
||||
综合测算
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{chart && (
|
||||
<div className="mx-auto w-full max-w-lg">
|
||||
<BaziChartDisplay chart={chart} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showAi && (
|
||||
<div className="mx-auto h-96 w-full max-w-lg flex-1">
|
||||
<ResultAI
|
||||
completion={completion}
|
||||
isLoading={isLoading}
|
||||
onCompletion={handleAnalyze}
|
||||
error={error}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { readStreamableValue } from "ai/rsc";
|
||||
import { Compass, ListRestart } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import Result from "@/components/result";
|
||||
import ResultAI from "@/components/result-ai";
|
||||
import DateTimePicker, {
|
||||
nowDateString,
|
||||
nowTimeString,
|
||||
} from "@/components/shared/datetime-picker";
|
||||
import HexagramInput from "@/components/shared/hexagram-input";
|
||||
import RegionSelect, {
|
||||
useRegionLocation,
|
||||
} from "@/components/shared/region-select";
|
||||
import { getLiuyaoAnswer } from "@/app/actions/liuyao";
|
||||
import type { GuaResult } from "@/lib/calc/hexagram";
|
||||
import { ERROR_PREFIX } from "@/lib/constant";
|
||||
import todayJson from "@/lib/data/today.json";
|
||||
|
||||
const todayData: string[] = todayJson;
|
||||
|
||||
export default function LiuyaoForm() {
|
||||
const [question, setQuestion] = useState("");
|
||||
const [provinceCode, setProvinceCode] = useState("");
|
||||
const [cityCode, setCityCode] = useState("");
|
||||
const [calcDate, setCalcDate] = useState(nowDateString);
|
||||
const [calcTime, setCalcTime] = useState(nowTimeString);
|
||||
const [castMode, setCastMode] = useState<"online" | "offline">("online");
|
||||
const [guaData, setGuaData] = useState<GuaResult | null>(null);
|
||||
const [completion, setCompletion] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [showAi, setShowAi] = useState(false);
|
||||
|
||||
const location = useRegionLocation(provinceCode, cityCode);
|
||||
const formReady = question.trim() !== "" && location !== null;
|
||||
|
||||
function validate(): string | null {
|
||||
if (!question.trim()) {
|
||||
return "请输入问事";
|
||||
}
|
||||
if (!location) {
|
||||
return "请选择起卦地域";
|
||||
}
|
||||
if (!guaData) {
|
||||
return "请先完成起卦(线上摇卦或线下录入)";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function handleAnalyze() {
|
||||
const err = validate();
|
||||
if (err) {
|
||||
setError(err);
|
||||
return;
|
||||
}
|
||||
|
||||
setError("");
|
||||
setCompletion("");
|
||||
setIsLoading(true);
|
||||
setShowAi(true);
|
||||
|
||||
try {
|
||||
const { data, error: apiError } = await getLiuyaoAnswer({
|
||||
question,
|
||||
calcDate,
|
||||
calcTime,
|
||||
locationName: location!.name,
|
||||
longitude: location!.longitude,
|
||||
guaMark: guaData!.result.guaMark,
|
||||
guaTitle: guaData!.result.guaTitle,
|
||||
guaResult: guaData!.result.guaResult,
|
||||
guaChange: guaData!.result.guaChange,
|
||||
});
|
||||
|
||||
if (apiError) {
|
||||
setError(apiError);
|
||||
return;
|
||||
}
|
||||
if (data) {
|
||||
let ret = "";
|
||||
for await (const delta of readStreamableValue(data)) {
|
||||
if (typeof delta === "string" && delta.startsWith(ERROR_PREFIX)) {
|
||||
setError(delta.slice(ERROR_PREFIX.length));
|
||||
return;
|
||||
}
|
||||
ret += delta ?? "";
|
||||
setCompletion(ret);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : String(e));
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
setQuestion("");
|
||||
setProvinceCode("");
|
||||
setCityCode("");
|
||||
setCalcDate(nowDateString());
|
||||
setCalcTime(nowTimeString());
|
||||
setGuaData(null);
|
||||
setCompletion("");
|
||||
setError("");
|
||||
setShowAi(false);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
function handleGuaResult(data: GuaResult) {
|
||||
setGuaData(data);
|
||||
setShowAi(false);
|
||||
setCompletion("");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col gap-4 px-4 py-6">
|
||||
<div className="mx-auto w-full max-w-lg space-y-5">
|
||||
<section className="space-y-2">
|
||||
<label className="text-sm font-medium">问事</label>
|
||||
<Textarea
|
||||
placeholder="您想算点什么?"
|
||||
value={question}
|
||||
onChange={(e) => setQuestion(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{todayData.map((item, index) => (
|
||||
<button
|
||||
key={index}
|
||||
type="button"
|
||||
onClick={() => setQuestion(item)}
|
||||
className="rounded-md border bg-secondary px-2 py-1 text-xs text-muted-foreground transition hover:bg-accent"
|
||||
>
|
||||
{item}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<RegionSelect
|
||||
label="起卦地域"
|
||||
provinceCode={provinceCode}
|
||||
cityCode={cityCode}
|
||||
onProvinceChange={setProvinceCode}
|
||||
onCityChange={setCityCode}
|
||||
/>
|
||||
|
||||
<DateTimePicker
|
||||
label="起卦时辰"
|
||||
date={calcDate}
|
||||
time={calcTime}
|
||||
onDateChange={setCalcDate}
|
||||
onTimeChange={setCalcTime}
|
||||
/>
|
||||
|
||||
<section className="space-y-2">
|
||||
<label className="text-sm font-medium">起卦方式</label>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={castMode === "online" ? "default" : "outline"}
|
||||
onClick={() => {
|
||||
setCastMode("online");
|
||||
setGuaData(null);
|
||||
setShowAi(false);
|
||||
}}
|
||||
>
|
||||
线上摇卦
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant={castMode === "offline" ? "default" : "outline"}
|
||||
onClick={() => {
|
||||
setCastMode("offline");
|
||||
setGuaData(null);
|
||||
setShowAi(false);
|
||||
}}
|
||||
>
|
||||
线下录入
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<HexagramInput
|
||||
key={castMode}
|
||||
mode={castMode}
|
||||
enabled={formReady}
|
||||
onResult={handleGuaResult}
|
||||
onClear={() => setGuaData(null)}
|
||||
/>
|
||||
|
||||
{guaData && (
|
||||
<div className="rounded-lg border bg-card p-4">
|
||||
<Result {...guaData.result} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && !showAi && (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={handleReset} className="flex-1">
|
||||
<ListRestart size={16} className="mr-1" />
|
||||
重来
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleAnalyze}
|
||||
disabled={!guaData || isLoading}
|
||||
className="flex-1"
|
||||
>
|
||||
<Compass size={16} className="mr-1" />
|
||||
测算
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{showAi && (
|
||||
<div className="mx-auto h-96 w-full max-w-lg flex-1">
|
||||
<ResultAI
|
||||
completion={completion}
|
||||
isLoading={isLoading}
|
||||
onCompletion={handleAnalyze}
|
||||
error={error}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import Header from "@/components/header";
|
||||
import Footer from "@/components/footer";
|
||||
|
||||
export default function PageShell({
|
||||
children,
|
||||
className = "",
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col">
|
||||
<Header />
|
||||
<div className={`mx-auto flex w-full flex-1 flex-col ${className}`}>
|
||||
{children}
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
"use client";
|
||||
|
||||
interface DateTimePickerProps {
|
||||
date: string;
|
||||
time: string;
|
||||
onDateChange: (date: string) => void;
|
||||
onTimeChange: (time: string) => void;
|
||||
label?: string;
|
||||
timeDisabled?: boolean;
|
||||
}
|
||||
|
||||
export function nowDateString() {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export function nowTimeString() {
|
||||
const d = new Date();
|
||||
return `${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
export default function DateTimePicker({
|
||||
date,
|
||||
time,
|
||||
onDateChange,
|
||||
onTimeChange,
|
||||
label = "时间",
|
||||
timeDisabled = false,
|
||||
}: DateTimePickerProps) {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">{label}</label>
|
||||
<div className="grid gap-2 sm:grid-cols-2">
|
||||
<input
|
||||
type="date"
|
||||
className="rounded-md border bg-background px-3 py-2 text-sm disabled:opacity-50"
|
||||
value={date}
|
||||
onChange={(e) => onDateChange(e.target.value)}
|
||||
/>
|
||||
<input
|
||||
type="time"
|
||||
className="rounded-md border bg-background px-3 py-2 text-sm disabled:opacity-50"
|
||||
value={time}
|
||||
disabled={timeDisabled}
|
||||
onChange={(e) => onTimeChange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { bool } from "aimless.js";
|
||||
import Coin from "@/components/coin";
|
||||
import Hexagram from "@/components/hexagram";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
buildHexagramList,
|
||||
COIN_OPTIONS,
|
||||
computeGuaResult,
|
||||
type GuaResult,
|
||||
YAO_LABELS,
|
||||
} from "@/lib/calc/hexagram";
|
||||
|
||||
const AUTO_DELAY = 600;
|
||||
|
||||
interface HexagramInputProps {
|
||||
mode: "online" | "offline";
|
||||
enabled: boolean;
|
||||
onResult: (data: GuaResult) => void;
|
||||
onClear: () => void;
|
||||
}
|
||||
|
||||
export default function HexagramInput({
|
||||
mode,
|
||||
enabled,
|
||||
onResult,
|
||||
onClear,
|
||||
}: HexagramInputProps) {
|
||||
const [frontList, setFrontList] = useState([true, true, true]);
|
||||
const [rotation, setRotation] = useState(false);
|
||||
const [hexagramList, setHexagramList] = useState<
|
||||
GuaResult["list"]
|
||||
>([]);
|
||||
const [count, setCount] = useState(0);
|
||||
const [offlineCounts, setOfflineCounts] = useState<(number | null)[]>(
|
||||
Array(6).fill(null),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setHexagramList([]);
|
||||
setCount(0);
|
||||
setOfflineCounts(Array(6).fill(null));
|
||||
setRotation(false);
|
||||
}, [mode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
mode !== "online" ||
|
||||
!enabled ||
|
||||
rotation ||
|
||||
hexagramList.length >= 6 ||
|
||||
count >= 6
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const timer = setTimeout(startOnlineCast, AUTO_DELAY);
|
||||
return () => clearTimeout(timer);
|
||||
}, [mode, enabled, rotation, count, hexagramList.length]);
|
||||
|
||||
function finishList(list: GuaResult["list"]) {
|
||||
const result = computeGuaResult(list);
|
||||
if (result) {
|
||||
onResult({ list, result });
|
||||
}
|
||||
}
|
||||
|
||||
function onTransitionEnd() {
|
||||
setRotation(false);
|
||||
const frontCount = frontList.reduce(
|
||||
(acc, val) => (val ? acc + 1 : acc),
|
||||
0,
|
||||
);
|
||||
setHexagramList((list) => {
|
||||
const newList = [
|
||||
...list,
|
||||
{
|
||||
change: frontCount === 0 || frontCount === 3,
|
||||
yang: frontCount >= 2,
|
||||
separate: list.length === 3,
|
||||
},
|
||||
];
|
||||
if (newList.length === 6) {
|
||||
finishList(newList);
|
||||
}
|
||||
return newList;
|
||||
});
|
||||
}
|
||||
|
||||
function startOnlineCast() {
|
||||
if (rotation || !enabled || hexagramList.length >= 6) {
|
||||
return;
|
||||
}
|
||||
setFrontList([bool(), bool(), bool()]);
|
||||
setRotation(true);
|
||||
setCount((c) => c + 1);
|
||||
}
|
||||
|
||||
function handleOfflineSelect(index: number, frontCount: number) {
|
||||
const next = [...offlineCounts];
|
||||
next[index] = frontCount;
|
||||
setOfflineCounts(next);
|
||||
}
|
||||
|
||||
function confirmOffline() {
|
||||
if (offlineCounts.some((v) => v === null)) {
|
||||
return;
|
||||
}
|
||||
const list = buildHexagramList(offlineCounts as number[]);
|
||||
finishList(list);
|
||||
setHexagramList(list);
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
setHexagramList([]);
|
||||
setCount(0);
|
||||
setOfflineCounts(Array(6).fill(null));
|
||||
setRotation(false);
|
||||
onClear();
|
||||
}
|
||||
|
||||
const complete = hexagramList.length === 6;
|
||||
const offlineReady = offlineCounts.every((v) => v !== null);
|
||||
|
||||
if (!enabled) {
|
||||
return (
|
||||
<p className="text-center text-sm text-muted-foreground">
|
||||
请先填写问事、地域和起卦时辰
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col items-center gap-4">
|
||||
{mode === "online" && !complete && (
|
||||
<>
|
||||
<Coin
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
frontList={frontList}
|
||||
rotation={rotation}
|
||||
/>
|
||||
<span className="text-lg font-medium">
|
||||
🎲 第{" "}
|
||||
<span className="font-mono text-xl font-bold text-orange-500">
|
||||
{count === 0 ? "-/-" : `${count}/6`}
|
||||
</span>{" "}
|
||||
次卜筮
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
|
||||
{mode === "offline" && !complete && (
|
||||
<div className="w-full max-w-md space-y-2">
|
||||
<p className="text-center text-xs text-muted-foreground">
|
||||
人工抛铜钱后,按从下到上(初爻→上爻)录入每爻结果
|
||||
</p>
|
||||
{YAO_LABELS.map((label, index) => (
|
||||
<div
|
||||
key={label}
|
||||
className="flex flex-wrap items-center gap-2 rounded-md border p-2"
|
||||
>
|
||||
<span className="w-10 shrink-0 text-sm font-medium">{label}</span>
|
||||
{COIN_OPTIONS.map((opt) => (
|
||||
<button
|
||||
key={opt.count}
|
||||
type="button"
|
||||
onClick={() => handleOfflineSelect(index, opt.count)}
|
||||
className={`rounded border px-2 py-1 text-xs transition ${
|
||||
offlineCounts[index] === opt.count
|
||||
? "border-primary bg-primary/10 text-primary"
|
||||
: "hover:bg-accent"
|
||||
}`}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
<Button
|
||||
className="w-full"
|
||||
disabled={!offlineReady}
|
||||
onClick={confirmOffline}
|
||||
>
|
||||
确认卦象
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hexagramList.length > 0 && (
|
||||
<div className="flex flex-col items-center gap-3 sm:flex-row">
|
||||
<Hexagram list={hexagramList} />
|
||||
{complete && (
|
||||
<Button size="sm" variant="outline" onClick={handleReset}>
|
||||
重新起卦
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
"use client";
|
||||
|
||||
import { getProvinces, getCities, getRegionLocation } from "@/lib/data/regions";
|
||||
|
||||
interface RegionSelectProps {
|
||||
provinceCode: string;
|
||||
cityCode: string;
|
||||
onProvinceChange: (code: string) => void;
|
||||
onCityChange: (code: string) => void;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export default function RegionSelect({
|
||||
provinceCode,
|
||||
cityCode,
|
||||
onProvinceChange,
|
||||
onCityChange,
|
||||
label = "出生地域",
|
||||
}: RegionSelectProps) {
|
||||
const provinces = getProvinces();
|
||||
const cities = provinceCode ? getCities(provinceCode) : [];
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">{label}</label>
|
||||
<div className="grid gap-2 sm:grid-cols-2">
|
||||
<select
|
||||
className="rounded-md border bg-background px-3 py-2 text-sm"
|
||||
value={provinceCode}
|
||||
onChange={(e) => {
|
||||
onProvinceChange(e.target.value);
|
||||
onCityChange("");
|
||||
}}
|
||||
>
|
||||
<option value="">选择省份</option>
|
||||
{provinces.map((p) => (
|
||||
<option key={p.code} value={p.code}>
|
||||
{p.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className="rounded-md border bg-background px-3 py-2 text-sm"
|
||||
value={cityCode}
|
||||
onChange={(e) => onCityChange(e.target.value)}
|
||||
disabled={!provinceCode}
|
||||
>
|
||||
<option value="">选择城市/区县</option>
|
||||
{cities.map((c) => (
|
||||
<option key={c.code} value={c.code}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function useRegionLocation(provinceCode: string, cityCode: string) {
|
||||
return provinceCode
|
||||
? getRegionLocation(provinceCode, cityCode)
|
||||
: null;
|
||||
}
|
||||
+12
-12
@@ -16,7 +16,7 @@
|
||||
│
|
||||
┌────────▼────────┐
|
||||
│ PM2 │
|
||||
│ zhimingge │ :3000
|
||||
│ zhimingge │ :3130
|
||||
└────────┬────────┘
|
||||
│
|
||||
┌────────▼────────┐
|
||||
@@ -38,7 +38,7 @@
|
||||
| 安装目录 | `/opt/zhimingge` |
|
||||
| 进程管理 | PM2 |
|
||||
| 构建模式 | Next.js `output: "standalone"` |
|
||||
| 默认端口 | 3000 |
|
||||
| 默认端口 | **3130** |
|
||||
|
||||
---
|
||||
|
||||
@@ -172,8 +172,8 @@ OPENAI_API_KEY=你的密钥
|
||||
OPENAI_BASE_URL=https://op.bz121.com/v1
|
||||
OPENAI_MODEL=huihui_ai/gemma-4-abliterated:e4b
|
||||
|
||||
# 服务端口
|
||||
PORT=3000
|
||||
# 服务端口(与 PM2 ecosystem.config.cjs 一致)
|
||||
PORT=3130
|
||||
NODE_ENV=production
|
||||
```
|
||||
|
||||
@@ -247,7 +247,7 @@ pm2 delete zhimingge # 删除进程
|
||||
|
||||
```bash
|
||||
cd /opt/zhimingge/.next/standalone
|
||||
PORT=3000 node server.js
|
||||
PORT=3130 node server.js
|
||||
```
|
||||
|
||||
对应 PM2 配置片段:
|
||||
@@ -258,7 +258,7 @@ PORT=3000 node server.js
|
||||
cwd: "/opt/zhimingge/.next/standalone",
|
||||
script: "server.js",
|
||||
env: {
|
||||
PORT: 3000,
|
||||
PORT: 3130,
|
||||
NODE_ENV: "production",
|
||||
},
|
||||
}
|
||||
@@ -269,11 +269,11 @@ PORT=3000 node server.js
|
||||
### 7.6 验证
|
||||
|
||||
```bash
|
||||
curl -I http://127.0.0.1:3000
|
||||
curl -I http://127.0.0.1:3130
|
||||
# 应返回 HTTP/1.1 200
|
||||
```
|
||||
|
||||
浏览器访问:`http://服务器IP:3000`
|
||||
浏览器访问:`http://服务器IP:3130`
|
||||
|
||||
---
|
||||
|
||||
@@ -291,7 +291,7 @@ server {
|
||||
server_name zhimingge.example.com;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_pass http://127.0.0.1:3130;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
@@ -359,8 +359,8 @@ ufw allow 80
|
||||
ufw allow 443
|
||||
ufw enable
|
||||
|
||||
# 若不用 Nginx,直接暴露 3000
|
||||
ufw allow 3000
|
||||
# 若不用 Nginx,直接暴露 3130
|
||||
ufw allow 3130
|
||||
```
|
||||
|
||||
---
|
||||
@@ -446,7 +446,7 @@ pm2 save && pm2 startup
|
||||
cd /opt/zhimingge && git pull && pnpm install && pnpm run build && pm2 restart zhimingge
|
||||
|
||||
# 查看状态
|
||||
pm2 status && curl -I http://127.0.0.1:3000
|
||||
pm2 status && curl -I http://127.0.0.1:3130
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
+1
-1
@@ -341,7 +341,7 @@ OPENAI_MODEL=huihui_ai/gemma-4-abliterated:e4b
|
||||
| `OPENAI_API_KEY` | 是 | — | AI 接口密钥 |
|
||||
| `OPENAI_BASE_URL` | 否 | `https://op.bz121.com/v1` | API 地址 |
|
||||
| `OPENAI_MODEL` | 否 | `huihui_ai/gemma-4-abliterated:e4b` | 模型名 |
|
||||
| `PORT` | 否 | `3000` | 服务端口 |
|
||||
| `PORT` | 否 | `3130` | 服务端口 |
|
||||
| `NODE_ENV` | 否 | `production` | 运行环境 |
|
||||
| `UMAMI_ID` | 否 | — | 访问统计(可选,可不用) |
|
||||
| `UMAMI_URL` | 否 | — | 统计脚本地址(可选) |
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/**
|
||||
* PM2 进程配置 — 知命阁(zhimingge)
|
||||
* 部署目录:/opt/zhimingge
|
||||
* 生产端口:3130
|
||||
*
|
||||
* 启动:pm2 start ecosystem.config.cjs
|
||||
* 首次:pm2 start ecosystem.config.cjs
|
||||
* 重启:pm2 restart zhimingge
|
||||
* 日志:pm2 logs zhimingge
|
||||
*/
|
||||
module.exports = {
|
||||
apps: [
|
||||
@@ -11,7 +13,7 @@ module.exports = {
|
||||
name: "zhimingge",
|
||||
cwd: "/opt/zhimingge",
|
||||
script: "node_modules/next/dist/bin/next",
|
||||
args: "start",
|
||||
args: "start -p 3130",
|
||||
instances: 1,
|
||||
exec_mode: "fork",
|
||||
autorestart: true,
|
||||
@@ -19,7 +21,7 @@ module.exports = {
|
||||
max_memory_restart: "512M",
|
||||
env: {
|
||||
NODE_ENV: "production",
|
||||
PORT: 3000,
|
||||
PORT: 3130,
|
||||
},
|
||||
error_file: "/opt/zhimingge/logs/pm2-error.log",
|
||||
out_file: "/opt/zhimingge/logs/pm2-out.log",
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
"use server";
|
||||
|
||||
import { streamText } from "ai";
|
||||
import { createOpenAI } from "@ai-sdk/openai";
|
||||
import { createStreamableValue } from "ai/rsc";
|
||||
import { ERROR_PREFIX } from "@/lib/constant";
|
||||
|
||||
const model =
|
||||
process.env.OPENAI_MODEL ?? "huihui_ai/gemma-4-abliterated:e4b";
|
||||
const openai = createOpenAI({
|
||||
baseURL: process.env.OPENAI_BASE_URL ?? "https://op.bz121.com/v1",
|
||||
});
|
||||
|
||||
const STREAM_INTERVAL = 60;
|
||||
const MAX_SIZE = 6;
|
||||
|
||||
export async function streamAIResponse(
|
||||
system: string,
|
||||
user: string,
|
||||
): Promise<{ data?: ReturnType<typeof createStreamableValue<string>>["value"]; error?: string }> {
|
||||
const stream = createStreamableValue<string>();
|
||||
|
||||
try {
|
||||
const { fullStream } = streamText({
|
||||
temperature: 0.5,
|
||||
model: openai(model),
|
||||
messages: [
|
||||
{ role: "system", content: system },
|
||||
{ role: "user", content: user },
|
||||
],
|
||||
maxRetries: 0,
|
||||
});
|
||||
|
||||
let buffer = "";
|
||||
let done = false;
|
||||
const intervalId = setInterval(() => {
|
||||
if (done && buffer.length === 0) {
|
||||
clearInterval(intervalId);
|
||||
stream.done();
|
||||
return;
|
||||
}
|
||||
if (buffer.length <= MAX_SIZE) {
|
||||
stream.update(buffer);
|
||||
buffer = "";
|
||||
} else {
|
||||
const chunk = buffer.slice(0, MAX_SIZE);
|
||||
buffer = buffer.slice(MAX_SIZE);
|
||||
stream.update(chunk);
|
||||
}
|
||||
}, STREAM_INTERVAL);
|
||||
|
||||
(async () => {
|
||||
for await (const part of fullStream) {
|
||||
switch (part.type) {
|
||||
case "text-delta":
|
||||
buffer += part.textDelta;
|
||||
break;
|
||||
case "error": {
|
||||
const err = part.error as { message?: string };
|
||||
stream.update(ERROR_PREFIX + (err.message ?? String(part.error)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
.catch(console.error)
|
||||
.finally(() => {
|
||||
done = true;
|
||||
});
|
||||
|
||||
return { data: stream.value };
|
||||
} catch (err) {
|
||||
stream.done();
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
return { error: message };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import { Solar } from "lunar-javascript";
|
||||
import {
|
||||
adjustToTrueSolarTime,
|
||||
formatDateTime,
|
||||
parseDateTime,
|
||||
} from "@/lib/calc/time";
|
||||
|
||||
export interface BaziInput {
|
||||
date: string;
|
||||
time: string;
|
||||
gender: "male" | "female";
|
||||
longitude: number;
|
||||
unknownHour?: boolean;
|
||||
}
|
||||
|
||||
export interface PillarInfo {
|
||||
ganZhi: string;
|
||||
shiShenGan: string;
|
||||
shiShenZhi: string[];
|
||||
hideGan: string[];
|
||||
naYin: string;
|
||||
}
|
||||
|
||||
export interface DaYunInfo {
|
||||
ganZhi: string;
|
||||
startAge: number;
|
||||
}
|
||||
|
||||
export interface BaziChart {
|
||||
birthTime: string;
|
||||
trueSolarTime: string;
|
||||
unknownHour: boolean;
|
||||
lunarDate: string;
|
||||
pillars: {
|
||||
year: PillarInfo;
|
||||
month: PillarInfo;
|
||||
day: PillarInfo;
|
||||
time: PillarInfo;
|
||||
};
|
||||
daYun: {
|
||||
startYear: number;
|
||||
startMonth: number;
|
||||
startDay: number;
|
||||
items: DaYunInfo[];
|
||||
};
|
||||
liuNian: { year: number; ganZhi: string }[];
|
||||
shenSha: {
|
||||
ji: string[];
|
||||
xiong: string[];
|
||||
};
|
||||
}
|
||||
|
||||
function buildPillar(
|
||||
ganZhi: string,
|
||||
shiShenGan: string,
|
||||
shiShenZhi: string[],
|
||||
hideGan: string[],
|
||||
naYin: string,
|
||||
): PillarInfo {
|
||||
return { ganZhi, shiShenGan, shiShenZhi, hideGan, naYin };
|
||||
}
|
||||
|
||||
export function calculateBazi(input: BaziInput): BaziChart {
|
||||
const localTime = parseDateTime(input.date, input.time);
|
||||
const trueSolar = adjustToTrueSolarTime(localTime, input.longitude);
|
||||
|
||||
const solar = Solar.fromYmdHms(
|
||||
trueSolar.getFullYear(),
|
||||
trueSolar.getMonth() + 1,
|
||||
trueSolar.getDate(),
|
||||
input.unknownHour ? 12 : trueSolar.getHours(),
|
||||
input.unknownHour ? 0 : trueSolar.getMinutes(),
|
||||
0,
|
||||
);
|
||||
|
||||
const lunar = solar.getLunar();
|
||||
const ec = lunar.getEightChar();
|
||||
const genderCode = input.gender === "male" ? 1 : 0;
|
||||
const yun = ec.getYun(genderCode);
|
||||
|
||||
const currentYear = new Date().getFullYear();
|
||||
const liuNian: { year: number; ganZhi: string }[] = [];
|
||||
for (let year = currentYear - 2; year <= currentYear + 3; year++) {
|
||||
const yearSolar = Solar.fromYmdHms(year, 6, 1, 12, 0, 0);
|
||||
liuNian.push({
|
||||
year,
|
||||
ganZhi: yearSolar.getLunar().getYearInGanZhi(),
|
||||
});
|
||||
}
|
||||
|
||||
const daYunList = yun.getDaYun();
|
||||
const daYunItems: DaYunInfo[] = [];
|
||||
let age = yun.getStartYear();
|
||||
for (const dy of daYunList) {
|
||||
const gz = dy.getGanZhi();
|
||||
if (!gz) {
|
||||
continue;
|
||||
}
|
||||
daYunItems.push({ ganZhi: gz, startAge: age });
|
||||
age += 10;
|
||||
if (daYunItems.length >= 8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
birthTime: formatDateTime(localTime),
|
||||
trueSolarTime: formatDateTime(trueSolar),
|
||||
unknownHour: !!input.unknownHour,
|
||||
lunarDate: lunar.toString(),
|
||||
pillars: {
|
||||
year: buildPillar(
|
||||
ec.getYear(),
|
||||
ec.getYearShiShenGan(),
|
||||
ec.getYearShiShenZhi(),
|
||||
ec.getYearHideGan(),
|
||||
ec.getYearNaYin(),
|
||||
),
|
||||
month: buildPillar(
|
||||
ec.getMonth(),
|
||||
ec.getMonthShiShenGan(),
|
||||
ec.getMonthShiShenZhi(),
|
||||
ec.getMonthHideGan(),
|
||||
ec.getMonthNaYin(),
|
||||
),
|
||||
day: buildPillar(
|
||||
ec.getDay(),
|
||||
ec.getDayShiShenGan(),
|
||||
ec.getDayShiShenZhi(),
|
||||
ec.getDayHideGan(),
|
||||
ec.getDayNaYin(),
|
||||
),
|
||||
time: buildPillar(
|
||||
input.unknownHour ? "不详" : ec.getTime(),
|
||||
input.unknownHour ? "—" : ec.getTimeShiShenGan(),
|
||||
input.unknownHour ? [] : ec.getTimeShiShenZhi(),
|
||||
input.unknownHour ? [] : ec.getTimeHideGan(),
|
||||
input.unknownHour ? "—" : ec.getTimeNaYin(),
|
||||
),
|
||||
},
|
||||
daYun: {
|
||||
startYear: yun.getStartYear(),
|
||||
startMonth: yun.getStartMonth(),
|
||||
startDay: yun.getStartDay(),
|
||||
items: daYunItems,
|
||||
},
|
||||
liuNian,
|
||||
shenSha: {
|
||||
ji: lunar.getDayJiShen(),
|
||||
xiong: lunar.getDayXiongSha(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function formatBaziForPrompt(chart: BaziChart): string {
|
||||
const p = chart.pillars;
|
||||
const lines = [
|
||||
`出生时间:${chart.birthTime}`,
|
||||
`真太阳时:${chart.trueSolarTime}${chart.unknownHour ? "(时辰不详,按中午排盘)" : ""}`,
|
||||
`农历:${chart.lunarDate}`,
|
||||
"",
|
||||
"【四柱】",
|
||||
`年柱:${p.year.ganZhi}(天干十神:${p.year.shiShenGan},地支十神:${p.year.shiShenZhi.join("、")},藏干:${p.year.hideGan.join("、")},纳音:${p.year.naYin})`,
|
||||
`月柱:${p.month.ganZhi}(天干十神:${p.month.shiShenGan},地支十神:${p.month.shiShenZhi.join("、")},藏干:${p.month.hideGan.join("、")},纳音:${p.month.naYin})`,
|
||||
`日柱:${p.day.ganZhi}(天干十神:${p.day.shiShenGan},地支十神:${p.day.shiShenZhi.join("、")},藏干:${p.day.hideGan.join("、")},纳音:${p.day.naYin})`,
|
||||
`时柱:${p.time.ganZhi}(天干十神:${p.time.shiShenGan},地支十神:${p.time.shiShenZhi.join("、") || "—"},藏干:${p.time.hideGan.join("、") || "—"},纳音:${p.time.naYin})`,
|
||||
"",
|
||||
`【大运】起运 ${chart.daYun.startYear} 年 ${chart.daYun.startMonth} 月 ${chart.daYun.startDay} 天`,
|
||||
chart.daYun.items.map((d) => `${d.startAge}岁起 ${d.ganZhi}`).join(" → "),
|
||||
"",
|
||||
`【流年】${chart.liuNian.map((l) => `${l.year}(${l.ganZhi})`).join("、")}`,
|
||||
"",
|
||||
`【神煞】吉神:${chart.shenSha.ji.join("、") || "无"};凶煞:${chart.shenSha.xiong.join("、") || "无"}`,
|
||||
];
|
||||
return lines.join("\n");
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import guaIndexData from "@/lib/data/gua-index.json";
|
||||
import guaListData from "@/lib/data/gua-list.json";
|
||||
import type { HexagramObj } from "@/components/hexagram";
|
||||
import type { ResultObj } from "@/components/result";
|
||||
|
||||
const GUA_DICT1 = ["坤", "震", "坎", "兑", "艮", "离", "巽", "乾"];
|
||||
const GUA_DICT2 = ["地", "雷", "水", "泽", "山", "火", "风", "天"];
|
||||
const CHANGE_YANG = ["初九", "九二", "九三", "九四", "九五", "上九"];
|
||||
const CHANGE_YIN = ["初六", "六二", "六三", "六四", "六五", "上六"];
|
||||
|
||||
/** 三钱法:正面数 0~3 → 爻象 */
|
||||
export function frontCountToLine(frontCount: number): Omit<HexagramObj, "separate"> {
|
||||
return {
|
||||
change: frontCount === 0 || frontCount === 3,
|
||||
yang: frontCount >= 2,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildHexagramList(frontCounts: number[]): HexagramObj[] {
|
||||
return frontCounts.map((count, index) => ({
|
||||
...frontCountToLine(count),
|
||||
separate: index === 3,
|
||||
}));
|
||||
}
|
||||
|
||||
export function computeGuaResult(list: HexagramObj[]): ResultObj | null {
|
||||
if (list.length !== 6) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const changeList: string[] = [];
|
||||
list.forEach((value, index) => {
|
||||
if (!value.change) {
|
||||
return;
|
||||
}
|
||||
changeList.push(value.yang ? CHANGE_YANG[index] : CHANGE_YIN[index]);
|
||||
});
|
||||
|
||||
const upIndex =
|
||||
(list[5].yang ? 4 : 0) + (list[4].yang ? 2 : 0) + (list[3].yang ? 1 : 0);
|
||||
const downIndex =
|
||||
(list[2].yang ? 4 : 0) + (list[1].yang ? 2 : 0) + (list[0].yang ? 1 : 0);
|
||||
|
||||
const guaIndex = guaIndexData[upIndex][downIndex] - 1;
|
||||
const guaName1 = guaListData[guaIndex];
|
||||
|
||||
let guaName2: string;
|
||||
if (upIndex === downIndex) {
|
||||
guaName2 = GUA_DICT1[upIndex] + "为" + GUA_DICT2[upIndex];
|
||||
} else {
|
||||
guaName2 = GUA_DICT2[upIndex] + GUA_DICT2[downIndex] + guaName1;
|
||||
}
|
||||
|
||||
const guaDesc = GUA_DICT1[upIndex] + "上" + GUA_DICT1[downIndex] + "下";
|
||||
|
||||
return {
|
||||
guaMark: `${(guaIndex + 1).toString().padStart(2, "0")}.${guaName2}`,
|
||||
guaTitle: `周易第${guaIndex + 1}卦`,
|
||||
guaResult: `${guaName1}卦(${guaName2})_${guaDesc}`,
|
||||
guaChange:
|
||||
changeList.length === 0 ? "无变爻" : `变爻: ${changeList.toString()}`,
|
||||
};
|
||||
}
|
||||
|
||||
export const YAO_LABELS = ["初爻", "二爻", "三爻", "四爻", "五爻", "上爻"];
|
||||
|
||||
export const COIN_OPTIONS = [
|
||||
{ count: 0, label: "老阴", desc: "0 正 · 变爻 ✕" },
|
||||
{ count: 1, label: "少阴", desc: "1 正" },
|
||||
{ count: 2, label: "少阳", desc: "2 正" },
|
||||
{ count: 3, label: "老阳", desc: "3 正 · 变爻 ○" },
|
||||
];
|
||||
|
||||
export interface GuaResult {
|
||||
list: HexagramObj[];
|
||||
result: ResultObj;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/** 中国标准时间基准经度(UTC+8) */
|
||||
export const CHINA_STANDARD_MERIDIAN = 120;
|
||||
|
||||
/**
|
||||
* 根据出生地经度校正真太阳时。
|
||||
* 每差 1 度经度,时间差约 4 分钟。
|
||||
*/
|
||||
export function adjustToTrueSolarTime(
|
||||
date: Date,
|
||||
longitude: number,
|
||||
standardMeridian = CHINA_STANDARD_MERIDIAN,
|
||||
): Date {
|
||||
const offsetMinutes = (longitude - standardMeridian) * 4;
|
||||
return new Date(date.getTime() + offsetMinutes * 60 * 1000);
|
||||
}
|
||||
|
||||
export function formatDateTime(date: Date): string {
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
}
|
||||
|
||||
export function parseDateTime(
|
||||
dateStr: string,
|
||||
timeStr: string,
|
||||
): Date {
|
||||
const [year, month, day] = dateStr.split("-").map(Number);
|
||||
const [hour, minute] = timeStr.split(":").map(Number);
|
||||
return new Date(year, month - 1, day, hour, minute, 0);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { Solar } from "lunar-javascript";
|
||||
import {
|
||||
adjustToTrueSolarTime,
|
||||
formatDateTime,
|
||||
parseDateTime,
|
||||
} from "@/lib/calc/time";
|
||||
|
||||
export interface TimingInfo {
|
||||
solarTime: string;
|
||||
lunarDate: string;
|
||||
yearGanZhi: string;
|
||||
monthGanZhi: string;
|
||||
dayGanZhi: string;
|
||||
timeGanZhi: string;
|
||||
prevJieQi: string;
|
||||
nextJieQi: string;
|
||||
}
|
||||
|
||||
export function getTimingInfo(dateTime: Date): TimingInfo {
|
||||
const solar = Solar.fromYmdHms(
|
||||
dateTime.getFullYear(),
|
||||
dateTime.getMonth() + 1,
|
||||
dateTime.getDate(),
|
||||
dateTime.getHours(),
|
||||
dateTime.getMinutes(),
|
||||
0,
|
||||
);
|
||||
const lunar = solar.getLunar();
|
||||
|
||||
return {
|
||||
solarTime: formatDateTime(dateTime),
|
||||
lunarDate: lunar.toString(),
|
||||
yearGanZhi: lunar.getYearInGanZhi(),
|
||||
monthGanZhi: lunar.getMonthInGanZhi(),
|
||||
dayGanZhi: lunar.getDayInGanZhi(),
|
||||
timeGanZhi: lunar.getTimeInGanZhi(),
|
||||
prevJieQi: lunar.getPrevJieQi()?.getName() ?? "—",
|
||||
nextJieQi: lunar.getNextJieQi()?.getName() ?? "—",
|
||||
};
|
||||
}
|
||||
|
||||
export function getTimingInfoFromStrings(
|
||||
date: string,
|
||||
time: string,
|
||||
): TimingInfo {
|
||||
return getTimingInfo(parseDateTime(date, time));
|
||||
}
|
||||
|
||||
export function getTimingInfoWithLongitude(
|
||||
date: string,
|
||||
time: string,
|
||||
longitude: number,
|
||||
): { timing: TimingInfo; trueSolarTime: string } {
|
||||
const local = parseDateTime(date, time);
|
||||
const trueSolar = adjustToTrueSolarTime(local, longitude);
|
||||
return {
|
||||
timing: getTimingInfo(trueSolar),
|
||||
trueSolarTime: formatDateTime(trueSolar),
|
||||
};
|
||||
}
|
||||
|
||||
export function formatLiuyaoTimingForPrompt(
|
||||
timing: TimingInfo,
|
||||
trueSolarTime: string,
|
||||
locationName: string,
|
||||
longitude: number,
|
||||
): string {
|
||||
return [
|
||||
"【起卦时空 · 天时】",
|
||||
`起卦时刻:${timing.solarTime}`,
|
||||
`真太阳时:${trueSolarTime}`,
|
||||
`农历:${timing.lunarDate}`,
|
||||
`年柱:${timing.yearGanZhi},月柱:${timing.monthGanZhi},日柱:${timing.dayGanZhi},时柱:${timing.timeGanZhi}`,
|
||||
`节气:上一节气 ${timing.prevJieQi},下一节气 ${timing.nextJieQi}`,
|
||||
"",
|
||||
"【起卦地域 · 地利】",
|
||||
`位置:${locationName}`,
|
||||
`经度:${longitude}°`,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
export function formatTimingForPrompt(
|
||||
timing: TimingInfo,
|
||||
locationName: string,
|
||||
longitude: number,
|
||||
): string {
|
||||
return [
|
||||
"【天时】",
|
||||
`测算时刻:${timing.solarTime}`,
|
||||
`农历:${timing.lunarDate}`,
|
||||
`年柱:${timing.yearGanZhi},月柱:${timing.monthGanZhi},日柱:${timing.dayGanZhi},时柱:${timing.timeGanZhi}`,
|
||||
`节气:上一节气 ${timing.prevJieQi},下一节气 ${timing.nextJieQi}`,
|
||||
"",
|
||||
"【地利】",
|
||||
`当前位置:${locationName}`,
|
||||
`经度:${longitude}°`,
|
||||
].join("\n");
|
||||
}
|
||||
+51
-2
@@ -1,13 +1,54 @@
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
const CONTENT_ROOT = path.join(process.cwd(), "content", "zhouyi", "docs");
|
||||
const DOCS_ROOT = path.join(process.cwd(), "content", "zhouyi", "docs");
|
||||
const OTHER_ROOT = path.join(DOCS_ROOT, "other");
|
||||
|
||||
export type LearnVariant = "traditional" | "simplified";
|
||||
|
||||
function getVariantRoot(variant: LearnVariant): string {
|
||||
return variant === "traditional" ? DOCS_ROOT : OTHER_ROOT;
|
||||
}
|
||||
|
||||
export async function listGuaMarks(
|
||||
variant: LearnVariant = "traditional",
|
||||
): Promise<string[]> {
|
||||
const dir = getVariantRoot(variant);
|
||||
const entries = await fs.readdir(dir, { withFileTypes: true });
|
||||
return entries
|
||||
.filter((entry) => entry.isDirectory() && /^\d{2}\./.test(entry.name))
|
||||
.map((entry) => entry.name)
|
||||
.sort();
|
||||
}
|
||||
|
||||
export async function readGuaMarkdown(guaMark: string): Promise<string> {
|
||||
const filePath = path.join(CONTENT_ROOT, guaMark, "index.md");
|
||||
const filePath = path.join(DOCS_ROOT, guaMark, "index.md");
|
||||
return fs.readFile(filePath, "utf-8");
|
||||
}
|
||||
|
||||
export async function readLearnMarkdown(
|
||||
guaMark: string,
|
||||
variant: LearnVariant = "traditional",
|
||||
): Promise<string> {
|
||||
const root = getVariantRoot(variant);
|
||||
const filePath =
|
||||
guaMark === "index"
|
||||
? path.join(root, "index.md")
|
||||
: path.join(root, guaMark, "index.md");
|
||||
return fs.readFile(filePath, "utf-8");
|
||||
}
|
||||
|
||||
export function stripFrontmatter(content: string): string {
|
||||
if (!content.startsWith("---")) {
|
||||
return content;
|
||||
}
|
||||
const end = content.indexOf("---", 3);
|
||||
if (end === -1) {
|
||||
return content;
|
||||
}
|
||||
return content.slice(end + 3).trimStart();
|
||||
}
|
||||
|
||||
export function extractZhangMingRen(guaDetail: string): string | undefined {
|
||||
return guaDetail
|
||||
.match(/(\*\*台灣張銘仁[\s\S]*?)(?=周易第\d+卦)/)?.[1]
|
||||
@@ -39,3 +80,11 @@ export function extractChangeDetails(
|
||||
|
||||
return changeList;
|
||||
}
|
||||
|
||||
export function getGuaNumber(guaMark: string): number {
|
||||
return parseInt(guaMark.split(".")[0], 10);
|
||||
}
|
||||
|
||||
export function getGuaName(guaMark: string): string {
|
||||
return guaMark.split(".").slice(1).join(".");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"110000": {
|
||||
"name": "北京市",
|
||||
"longitude": 116.4074,
|
||||
"children": {
|
||||
"110101": { "name": "东城区", "longitude": 116.4164 },
|
||||
"110105": { "name": "朝阳区", "longitude": 116.4434 },
|
||||
"110108": { "name": "海淀区", "longitude": 116.2983 }
|
||||
}
|
||||
},
|
||||
"310000": {
|
||||
"name": "上海市",
|
||||
"longitude": 121.4737,
|
||||
"children": {
|
||||
"310101": { "name": "黄浦区", "longitude": 121.4903 },
|
||||
"310115": { "name": "浦东新区", "longitude": 121.5447 },
|
||||
"310104": { "name": "徐汇区", "longitude": 121.4365 }
|
||||
}
|
||||
},
|
||||
"440000": {
|
||||
"name": "广东省",
|
||||
"longitude": 113.2665,
|
||||
"children": {
|
||||
"440100": { "name": "广州市", "longitude": 113.2644 },
|
||||
"440300": { "name": "深圳市", "longitude": 114.0579 },
|
||||
"440600": { "name": "佛山市", "longitude": 113.1214 }
|
||||
}
|
||||
},
|
||||
"330000": {
|
||||
"name": "浙江省",
|
||||
"longitude": 120.1536,
|
||||
"children": {
|
||||
"330100": { "name": "杭州市", "longitude": 120.1551 },
|
||||
"330200": { "name": "宁波市", "longitude": 121.5503 },
|
||||
"330300": { "name": "温州市", "longitude": 120.6994 }
|
||||
}
|
||||
},
|
||||
"320000": {
|
||||
"name": "江苏省",
|
||||
"longitude": 118.7969,
|
||||
"children": {
|
||||
"320100": { "name": "南京市", "longitude": 118.7969 },
|
||||
"320500": { "name": "苏州市", "longitude": 120.5853 },
|
||||
"320200": { "name": "无锡市", "longitude": 120.3119 }
|
||||
}
|
||||
},
|
||||
"510000": {
|
||||
"name": "四川省",
|
||||
"longitude": 104.0665,
|
||||
"children": {
|
||||
"510100": { "name": "成都市", "longitude": 104.0665 },
|
||||
"510700": { "name": "绵阳市", "longitude": 104.6796 }
|
||||
}
|
||||
},
|
||||
"420000": {
|
||||
"name": "湖北省",
|
||||
"longitude": 114.3419,
|
||||
"children": {
|
||||
"420100": { "name": "武汉市", "longitude": 114.3055 },
|
||||
"420500": { "name": "宜昌市", "longitude": 111.2865 }
|
||||
}
|
||||
},
|
||||
"610000": {
|
||||
"name": "陕西省",
|
||||
"longitude": 108.9398,
|
||||
"children": {
|
||||
"610100": { "name": "西安市", "longitude": 108.9398 },
|
||||
"610300": { "name": "宝鸡市", "longitude": 107.2376 }
|
||||
}
|
||||
},
|
||||
"370000": {
|
||||
"name": "山东省",
|
||||
"longitude": 117.0009,
|
||||
"children": {
|
||||
"370100": { "name": "济南市", "longitude": 117.1205 },
|
||||
"370200": { "name": "青岛市", "longitude": 120.3826 }
|
||||
}
|
||||
},
|
||||
"430000": {
|
||||
"name": "湖南省",
|
||||
"longitude": 112.9834,
|
||||
"children": {
|
||||
"430100": { "name": "长沙市", "longitude": 112.9388 },
|
||||
"430200": { "name": "株洲市", "longitude": 113.1340 }
|
||||
}
|
||||
},
|
||||
"500000": {
|
||||
"name": "重庆市",
|
||||
"longitude": 106.5516,
|
||||
"children": {
|
||||
"500103": { "name": "渝中区", "longitude": 106.5629 },
|
||||
"500112": { "name": "渝北区", "longitude": 106.6304 }
|
||||
}
|
||||
},
|
||||
"350000": {
|
||||
"name": "福建省",
|
||||
"longitude": 119.2965,
|
||||
"children": {
|
||||
"350100": { "name": "福州市", "longitude": 119.2965 },
|
||||
"350200": { "name": "厦门市", "longitude": 118.0894 }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import regionsData from "@/lib/data/regions.json";
|
||||
|
||||
export interface RegionNode {
|
||||
name: string;
|
||||
longitude: number;
|
||||
children?: Record<string, RegionNode>;
|
||||
}
|
||||
|
||||
export type RegionsData = Record<string, RegionNode>;
|
||||
|
||||
export const regions = regionsData as RegionsData;
|
||||
|
||||
export function getProvinces(): { code: string; name: string }[] {
|
||||
return Object.entries(regions).map(([code, node]) => ({
|
||||
code,
|
||||
name: node.name,
|
||||
}));
|
||||
}
|
||||
|
||||
export function getCities(provinceCode: string): { code: string; name: string }[] {
|
||||
const province = regions[provinceCode];
|
||||
if (!province?.children) {
|
||||
return [];
|
||||
}
|
||||
return Object.entries(province.children).map(([code, node]) => ({
|
||||
code,
|
||||
name: node.name,
|
||||
}));
|
||||
}
|
||||
|
||||
export function getRegionLocation(
|
||||
provinceCode: string,
|
||||
cityCode: string,
|
||||
): { name: string; longitude: number } | null {
|
||||
const province = regions[provinceCode];
|
||||
if (!province) {
|
||||
return null;
|
||||
}
|
||||
const city = province.children?.[cityCode];
|
||||
if (city) {
|
||||
return {
|
||||
name: `${province.name}${city.name}`,
|
||||
longitude: city.longitude,
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: province.name,
|
||||
longitude: province.longitude,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
export const LIUYAO_SYSTEM_PROMPT = `你是一位精通《周易》六爻的 AI 解读师,根据用户提供的卦象、起卦时空和问事,给出准确的卦象解读和实用建议。
|
||||
|
||||
任务要求:逻辑清晰,语气得当
|
||||
1. 结合起卦时辰(节气、日柱、时辰)与地域,分析天时地利对卦象的影响
|
||||
2. 解读主卦、变爻及变卦,说明整体趋势和吉凶
|
||||
3. 针对用户问事,结合卦象给出具体分析和可行建议`;
|
||||
|
||||
export const BAZI_SYSTEM_PROMPT = `你是一位精通子平八字的命理分析师,根据用户提供的排盘信息和问题,给出专业、清晰的命理解读。
|
||||
|
||||
任务要求:
|
||||
1. 分析命局格局与五行喜忌
|
||||
2. 解读十神组合含义
|
||||
3. 结合大运流年分析趋势
|
||||
4. 提示相关神煞吉凶
|
||||
5. 针对用户具体问题给出切实可行的建议
|
||||
语气得当,逻辑清晰,避免绝对化断言。`;
|
||||
|
||||
export const COMBINED_SYSTEM_PROMPT = `你是一位融合天时、地利、人和的综合命理顾问,精通子平八字与周易六爻。
|
||||
|
||||
任务要求:
|
||||
1. 综合天时(节气、日柱时辰)、地利(地域经度方位)、人和(八字命局)进行分析
|
||||
2. 若用户提供卦象,结合卦辞与变爻补充解读
|
||||
3. 针对用户问事给出具体、可操作的指引
|
||||
语气得当,逻辑清晰,各维度分析要有机融合而非简单罗列。`;
|
||||
+11
-4
@@ -1,11 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# 知命阁(zhimingge)服务器更新脚本
|
||||
# 知命阁(zhimingge)Ubuntu 服务器更新脚本
|
||||
# 用法:cd /opt/zhimingge && bash scripts/deploy.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
APP_DIR="/opt/zhimingge"
|
||||
APP_NAME="zhimingge"
|
||||
APP_PORT="${PORT:-3130}"
|
||||
|
||||
cd "$APP_DIR"
|
||||
|
||||
@@ -22,8 +23,14 @@ echo "==> 确保日志目录存在..."
|
||||
mkdir -p logs
|
||||
|
||||
echo "==> 重启 PM2..."
|
||||
pm2 restart "$APP_NAME" || pm2 start ecosystem.config.cjs
|
||||
if pm2 describe "$APP_NAME" > /dev/null 2>&1; then
|
||||
pm2 restart "$APP_NAME"
|
||||
else
|
||||
pm2 start ecosystem.config.cjs
|
||||
fi
|
||||
|
||||
echo "==> 部署完成"
|
||||
pm2 save
|
||||
|
||||
echo "==> 部署完成,验证 http://127.0.0.1:${APP_PORT} ..."
|
||||
pm2 status "$APP_NAME"
|
||||
curl -s -o /dev/null -w "HTTP %{http_code}\n" http://127.0.0.1:3000 || true
|
||||
curl -s -o /dev/null -w "HTTP %{http_code}\n" "http://127.0.0.1:${APP_PORT}" || true
|
||||
|
||||
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
declare module "lunar-javascript" {
|
||||
export class Solar {
|
||||
static fromYmdHms(
|
||||
year: number,
|
||||
month: number,
|
||||
day: number,
|
||||
hour: number,
|
||||
minute: number,
|
||||
second: number,
|
||||
): Solar;
|
||||
getLunar(): Lunar;
|
||||
toYmd(): string;
|
||||
toYmdHms(): string;
|
||||
}
|
||||
|
||||
export class Lunar {
|
||||
getEightChar(): EightChar;
|
||||
getDayInGanZhi(): string;
|
||||
getTimeInGanZhi(): string;
|
||||
getYearInGanZhi(): string;
|
||||
getMonthInGanZhi(): string;
|
||||
getDayJiShen(): string[];
|
||||
getDayXiongSha(): string[];
|
||||
getPrevJieQi(): JieQi | null;
|
||||
getNextJieQi(): JieQi | null;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
export class EightChar {
|
||||
getYear(): string;
|
||||
getMonth(): string;
|
||||
getDay(): string;
|
||||
getTime(): string;
|
||||
getYearShiShenGan(): string;
|
||||
getMonthShiShenGan(): string;
|
||||
getDayShiShenGan(): string;
|
||||
getTimeShiShenGan(): string;
|
||||
getYearShiShenZhi(): string[];
|
||||
getMonthShiShenZhi(): string[];
|
||||
getDayShiShenZhi(): string[];
|
||||
getTimeShiShenZhi(): string[];
|
||||
getYearHideGan(): string[];
|
||||
getMonthHideGan(): string[];
|
||||
getDayHideGan(): string[];
|
||||
getTimeHideGan(): string[];
|
||||
getYearNaYin(): string;
|
||||
getMonthNaYin(): string;
|
||||
getDayNaYin(): string;
|
||||
getTimeNaYin(): string;
|
||||
getYun(gender: number, sect?: number): Yun;
|
||||
}
|
||||
|
||||
export class Yun {
|
||||
getStartYear(): number;
|
||||
getStartMonth(): number;
|
||||
getStartDay(): number;
|
||||
getDaYun(): DaYun[];
|
||||
}
|
||||
|
||||
export class DaYun {
|
||||
getGanZhi(): string;
|
||||
getLiuNian(): LiuNian[];
|
||||
}
|
||||
|
||||
export class LiuNian {
|
||||
getGanZhi(): string;
|
||||
getYear(): number;
|
||||
}
|
||||
|
||||
export class JieQi {
|
||||
getName(): string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user