feat: migrate rice preview to Next.js
Verify mini program and deploy preview / verify-deploy (push) Successful in 3m0s

This commit is contained in:
2026-09-20 14:22:47 +08:00
parent 5a16113a6d
commit 2bf21a9f97
29 changed files with 6338 additions and 47 deletions
+23
View File
@@ -0,0 +1,23 @@
'use client';
import { motion } from 'motion/react';
import Image from 'next/image';
import Link from 'next/link';
import { useEffect, useState } from 'react';
import { apiRequest, ensureLogin } from '../lib/api';
export default function RiceHome() {
const [test,setTest]=useState(null),[results,setResults]=useState([]),[code,setCode]=useState(''),[message,setMessage]=useState(''),[error,setError]=useState('');
useEffect(()=>{Promise.all([apiRequest('/api/v1/tests/rice'),ensureLogin().then(()=>apiRequest('/api/v1/me/results?test_slug=rice'))]).then(([data,history])=>{setTest(data);setResults(history);}).catch(reason=>setError(reason.message));},[]);
async function bind(){if(code.trim().length!==6){setMessage('请输入 6 位绑定码');return;}try{const data=await apiRequest('/api/v1/me/link-code/confirm',{method:'POST',body:{code:code.trim().toUpperCase()}});localStorage.setItem('rice_token',data.token);setMessage('档案已连接');setResults(await apiRequest('/api/v1/me/results?test_slug=rice'));}catch(reason){setMessage(reason.message);}}
if(error)return <main className="centerState"><h1>暂时没接上服务</h1><p>{error}</p><button onClick={()=>location.reload()}>重新加载</button></main>;
if(!test)return <main className="centerState">正在摆好饭桌…</main>;
return <main className="homeShell">
<header className="topbar"><strong>RICE PK</strong><span>独立饭类版</span></header>
<motion.section className="hero" initial={{opacity:0,y:18}} animate={{opacity:1,y:0}}>
<Image src="/assets/test-covers/rice.jpg" width={900} height={1200} priority sizes="(max-width: 720px) 100vw, 430px" alt="各种各样的饭二选一" />
<div className="heroCopy"><small>ONLY RICE · {test.candidate_count} 强</small><h1>{test.title}</h1><p>{test.subtitle}</p><Link className="primary" href="/test">开始选饭</Link></div>
</motion.section>
<section className="history"><div className="sectionHead"><h2>我的饭类结果</h2><span>{results.length} 次</span></div>{results.length?results.map(result=><Link className="resultRow" key={result.id} href={`/results/${result.id}`}><b>#1</b><span><small>{new Date(result.completed_at).toLocaleDateString()}</small><strong>{result.champion_name}</strong></span><i>→</i></Link>):<p className="empty">还没有冠军,第一轮现在开始。</p>}</section>
<section className="bindPanel"><h2>已有偏爱研究所档案?</h2><p>在综合版生成绑定码,在这里确认后合并两边历史。</p><div><input value={code} onChange={event=>setCode(event.target.value)} maxLength={6} placeholder="6 位绑定码"/><button onClick={bind}>确认连接</button></div>{message?<output>{message}</output>:null}</section>
</main>;
}