refactor(app): 重构应用入口和首页
- layout.tsx: 更新元数据,设置中文语言,简化布局结构 - page.tsx: 重构首页为 AI 聊天界面,集成欢迎、输入框和快捷操作
This commit is contained in:
parent
01777b3786
commit
9356c87180
@ -1,20 +1,12 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { Geist, Geist_Mono } from "next/font/google";
|
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
|
||||||
const geistSans = Geist({
|
|
||||||
variable: "--font-geist-sans",
|
|
||||||
subsets: ["latin"],
|
|
||||||
});
|
|
||||||
|
|
||||||
const geistMono = Geist_Mono({
|
|
||||||
variable: "--font-geist-mono",
|
|
||||||
subsets: ["latin"],
|
|
||||||
});
|
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Create Next App",
|
title: "cchcode - AI 智能助手",
|
||||||
description: "Generated by create next app",
|
description: "基于 Claude 的智能对话助手",
|
||||||
|
icons: {
|
||||||
|
icon: "/favicon.ico",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
@ -23,10 +15,8 @@ export default function RootLayout({
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="zh-CN">
|
||||||
<body
|
<body className="antialiased">
|
||||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
121
src/app/page.tsx
121
src/app/page.tsx
@ -1,65 +1,70 @@
|
|||||||
import Image from "next/image";
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { AppLayout } from '@/components/layout/AppLayout';
|
||||||
|
import { Welcome } from '@/components/features/Welcome';
|
||||||
|
import { ChatInput } from '@/components/features/ChatInput';
|
||||||
|
import { QuickActions } from '@/components/features/QuickActions';
|
||||||
|
import { models, tools as initialTools, quickActions, currentUser, getGreeting } from '@/data/mock';
|
||||||
|
import type { Model, Tool, QuickAction } from '@/types';
|
||||||
|
|
||||||
|
export default function HomePage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [selectedModel, setSelectedModel] = useState<Model>(models[1]); // Sonnet as default
|
||||||
|
const [tools, setTools] = useState<Tool[]>(initialTools);
|
||||||
|
|
||||||
|
const greeting = getGreeting(currentUser.name);
|
||||||
|
|
||||||
|
const handleToolToggle = (toolId: string) => {
|
||||||
|
setTools((prev) =>
|
||||||
|
prev.map((tool) =>
|
||||||
|
tool.id === toolId ? { ...tool, enabled: !tool.enabled } : tool
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEnableAllTools = (enabled: boolean) => {
|
||||||
|
setTools((prev) =>
|
||||||
|
prev.map((tool) => ({ ...tool, enabled }))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSend = (message: string) => {
|
||||||
|
// 在实际应用中,这里会创建新对话并跳转
|
||||||
|
console.log('Sending message:', message);
|
||||||
|
router.push('/chat/1');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleQuickAction = (action: QuickAction) => {
|
||||||
|
if (action.prompt) {
|
||||||
|
handleSend(action.prompt);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default function Home() {
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
<AppLayout>
|
||||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
<div className="w-full max-w-[900px] mx-auto">
|
||||||
<Image
|
{/* 欢迎区域 */}
|
||||||
className="dark:invert"
|
<Welcome greeting={greeting} className="mb-8" />
|
||||||
src="/next.svg"
|
|
||||||
alt="Next.js logo"
|
{/* 聊天输入框 */}
|
||||||
width={100}
|
<ChatInput
|
||||||
height={20}
|
models={models}
|
||||||
priority
|
selectedModel={selectedModel}
|
||||||
|
onModelSelect={setSelectedModel}
|
||||||
|
tools={tools}
|
||||||
|
onToolToggle={handleToolToggle}
|
||||||
|
onEnableAllTools={handleEnableAllTools}
|
||||||
|
onSend={handleSend}
|
||||||
/>
|
/>
|
||||||
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
|
||||||
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
{/* 快捷操作 */}
|
||||||
To get started, edit the page.tsx file.
|
<QuickActions
|
||||||
</h1>
|
actions={quickActions}
|
||||||
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
onSelect={handleQuickAction}
|
||||||
Looking for a starting point or more instructions? Head over to{" "}
|
|
||||||
<a
|
|
||||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
|
||||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
|
||||||
>
|
|
||||||
Templates
|
|
||||||
</a>{" "}
|
|
||||||
or the{" "}
|
|
||||||
<a
|
|
||||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
|
||||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
|
||||||
>
|
|
||||||
Learning
|
|
||||||
</a>{" "}
|
|
||||||
center.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
|
||||||
<a
|
|
||||||
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
|
||||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<Image
|
|
||||||
className="dark:invert"
|
|
||||||
src="/vercel.svg"
|
|
||||||
alt="Vercel logomark"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
/>
|
/>
|
||||||
Deploy Now
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
|
||||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
Documentation
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</div>
|
</div>
|
||||||
|
</AppLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user