diff --git a/.gitignore b/.gitignore index d781a65..dd76867 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ .next/ .env *.tar.gz +data/ diff --git a/app/chat/page.jsx b/app/chat/page.jsx index 4ef9611..aa5cfc3 100644 --- a/app/chat/page.jsx +++ b/app/chat/page.jsx @@ -2,7 +2,6 @@ import { useEffect, useRef, useState } from 'react'; import { useRouter } from 'next/navigation'; -// ── 星空Canvas ────────────────────────────────────────── function Starfield() { const canvasRef = useRef(null); useEffect(() => { @@ -62,16 +61,9 @@ function Starfield() { window.removeEventListener('resize', resize); }; }, []); - return ( - - ); + return ; } -// ── 淡入淡出文字组件 ────────────────────────────────────── function FadeText({ text, visible, className = '' }) { return (
{ const timers = [ setTimeout(() => setPhase(1), 600), @@ -100,24 +90,10 @@ function Intro({ onDone }) { return (
- - -
= 5 ? 1 : 0, transform: phase >= 5 ? 'translateY(0)' : 'translateY(12px)' }} - > -
@@ -125,34 +101,50 @@ function Intro({ onDone }) { ); } -// ── 单问题沉浸视图 ──────────────────────────────────────── -function QuestionView({ question, onAnswer, questionIndex, total }) { +const fixedOptions = { + fixed_gender: ['男生', '女生', '不想说'], + fixed_age: ['20以下', '20-25', '26-30', '31-40', '40以上'], + fixed_birth_month: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], + fixed_birth_day: Array.from({ length: 31 }, (_, i) => `${i + 1}日`), +}; + +function QuestionView({ prompt, onAnswer }) { const [visible, setVisible] = useState(false); const [input, setInput] = useState(''); const [leaving, setLeaving] = useState(false); + const [picked, setPicked] = useState(''); const inputRef = useRef(null); useEffect(() => { setVisible(false); setInput(''); setLeaving(false); + setPicked(''); const t = setTimeout(() => { setVisible(true); - setTimeout(() => inputRef.current?.focus(), 600); + if ((prompt?.type || 'text') === 'text') { + setTimeout(() => inputRef.current?.focus(), 600); + } }, 100); return () => clearTimeout(t); - }, [question]); + }, [prompt]); - const submit = () => { - if (!input.trim()) return; + const submit = (val) => { + const answer = (val || '').trim(); + if (!answer) return; setLeaving(true); - setTimeout(() => onAnswer(input.trim()), 800); + setTimeout(() => onAnswer(answer), 700); }; + const type = prompt?.type || 'text'; + const isChoice = type === 'choice' || type.startsWith('fixed_'); + const question = prompt?.question || prompt?.reply || ''; + const options = type === 'choice' ? (prompt.options || []) : (fixedOptions[type] || []); + const compact = type === 'fixed_birth_day'; + return (
-
- {/* 问题 */} +
- {/* 输入 */} -
-