Initial commit: 国土空间规划课程智能体 v1.0
单容器 Docker 架构的国土空间规划课程智能问答系统,集成 FastAPI 后端与 Next.js 前端。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,422 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
import { useChatStore } from "@/store/chat";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Send, Loader2, Bot, User, StopCircle, ArrowDown, Paperclip } from "lucide-react";
|
||||
import MessageList from "./message-list";
|
||||
import QuickQuestions from "./quick-questions";
|
||||
import ModeSelector, { ChatMode } from "./mode-selector";
|
||||
import ModelSelector from "./model-selector";
|
||||
import KnowledgeSelector, { KnowledgeBase } from "./knowledge-selector";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { knowledgeBaseAPI } from "@/lib/api";
|
||||
|
||||
export default function ChatInterface() {
|
||||
const [inputMessage, setInputMessage] = useState("");
|
||||
const [isComposing, setIsComposing] = useState(false);
|
||||
const [chatMode, setChatMode] = useState<ChatMode>("normal");
|
||||
const [selectedModel, setSelectedModel] = useState("deepseek-ai/DeepSeek-V3");
|
||||
const [selectedKnowledgeBases, setSelectedKnowledgeBases] = useState<string[]>([]);
|
||||
const [systemKnowledgeBases, setSystemKnowledgeBases] = useState<KnowledgeBase[]>([]);
|
||||
const [userKnowledgeBases, setUserKnowledgeBases] = useState<KnowledgeBase[]>([]);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const {
|
||||
currentSession,
|
||||
messages,
|
||||
isLoading,
|
||||
isStreaming,
|
||||
sendMessage,
|
||||
streamMessage,
|
||||
stopGeneration,
|
||||
createSession,
|
||||
selectSession,
|
||||
} = useChatStore();
|
||||
|
||||
// 调试日志
|
||||
useEffect(() => {
|
||||
console.log("[DEBUG-CHAT-INTERFACE] 组件状态:", {
|
||||
currentSession: currentSession?.id,
|
||||
messagesCount: messages.length,
|
||||
isLoading,
|
||||
isStreaming,
|
||||
messages: messages.map(m => ({ id: m.id, role: m.role, contentLength: m.content.length }))
|
||||
});
|
||||
}, [currentSession, messages, isLoading, isStreaming]);
|
||||
|
||||
// 自动滚动到底部
|
||||
useEffect(() => {
|
||||
messagesEndRef.current?.scrollIntoView({
|
||||
behavior: isStreaming ? "auto" : "smooth"
|
||||
});
|
||||
}, [messages, isStreaming]);
|
||||
|
||||
// 加载知识库(区分系统知识库和用户知识库)
|
||||
useEffect(() => {
|
||||
const loadKnowledgeBases = async () => {
|
||||
try {
|
||||
const bases = await knowledgeBaseAPI.getKnowledgeBases();
|
||||
|
||||
console.log("[DEBUG] 加载的知识库:", bases.map(kb => ({
|
||||
id: kb.id,
|
||||
name: kb.name,
|
||||
is_system: kb.is_system
|
||||
})));
|
||||
|
||||
// 转换为KnowledgeSelector需要的格式
|
||||
const formattedBases: KnowledgeBase[] = bases.map(kb => ({
|
||||
id: kb.id.toString(),
|
||||
name: kb.name,
|
||||
description: kb.description || "",
|
||||
documentCount: kb.document_count,
|
||||
enabled: true, // 默认启用
|
||||
isSystem: kb.is_system === true, // 明确检查是否为 true
|
||||
}));
|
||||
|
||||
// 分离系统知识库和用户知识库
|
||||
const systemBases = formattedBases.filter(kb => kb.isSystem === true);
|
||||
const userBases = formattedBases.filter(kb => kb.isSystem !== true);
|
||||
|
||||
console.log("[DEBUG] 系统知识库:", systemBases.map(kb => ({ id: kb.id, name: kb.name })));
|
||||
console.log("[DEBUG] 用户知识库:", userBases.map(kb => ({ id: kb.id, name: kb.name })));
|
||||
|
||||
setSystemKnowledgeBases(systemBases);
|
||||
setUserKnowledgeBases(userBases);
|
||||
} catch (error) {
|
||||
console.error("加载知识库失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
loadKnowledgeBases();
|
||||
}, []);
|
||||
|
||||
const handleSendMessage = async () => {
|
||||
if (!inputMessage.trim() || isLoading || isStreaming) return;
|
||||
|
||||
const message = inputMessage.trim();
|
||||
setInputMessage("");
|
||||
|
||||
console.log("[DEBUG-CHAT] 发送消息:", {
|
||||
message: message,
|
||||
chatMode: chatMode,
|
||||
selectedKnowledgeBases: selectedKnowledgeBases,
|
||||
selectedModel: selectedModel,
|
||||
currentSession: currentSession?.id
|
||||
});
|
||||
|
||||
// 如果没有当前会话,先创建一个新会话
|
||||
if (!currentSession) {
|
||||
const newSession = await createSession("新对话");
|
||||
if (newSession) {
|
||||
await selectSession(newSession.id);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用流式发送,传递聊天模式、选中的知识库ID和模型ID
|
||||
await streamMessage(message, chatMode, selectedKnowledgeBases, selectedModel);
|
||||
};
|
||||
|
||||
const handleKeyPress = (e: React.KeyboardEvent) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSendMessage();
|
||||
}
|
||||
};
|
||||
|
||||
const handleQuickQuestion = async (question: string) => {
|
||||
setInputMessage(question);
|
||||
|
||||
// 聚焦到输入框
|
||||
setTimeout(() => {
|
||||
if (inputRef.current) {
|
||||
inputRef.current.focus();
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
|
||||
// Debug logging
|
||||
console.log("[CHAT-INTERFACE] Current state:", {
|
||||
hasSession: !!currentSession,
|
||||
sessionId: currentSession?.id,
|
||||
messagesCount: messages.length
|
||||
});
|
||||
|
||||
if (!currentSession) {
|
||||
return (
|
||||
<div className="flex-1 flex flex-col bg-background h-full">
|
||||
{/* 上部:欢迎内容区域 - 使用 flex-1 + 可滚动 */}
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
<div className="h-full flex items-center justify-center p-6">
|
||||
<div className="text-center max-w-2xl px-4">
|
||||
<div className="w-16 h-16 bg-gradient-to-r from-blue-600 to-purple-600 rounded-xl flex items-center justify-center mx-auto mb-4 shadow-lg">
|
||||
<Bot className="w-8 h-8 text-white" />
|
||||
</div>
|
||||
<h3 className="text-2xl font-bold text-foreground mb-2">
|
||||
欢迎使用国土空间规划课程智能体
|
||||
</h3>
|
||||
<p className="text-muted-foreground mb-6">
|
||||
基于大模型的智能问答系统,为您提供专业的国土空间规划知识服务
|
||||
</p>
|
||||
<QuickQuestions onSelect={handleQuickQuestion} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 底部:输入区域 - 不使用 sticky,直接作为 flex 子元素 */}
|
||||
<div className="border-t border-border bg-card p-4 lg:p-6 flex-shrink-0">
|
||||
{/* 功能选择器 */}
|
||||
<div className="mb-4 space-y-3">
|
||||
<div className="flex items-center space-x-2">
|
||||
<ModeSelector mode={chatMode} onModeChange={setChatMode} />
|
||||
<ModelSelector
|
||||
selectedModel={selectedModel}
|
||||
onModelChange={setSelectedModel}
|
||||
className="flex-shrink-0"
|
||||
/>
|
||||
<KnowledgeSelector
|
||||
selectedBases={selectedKnowledgeBases}
|
||||
onBasesChange={setSelectedKnowledgeBases}
|
||||
systemKnowledgeBases={systemKnowledgeBases}
|
||||
userKnowledgeBases={userKnowledgeBases}
|
||||
className="flex-shrink-0"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-9 px-3 flex-shrink-0"
|
||||
title="上传附件"
|
||||
>
|
||||
<Paperclip className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 输入框和发送按钮 */}
|
||||
<div className="flex items-end space-x-3">
|
||||
<div className="flex-1">
|
||||
<div className="relative">
|
||||
<Input
|
||||
ref={inputRef}
|
||||
value={inputMessage}
|
||||
onChange={(e) => setInputMessage(e.target.value)}
|
||||
onKeyPress={handleKeyPress}
|
||||
onCompositionStart={() => setIsComposing(true)}
|
||||
onCompositionEnd={() => setIsComposing(false)}
|
||||
placeholder="输入您的问题..."
|
||||
disabled={isLoading || isStreaming}
|
||||
className={cn(
|
||||
"min-h-[48px] resize-none touch-manipulation pr-12 rounded-xl",
|
||||
"border-border/50 bg-background/80 backdrop-blur-sm",
|
||||
"focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500/50",
|
||||
"transition-all duration-200"
|
||||
)}
|
||||
/>
|
||||
{isStreaming && (
|
||||
<div className="absolute right-3 top-1/2 -translate-y-1/2">
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" />
|
||||
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" style={{ animationDelay: '0.1s' }} />
|
||||
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" style={{ animationDelay: '0.2s' }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleSendMessage}
|
||||
disabled={!inputMessage.trim() || isLoading || isStreaming}
|
||||
size="icon"
|
||||
className={cn(
|
||||
"h-12 w-12 flex-shrink-0 touch-manipulation rounded-xl",
|
||||
"bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700",
|
||||
"shadow-lg hover:shadow-xl transition-all duration-200",
|
||||
"disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
)}
|
||||
>
|
||||
{isLoading || isStreaming ? (
|
||||
<Loader2 className="w-5 h-5 animate-spin" />
|
||||
) : (
|
||||
<Send className="w-5 h-5" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 输入提示 */}
|
||||
<div className="mt-3 flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span className="hidden sm:block">按 Enter 发送,Shift + Enter 换行</span>
|
||||
<span className="sm:hidden">点击发送按钮发送消息</span>
|
||||
{isStreaming && (
|
||||
<span className="flex items-center gap-1 text-blue-600">
|
||||
<div className="w-1.5 h-1.5 bg-blue-500 rounded-full animate-pulse" />
|
||||
正在生成回复...
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex-1 flex flex-col bg-background h-full">
|
||||
{/* 聊天头部 - 不需要 sticky,作为 flex 子元素自然在顶部 */}
|
||||
<div className="border-b border-border bg-card p-4 lg:p-6 flex-shrink-0">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="w-8 h-8 bg-gradient-to-r from-blue-600 to-purple-600 rounded-lg flex items-center justify-center flex-shrink-0 shadow-sm">
|
||||
<Bot className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h2 className="text-lg font-semibold text-foreground truncate">
|
||||
{currentSession.title}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<div className="flex items-center gap-2">
|
||||
{isStreaming && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={stopGeneration}
|
||||
className="text-red-600 hover:text-red-700 hover:bg-red-50"
|
||||
>
|
||||
<StopCircle className="w-4 h-4 mr-2" />
|
||||
停止生成
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })}
|
||||
className="opacity-60 hover:opacity-100"
|
||||
>
|
||||
<ArrowDown className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 消息列表 - 使用 flex-1 占据剩余空间 + 可滚动 */}
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
{messages.length === 0 ? (
|
||||
<div className="h-full flex items-center justify-center p-6">
|
||||
<div className="text-center max-w-2xl">
|
||||
<div className="w-16 h-16 bg-gradient-to-r from-blue-600 to-purple-600 rounded-xl flex items-center justify-center mx-auto mb-4 shadow-lg">
|
||||
<Bot className="w-8 h-8 text-white" />
|
||||
</div>
|
||||
<h3 className="text-2xl font-bold text-foreground mb-2">
|
||||
开始对话
|
||||
</h3>
|
||||
<p className="text-muted-foreground mb-6 max-w-lg mx-auto">
|
||||
输入您的问题,我将为您提供专业的国土空间规划知识解答
|
||||
</p>
|
||||
<QuickQuestions onSelect={handleQuickQuestion} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<MessageList messages={messages} />
|
||||
<div ref={messagesEndRef} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 输入区域 - 不需要 sticky,作为 flex 子元素自然在底部 */}
|
||||
<div className="border-t border-border bg-card p-4 lg:p-6 flex-shrink-0">
|
||||
{/* 功能选择器 */}
|
||||
<div className="mb-4 space-y-3">
|
||||
<div className="flex items-center space-x-2">
|
||||
<ModeSelector mode={chatMode} onModeChange={setChatMode} />
|
||||
<ModelSelector
|
||||
selectedModel={selectedModel}
|
||||
onModelChange={setSelectedModel}
|
||||
className="flex-shrink-0"
|
||||
/>
|
||||
<KnowledgeSelector
|
||||
selectedBases={selectedKnowledgeBases}
|
||||
onBasesChange={setSelectedKnowledgeBases}
|
||||
systemKnowledgeBases={systemKnowledgeBases}
|
||||
userKnowledgeBases={userKnowledgeBases}
|
||||
className="flex-shrink-0"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-9 px-3 flex-shrink-0"
|
||||
title="上传附件"
|
||||
>
|
||||
<Paperclip className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 输入框和发送按钮 */}
|
||||
<div className="flex items-end space-x-3">
|
||||
<div className="flex-1">
|
||||
<div className="relative">
|
||||
<Input
|
||||
ref={inputRef}
|
||||
value={inputMessage}
|
||||
onChange={(e) => setInputMessage(e.target.value)}
|
||||
onKeyPress={handleKeyPress}
|
||||
onCompositionStart={() => setIsComposing(true)}
|
||||
onCompositionEnd={() => setIsComposing(false)}
|
||||
placeholder="输入您的问题..."
|
||||
disabled={isLoading || isStreaming}
|
||||
className={cn(
|
||||
"min-h-[48px] resize-none touch-manipulation pr-12 rounded-xl",
|
||||
"border-border/50 bg-background/80 backdrop-blur-sm",
|
||||
"focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500/50",
|
||||
"transition-all duration-200"
|
||||
)}
|
||||
/>
|
||||
{isStreaming && (
|
||||
<div className="absolute right-3 top-1/2 -translate-y-1/2">
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" />
|
||||
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" style={{ animationDelay: '0.1s' }} />
|
||||
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" style={{ animationDelay: '0.2s' }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleSendMessage}
|
||||
disabled={!inputMessage.trim() || isLoading || isStreaming}
|
||||
size="icon"
|
||||
className={cn(
|
||||
"h-12 w-12 flex-shrink-0 touch-manipulation rounded-xl",
|
||||
"bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700",
|
||||
"shadow-lg hover:shadow-xl transition-all duration-200",
|
||||
"disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
)}
|
||||
>
|
||||
{isLoading || isStreaming ? (
|
||||
<Loader2 className="w-5 h-5 animate-spin" />
|
||||
) : (
|
||||
<Send className="w-5 h-5" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 输入提示 */}
|
||||
<div className="mt-3 flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span className="hidden sm:block">按 Enter 发送,Shift + Enter 换行</span>
|
||||
<span className="sm:hidden">点击发送按钮发送消息</span>
|
||||
{isStreaming && (
|
||||
<span className="flex items-center gap-1 text-blue-600">
|
||||
<div className="w-1.5 h-1.5 bg-blue-500 rounded-full animate-pulse" />
|
||||
正在生成回复...
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Download, FileText, FileJson, File } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useChatStore } from "@/store/chat";
|
||||
import { toast } from "sonner";
|
||||
|
||||
interface ExportDialogProps {
|
||||
sessionId: number;
|
||||
sessionTitle: string;
|
||||
children: React.ReactNode;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
export default function ExportDialog({ sessionId, sessionTitle, children, onClose }: ExportDialogProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [format, setFormat] = useState("json");
|
||||
const [isExporting, setIsExporting] = useState(false);
|
||||
const { exportSession } = useChatStore();
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsExporting(true);
|
||||
try {
|
||||
await exportSession(sessionId, format);
|
||||
handleClose();
|
||||
toast.success("导出成功");
|
||||
} catch (error) {
|
||||
toast.error("导出失败");
|
||||
} finally {
|
||||
setIsExporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const formatOptions = [
|
||||
{
|
||||
value: "json",
|
||||
label: "JSON 格式",
|
||||
description: "完整的结构化数据,包含所有元数据",
|
||||
icon: FileJson,
|
||||
},
|
||||
{
|
||||
value: "markdown",
|
||||
label: "Markdown 格式",
|
||||
description: "可读性好的文本格式,适合分享",
|
||||
icon: FileText,
|
||||
},
|
||||
{
|
||||
value: "pdf",
|
||||
label: "PDF 格式",
|
||||
description: "适合打印和正式文档",
|
||||
icon: File,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
{children}
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>导出会话</DialogTitle>
|
||||
<DialogDescription>
|
||||
选择导出格式来下载 "{sessionTitle}" 会话
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
<RadioGroup value={format} onValueChange={setFormat}>
|
||||
{formatOptions.map((option) => {
|
||||
const Icon = option.icon;
|
||||
return (
|
||||
<div key={option.value} className="flex items-start space-x-3">
|
||||
<RadioGroupItem value={option.value} id={option.value} />
|
||||
<div className="flex-1">
|
||||
<Label htmlFor={option.value} className="flex items-center gap-2 cursor-pointer">
|
||||
<Icon className="h-4 w-4" />
|
||||
<span className="font-medium">{option.label}</span>
|
||||
</Label>
|
||||
<p className="text-sm text-gray-500 mt-1">
|
||||
{option.description}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={handleClose}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleExport} disabled={isExporting}>
|
||||
{isExporting ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2" />
|
||||
导出中...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-4 w-4 mr-2" />
|
||||
导出
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuCheckboxItem,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ChevronDown, Database, FileText, BookOpen, Scale } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
// 系统知识库图标映射
|
||||
const getSystemKnowledgeBaseIcon = (name: string) => {
|
||||
if (name.includes("法律法规")) return Scale;
|
||||
if (name.includes("原理")) return BookOpen;
|
||||
if (name.includes("案例")) return FileText;
|
||||
return Database;
|
||||
};
|
||||
|
||||
export interface KnowledgeBase {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
documentCount: number;
|
||||
enabled: boolean;
|
||||
isSystem?: boolean; // 是否为系统知识库
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
}
|
||||
|
||||
interface KnowledgeSelectorProps {
|
||||
selectedBases: string[];
|
||||
onBasesChange: (baseIds: string[]) => void;
|
||||
systemKnowledgeBases?: KnowledgeBase[]; // 系统知识库列表(从后端动态加载)
|
||||
userKnowledgeBases?: KnowledgeBase[]; // 用户的知识库列表
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function KnowledgeSelector({
|
||||
selectedBases,
|
||||
onBasesChange,
|
||||
systemKnowledgeBases = [],
|
||||
userKnowledgeBases = [],
|
||||
className
|
||||
}: KnowledgeSelectorProps) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
// 为系统知识库添加图标(如果还没有的话)
|
||||
const systemBasesWithIcons = systemKnowledgeBases.map(kb => ({
|
||||
...kb,
|
||||
icon: kb.icon || getSystemKnowledgeBaseIcon(kb.name),
|
||||
isSystem: true,
|
||||
}));
|
||||
|
||||
// 合并系统知识库和用户知识库
|
||||
const allKnowledgeBases = [
|
||||
...systemBasesWithIcons,
|
||||
...userKnowledgeBases.map(kb => ({
|
||||
...kb,
|
||||
isSystem: false, // 用户知识库标记为非系统
|
||||
}))
|
||||
];
|
||||
|
||||
const enabledBases = allKnowledgeBases.filter(base => base.enabled);
|
||||
const selectedCount = selectedBases.length;
|
||||
const totalEnabled = enabledBases.length;
|
||||
|
||||
const handleToggleBase = (baseId: string) => {
|
||||
const newSelectedBases = selectedBases.includes(baseId)
|
||||
? selectedBases.filter(id => id !== baseId)
|
||||
: [...selectedBases, baseId];
|
||||
onBasesChange(newSelectedBases);
|
||||
};
|
||||
|
||||
const handleSelectAll = () => {
|
||||
const allEnabledIds = enabledBases.map(base => base.id);
|
||||
onBasesChange(allEnabledIds);
|
||||
};
|
||||
|
||||
const handleSelectNone = () => {
|
||||
onBasesChange([]);
|
||||
};
|
||||
|
||||
return (
|
||||
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"h-9 px-3 text-sm font-medium",
|
||||
"border-border/50 bg-background/80 hover:bg-muted/50",
|
||||
"transition-all duration-200",
|
||||
className
|
||||
)}
|
||||
>
|
||||
<Database className="w-4 h-4 mr-2" />
|
||||
<span className="hidden sm:inline">
|
||||
知识库 {selectedCount > 0 && `(${selectedCount})`}
|
||||
</span>
|
||||
<span className="sm:hidden">
|
||||
知识库 {selectedCount > 0 && `(${selectedCount})`}
|
||||
</span>
|
||||
<ChevronDown className="w-3 h-3 ml-1 opacity-50" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-72">
|
||||
<div className="px-2 py-1.5 text-xs font-medium text-muted-foreground">
|
||||
选择知识库
|
||||
</div>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
{/* 快速操作 */}
|
||||
<div className="px-2 py-1.5">
|
||||
<div className="flex space-x-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleSelectAll}
|
||||
className="h-7 px-2 text-xs"
|
||||
>
|
||||
全选
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleSelectNone}
|
||||
className="h-7 px-2 text-xs"
|
||||
>
|
||||
清空
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
{/* 系统知识库 */}
|
||||
{systemBasesWithIcons.length > 0 && (
|
||||
<div className="px-2 py-1">
|
||||
<div className="text-xs font-medium text-muted-foreground mb-2 flex items-center">
|
||||
<Database className="w-3 h-3 mr-1" />
|
||||
系统知识库
|
||||
</div>
|
||||
{systemBasesWithIcons.map((base) => {
|
||||
const BaseIcon = base.icon || Database;
|
||||
const isSelected = selectedBases.includes(base.id);
|
||||
const isDisabled = !base.enabled;
|
||||
|
||||
return (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={base.id}
|
||||
checked={isSelected}
|
||||
onCheckedChange={() => handleToggleBase(base.id)}
|
||||
disabled={isDisabled}
|
||||
className={cn(
|
||||
"flex items-start space-x-3 p-3 cursor-pointer",
|
||||
isDisabled && "opacity-50 cursor-not-allowed"
|
||||
)}
|
||||
>
|
||||
<BaseIcon className="w-4 h-4 mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="font-medium text-sm">{base.name}</span>
|
||||
{isSelected && (
|
||||
<Badge variant="secondary" className="text-xs">
|
||||
已选
|
||||
</Badge>
|
||||
)}
|
||||
{isDisabled && (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
不可用
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{base.description}
|
||||
</p>
|
||||
<div className="flex items-center space-x-1 mt-1">
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{base.documentCount} 个文档
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</DropdownMenuCheckboxItem>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 用户知识库 */}
|
||||
{userKnowledgeBases.length > 0 && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<div className="px-2 py-1">
|
||||
<div className="text-xs font-medium text-muted-foreground mb-2 flex items-center">
|
||||
<FileText className="w-3 h-3 mr-1" />
|
||||
我的知识库
|
||||
</div>
|
||||
{userKnowledgeBases.map((base) => {
|
||||
const isSelected = selectedBases.includes(base.id);
|
||||
const isDisabled = !base.enabled;
|
||||
|
||||
return (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={base.id}
|
||||
checked={isSelected}
|
||||
onCheckedChange={() => handleToggleBase(base.id)}
|
||||
disabled={isDisabled}
|
||||
className={cn(
|
||||
"flex items-start space-x-3 p-3 cursor-pointer",
|
||||
isDisabled && "opacity-50 cursor-not-allowed"
|
||||
)}
|
||||
>
|
||||
<BookOpen className="w-4 h-4 mt-0.5 flex-shrink-0 text-green-500" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="font-medium text-sm">{base.name}</span>
|
||||
{isSelected && (
|
||||
<Badge variant="secondary" className="text-xs">
|
||||
已选
|
||||
</Badge>
|
||||
)}
|
||||
{isDisabled && (
|
||||
<Badge variant="outline" className="text-xs">
|
||||
不可用
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{base.description}
|
||||
</p>
|
||||
<div className="flex items-center space-x-1 mt-1">
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{base.documentCount} 个文档
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</DropdownMenuCheckboxItem>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{selectedCount > 0 && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<div className="px-2 py-1.5 text-xs text-muted-foreground text-center">
|
||||
已选择 {selectedCount} 个知识库
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
"use client";
|
||||
|
||||
import { ChatMessage, ThinkingStep } from "@/types";
|
||||
import { User, Bot, MoreVertical, ThumbsUp, ThumbsDown, Copy, Edit, RotateCcw, Trash2, Loader2, CheckCircle2, FileSearch, Brain, Sparkles } from "lucide-react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
|
||||
import { tomorrow } from "react-syntax-highlighter/dist/esm/styles/prism";
|
||||
import { formatDistanceToNow } from "date-fns";
|
||||
import { zhCN } from "date-fns/locale";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { useChatStore } from "@/store/chat";
|
||||
import SourceReferences from "./source-references";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
interface MessageItemProps {
|
||||
message: ChatMessage;
|
||||
}
|
||||
|
||||
// 思考过程组件
|
||||
const ThinkingProcess = ({ thinking }: { thinking: ThinkingStep[] }) => {
|
||||
if (!thinking || thinking.length === 0) return null;
|
||||
|
||||
const getStageIcon = (stage: string) => {
|
||||
switch (stage) {
|
||||
case 'understanding': return <Brain className="h-4 w-4" />;
|
||||
case 'retrieving': return <FileSearch className="h-4 w-4 animate-spin" />;
|
||||
case 'retrieved': return <CheckCircle2 className="h-4 w-4 text-green-500" />;
|
||||
case 'generating': return <Sparkles className="h-4 w-4 animate-pulse" />;
|
||||
default: return <Loader2 className="h-4 w-4" />;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mb-3 space-y-2 text-sm text-muted-foreground bg-muted/50 rounded-lg p-3">
|
||||
{thinking.map((step, index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
{getStageIcon(step.stage)}
|
||||
<span>{step.message}</span>
|
||||
{step.time && (
|
||||
<span className="text-xs">({step.time}s)</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default function MessageItem({ message }: MessageItemProps) {
|
||||
const isUser = message.role === "user";
|
||||
const isAssistant = message.role === "assistant";
|
||||
const { editMessage, regenerateMessage, feedbackMessage, isStreaming } = useChatStore();
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [editContent, setEditContent] = useState(message.content);
|
||||
|
||||
// 添加调试信息
|
||||
console.log(`[DEBUG-MESSAGE] 渲染消息 ${message.id}:`, {
|
||||
role: message.role,
|
||||
contentLength: message.content.length,
|
||||
contentPreview: message.content.substring(0, 50) + "..."
|
||||
});
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(message.content);
|
||||
toast.success("已复制到剪贴板");
|
||||
} catch (error) {
|
||||
toast.error("复制失败");
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = () => {
|
||||
setIsEditing(true);
|
||||
};
|
||||
|
||||
const handleSaveEdit = async () => {
|
||||
try {
|
||||
await editMessage(message.id, editContent);
|
||||
setIsEditing(false);
|
||||
toast.success("消息已更新");
|
||||
} catch (error) {
|
||||
toast.error("编辑失败");
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelEdit = () => {
|
||||
setEditContent(message.content);
|
||||
setIsEditing(false);
|
||||
};
|
||||
|
||||
const handleRegenerate = async () => {
|
||||
try {
|
||||
await regenerateMessage(message.id);
|
||||
toast.success("正在重新生成回复");
|
||||
} catch (error) {
|
||||
toast.error("重新生成失败");
|
||||
}
|
||||
};
|
||||
|
||||
const handleFeedback = async (feedback: "like" | "dislike") => {
|
||||
try {
|
||||
await feedbackMessage(message.id, feedback);
|
||||
toast.success("感谢您的反馈");
|
||||
} catch (error) {
|
||||
toast.error("反馈提交失败");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`flex gap-3 p-4 ${isAssistant ? 'justify-start' : 'justify-end'}`}>
|
||||
{isAssistant && (
|
||||
<div className="flex-shrink-0">
|
||||
<div className="w-8 h-8 bg-gradient-to-r from-blue-600 to-blue-800 rounded-lg flex items-center justify-center shadow-sm">
|
||||
<Bot className="w-4 h-4 text-white" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={`flex-1 max-w-[80%] ${isAssistant ? '' : 'flex justify-end'}`}>
|
||||
<div className={`mit-card ${isAssistant ? 'bg-card' : 'bg-primary text-primary-foreground'}`}>
|
||||
{isEditing ? (
|
||||
<div className="space-y-2">
|
||||
<textarea
|
||||
value={editContent}
|
||||
onChange={(e) => setEditContent(e.target.value)}
|
||||
className="w-full p-2 border rounded resize-none"
|
||||
rows={3}
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<Button size="sm" onClick={handleSaveEdit}>
|
||||
保存
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={handleCancelEdit}>
|
||||
取消
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{/* 思考过程组件 */}
|
||||
{isAssistant && message.thinking && (
|
||||
<ThinkingProcess thinking={message.thinking} />
|
||||
)}
|
||||
|
||||
{/* 消息内容 */}
|
||||
<div className="prose prose-sm max-w-none dark:prose-invert">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
code({ node, inline, className, children, ...props }: any) {
|
||||
const match = /language-(\w+)/.exec(className || "");
|
||||
return !inline && match ? (
|
||||
<SyntaxHighlighter
|
||||
style={tomorrow}
|
||||
language={match[1]}
|
||||
PreTag="div"
|
||||
className="rounded-md"
|
||||
{...props}
|
||||
>
|
||||
{String(children).replace(/\n$/, "")}
|
||||
</SyntaxHighlighter>
|
||||
) : (
|
||||
<code className={className} {...props}>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
},
|
||||
table: ({ children }) => (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="min-w-full border-collapse border border-border">
|
||||
{children}
|
||||
</table>
|
||||
</div>
|
||||
),
|
||||
th: ({ children }) => (
|
||||
<th className="border border-border bg-muted px-3 py-2 text-left font-medium">
|
||||
{children}
|
||||
</th>
|
||||
),
|
||||
td: ({ children }) => (
|
||||
<td className="border border-border px-3 py-2">
|
||||
{children}
|
||||
</td>
|
||||
),
|
||||
}}
|
||||
>
|
||||
{message.content}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
|
||||
{/* 知识来源 */}
|
||||
{isAssistant && message.metadata?.sources && message.metadata.sources.length > 0 && (
|
||||
<div className="mt-4 pt-4 border-t border-border">
|
||||
<SourceReferences sources={message.metadata.sources} maxSources={5} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<div className={`flex items-center gap-1 mt-2 opacity-0 group-hover:opacity-100 transition-opacity ${
|
||||
isAssistant ? "flex-row" : "flex-row-reverse"
|
||||
}`}>
|
||||
{/* 复制按钮 */}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={handleCopy}
|
||||
className="h-7 w-7 p-0 hover:bg-muted/50"
|
||||
>
|
||||
<Copy className="h-3 w-3" />
|
||||
</Button>
|
||||
|
||||
{/* 用户消息操作 */}
|
||||
{isUser && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={handleEdit}
|
||||
className="h-7 w-7 p-0 hover:bg-muted/50"
|
||||
>
|
||||
<Edit className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* 助手消息操作 */}
|
||||
{isAssistant && (
|
||||
<>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={handleRegenerate}
|
||||
className="h-7 w-7 p-0 hover:bg-muted/50"
|
||||
>
|
||||
<RotateCcw className="h-3 w-3" />
|
||||
</Button>
|
||||
|
||||
{/* 反馈按钮 */}
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleFeedback("like")}
|
||||
className={`h-7 w-7 p-0 hover:bg-muted/50 ${
|
||||
message.feedback === "like" ? "text-green-600" : ""
|
||||
}`}
|
||||
>
|
||||
<ThumbsUp className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleFeedback("dislike")}
|
||||
className={`h-7 w-7 p-0 hover:bg-muted/50 ${
|
||||
message.feedback === "dislike" ? "text-red-600" : ""
|
||||
}`}
|
||||
>
|
||||
<ThumbsDown className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 时间戳和编辑标记 */}
|
||||
<div className={`text-xs text-muted-foreground mt-1 ${
|
||||
isUser ? "text-right" : "text-left"
|
||||
}`}>
|
||||
{message.created_at ? formatDistanceToNow(
|
||||
new Date(new Date(message.created_at).getTime() + 8 * 60 * 60 * 1000),
|
||||
{
|
||||
addSuffix: true,
|
||||
locale: zhCN
|
||||
}) : '未知时间'}
|
||||
{message.edited && (
|
||||
<span className="ml-1 text-muted-foreground">(已编辑)</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!isAssistant && (
|
||||
<div className="flex-shrink-0">
|
||||
<div className="w-8 h-8 bg-gradient-to-r from-gray-600 to-gray-800 rounded-lg flex items-center justify-center shadow-sm">
|
||||
<User className="w-4 h-4 text-white" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { ChatMessage } from "@/types";
|
||||
import MessageItem from "./message-item";
|
||||
|
||||
interface MessageListProps {
|
||||
messages: ChatMessage[];
|
||||
}
|
||||
|
||||
export default function MessageList({ messages }: MessageListProps) {
|
||||
return (
|
||||
<div className="space-y-4 p-4">
|
||||
{messages.map((message) => (
|
||||
<MessageItem key={message.id} message={message} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { ChevronDown, MessageSquare, Database } from "lucide-react";
|
||||
|
||||
export type ChatMode = "normal" | "rag";
|
||||
|
||||
interface ModeSelectorProps {
|
||||
mode: ChatMode;
|
||||
onModeChange: (mode: ChatMode) => void;
|
||||
}
|
||||
|
||||
const modeConfig = {
|
||||
normal: {
|
||||
label: "普通对话",
|
||||
icon: MessageSquare,
|
||||
description: "基础AI对话"
|
||||
},
|
||||
rag: {
|
||||
label: "知识库检索",
|
||||
icon: Database,
|
||||
description: "基于国土空间规划知识库"
|
||||
}
|
||||
};
|
||||
|
||||
export default function ModeSelector({ mode, onModeChange }: ModeSelectorProps) {
|
||||
const currentMode = modeConfig[mode];
|
||||
const Icon = currentMode.icon;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" className="gap-2">
|
||||
<Icon className="h-4 w-4" />
|
||||
<span>{currentMode.label}</span>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start">
|
||||
{Object.entries(modeConfig).map(([key, config]) => {
|
||||
const ModeIcon = config.icon;
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={key}
|
||||
onClick={() => onModeChange(key as ChatMode)}
|
||||
className="gap-2"
|
||||
>
|
||||
<ModeIcon className="h-4 w-4" />
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium">{config.label}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{config.description}
|
||||
</span>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuSeparator,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ChevronDown, Cpu, Zap, Sparkles } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export interface ModelOption {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
provider: string;
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
}
|
||||
|
||||
interface ModelSelectorProps {
|
||||
selectedModel: string;
|
||||
onModelChange: (modelId: string) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const models: ModelOption[] = [
|
||||
{
|
||||
id: "deepseek-ai/DeepSeek-V3",
|
||||
name: "DeepSeek-V3",
|
||||
description: "DeepSeek 最新版本,强大的推理能力",
|
||||
provider: "DeepSeek",
|
||||
icon: Sparkles,
|
||||
},
|
||||
{
|
||||
id: "Qwen/QwQ-32B",
|
||||
name: "QwQ-32B",
|
||||
description: "Qwen 量子化模型,高效推理",
|
||||
provider: "Qwen",
|
||||
icon: Zap,
|
||||
},
|
||||
];
|
||||
|
||||
export default function ModelSelector({
|
||||
selectedModel,
|
||||
onModelChange,
|
||||
className
|
||||
}: ModelSelectorProps) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const selectedModelData = models.find(model => model.id === selectedModel) || models[0];
|
||||
const IconComponent = selectedModelData.icon || Cpu;
|
||||
|
||||
return (
|
||||
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"h-9 px-3 text-sm font-medium",
|
||||
"border-border/50 bg-background/80 hover:bg-muted/50",
|
||||
"transition-all duration-200",
|
||||
className
|
||||
)}
|
||||
>
|
||||
<IconComponent className="w-4 h-4 mr-2" />
|
||||
<span className="hidden sm:inline">{selectedModelData.name}</span>
|
||||
<span className="sm:hidden">{selectedModelData.name.split(' ')[0]}</span>
|
||||
<ChevronDown className="w-3 h-3 ml-1 opacity-50" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-64">
|
||||
<div className="px-2 py-1.5 text-xs font-medium text-muted-foreground">
|
||||
选择AI模型
|
||||
</div>
|
||||
<DropdownMenuSeparator />
|
||||
{models.map((model) => {
|
||||
const ModelIcon = model.icon || Cpu;
|
||||
const isSelected = model.id === selectedModel;
|
||||
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={model.id}
|
||||
onClick={() => {
|
||||
onModelChange(model.id);
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-start space-x-3 p-3 cursor-pointer",
|
||||
isSelected && "bg-muted/50"
|
||||
)}
|
||||
>
|
||||
<ModelIcon className="w-4 h-4 mt-0.5 flex-shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="font-medium text-sm">{model.name}</span>
|
||||
{isSelected && (
|
||||
<Badge variant="secondary" className="text-xs">
|
||||
已选择
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{model.description}
|
||||
</p>
|
||||
<div className="flex items-center space-x-1 mt-1">
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{model.provider}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { MessageSquare } from "lucide-react";
|
||||
|
||||
interface QuickQuestionsProps {
|
||||
onSelect: (question: string) => void;
|
||||
}
|
||||
|
||||
const quickQuestions = [
|
||||
"什么是国土空间规划?",
|
||||
"国土空间规划的主要原则是什么?",
|
||||
"如何进行国土空间规划编制?",
|
||||
"国土空间规划与城市规划的区别?",
|
||||
"国土空间规划中的三区三线是什么?",
|
||||
"如何评价国土空间规划的合理性?",
|
||||
];
|
||||
|
||||
export default function QuickQuestions({ onSelect }: QuickQuestionsProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="text-sm text-muted-foreground text-center">
|
||||
快速开始,选择一个问题:
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 max-w-4xl mx-auto">
|
||||
{quickQuestions.map((question, index) => (
|
||||
<Button
|
||||
key={index}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="justify-start text-left h-auto p-4 hover:bg-muted/50 transition-colors"
|
||||
onClick={() => onSelect(question)}
|
||||
>
|
||||
<MessageSquare className="w-4 h-4 mr-3 flex-shrink-0" />
|
||||
<span className="text-sm leading-relaxed">{question}</span>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAuthStore } from "@/store/auth";
|
||||
import { useChatStore } from "@/store/chat";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import {
|
||||
Plus,
|
||||
MessageSquare,
|
||||
Menu,
|
||||
X,
|
||||
Edit2,
|
||||
Trash2,
|
||||
Download,
|
||||
MoreVertical,
|
||||
Search,
|
||||
Calendar,
|
||||
Clock,
|
||||
ChevronRight
|
||||
} from "lucide-react";
|
||||
import { formatDistanceToNow } from "date-fns";
|
||||
import { zhCN } from "date-fns/locale";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { toast } from "sonner";
|
||||
import ExportDialog from "./export-dialog";
|
||||
|
||||
export default function Sidebar() {
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||
const [editingSession, setEditingSession] = useState<number | null>(null);
|
||||
const [editTitle, setEditTitle] = useState("");
|
||||
const [deleteSessionId, setDeleteSessionId] = useState<number | null>(null);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [openDropdownId, setOpenDropdownId] = useState<number | null>(null);
|
||||
const router = useRouter();
|
||||
const { sessions, currentSession, selectSession, createSession, renameSession, deleteSession } = useChatStore();
|
||||
|
||||
// 过滤会话(按创建时间排序)
|
||||
const filteredSessions = () => {
|
||||
if (!searchQuery) {
|
||||
return sessions.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
||||
}
|
||||
|
||||
return sessions
|
||||
.filter(session =>
|
||||
session.title.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
)
|
||||
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
||||
};
|
||||
|
||||
const handleNewChat = async () => {
|
||||
const newSession = await createSession("新对话");
|
||||
if (newSession) {
|
||||
selectSession(newSession.id);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectSession = async (sessionId: number) => {
|
||||
await selectSession(sessionId);
|
||||
setIsMobileMenuOpen(false);
|
||||
};
|
||||
|
||||
const handleRenameSession = (sessionId: number, currentTitle: string) => {
|
||||
setEditingSession(sessionId);
|
||||
setEditTitle(currentTitle);
|
||||
};
|
||||
|
||||
const handleSaveRename = async () => {
|
||||
if (editingSession && editTitle.trim()) {
|
||||
try {
|
||||
await renameSession(editingSession, editTitle.trim());
|
||||
setEditingSession(null);
|
||||
setEditTitle("");
|
||||
toast.success("会话重命名成功");
|
||||
} catch (error) {
|
||||
toast.error("重命名失败");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelRename = () => {
|
||||
setEditingSession(null);
|
||||
setEditTitle("");
|
||||
};
|
||||
|
||||
const handleDeleteSession = (sessionId: number) => {
|
||||
setDeleteSessionId(sessionId);
|
||||
};
|
||||
|
||||
const handleConfirmDelete = async () => {
|
||||
if (deleteSessionId) {
|
||||
try {
|
||||
await deleteSession(deleteSessionId);
|
||||
setDeleteSessionId(null);
|
||||
toast.success("会话已删除");
|
||||
} catch (error) {
|
||||
toast.error("删除失败");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelDelete = () => {
|
||||
setDeleteSessionId(null);
|
||||
};
|
||||
|
||||
const renderSessionItem = (session: any) => {
|
||||
return (
|
||||
<div
|
||||
key={session.id}
|
||||
className={`group relative flex items-center gap-3 px-3 py-2 rounded-lg cursor-pointer transition-all hover:bg-muted/50 ${
|
||||
currentSession?.id === session.id ? 'bg-muted border border-border' : ''
|
||||
}`}
|
||||
onClick={() => handleSelectSession(session.id)}
|
||||
>
|
||||
<MessageSquare className="w-4 h-4 text-muted-foreground flex-shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-sm font-medium text-foreground truncate">
|
||||
{session.title}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{session.created_at ? (() => {
|
||||
const rawDate = new Date(session.created_at);
|
||||
const date = new Date(rawDate.getTime() + 8 * 60 * 60 * 1000);
|
||||
const now = new Date();
|
||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
|
||||
if (date >= today) {
|
||||
// 今天:只显示时间
|
||||
return date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit', timeZone: 'Asia/Shanghai' });
|
||||
} else {
|
||||
// 昨天及更早:显示日期+时间
|
||||
return date.toLocaleString('zh-CN', {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
timeZone: 'Asia/Shanghai'
|
||||
});
|
||||
}
|
||||
})() : '未知时间'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<DropdownMenu
|
||||
open={openDropdownId === session.id}
|
||||
onOpenChange={(open) => setOpenDropdownId(open ? session.id : null)}
|
||||
>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity h-6 w-6 p-0"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<MoreVertical className="w-3 h-3" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={(e) => e.stopPropagation()}>
|
||||
<DropdownMenuItem
|
||||
onSelect={() => {
|
||||
handleRenameSession(session.id, session.title);
|
||||
}}
|
||||
>
|
||||
<Edit2 className="w-4 h-4 mr-2" />
|
||||
重命名
|
||||
</DropdownMenuItem>
|
||||
<ExportDialog
|
||||
sessionId={session.id}
|
||||
sessionTitle={session.title}
|
||||
onClose={() => setOpenDropdownId(null)}
|
||||
>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>
|
||||
<Download className="w-4 h-4 mr-2" />
|
||||
导出
|
||||
</DropdownMenuItem>
|
||||
</ExportDialog>
|
||||
<DropdownMenuItem
|
||||
onSelect={() => {
|
||||
handleDeleteSession(session.id);
|
||||
}}
|
||||
className="text-destructive"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
删除
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 移动端菜单按钮 */}
|
||||
<div className="lg:hidden fixed top-4 left-4 z-50">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
|
||||
>
|
||||
{isMobileMenuOpen ? <X className="w-4 h-4" /> : <Menu className="w-4 h-4" />}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 侧边栏 */}
|
||||
<div className={`
|
||||
fixed lg:static inset-y-0 left-0 z-40 w-80 max-w-[85vw] bg-card/50 backdrop-blur-sm border-r border-border transform transition-transform duration-300 ease-in-out mobile-safe-area lg:h-full
|
||||
${isMobileMenuOpen ? 'translate-x-0' : '-translate-x-full lg:translate-x-0'}
|
||||
`}>
|
||||
<div className="flex flex-col h-full">
|
||||
{/* 头部 */}
|
||||
<div className="p-4 border-b">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h2 className="text-lg font-semibold text-foreground">对话历史</h2>
|
||||
<Button
|
||||
onClick={handleNewChat}
|
||||
size="sm"
|
||||
className="h-8 px-3"
|
||||
>
|
||||
<Plus className="w-4 h-4 mr-1" />
|
||||
新建对话
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 搜索框 */}
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="搜索对话..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-9 h-9"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 会话列表 */}
|
||||
<ScrollArea className="flex-1 px-2">
|
||||
<div className="py-4">
|
||||
<div className="space-y-1">
|
||||
{filteredSessions().map(renderSessionItem)}
|
||||
</div>
|
||||
|
||||
{sessions.length === 0 && (
|
||||
<div className="text-center py-8">
|
||||
<MessageSquare className="w-12 h-12 text-muted-foreground mx-auto mb-3" />
|
||||
<p className="text-sm text-muted-foreground mb-2">还没有对话记录</p>
|
||||
<p className="text-xs text-muted-foreground">开始一个新的对话吧</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 移动端遮罩 */}
|
||||
{isMobileMenuOpen && (
|
||||
<div
|
||||
className="lg:hidden fixed inset-0 bg-black bg-opacity-50 z-30"
|
||||
onClick={() => setIsMobileMenuOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 重命名对话框 */}
|
||||
<Dialog open={!!editingSession} onOpenChange={handleCancelRename}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>重命名会话</DialogTitle>
|
||||
<DialogDescription>
|
||||
为这个会话输入一个新的名称
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4">
|
||||
<Input
|
||||
value={editTitle}
|
||||
onChange={(e) => setEditTitle(e.target.value)}
|
||||
placeholder="输入新的会话名称"
|
||||
onKeyPress={(e) => {
|
||||
if (e.key === 'Enter' && editTitle.trim()) {
|
||||
handleSaveRename();
|
||||
}
|
||||
}}
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={handleCancelRename}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleSaveRename} disabled={!editTitle.trim()}>
|
||||
保存
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* 删除确认对话框 */}
|
||||
<Dialog open={!!deleteSessionId} onOpenChange={() => setDeleteSessionId(null)}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>删除会话</DialogTitle>
|
||||
<DialogDescription>
|
||||
确定要删除这个会话吗?此操作无法撤销,会话中的所有消息都将被删除。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={handleCancelDelete}>
|
||||
取消
|
||||
</Button>
|
||||
<Button variant="destructive" onClick={handleConfirmDelete}>
|
||||
删除
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
"use client";
|
||||
|
||||
import { FileText, ExternalLink, Star, Database, Globe } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
|
||||
interface SourceReference {
|
||||
title: string;
|
||||
filename?: string;
|
||||
page?: number;
|
||||
score?: number;
|
||||
preview: string;
|
||||
url?: string;
|
||||
source_type?: "web" | "rag";
|
||||
}
|
||||
|
||||
interface SourceReferencesProps {
|
||||
sources: SourceReference[];
|
||||
maxSources?: number;
|
||||
}
|
||||
|
||||
export default function SourceReferences({ sources, maxSources = 5 }: SourceReferencesProps) {
|
||||
if (!sources || sources.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const displaySources = sources.slice(0, maxSources);
|
||||
const ragSources = displaySources.filter(s => s.source_type !== "web");
|
||||
const webSources = displaySources.filter(s => s.source_type === "web");
|
||||
|
||||
return (
|
||||
<div className="mt-4 space-y-3">
|
||||
{ragSources.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-sm text-blue-600">
|
||||
<Database className="h-4 w-4" />
|
||||
<span>知识库来源 ({ragSources.length})</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
{ragSources.map((source, index) => (
|
||||
<Card key={index} className="border border-blue-200 bg-blue-50/30 hover:border-blue-300 transition-colors">
|
||||
<CardHeader className="pb-2">
|
||||
<div className="flex items-start justify-between">
|
||||
<CardTitle className="text-sm font-medium line-clamp-2">
|
||||
{source.title}
|
||||
</CardTitle>
|
||||
{source.score != null && source.score > 0 && source.score < 1 && (
|
||||
<div className="flex items-center gap-1 ml-2">
|
||||
<Star className="h-3 w-3 text-yellow-500" />
|
||||
<span className="text-xs text-gray-500">
|
||||
{(source.score * 100).toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
{source.filename}
|
||||
{source.page && ` • 第 ${source.page} 页`}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="pt-0">
|
||||
<p className="text-xs text-gray-600 line-clamp-2">
|
||||
{source.preview}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{webSources.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-sm text-green-600">
|
||||
<Globe className="h-4 w-4" />
|
||||
<span>网络来源 ({webSources.length})</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
{webSources.map((source, index) => (
|
||||
<Card key={index} className="border border-green-200 bg-green-50/30 hover:border-green-300 transition-colors">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium line-clamp-2">
|
||||
{source.title}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="pt-0">
|
||||
<p className="text-xs text-gray-600 line-clamp-2 mb-2">
|
||||
{source.preview}
|
||||
</p>
|
||||
{source.url && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-6 text-xs"
|
||||
onClick={() => window.open(source.url, '_blank')}
|
||||
>
|
||||
<ExternalLink className="h-3 w-3 mr-1" />
|
||||
查看原文
|
||||
</Button>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{sources.length > maxSources && (
|
||||
<div className="text-xs text-gray-500 text-center">
|
||||
还有 {sources.length - maxSources} 个相关来源
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useRef, useCallback, useState, useEffect } from "react";
|
||||
import ForceGraph2D from "react-force-graph-2d";
|
||||
import { BookStructure, Chapter, Section, Subsection } from "@/types";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { RotateCcw, ZoomIn, ZoomOut } from "lucide-react";
|
||||
import NodeDetailDialog from "./node-detail-dialog";
|
||||
|
||||
interface GraphNode {
|
||||
id: string;
|
||||
name: string;
|
||||
type: 'root' | 'chapter' | 'section';
|
||||
nodeId?: number; // 节点在数据库中的ID
|
||||
nodeType?: 'chapter' | 'section'; // 用于详情对话框
|
||||
sectionData?: { subsections: Array<{ id: number; title: string }> }; // 存储节的小节(知识点)数据
|
||||
val?: number;
|
||||
color?: string;
|
||||
fx?: number;
|
||||
fy?: number;
|
||||
x?: number; // 初始x位置
|
||||
y?: number; // 初始y位置
|
||||
_fullLabel?: string; // 完整标签用于tooltip
|
||||
}
|
||||
|
||||
interface GraphLink {
|
||||
source: string;
|
||||
target: string;
|
||||
type: 'root-chapter' | 'chapter-section';
|
||||
}
|
||||
|
||||
interface GraphData {
|
||||
nodes: GraphNode[];
|
||||
links: GraphLink[];
|
||||
}
|
||||
|
||||
interface KnowledgeGraphProps {
|
||||
bookStructure: BookStructure;
|
||||
onNodeClick?: (node: GraphNode) => void;
|
||||
}
|
||||
|
||||
// 标签尺寸配置(分级字体大小,不限制宽度)
|
||||
const LABEL_CONFIG = {
|
||||
root: {
|
||||
fontSize: 18,
|
||||
padding: 8,
|
||||
},
|
||||
chapter: {
|
||||
fontSize: 15,
|
||||
padding: 6,
|
||||
},
|
||||
section: {
|
||||
fontSize: 13,
|
||||
padding: 5,
|
||||
},
|
||||
};
|
||||
|
||||
export default function KnowledgeGraph({ bookStructure, onNodeClick }: KnowledgeGraphProps) {
|
||||
const graphRef = useRef<any>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const [selectedNode, setSelectedNode] = useState<GraphNode | null>(null);
|
||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||
const [dimensions, setDimensions] = useState({ width: 1200, height: 800 });
|
||||
|
||||
// 响应式尺寸计算
|
||||
useEffect(() => {
|
||||
const updateDimensions = () => {
|
||||
if (containerRef.current) {
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
setDimensions({
|
||||
width: rect.width,
|
||||
height: Math.max(600, rect.height),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
updateDimensions();
|
||||
window.addEventListener('resize', updateDimensions);
|
||||
return () => window.removeEventListener('resize', updateDimensions);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 将书籍结构数据转换为图谱数据
|
||||
const graphData: GraphData = useMemo(() => {
|
||||
const nodes: GraphNode[] = [];
|
||||
const links: GraphLink[] = [];
|
||||
|
||||
// 调试信息
|
||||
console.log("知识图谱数据:", bookStructure);
|
||||
console.log("章节数量:", bookStructure?.chapters?.length || 0);
|
||||
|
||||
// 创建根节点(书籍,固定在中心)
|
||||
const rootNode: GraphNode = {
|
||||
id: 'root',
|
||||
name: bookStructure.book.title,
|
||||
type: 'root',
|
||||
val: 25, // 增大根节点
|
||||
color: '#3b82f6', // 蓝色
|
||||
fx: 0, // 固定x坐标
|
||||
fy: 0, // 固定y坐标
|
||||
_fullLabel: bookStructure.book.title, // 存储完整标签用于tooltip
|
||||
};
|
||||
nodes.push(rootNode);
|
||||
|
||||
// 检查是否有章节数据
|
||||
if (!bookStructure.chapters || bookStructure.chapters.length === 0) {
|
||||
console.warn("警告: 没有章节数据");
|
||||
return { nodes, links };
|
||||
}
|
||||
|
||||
// 章节颜色配置
|
||||
const chapterColors = [
|
||||
'#8b5cf6', // 紫色
|
||||
'#ec4899', // 粉色
|
||||
'#f59e0b', // 橙色
|
||||
'#10b981', // 绿色
|
||||
'#06b6d4', // 青色
|
||||
'#ef4444', // 红色
|
||||
];
|
||||
|
||||
// 为每个章节创建节点和连接
|
||||
const chapterCount = bookStructure.chapters.length;
|
||||
const chapterAngleStep = (2 * Math.PI) / chapterCount;
|
||||
|
||||
bookStructure.chapters.forEach((chapter, chapterIndex) => {
|
||||
console.log(`处理章节 ${chapterIndex + 1}:`, chapter.title, "节数量:", chapter.sections?.length || 0);
|
||||
const chapterNodeId = `chapter-${chapter.id}`;
|
||||
const chapterColor = chapterColors[chapterIndex % chapterColors.length];
|
||||
|
||||
// 计算章节节点的初始位置(圆形分布)
|
||||
const chapterRadius = 400;
|
||||
const angle = chapterIndex * chapterAngleStep;
|
||||
const initialX = Math.cos(angle) * chapterRadius;
|
||||
const initialY = Math.sin(angle) * chapterRadius;
|
||||
|
||||
// 创建章节节点
|
||||
const chapterNode: GraphNode = {
|
||||
id: chapterNodeId,
|
||||
name: chapter.title,
|
||||
type: 'chapter',
|
||||
nodeId: chapter.id,
|
||||
nodeType: 'chapter',
|
||||
val: 18, // 章节节点大小
|
||||
color: chapterColor,
|
||||
_fullLabel: chapter.title,
|
||||
x: initialX,
|
||||
y: initialY,
|
||||
};
|
||||
nodes.push(chapterNode);
|
||||
|
||||
// 连接根节点到章节节点
|
||||
links.push({
|
||||
source: 'root',
|
||||
target: chapterNodeId,
|
||||
type: 'root-chapter',
|
||||
});
|
||||
|
||||
// 检查是否有节数据
|
||||
if (!chapter.sections || chapter.sections.length === 0) {
|
||||
console.warn(`章节 ${chapter.title} 没有节数据`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 为每个节创建节点
|
||||
const sectionCount = chapter.sections.length;
|
||||
const sectionAngleStep = sectionCount > 1 ? (2 * Math.PI) / sectionCount : 0;
|
||||
|
||||
chapter.sections.forEach((section, sectionIndex) => {
|
||||
const sectionNodeId = `section-${section.id}`;
|
||||
|
||||
// 计算节节点的初始位置(围绕章节节点)
|
||||
const sectionRadius = 250;
|
||||
const sectionAngle = sectionAngleStep * sectionIndex;
|
||||
const sectionX = initialX + Math.cos(angle + sectionAngle) * sectionRadius;
|
||||
const sectionY = initialY + Math.sin(angle + sectionAngle) * sectionRadius;
|
||||
|
||||
// 创建节节点(包含小节数据,用于点击后展开)
|
||||
const sectionNode: GraphNode = {
|
||||
id: sectionNodeId,
|
||||
name: section.title,
|
||||
type: 'section',
|
||||
nodeId: section.id,
|
||||
nodeType: 'section',
|
||||
sectionData: {
|
||||
subsections: section.subsections || []
|
||||
},
|
||||
val: 12, // 节节点大小
|
||||
color: chapterColor + 'CC', // 添加透明度
|
||||
_fullLabel: section.title,
|
||||
x: sectionX,
|
||||
y: sectionY,
|
||||
};
|
||||
nodes.push(sectionNode);
|
||||
|
||||
// 连接章节节点到节节点
|
||||
links.push({
|
||||
source: chapterNodeId,
|
||||
target: sectionNodeId,
|
||||
type: 'chapter-section',
|
||||
});
|
||||
|
||||
// 注意:小节(知识点)不在图谱中直接展示,点击节节点后在对话框中展开
|
||||
});
|
||||
});
|
||||
|
||||
console.log("图谱节点数量:", nodes.length, "链接数量:", links.length);
|
||||
return { nodes, links };
|
||||
}, [bookStructure]);
|
||||
|
||||
// 节点点击处理
|
||||
const handleNodeClick = useCallback((node: GraphNode) => {
|
||||
// 只有非根节点才能点击查看详情
|
||||
if (node.type !== 'root' && node.nodeId && node.nodeType) {
|
||||
setSelectedNode(node);
|
||||
setIsDialogOpen(true);
|
||||
}
|
||||
if (onNodeClick) {
|
||||
onNodeClick(node);
|
||||
}
|
||||
}, [onNodeClick]);
|
||||
|
||||
// 重置视图
|
||||
const handleResetView = useCallback(() => {
|
||||
if (graphRef.current) {
|
||||
graphRef.current.zoomToFit(400, 20);
|
||||
graphRef.current.centerAt(0, 0, 1000);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 放大
|
||||
const handleZoomIn = useCallback(() => {
|
||||
if (graphRef.current) {
|
||||
const currentZoom = graphRef.current.zoom() || 1;
|
||||
graphRef.current.zoom(currentZoom * 1.2, 200);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 缩小
|
||||
const handleZoomOut = useCallback(() => {
|
||||
if (graphRef.current) {
|
||||
const currentZoom = graphRef.current.zoom() || 1;
|
||||
graphRef.current.zoom(currentZoom * 0.8, 200);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="relative w-full h-full">
|
||||
{/* 控制按钮 */}
|
||||
<div className="absolute top-4 right-4 z-10 flex flex-col space-y-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={handleZoomIn}
|
||||
className="bg-background/80 backdrop-blur-sm"
|
||||
title="放大"
|
||||
>
|
||||
<ZoomIn className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={handleZoomOut}
|
||||
className="bg-background/80 backdrop-blur-sm"
|
||||
title="缩小"
|
||||
>
|
||||
<ZoomOut className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={handleResetView}
|
||||
className="bg-background/80 backdrop-blur-sm"
|
||||
title="重置视图"
|
||||
>
|
||||
<RotateCcw className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 知识图谱 */}
|
||||
<ForceGraph2D
|
||||
ref={graphRef}
|
||||
graphData={graphData}
|
||||
nodeLabel={(node: any) => node._fullLabel || node.name}
|
||||
nodeColor={(node: any) => node.color || '#3b82f6'}
|
||||
nodeVal={(node: any) => node.val || 8}
|
||||
nodeRelSize={6}
|
||||
// 碰撞检测和力衰减优化
|
||||
d3AlphaDecay={0.02}
|
||||
d3AlphaMin={0.005}
|
||||
cooldownTicks={200}
|
||||
linkColor={(link: any) => {
|
||||
if (link.type === 'root-chapter') {
|
||||
return '#64748b'; // 灰色
|
||||
}
|
||||
return link.source.color || '#94a3b8'; // 使用章节颜色
|
||||
}}
|
||||
linkWidth={(link: any) => {
|
||||
if (link.type === 'root-chapter') {
|
||||
return 3;
|
||||
}
|
||||
return 2;
|
||||
}}
|
||||
linkDirectionalArrowLength={6}
|
||||
linkDirectionalArrowRelPos={1}
|
||||
linkCurvature={0.15}
|
||||
onNodeClick={(node: any) => handleNodeClick(node)}
|
||||
onNodeDragEnd={(node: any) => {
|
||||
// 保持根节点固定
|
||||
if (node.id !== 'root') {
|
||||
node.fx = node.x;
|
||||
node.fy = node.y;
|
||||
}
|
||||
}}
|
||||
onNodeHover={(node: any) => {
|
||||
if (typeof document !== 'undefined') {
|
||||
if (node) {
|
||||
document.body.style.cursor = 'pointer';
|
||||
} else {
|
||||
document.body.style.cursor = 'default';
|
||||
}
|
||||
}
|
||||
}}
|
||||
onEngineStop={() => {
|
||||
if (graphRef.current) {
|
||||
// 确保根节点在中心
|
||||
graphRef.current.centerAt(0, 0, 1000);
|
||||
graphRef.current.zoomToFit(400, 30);
|
||||
}
|
||||
}}
|
||||
nodeCanvasObject={(node: any, ctx: CanvasRenderingContext2D, globalScale: number) => {
|
||||
const label = node.name;
|
||||
|
||||
// 获取分级标签配置(只使用字体大小和padding,不限制宽度)
|
||||
const config = LABEL_CONFIG[node.type as 'root' | 'chapter' | 'section'] || LABEL_CONFIG.section;
|
||||
const fontSize = Math.max(9, config.fontSize / globalScale);
|
||||
const padding = config.padding / globalScale;
|
||||
|
||||
// 设置字体
|
||||
ctx.font = `bold ${fontSize}px "Microsoft YaHei", "SimHei", "Arial", sans-serif`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
|
||||
// 测量完整文本尺寸(不截断)
|
||||
const textWidth = ctx.measureText(label).width;
|
||||
const textHeight = fontSize;
|
||||
|
||||
// 计算标签位置(在节点下方,根据节点大小调整间距)
|
||||
const nodeRadius = node.val || 8;
|
||||
const labelY = node.y + nodeRadius + textHeight / 2 + padding * 2;
|
||||
const labelX = node.x;
|
||||
|
||||
// 计算背景尺寸(完全根据实际文本宽度,不限制)
|
||||
const bgWidth = textWidth + padding * 2;
|
||||
const bgHeight = textHeight + padding * 2;
|
||||
const radius = Math.max(2, 4 / globalScale);
|
||||
|
||||
// 背景色(根据节点类型调整透明度)
|
||||
const bgAlpha = node.type === 'knowledge' ? 0.92 : 0.95;
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${bgAlpha})`;
|
||||
ctx.strokeStyle = node.color || '#3b82f6';
|
||||
ctx.lineWidth = Math.max(1, 1.5 / globalScale);
|
||||
|
||||
// 绘制圆角矩形背景
|
||||
const x = labelX - bgWidth / 2;
|
||||
const y = labelY - textHeight / 2 - padding;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x + radius, y);
|
||||
ctx.lineTo(x + bgWidth - radius, y);
|
||||
ctx.quadraticCurveTo(x + bgWidth, y, x + bgWidth, y + radius);
|
||||
ctx.lineTo(x + bgWidth, y + bgHeight - radius);
|
||||
ctx.quadraticCurveTo(x + bgWidth, y + bgHeight, x + bgWidth - radius, y + bgHeight);
|
||||
ctx.lineTo(x + radius, y + bgHeight);
|
||||
ctx.quadraticCurveTo(x, y + bgHeight, x, y + bgHeight - radius);
|
||||
ctx.lineTo(x, y + radius);
|
||||
ctx.quadraticCurveTo(x, y, x + radius, y);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
|
||||
// 绘制完整文本(使用节点颜色,不截断)
|
||||
ctx.fillStyle = node.color || '#3b82f6';
|
||||
ctx.fillText(label, labelX, labelY);
|
||||
}}
|
||||
width={dimensions.width}
|
||||
height={dimensions.height}
|
||||
/>
|
||||
|
||||
{/* 节点详情对话框 */}
|
||||
{selectedNode && selectedNode.nodeId && selectedNode.nodeType && (
|
||||
<NodeDetailDialog
|
||||
open={isDialogOpen}
|
||||
onOpenChange={setIsDialogOpen}
|
||||
nodeType={selectedNode.nodeType}
|
||||
nodeId={selectedNode.nodeId}
|
||||
nodeTitle={selectedNode.name}
|
||||
subsections={selectedNode.sectionData?.subsections}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,357 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Loader2, BookOpen, FileText, ChevronRight } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { courseContentAPI } from "@/lib/api";
|
||||
|
||||
interface Subsection {
|
||||
id: number;
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface NodeDetailDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
nodeType: "chapter" | "section";
|
||||
nodeId: number;
|
||||
nodeTitle: string;
|
||||
subsections?: Subsection[]; // 节节点的小节(知识点)列表
|
||||
subsectionId?: number; // 如果指定,直接显示该小节的内容
|
||||
}
|
||||
|
||||
export default function NodeDetailDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
nodeType,
|
||||
nodeId,
|
||||
nodeTitle,
|
||||
subsections,
|
||||
subsectionId,
|
||||
}: NodeDetailDialogProps) {
|
||||
const [content, setContent] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [selectedSubsection, setSelectedSubsection] = useState<number | null>(subsectionId || null);
|
||||
const [subsectionContent, setSubsectionContent] = useState<string | null>(null);
|
||||
const [loadingSubsection, setLoadingSubsection] = useState(false);
|
||||
|
||||
const loadContent = async () => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
console.log("加载内容 - nodeType:", nodeType, "nodeId:", nodeId);
|
||||
let result;
|
||||
switch (nodeType) {
|
||||
case "chapter":
|
||||
result = await courseContentAPI.getChapterContent(nodeId);
|
||||
break;
|
||||
case "section":
|
||||
result = await courseContentAPI.getSectionContent(nodeId);
|
||||
break;
|
||||
default:
|
||||
throw new Error("未知的节点类型");
|
||||
}
|
||||
|
||||
console.log("内容加载成功,长度:", result.content?.length || 0);
|
||||
setContent(result.content);
|
||||
} catch (err: any) {
|
||||
console.error("加载内容失败:", err);
|
||||
setError(err.message || "加载内容失败");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubsectionClick = async (subsectionId: number) => {
|
||||
if (selectedSubsection === subsectionId && subsectionContent) {
|
||||
// 如果已选中且已加载,则关闭
|
||||
setSelectedSubsection(null);
|
||||
setSubsectionContent(null);
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedSubsection(subsectionId);
|
||||
setLoadingSubsection(true);
|
||||
setSubsectionContent(null);
|
||||
|
||||
try {
|
||||
const result = await courseContentAPI.getSubsectionContent(subsectionId);
|
||||
setSubsectionContent(result.content);
|
||||
} catch (err: any) {
|
||||
console.error("加载小节内容失败:", err);
|
||||
setError(err.message || "加载小节内容失败");
|
||||
} finally {
|
||||
setLoadingSubsection(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
console.log("对话框打开 - nodeType:", nodeType, "nodeId:", nodeId, "subsectionId:", subsectionId, "subsections:", subsections?.length || 0);
|
||||
|
||||
// 如果指定了subsectionId,直接加载小节内容
|
||||
if (subsectionId) {
|
||||
console.log("直接加载小节内容,ID:", subsectionId);
|
||||
setSelectedSubsection(subsectionId);
|
||||
setLoadingSubsection(true);
|
||||
setSubsectionContent(null);
|
||||
setError(null);
|
||||
|
||||
courseContentAPI.getSubsectionContent(subsectionId)
|
||||
.then((result) => {
|
||||
console.log("小节内容加载成功,长度:", result.content?.length || 0);
|
||||
setSubsectionContent(result.content);
|
||||
})
|
||||
.catch((err: any) => {
|
||||
console.error("加载小节内容失败:", err);
|
||||
setError(err.message || "加载小节内容失败");
|
||||
})
|
||||
.finally(() => {
|
||||
setLoadingSubsection(false);
|
||||
});
|
||||
} else if (nodeId && nodeId > 0) {
|
||||
// 否则加载章节或节内容(nodeId必须大于0)
|
||||
console.log("加载章节/节内容,ID:", nodeId);
|
||||
loadContent();
|
||||
} else {
|
||||
// 如果既没有subsectionId也没有有效的nodeId,显示错误
|
||||
console.warn("无效的节点ID - nodeId:", nodeId, "subsectionId:", subsectionId);
|
||||
setError("无效的节点ID");
|
||||
}
|
||||
} else {
|
||||
// 关闭对话框时重置状态
|
||||
setContent(null);
|
||||
setError(null);
|
||||
setSelectedSubsection(subsectionId || null);
|
||||
setSubsectionContent(null);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [open, nodeId, subsectionId]);
|
||||
|
||||
const getTypeLabel = () => {
|
||||
if (subsectionId) {
|
||||
return "小节(知识点)";
|
||||
}
|
||||
switch (nodeType) {
|
||||
case "chapter":
|
||||
return "章节";
|
||||
case "section":
|
||||
return "节";
|
||||
default:
|
||||
return "节点";
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-4xl max-h-[85vh] overflow-hidden flex flex-col">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center space-x-2">
|
||||
{nodeType === "chapter" ? (
|
||||
<BookOpen className="w-5 h-5" />
|
||||
) : (
|
||||
<FileText className="w-5 h-5" />
|
||||
)}
|
||||
<span>{nodeTitle}</span>
|
||||
</DialogTitle>
|
||||
<DialogDescription>{getTypeLabel()}详细信息</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex-1 overflow-y-auto mt-4">
|
||||
{/* 如果指定了subsectionId,直接显示小节内容 */}
|
||||
{subsectionId ? (
|
||||
<>
|
||||
{loadingSubsection && (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="w-8 h-8 animate-spin text-muted-foreground" />
|
||||
<span className="ml-2 text-muted-foreground">加载中...</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && !loadingSubsection && (
|
||||
<div className="text-center py-12">
|
||||
<p className="text-destructive">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{subsectionContent && !loadingSubsection && !error && (
|
||||
<div className="prose prose-sm max-w-none dark:prose-invert prose-table:overflow-x-auto text-sm text-foreground leading-relaxed">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
table: ({ children }) => (
|
||||
<div className="overflow-x-auto my-4">
|
||||
<table className="min-w-full border-collapse border border-border">
|
||||
{children}
|
||||
</table>
|
||||
</div>
|
||||
),
|
||||
thead: ({ children }) => (
|
||||
<thead className="bg-muted">{children}</thead>
|
||||
),
|
||||
tbody: ({ children }) => <tbody>{children}</tbody>,
|
||||
tr: ({ children }) => (
|
||||
<tr className="border-b border-border">{children}</tr>
|
||||
),
|
||||
th: ({ children }) => (
|
||||
<th className="border border-border px-4 py-2 text-left font-semibold">
|
||||
{children}
|
||||
</th>
|
||||
),
|
||||
td: ({ children }) => (
|
||||
<td className="border border-border px-4 py-2">
|
||||
{children}
|
||||
</td>
|
||||
),
|
||||
}}
|
||||
>
|
||||
{subsectionContent}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{isLoading && (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2 className="w-8 h-8 animate-spin text-muted-foreground" />
|
||||
<span className="ml-2 text-muted-foreground">加载中...</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && !isLoading && (
|
||||
<div className="text-center py-12">
|
||||
<p className="text-destructive">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 显示章节/节内容 */}
|
||||
{content && !isLoading && !error && (
|
||||
<div className="space-y-4">
|
||||
{/* 主要内容 */}
|
||||
<div className="prose prose-sm max-w-none dark:prose-invert prose-table:overflow-x-auto text-sm text-foreground leading-relaxed">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
table: ({ children }) => (
|
||||
<div className="overflow-x-auto my-4">
|
||||
<table className="min-w-full border-collapse border border-border">
|
||||
{children}
|
||||
</table>
|
||||
</div>
|
||||
),
|
||||
thead: ({ children }) => (
|
||||
<thead className="bg-muted">{children}</thead>
|
||||
),
|
||||
tbody: ({ children }) => <tbody>{children}</tbody>,
|
||||
tr: ({ children }) => (
|
||||
<tr className="border-b border-border">{children}</tr>
|
||||
),
|
||||
th: ({ children }) => (
|
||||
<th className="border border-border px-4 py-2 text-left font-semibold">
|
||||
{children}
|
||||
</th>
|
||||
),
|
||||
td: ({ children }) => (
|
||||
<td className="border border-border px-4 py-2">
|
||||
{children}
|
||||
</td>
|
||||
),
|
||||
}}
|
||||
>
|
||||
{content}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
|
||||
{/* 如果是节节点,显示小节(知识点)列表 */}
|
||||
{nodeType === "section" && subsections && subsections.length > 0 && (
|
||||
<div className="mt-6 pt-6 border-t border-border">
|
||||
<h3 className="text-lg font-semibold mb-4 flex items-center space-x-2">
|
||||
<FileText className="w-5 h-5" />
|
||||
<span>小节(知识点) ({subsections.length} 个)</span>
|
||||
</h3>
|
||||
<div className="space-y-2">
|
||||
{subsections.map((subsection) => (
|
||||
<div key={subsection.id} className="border border-border rounded-lg overflow-hidden">
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="w-full justify-between text-left h-auto py-3 px-4"
|
||||
onClick={() => handleSubsectionClick(subsection.id)}
|
||||
>
|
||||
<span className="flex-1 text-sm">{subsection.title}</span>
|
||||
<ChevronRight
|
||||
className={`w-4 h-4 transition-transform ${
|
||||
selectedSubsection === subsection.id ? "rotate-90" : ""
|
||||
}`}
|
||||
/>
|
||||
</Button>
|
||||
{selectedSubsection === subsection.id && (
|
||||
<div className="px-4 pb-4 pt-2 border-t border-border bg-muted/50">
|
||||
{loadingSubsection ? (
|
||||
<div className="flex items-center justify-center py-4">
|
||||
<Loader2 className="w-5 h-5 animate-spin text-muted-foreground" />
|
||||
<span className="ml-2 text-sm text-muted-foreground">加载中...</span>
|
||||
</div>
|
||||
) : subsectionContent ? (
|
||||
<div className="prose prose-sm max-w-none dark:prose-invert prose-table:overflow-x-auto text-sm text-foreground leading-relaxed pt-2">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
table: ({ children }) => (
|
||||
<div className="overflow-x-auto my-4">
|
||||
<table className="min-w-full border-collapse border border-border">
|
||||
{children}
|
||||
</table>
|
||||
</div>
|
||||
),
|
||||
thead: ({ children }) => (
|
||||
<thead className="bg-muted">{children}</thead>
|
||||
),
|
||||
tbody: ({ children }) => <tbody>{children}</tbody>,
|
||||
tr: ({ children }) => (
|
||||
<tr className="border-b border-border">{children}</tr>
|
||||
),
|
||||
th: ({ children }) => (
|
||||
<th className="border border-border px-4 py-2 text-left font-semibold">
|
||||
{children}
|
||||
</th>
|
||||
),
|
||||
td: ({ children }) => (
|
||||
<td className="border border-border px-4 py-2">
|
||||
{children}
|
||||
</td>
|
||||
),
|
||||
}}
|
||||
>
|
||||
{subsectionContent}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { motion } from "framer-motion";
|
||||
import {
|
||||
MessageSquare,
|
||||
BookOpen,
|
||||
Image,
|
||||
BarChart3,
|
||||
ArrowRight,
|
||||
CheckCircle
|
||||
} from "lucide-react";
|
||||
import { BentoCard, BentoGrid } from "@/components/magicui/bento-grid";
|
||||
import { User } from "@/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface FeaturesSectionProps {
|
||||
isAuthenticated: boolean;
|
||||
user: User | null;
|
||||
}
|
||||
|
||||
export default function FeaturesSection({ isAuthenticated, user }: FeaturesSectionProps) {
|
||||
const features = [
|
||||
{
|
||||
Icon: MessageSquare,
|
||||
name: "智能问答",
|
||||
description: "基于大模型的智能问答系统,支持多轮对话和上下文理解",
|
||||
href: isAuthenticated ? "/chat" : "#",
|
||||
cta: isAuthenticated ? "开始对话" : "了解更多",
|
||||
className: "lg:col-start-1 lg:col-end-2 lg:row-start-1 lg:row-end-3",
|
||||
stats: isAuthenticated ? { count: 0, label: "次对话" } : undefined,
|
||||
},
|
||||
{
|
||||
Icon: BookOpen,
|
||||
name: "知识库管理",
|
||||
description: "多模态知识库,支持文档上传、向量化和智能检索",
|
||||
href: isAuthenticated ? "/knowledge" : "#",
|
||||
cta: isAuthenticated ? "管理文档" : "了解更多",
|
||||
className: "lg:col-start-1 lg:col-end-2 lg:row-start-3 lg:row-end-4",
|
||||
stats: isAuthenticated ? { count: 0, label: "个文档" } : undefined,
|
||||
},
|
||||
{
|
||||
Icon: Image,
|
||||
name: "空间出图",
|
||||
description: "结合空间规划知识的图像生成和分析功能",
|
||||
href: isAuthenticated ? "/spatial" : "#",
|
||||
cta: isAuthenticated ? "生成图像" : "了解更多",
|
||||
className: "lg:col-start-2 lg:col-end-3 lg:row-start-1 lg:row-end-2",
|
||||
stats: isAuthenticated ? { count: 0, label: "张图片" } : undefined,
|
||||
},
|
||||
{
|
||||
Icon: BarChart3,
|
||||
name: "学习分析",
|
||||
description: "学习数据统计和可视化,帮助了解学习进度",
|
||||
href: isAuthenticated ? "/analytics" : "#",
|
||||
cta: isAuthenticated ? "查看分析" : "了解更多",
|
||||
className: "lg:col-start-2 lg:col-end-3 lg:row-start-2 lg:row-end-3",
|
||||
stats: isAuthenticated ? { count: 0, label: "个报告" } : undefined,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<section className="py-24 sm:py-32">
|
||||
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
|
||||
<div className="mx-auto max-w-2xl text-center">
|
||||
<h2 className="text-base font-semibold leading-7 text-primary">
|
||||
{isAuthenticated ? "功能模块" : "核心功能"}
|
||||
</h2>
|
||||
<p className="mt-2 text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
|
||||
{isAuthenticated ? "选择您需要的功能" : "强大的AI学习助手"}
|
||||
</p>
|
||||
<p className="mt-6 text-lg leading-8 text-gray-600">
|
||||
{isAuthenticated
|
||||
? "点击下方卡片开始使用各项功能"
|
||||
: "基于先进的大模型技术,为您提供专业的国土空间规划学习体验"
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mx-auto mt-16 max-w-2xl sm:mt-20 lg:mt-24 lg:max-w-none">
|
||||
<BentoGrid className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
||||
{features.map((feature) => {
|
||||
if (isAuthenticated) {
|
||||
// 登录状态:使用自定义卡片
|
||||
return (
|
||||
<Link key={feature.name} href={feature.href} className="block h-full">
|
||||
<motion.div
|
||||
className={cn(
|
||||
"group relative col-span-3 flex flex-col justify-between overflow-hidden rounded-xl h-full",
|
||||
"bg-background [box-shadow:0_0_0_1px_rgba(0,0,0,.03),0_2px_4px_rgba(0,0,0,.05),0_12px_24px_rgba(0,0,0,.05)]",
|
||||
"dark:bg-background transform-gpu dark:[box-shadow:0_-20px_80px_-20px_#ffffff1f_inset] dark:[border:1px_solid_rgba(255,255,255,.1)]",
|
||||
feature.className
|
||||
)}
|
||||
whileHover={{ scale: 1.02 }}
|
||||
whileTap={{ scale: 0.98 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
>
|
||||
<div className="z-10 flex transform-gpu flex-col gap-1 p-6 transition-all duration-300 group-hover:-translate-y-5">
|
||||
<feature.Icon className="h-12 w-12 origin-left transform-gpu text-neutral-700 transition-all duration-300 ease-in-out group-hover:scale-75 dark:text-neutral-300" />
|
||||
<h3 className="text-xl font-semibold text-neutral-700 dark:text-neutral-300">
|
||||
{feature.name}
|
||||
</h3>
|
||||
<p className="max-w-lg text-neutral-400">{feature.description}</p>
|
||||
{feature.stats && (
|
||||
<div className="flex items-center text-sm text-gray-500 mt-4">
|
||||
<span className="font-medium">
|
||||
{feature.stats.count} {feature.stats.label}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<motion.div
|
||||
className="pointer-events-none absolute bottom-0 flex w-full translate-y-10 transform-gpu flex-row items-center p-4 opacity-0 transition-all duration-300 group-hover:translate-y-0 group-hover:opacity-100"
|
||||
whileHover={{ x: 4 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
>
|
||||
<span className="flex items-center text-sm font-medium text-neutral-700 dark:text-neutral-300 pointer-events-auto">
|
||||
{feature.cta}
|
||||
<ArrowRight className="ms-2 h-4 w-4" />
|
||||
</span>
|
||||
</motion.div>
|
||||
|
||||
<div className="pointer-events-none absolute inset-0 transform-gpu transition-all duration-300 group-hover:bg-black/[.03] group-hover:dark:bg-neutral-800/10" />
|
||||
</motion.div>
|
||||
</Link>
|
||||
);
|
||||
} else {
|
||||
// 未登录状态:使用标准 BentoCard
|
||||
return (
|
||||
<BentoCard
|
||||
key={feature.name}
|
||||
className={feature.className}
|
||||
Icon={feature.Icon}
|
||||
name={feature.name}
|
||||
description={feature.description}
|
||||
cta={feature.cta}
|
||||
href={feature.href}
|
||||
/>
|
||||
);
|
||||
}
|
||||
})}
|
||||
</BentoGrid>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { BookOpen, Mail, Phone, MapPin, MessageCircle } from "lucide-react";
|
||||
|
||||
export default function Footer() {
|
||||
const currentYear = new Date().getFullYear();
|
||||
|
||||
const footerLinks = {
|
||||
quickLinks: [
|
||||
{ name: "首页", href: "/" },
|
||||
{ name: "智能问答", href: "/chat" },
|
||||
{ name: "知识库管理", href: "/knowledge" },
|
||||
{ name: "空间出图", href: "/spatial" },
|
||||
{ name: "学习分析", href: "/analytics" },
|
||||
],
|
||||
resources: [
|
||||
{ name: "课程大纲", href: "#" },
|
||||
{ name: "线上讲座", href: "#" },
|
||||
{ name: "资料下载", href: "#" },
|
||||
{ name: "案例分析", href: "#" },
|
||||
{ name: "交流论坛", href: "#" },
|
||||
],
|
||||
};
|
||||
|
||||
const contactInfo = [
|
||||
{ icon: Mail, text: "contact@HIT-agent.com", href: "mailto:contact@HIT-agent.com" },
|
||||
{ icon: Phone, text: "0451-8641-2114", href: "tel:0451-8641-2114" },
|
||||
{ icon: MapPin, text: "哈尔滨市南岗区西大直街92号", href: "#" },
|
||||
];
|
||||
|
||||
return (
|
||||
<footer className="relative border-t bg-slate-900 dark:bg-slate-950 text-slate-300">
|
||||
<div className="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
{/* Main Footer Content */}
|
||||
<div className="py-12 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8">
|
||||
{/* Brand Column */}
|
||||
<div className="lg:col-span-1">
|
||||
<div className="flex items-center space-x-2 mb-4">
|
||||
<div className="w-10 h-10 bg-gradient-to-r from-blue-500 to-purple-600 rounded-xl flex items-center justify-center shadow-lg">
|
||||
<BookOpen className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<span className="text-lg font-bold text-white">
|
||||
国土空间规划课程智能体
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-sm text-slate-400 mb-6 max-w-xs">
|
||||
为国土空间规划学习者提供智能化学习体验和专业知识服务。
|
||||
</p>
|
||||
{/* Social Links */}
|
||||
<div className="flex items-center gap-3">
|
||||
<Link
|
||||
href="#"
|
||||
className="w-9 h-9 rounded-lg bg-slate-800 hover:bg-slate-700 flex items-center justify-center transition-colors"
|
||||
aria-label="微信"
|
||||
>
|
||||
<MessageCircle className="w-4 h-4" />
|
||||
</Link>
|
||||
<Link
|
||||
href="#"
|
||||
className="w-9 h-9 rounded-lg bg-slate-800 hover:bg-slate-700 flex items-center justify-center transition-colors"
|
||||
aria-label="微博"
|
||||
>
|
||||
<MessageCircle className="w-4 h-4" />
|
||||
</Link>
|
||||
<Link
|
||||
href="#"
|
||||
className="w-9 h-9 rounded-lg bg-slate-800 hover:bg-slate-700 flex items-center justify-center transition-colors"
|
||||
aria-label="通知"
|
||||
>
|
||||
<MessageCircle className="w-4 h-4" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quick Links */}
|
||||
<div>
|
||||
<h4 className="font-semibold mb-4 text-white">快速链接</h4>
|
||||
<ul className="space-y-3">
|
||||
{footerLinks.quickLinks.map((link) => (
|
||||
<li key={link.name}>
|
||||
<Link
|
||||
href={link.href}
|
||||
className="text-sm text-slate-400 hover:text-white transition-colors"
|
||||
>
|
||||
{link.name}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* Resources Links */}
|
||||
<div>
|
||||
<h4 className="font-semibold mb-4 text-white">学习资源</h4>
|
||||
<ul className="space-y-3">
|
||||
{footerLinks.resources.map((link) => (
|
||||
<li key={link.name}>
|
||||
<Link
|
||||
href={link.href}
|
||||
className="text-sm text-slate-400 hover:text-white transition-colors"
|
||||
>
|
||||
{link.name}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* Contact Info */}
|
||||
<div>
|
||||
<h4 className="font-semibold mb-4 text-white">联系我们</h4>
|
||||
<ul className="space-y-3">
|
||||
{contactInfo.map((contact, index) => (
|
||||
<li key={index}>
|
||||
{contact.href !== "#" ? (
|
||||
<a
|
||||
href={contact.href}
|
||||
className="text-sm text-slate-400 hover:text-white transition-colors flex items-start gap-2"
|
||||
>
|
||||
<contact.icon className="w-4 h-4 mt-0.5 flex-shrink-0" />
|
||||
<span>{contact.text}</span>
|
||||
</a>
|
||||
) : (
|
||||
<div className="text-sm text-slate-400 flex items-start gap-2">
|
||||
<contact.icon className="w-4 h-4 mt-0.5 flex-shrink-0" />
|
||||
<span>{contact.text}</span>
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom Bar */}
|
||||
<div className="py-6 border-t border-slate-800">
|
||||
<div className="flex flex-col md:flex-row justify-between items-center gap-4">
|
||||
<div className="text-sm text-slate-400">
|
||||
© {currentYear} 哈尔滨工业大学建筑与设计学院国土空间与区域发展研究所
|
||||
</div>
|
||||
<div className="flex items-center gap-6 text-sm text-slate-400">
|
||||
<Link href="#" className="hover:text-white transition-colors">
|
||||
隐私政策
|
||||
</Link>
|
||||
<Link href="#" className="hover:text-white transition-colors">
|
||||
使用条款
|
||||
</Link>
|
||||
<Link href="#" className="hover:text-white transition-colors">
|
||||
帮助中心
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { motion } from "framer-motion";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { AuroraText } from "@/components/magicui/aurora-text";
|
||||
import { User } from "@/types";
|
||||
import { MessageSquare, FileText, Image, BarChart3, ArrowRight } from "lucide-react";
|
||||
|
||||
interface HeroSectionProps {
|
||||
isAuthenticated: boolean;
|
||||
user: User | null;
|
||||
}
|
||||
|
||||
export default function HeroSection({ isAuthenticated, user }: HeroSectionProps) {
|
||||
const features = [
|
||||
{
|
||||
name: "智能问答",
|
||||
href: "/chat",
|
||||
icon: MessageSquare,
|
||||
description: "基于大模型的智能问答系统,专业知识即时解答",
|
||||
color: "from-blue-500 to-blue-600"
|
||||
},
|
||||
{
|
||||
name: "知识库管理",
|
||||
href: "/knowledge",
|
||||
icon: FileText,
|
||||
description: "多模态知识库,文档上传与智能检索",
|
||||
color: "from-green-500 to-green-600"
|
||||
},
|
||||
{
|
||||
name: "空间出图",
|
||||
href: "/spatial",
|
||||
icon: Image,
|
||||
description: "结合空间规划的AI图像生成与分析",
|
||||
color: "from-purple-500 to-purple-600"
|
||||
},
|
||||
{
|
||||
name: "学习分析",
|
||||
href: "/analytics",
|
||||
icon: BarChart3,
|
||||
description: "学习数据统计,追踪您的学习进度",
|
||||
color: "from-orange-500 to-orange-600"
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<section className="flex min-h-[90vh] w-full flex-col items-center justify-center py-20 relative">
|
||||
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
|
||||
{/* 描述区域 */}
|
||||
<motion.div
|
||||
className="text-center mb-16"
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.6 }}
|
||||
>
|
||||
<p className="text-lg leading-8 text-gray-600 max-w-2xl mx-auto">
|
||||
基于大模型技术的智能学习平台,提供专业的国土空间规划知识问答、文档管理和智能分析
|
||||
</p>
|
||||
{!isAuthenticated && (
|
||||
<div className="mt-10 flex items-center justify-center gap-x-6">
|
||||
<Button size="lg" asChild>
|
||||
<Link href="/register">开始使用</Link>
|
||||
</Button>
|
||||
<Button variant="outline" size="lg" asChild>
|
||||
<Link href="/login">登录</Link>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
|
||||
{/* 功能卡片 - 登录后显示 */}
|
||||
{isAuthenticated && (
|
||||
<motion.div
|
||||
className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6"
|
||||
initial={{ opacity: 0, y: 40 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.6, delay: 0.2 }}
|
||||
>
|
||||
{features.map((feature, index) => (
|
||||
<Link
|
||||
key={feature.name}
|
||||
href={feature.href}
|
||||
className="block group"
|
||||
>
|
||||
<motion.div
|
||||
className="relative p-6 rounded-2xl bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-800 hover:border-blue-300 dark:hover:border-blue-700 hover:shadow-xl transition-all duration-300"
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5, delay: 0.3 + index * 0.1 }}
|
||||
whileHover={{ y: -8, scale: 1.02 }}
|
||||
>
|
||||
{/* 图标 */}
|
||||
<div className={`w-14 h-14 rounded-xl bg-gradient-to-r ${feature.color} flex items-center justify-center mb-4 group-hover:scale-110 transition-transform duration-300`}>
|
||||
<feature.icon className="w-7 h-7 text-white" />
|
||||
</div>
|
||||
|
||||
{/* 标题 */}
|
||||
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-2 group-hover:text-blue-600 dark:group-hover:text-blue-400 transition-colors">
|
||||
{feature.name}
|
||||
</h3>
|
||||
|
||||
{/* 描述 */}
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400 mb-4">
|
||||
{feature.description}
|
||||
</p>
|
||||
|
||||
{/* 箭头 */}
|
||||
<div className="flex items-center text-sm font-medium text-blue-600 dark:text-blue-400">
|
||||
<span>立即使用</span>
|
||||
<ArrowRight className="ml-2 w-4 h-4 group-hover:translate-x-2 transition-transform duration-300" />
|
||||
</div>
|
||||
|
||||
{/* 装饰性背景 */}
|
||||
<div className="absolute inset-0 rounded-2xl bg-gradient-to-br from-blue-50/50 to-purple-50/50 dark:from-blue-950/20 dark:to-purple-950/20 opacity-0 group-hover:opacity-100 transition-opacity duration-300 -z-10" />
|
||||
</motion.div>
|
||||
</Link>
|
||||
))}
|
||||
</motion.div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useAuthStore } from "@/store/auth";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import Navbar from "./navbar";
|
||||
import { MessageSquare, Database, Image, BookOpen, Users, Award, ArrowRight, Mail, Phone, MapPin, GraduationCap } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { analyticsAPI } from "@/lib/api";
|
||||
|
||||
export default function HomePageContent() {
|
||||
const { isAuthenticated, user } = useAuthStore();
|
||||
const [stats, setStats] = useState([
|
||||
{ label: "活跃用户", value: "1,200+" },
|
||||
{ label: "知识文档", value: "5,000+" },
|
||||
{ label: "问答对话", value: "50,000+" },
|
||||
{ label: "生成图像", value: "10,000+" }
|
||||
]);
|
||||
const [isLoadingStats, setIsLoadingStats] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const loadPlatformStats = async () => {
|
||||
try {
|
||||
setIsLoadingStats(true);
|
||||
const data = await analyticsAPI.getPlatformStats();
|
||||
|
||||
// 格式化数字,添加千分位分隔符
|
||||
const formatNumber = (num: number) => {
|
||||
if (num >= 10000) {
|
||||
return `${(num / 10000).toFixed(1)}万+`;
|
||||
} else if (num >= 1000) {
|
||||
return `${(num / 1000).toFixed(1)}千+`;
|
||||
}
|
||||
return `${num}+`;
|
||||
};
|
||||
|
||||
setStats([
|
||||
{ label: "活跃用户", value: formatNumber(data.active_users) },
|
||||
{ label: "知识文档", value: formatNumber(data.knowledge_documents) },
|
||||
{ label: "问答对话", value: formatNumber(data.qa_dialogues) },
|
||||
{ label: "生成图像", value: formatNumber(data.generated_images) }
|
||||
]);
|
||||
} catch (error: any) {
|
||||
console.warn("加载平台统计数据失败,使用默认值:", error?.message || error);
|
||||
// 保持默认值,不显示错误给用户
|
||||
// 如果后端API不可用,继续显示默认的占位数据
|
||||
} finally {
|
||||
setIsLoadingStats(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadPlatformStats();
|
||||
}, []);
|
||||
|
||||
const features = [
|
||||
{
|
||||
icon: GraduationCap,
|
||||
title: "课程内容",
|
||||
description: "查看和管理国土空间规划课程内容,获取系统化的学习资源",
|
||||
href: "/course-content"
|
||||
},
|
||||
{
|
||||
icon: MessageSquare,
|
||||
title: "智能问答",
|
||||
description: "基于RAG技术的智能对话系统,提供专业准确的国土空间规划知识解答",
|
||||
href: "/chat"
|
||||
},
|
||||
{
|
||||
icon: Database,
|
||||
title: "知识库",
|
||||
description: "构建和管理专业知识库,支持多种文档格式的智能处理和分析",
|
||||
href: "/knowledge"
|
||||
},
|
||||
{
|
||||
icon: Users,
|
||||
title: "论坛社区",
|
||||
description: "参与系统优化建议与课程反馈的讨论,与同伴交流学习经验",
|
||||
href: "/forum"
|
||||
},
|
||||
{
|
||||
icon: Image,
|
||||
title: "空间设计",
|
||||
description: "AI驱动的空间规划图像生成,支持多种设计风格和规划类型",
|
||||
href: "/spatial"
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background">
|
||||
{/* 导航栏 */}
|
||||
<Navbar isAuthenticated={isAuthenticated} user={user} />
|
||||
|
||||
{/* Hero 区域 - 全屏背景 */}
|
||||
<section className="relative min-h-screen flex items-center justify-center border-b border-border overflow-hidden w-full">
|
||||
{/* 背景图片 - 充满整个屏幕 */}
|
||||
<div className="absolute inset-0 z-0 w-full h-full">
|
||||
<img
|
||||
src="/heilongjiang-spatial-planning.png"
|
||||
alt="黑龙江国土空间规划"
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
{/* 渐变遮罩,确保文字可读性 */}
|
||||
<div className="absolute inset-0 bg-gradient-to-b from-background/40 via-background/30 to-background/50"></div>
|
||||
</div>
|
||||
|
||||
{/* 内容 */}
|
||||
<div className="relative z-10 max-w-4xl mx-auto px-4 text-center w-full">
|
||||
<h1 className="text-5xl font-bold text-foreground mb-6 drop-shadow-lg">
|
||||
国土空间规划课程智能体
|
||||
</h1>
|
||||
<p className="text-xl text-foreground mb-8 leading-relaxed drop-shadow-md">
|
||||
基于先进AI技术的智能学习平台,为国土空间规划专业提供全方位的知识服务和实践支持
|
||||
</p>
|
||||
<div className="flex flex-col sm:flex-row gap-4 justify-center">
|
||||
{isAuthenticated ? (
|
||||
<Button asChild size="lg" className="h-12 px-8">
|
||||
<Link href="/chat">
|
||||
开始对话
|
||||
<ArrowRight className="ml-2 h-4 w-4" />
|
||||
</Link>
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button asChild size="lg" className="h-12 px-8">
|
||||
<Link href="/register">立即注册</Link>
|
||||
</Button>
|
||||
<Button asChild variant="outline" size="lg" className="h-12 px-8">
|
||||
<Link href="/login">登录系统</Link>
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 主要内容 */}
|
||||
<main className="mit-container">
|
||||
|
||||
{/* 功能特性 */}
|
||||
<section className="py-12 mt-0">
|
||||
<div className="text-center mb-12">
|
||||
<h2 className="text-3xl font-bold text-foreground mb-4">核心功能</h2>
|
||||
<p className="text-lg text-muted-foreground">
|
||||
集成多种AI技术,提供全面的学习支持
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mit-grid">
|
||||
{features.map((feature, index) => (
|
||||
<Card key={index} className="group cursor-pointer hover:scale-105 transition-transform duration-200">
|
||||
<CardHeader>
|
||||
<div className="w-16 h-16 bg-primary/10 rounded-lg flex items-center justify-center mb-4 group-hover:bg-primary/20 transition-colors">
|
||||
<feature.icon className="w-8 h-8 text-primary" />
|
||||
</div>
|
||||
<CardTitle className="text-xl">{feature.title}</CardTitle>
|
||||
<CardDescription className="text-base leading-relaxed">
|
||||
{feature.description}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
{/* 统计数据 */}
|
||||
<section className="border-y bg-muted/50 py-16">
|
||||
<div className="mit-container">
|
||||
<div className="text-center mb-12">
|
||||
<h2 className="text-3xl font-bold text-foreground mb-4">平台数据</h2>
|
||||
<p className="text-lg text-muted-foreground">
|
||||
持续增长的用户群体和丰富的内容资源
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-8">
|
||||
{stats.map((stat, index) => (
|
||||
<div key={index} className="text-center">
|
||||
<div className="text-3xl font-bold text-primary mb-2">
|
||||
{isLoadingStats ? "..." : stat.value}
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">{stat.label}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 统一封底区域 */}
|
||||
<footer className="border-t bg-card/50">
|
||||
<div className="mit-container">
|
||||
{/* 主要内容区域 - 三列布局(中间留空) */}
|
||||
<div className="py-12 border-b border-border/50">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-[2fr_2fr_1fr] gap-8 lg:gap-12">
|
||||
{/* 第一列:关于项目 */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold text-foreground mb-4">关于项目</h2>
|
||||
<p className="text-muted-foreground leading-relaxed mb-6">
|
||||
国土空间规划课程智能体是一个基于先进AI技术的智能学习平台,为国土空间规划专业提供全方位的知识服务和实践支持。平台集成了RAG技术、图像生成技术、数据分析技术等多种AI能力。
|
||||
</p>
|
||||
<div className="flex flex-col sm:flex-row gap-3">
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<a href="https://tsp.spacekg.com/#/" target="_blank" rel="noopener noreferrer">
|
||||
<BookOpen className="mr-2 h-4 w-4" />
|
||||
了解更多
|
||||
</a>
|
||||
</Button>
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<a href="https://homepage.hit.edu.cn/wusongtao" target="_blank" rel="noopener noreferrer">
|
||||
<Users className="mr-2 h-4 w-4" />
|
||||
联系我们
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 第二列:空白(用于增加间距) */}
|
||||
<div className="hidden lg:block"></div>
|
||||
|
||||
{/* 第三列:联系我们 */}
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-foreground mb-4">联系我们</h3>
|
||||
<ul className="space-y-3">
|
||||
<li className="flex items-start gap-3">
|
||||
<Mail className="w-5 h-5 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">邮箱</p>
|
||||
<a href="mailto:contact@hit-agent.com" className="text-sm text-foreground hover:text-primary transition-colors">
|
||||
contact@hit-agent.com
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li className="flex items-start gap-3">
|
||||
<Phone className="w-5 h-5 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">电话</p>
|
||||
<a href="tel:+86-451-86412114" className="text-sm text-foreground hover:text-primary transition-colors">
|
||||
+86-451-86412114
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li className="flex items-start gap-3">
|
||||
<MapPin className="w-5 h-5 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">地址</p>
|
||||
<p className="text-sm text-foreground">
|
||||
哈尔滨市南岗区西大直街92号
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer信息部分 */}
|
||||
<div className="py-8">
|
||||
<div className="text-center">
|
||||
<div className="flex items-center justify-center gap-2 mb-3">
|
||||
<div className="w-8 h-8 bg-gradient-to-r from-blue-600 to-blue-800 rounded-lg flex items-center justify-center">
|
||||
<BookOpen className="w-4 h-4 text-white" />
|
||||
</div>
|
||||
<span className="text-lg font-semibold">国土空间规划课程智能体</span>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Copyright © {new Date().getFullYear()} 哈尔滨工业大学建筑与设计学院国土空间与区域发展研究所
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import { ThemeToggle } from "@/components/ui/theme-toggle";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { useAuthStore } from "@/store/auth";
|
||||
import { BookOpen, LogOut, User as UserIcon, Settings, ChevronDown, MessageSquare, Database, Image, TrendingUp, GraduationCap } from "lucide-react";
|
||||
import { User } from "@/types";
|
||||
|
||||
interface NavbarProps {
|
||||
isAuthenticated: boolean;
|
||||
user: User | null;
|
||||
}
|
||||
|
||||
export default function Navbar({ isAuthenticated, user }: NavbarProps) {
|
||||
const { logout } = useAuthStore();
|
||||
|
||||
return (
|
||||
<nav className="border-b bg-background/95 backdrop-blur-sm sticky top-0 z-50">
|
||||
<div className="mit-container">
|
||||
<div className="flex justify-between items-center h-16">
|
||||
{/* Logo 和标题 */}
|
||||
<Link href="/" className="flex items-center space-x-3 hover:opacity-80 transition-opacity cursor-pointer">
|
||||
<div className="w-10 h-10 bg-gradient-to-r from-blue-600 to-blue-800 rounded-lg flex items-center justify-center shadow-sm">
|
||||
<BookOpen className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-lg font-semibold text-foreground">
|
||||
国土空间规划课程智能体
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Spatial Planning Course Agent
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
{/* 导航链接 */}
|
||||
{isAuthenticated && (
|
||||
<div className="hidden md:flex items-center space-x-1">
|
||||
<Link href="/course-content">
|
||||
<Button variant="ghost" className="flex items-center space-x-2 px-3 py-2 hover:bg-muted/50">
|
||||
<GraduationCap className="w-4 h-4" />
|
||||
<span className="text-sm">课程内容</span>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/chat">
|
||||
<Button variant="ghost" className="flex items-center space-x-2 px-3 py-2 hover:bg-muted/50">
|
||||
<MessageSquare className="w-4 h-4" />
|
||||
<span className="text-sm">智能问答</span>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/knowledge">
|
||||
<Button variant="ghost" className="flex items-center space-x-2 px-3 py-2 hover:bg-muted/50">
|
||||
<Database className="w-4 h-4" />
|
||||
<span className="text-sm">知识库</span>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/spatial">
|
||||
<Button variant="ghost" className="flex items-center space-x-2 px-3 py-2 hover:bg-muted/50">
|
||||
<Image className="w-4 h-4" />
|
||||
<span className="text-sm">空间设计</span>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center space-x-3">
|
||||
<ThemeToggle />
|
||||
<Link href="/forum">
|
||||
<Button variant="outline" size="sm">
|
||||
课程社区
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
{isAuthenticated && user ? (
|
||||
// 登录后状态 - 用户下拉菜单
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="flex items-center space-x-2 px-3 hover:bg-muted/50">
|
||||
<Avatar className="w-8 h-8">
|
||||
<AvatarFallback className="bg-gradient-to-r from-blue-600 to-blue-800 text-white text-sm font-medium">
|
||||
{user.full_name?.[0] || user.username[0] || "U"}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="hidden sm:block text-left">
|
||||
<div className="text-sm font-medium text-foreground">
|
||||
{user.full_name || user.username}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{user.email}
|
||||
</div>
|
||||
</div>
|
||||
<ChevronDown className="w-4 h-4 text-muted-foreground" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-56">
|
||||
<div className="px-2 py-1.5">
|
||||
<div className="font-medium text-sm">{user.full_name || user.username}</div>
|
||||
<div className="text-xs text-muted-foreground">{user.email}</div>
|
||||
</div>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href="/analytics" className="flex items-center cursor-pointer">
|
||||
<TrendingUp className="w-4 h-4 mr-2" />
|
||||
学习进度
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href="/profile" className="flex items-center cursor-pointer">
|
||||
<UserIcon className="w-4 h-4 mr-2" />
|
||||
个人资料
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href="/settings" className="flex items-center cursor-pointer">
|
||||
<Settings className="w-4 h-4 mr-2" />
|
||||
设置
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={logout} className="text-destructive cursor-pointer">
|
||||
<LogOut className="w-4 h-4 mr-2" />
|
||||
退出登录
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
) : (
|
||||
// 未登录状态
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button variant="ghost" asChild>
|
||||
<Link href="/login">登录</Link>
|
||||
</Button>
|
||||
<Button asChild>
|
||||
<Link href="/register">注册</Link>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
"use client";
|
||||
|
||||
import { NumberTicker } from "@/components/magicui/number-ticker";
|
||||
import { User } from "@/types";
|
||||
|
||||
interface StatsSectionProps {
|
||||
isAuthenticated: boolean;
|
||||
user: User | null;
|
||||
}
|
||||
|
||||
export default function StatsSection({ isAuthenticated, user }: StatsSectionProps) {
|
||||
// 未登录状态 - 全局统计
|
||||
const globalStats = [
|
||||
{ label: "智能问答", value: 1000, description: "问题解答" },
|
||||
{ label: "知识库", value: 50, description: "专业文档" },
|
||||
{ label: "用户", value: 500, description: "活跃用户" },
|
||||
{ label: "准确率", value: 95, description: "回答准确率", suffix: "%" },
|
||||
];
|
||||
|
||||
// 登录后状态 - 个人统计(模拟数据,实际应该从API获取)
|
||||
const personalStats = [
|
||||
{ label: "我的问答", value: 0, description: "已提问" },
|
||||
{ label: "我的文档", value: 0, description: "已上传" },
|
||||
{ label: "学习时长", value: 0, description: "分钟" },
|
||||
{ label: "知识点", value: 0, description: "已掌握", suffix: "%" },
|
||||
];
|
||||
|
||||
const stats = isAuthenticated ? personalStats : globalStats;
|
||||
|
||||
return (
|
||||
<section className="py-24 sm:py-32 bg-gray-50">
|
||||
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
|
||||
<div className="mx-auto max-w-2xl text-center">
|
||||
<h2 className="text-base font-semibold leading-7 text-primary">
|
||||
{isAuthenticated ? "学习统计" : "平台数据"}
|
||||
</h2>
|
||||
<p className="mt-2 text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
|
||||
{isAuthenticated ? "您的学习成果" : "值得信赖的数据"}
|
||||
</p>
|
||||
<p className="mt-6 text-lg leading-8 text-gray-600">
|
||||
{isAuthenticated
|
||||
? "跟踪您的学习进度,见证知识积累的过程"
|
||||
: "基于真实用户数据,展示平台的专业性和可靠性"
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mx-auto mt-16 max-w-2xl sm:mt-20 lg:mt-24 lg:max-w-none">
|
||||
<dl className="grid grid-cols-1 gap-x-8 gap-y-16 text-center lg:grid-cols-4">
|
||||
{stats.map((stat) => (
|
||||
<div key={stat.label} className="mx-auto flex max-w-xs flex-col gap-y-4">
|
||||
<dt className="text-base leading-7 text-gray-600">
|
||||
{stat.label}
|
||||
</dt>
|
||||
<dd className="order-first text-3xl font-semibold tracking-tight text-gray-900 sm:text-5xl">
|
||||
<NumberTicker value={stat.value} />
|
||||
{stat.suffix}
|
||||
</dd>
|
||||
<dd className="text-sm leading-6 text-gray-500">
|
||||
{stat.description}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,389 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
BookOpen,
|
||||
MessageSquare,
|
||||
Image,
|
||||
BarChart3,
|
||||
ArrowRight,
|
||||
CheckCircle,
|
||||
Users,
|
||||
Zap,
|
||||
Brain,
|
||||
Database,
|
||||
Mail,
|
||||
Phone,
|
||||
MapPin
|
||||
} from "lucide-react";
|
||||
import { FlickeringGrid } from "@/components/magicui/flickering-grid";
|
||||
import { AuroraText } from "@/components/magicui/aurora-text";
|
||||
import { NumberTicker } from "@/components/magicui/number-ticker";
|
||||
import { BentoCard, BentoGrid } from "@/components/magicui/bento-grid";
|
||||
import { ThemeToggle } from "@/components/ui/theme-toggle";
|
||||
|
||||
export default function LandingPage() {
|
||||
const [isHovered, setIsHovered] = useState<string | null>(null);
|
||||
|
||||
const features = [
|
||||
{
|
||||
icon: MessageSquare,
|
||||
name: "智能问答",
|
||||
description: "基于大模型的智能问答系统,支持多轮对话和上下文理解",
|
||||
href: "#",
|
||||
cta: "了解更多",
|
||||
className: "lg:col-start-1 lg:col-end-2 lg:row-start-1 lg:row-end-3",
|
||||
},
|
||||
{
|
||||
icon: BookOpen,
|
||||
name: "知识库管理",
|
||||
description: "多模态知识库,支持文档上传、向量化和智能检索",
|
||||
href: "#",
|
||||
cta: "了解更多",
|
||||
className: "lg:col-start-1 lg:col-end-2 lg:row-start-3 lg:row-end-4",
|
||||
},
|
||||
{
|
||||
icon: Image,
|
||||
name: "空间出图",
|
||||
description: "结合空间规划知识的图像生成和分析功能",
|
||||
href: "#",
|
||||
cta: "了解更多",
|
||||
className: "lg:col-start-2 lg:col-end-3 lg:row-start-1 lg:row-end-2",
|
||||
},
|
||||
{
|
||||
icon: BarChart3,
|
||||
name: "学习分析",
|
||||
description: "学习数据统计和可视化,帮助了解学习进度",
|
||||
href: "#",
|
||||
cta: "了解更多",
|
||||
className: "lg:col-start-2 lg:col-end-3 lg:row-start-2 lg:row-end-3",
|
||||
},
|
||||
];
|
||||
|
||||
const stats = [
|
||||
{ label: "智能问答", value: 1000, description: "问题解答" },
|
||||
{ label: "知识库", value: 50, description: "专业文档" },
|
||||
{ label: "用户", value: 500, description: "活跃用户" },
|
||||
{ label: "准确率", value: 95, description: "回答准确率", suffix: "%" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-app">
|
||||
{/* 导航栏 */}
|
||||
<nav className="border-b bg-background/80 backdrop-blur-sm sticky top-0 z-50">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="flex justify-between items-center h-16">
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="w-10 h-10 bg-gradient-to-r from-blue-500 to-purple-600 rounded-xl flex items-center justify-center shadow-lg">
|
||||
<BookOpen className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<span className="text-xl font-bold">
|
||||
国土空间规划课程智能体
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center space-x-4">
|
||||
<ThemeToggle />
|
||||
<Button variant="ghost" asChild>
|
||||
<Link href="/login">登录</Link>
|
||||
</Button>
|
||||
<Button asChild>
|
||||
<Link href="/register">注册</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{/* 主要内容 */}
|
||||
<main>
|
||||
{/* 英雄区域 */}
|
||||
<section className="flex h-[90vh] w-full flex-col items-center justify-center pb-15 relative">
|
||||
<FlickeringGrid
|
||||
className="absolute inset-0 z-0 [mask-image:radial-gradient(800px_circle_at_center,white,transparent)]"
|
||||
squareSize={4}
|
||||
gridGap={4}
|
||||
color="#60A5FA"
|
||||
maxOpacity={0.133}
|
||||
flickerChance={0.1}
|
||||
/>
|
||||
<div className="relative z-10 flex flex-col items-center justify-center gap-12 px-4">
|
||||
<div className="inline-flex items-center px-4 py-2 rounded-full bg-secondary/50 backdrop-blur-sm border border-border mb-4">
|
||||
<span className="text-sm font-medium">🚀 AI驱动的智能学习平台</span>
|
||||
</div>
|
||||
|
||||
<h1 className="text-center text-4xl font-bold md:text-6xl">
|
||||
<span className="bg-gradient-to-r from-foreground via-foreground/80 to-foreground/60 bg-clip-text text-transparent">
|
||||
智能化的{" "}
|
||||
</span>
|
||||
<AuroraText>国土空间规划</AuroraText>
|
||||
<br />
|
||||
<span className="text-3xl md:text-5xl">学习体验</span>
|
||||
</h1>
|
||||
|
||||
<p className="max-w-4xl p-2 text-center text-sm opacity-85 md:text-xl text-muted-foreground">
|
||||
基于先进的大语言模型技术,为国土空间规划课程提供智能问答、知识检索、
|
||||
空间出图和学习分析等全方位支持,让学习更高效、更智能。
|
||||
</p>
|
||||
|
||||
<div className="flex flex-col sm:flex-row gap-6 justify-center">
|
||||
<Button size="lg" className="text-lg" asChild>
|
||||
<Link href="/register">
|
||||
<span className="flex items-center">
|
||||
立即开始
|
||||
<ArrowRight className="ml-2 w-5 h-5" />
|
||||
</span>
|
||||
</Link>
|
||||
</Button>
|
||||
<Button variant="outline" size="lg" className="text-lg" asChild>
|
||||
<Link href="/login">已有账户?登录</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 统计数据 */}
|
||||
<section className="py-20 bg-secondary/30">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-6 lg:gap-8">
|
||||
{stats.map((stat, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="group text-center p-6 rounded-2xl bg-card backdrop-blur-sm border hover:shadow-lg transition-all duration-300 hover:scale-105"
|
||||
>
|
||||
<div className="text-3xl sm:text-4xl font-bold mb-2 group-hover:text-primary transition-colors">
|
||||
<NumberTicker value={stat.value} />
|
||||
{stat.suffix || '+'}
|
||||
</div>
|
||||
<div className="text-sm sm:text-base font-semibold mb-1">
|
||||
{stat.label}
|
||||
</div>
|
||||
<div className="text-xs sm:text-sm text-muted-foreground">
|
||||
{stat.description}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 核心功能 - Bento Grid */}
|
||||
<section className="py-24">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="text-center mb-20">
|
||||
<h2 className="text-4xl font-bold mb-6">
|
||||
核心功能
|
||||
</h2>
|
||||
<p className="text-xl text-muted-foreground max-w-3xl mx-auto">
|
||||
集成多种AI技术,为国土空间规划学习提供全方位的智能支持
|
||||
</p>
|
||||
</div>
|
||||
<BentoGrid className="lg:grid-cols-2 lg:grid-rows-3">
|
||||
{features.map((feature) => (
|
||||
<BentoCard
|
||||
key={feature.name}
|
||||
Icon={feature.icon}
|
||||
name={feature.name}
|
||||
description={feature.description}
|
||||
href={feature.href}
|
||||
cta={feature.cta}
|
||||
className={feature.className}
|
||||
/>
|
||||
))}
|
||||
</BentoGrid>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 技术优势 */}
|
||||
<section className="py-24 bg-secondary/30">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-12 lg:gap-16 items-center">
|
||||
<div>
|
||||
<h2 className="text-4xl font-bold mb-8">
|
||||
技术优势
|
||||
</h2>
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-start space-x-4 p-6 rounded-2xl bg-card backdrop-blur-sm border hover:shadow-md transition-all duration-300">
|
||||
<div className="w-12 h-12 bg-gradient-to-r from-green-500 to-emerald-500 rounded-xl flex items-center justify-center flex-shrink-0">
|
||||
<Brain className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-xl font-bold mb-3">
|
||||
先进的大语言模型
|
||||
</h3>
|
||||
<p className="text-muted-foreground leading-relaxed">
|
||||
基于硅基流动的Qwen3-30B模型,具备强大的理解和生成能力
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start space-x-4 p-6 rounded-2xl bg-card backdrop-blur-sm border hover:shadow-md transition-all duration-300">
|
||||
<div className="w-12 h-12 bg-gradient-to-r from-blue-500 to-cyan-500 rounded-xl flex items-center justify-center flex-shrink-0">
|
||||
<Database className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-xl font-bold mb-3">
|
||||
RAG知识检索
|
||||
</h3>
|
||||
<p className="text-muted-foreground leading-relaxed">
|
||||
结合向量数据库和语义检索,提供精准的知识匹配
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start space-x-4 p-6 rounded-2xl bg-card backdrop-blur-sm border hover:shadow-md transition-all duration-300">
|
||||
<div className="w-12 h-12 bg-gradient-to-r from-purple-500 to-pink-500 rounded-xl flex items-center justify-center flex-shrink-0">
|
||||
<Image className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-xl font-bold mb-3">
|
||||
多模态支持
|
||||
</h3>
|
||||
<p className="text-muted-foreground leading-relaxed">
|
||||
支持文本、图像、文档等多种模态的知识处理
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative">
|
||||
<div className="bg-gradient-to-br from-blue-600 via-purple-600 to-pink-600 rounded-3xl p-8 lg:p-12 text-white shadow-2xl">
|
||||
<div className="flex items-center space-x-4 mb-8">
|
||||
<div className="w-16 h-16 bg-white/20 rounded-2xl flex items-center justify-center">
|
||||
<Zap className="w-8 h-8" />
|
||||
</div>
|
||||
<h3 className="text-3xl font-bold">AI驱动</h3>
|
||||
</div>
|
||||
<p className="text-xl mb-8 leading-relaxed opacity-90">
|
||||
利用最新的AI技术,为国土空间规划学习提供智能化支持,
|
||||
让复杂的理论知识变得简单易懂。
|
||||
</p>
|
||||
<div className="flex items-center space-x-4 text-lg">
|
||||
<Users className="w-6 h-6" />
|
||||
<span className="font-semibold">500+ 用户信赖</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* CTA区域 */}
|
||||
<section className="py-24 bg-gradient-to-r from-blue-600 via-purple-600 to-pink-600 relative overflow-hidden">
|
||||
<div className="max-w-4xl mx-auto text-center px-4 sm:px-6 lg:px-8 relative z-10">
|
||||
<h2 className="text-4xl sm:text-5xl font-bold text-white mb-6">
|
||||
开始您的智能学习之旅
|
||||
</h2>
|
||||
<p className="text-xl text-white/90 mb-12 max-w-2xl mx-auto">
|
||||
立即注册,体验AI驱动的国土空间规划学习平台
|
||||
</p>
|
||||
<div className="flex flex-col sm:flex-row gap-6 justify-center">
|
||||
<Button size="lg" className="w-full sm:w-auto bg-white text-blue-600 hover:bg-white/90 px-8 py-4 text-lg font-semibold shadow-2xl" asChild>
|
||||
<Link href="/register">
|
||||
<span className="flex items-center">
|
||||
免费注册
|
||||
<ArrowRight className="ml-2 w-5 h-5" />
|
||||
</span>
|
||||
</Link>
|
||||
</Button>
|
||||
<Button size="lg" variant="outline" className="w-full sm:w-auto text-white border-white/30 hover:bg-white/10 px-8 py-4 text-lg font-semibold" asChild>
|
||||
<Link href="/login">立即登录</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
{/* 统一封底区域 */}
|
||||
<footer className="bg-card text-foreground border-t">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
{/* 主要内容区域 - 三列布局(中间留空) */}
|
||||
<div className="py-12 border-b border-border/50">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-[2fr_2fr_1fr] gap-8 lg:gap-12">
|
||||
{/* 第一列:关于项目 */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold text-foreground mb-4">关于项目</h2>
|
||||
<p className="text-muted-foreground leading-relaxed mb-6">
|
||||
国土空间规划课程智能体是一个基于先进AI技术的智能学习平台,为国土空间规划专业提供全方位的知识服务和实践支持。平台集成了RAG技术、图像生成技术、数据分析技术等多种AI能力。
|
||||
</p>
|
||||
<div className="flex flex-col sm:flex-row gap-3">
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<a href="https://tsp.spacekg.com/#/" target="_blank" rel="noopener noreferrer">
|
||||
<BookOpen className="mr-2 h-4 w-4" />
|
||||
了解更多
|
||||
</a>
|
||||
</Button>
|
||||
<Button asChild variant="outline" size="sm">
|
||||
<a href="https://homepage.hit.edu.cn/wusongtao" target="_blank" rel="noopener noreferrer">
|
||||
<Users className="mr-2 h-4 w-4" />
|
||||
联系我们
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 第二列:展示图片 */}
|
||||
<div className="hidden lg:flex items-center justify-center">
|
||||
<div className="relative w-full max-w-xs">
|
||||
<img
|
||||
src="/heilongjiang-spatial-planning.png"
|
||||
alt="黑龙江国土空间规划"
|
||||
className="w-full h-auto rounded-lg shadow-lg object-cover"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 第三列:联系我们 */}
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-foreground mb-4">联系我们</h3>
|
||||
<ul className="space-y-3">
|
||||
<li className="flex items-start gap-3">
|
||||
<Mail className="w-5 h-5 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">邮箱</p>
|
||||
<a href="mailto:contact@hit-agent.com" className="text-sm text-foreground hover:text-primary transition-colors">
|
||||
contact@hit-agent.com
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li className="flex items-start gap-3">
|
||||
<Phone className="w-5 h-5 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">电话</p>
|
||||
<a href="tel:+86-451-86412114" className="text-sm text-foreground hover:text-primary transition-colors">
|
||||
+86-451-86412114
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li className="flex items-start gap-3">
|
||||
<MapPin className="w-5 h-5 text-muted-foreground mt-0.5 flex-shrink-0" />
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">地址</p>
|
||||
<p className="text-sm text-foreground">
|
||||
哈尔滨市南岗区西大直街92号
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer信息部分 */}
|
||||
<div className="py-8">
|
||||
<div className="text-center">
|
||||
<div className="flex items-center justify-center gap-2 mb-3">
|
||||
<div className="w-8 h-8 bg-gradient-to-r from-blue-600 to-blue-800 rounded-lg flex items-center justify-center">
|
||||
<BookOpen className="w-4 h-4 text-white" />
|
||||
</div>
|
||||
<span className="text-lg font-semibold">国土空间规划课程智能体</span>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Copyright © {new Date().getFullYear()} 哈尔滨工业大学建筑与设计学院国土空间与区域发展研究所
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter, usePathname } from "next/navigation";
|
||||
import { useAuthStore } from "@/store/auth";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
MessageSquare,
|
||||
BookOpen,
|
||||
Image,
|
||||
Settings,
|
||||
Menu,
|
||||
X,
|
||||
User,
|
||||
LogOut,
|
||||
GraduationCap,
|
||||
TrendingUp
|
||||
} from "lucide-react";
|
||||
|
||||
const navItems = [
|
||||
{ id: "course-content", name: "课程内容", icon: GraduationCap, href: "/course-content" },
|
||||
{ id: "chat", name: "对话", icon: MessageSquare, href: "/chat" },
|
||||
{ id: "knowledge", name: "知识库", icon: BookOpen, href: "/knowledge" },
|
||||
{ id: "spatial", name: "空间出图", icon: Image, href: "/spatial" },
|
||||
];
|
||||
|
||||
export default function MobileNav() {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const { user, logout } = useAuthStore();
|
||||
|
||||
const handleNavClick = (href: string) => {
|
||||
router.push(href);
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
logout();
|
||||
router.push("/");
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 移动端导航栏 */}
|
||||
<div className="lg:hidden fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 mobile-safe-area z-50">
|
||||
<div className="flex items-center justify-around py-2">
|
||||
{navItems.map((item) => {
|
||||
const isActive = pathname === item.href;
|
||||
return (
|
||||
<Button
|
||||
key={item.id}
|
||||
variant={isActive ? "default" : "ghost"}
|
||||
size="sm"
|
||||
onClick={() => handleNavClick(item.href)}
|
||||
className={`flex flex-col items-center space-y-1 px-3 py-2 ${
|
||||
isActive ? "text-white" : "text-gray-600"
|
||||
}`}
|
||||
>
|
||||
<item.icon className="w-5 h-5" />
|
||||
<span className="text-xs">{item.name}</span>
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 移动端菜单按钮 */}
|
||||
<div className="lg:hidden fixed top-4 right-4 z-50">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
className="bg-white shadow-lg"
|
||||
>
|
||||
{isOpen ? <X className="w-4 h-4" /> : <Menu className="w-4 h-4" />}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 移动端侧边菜单 */}
|
||||
{isOpen && (
|
||||
<div className="lg:hidden fixed inset-0 z-40">
|
||||
{/* 遮罩 */}
|
||||
<div
|
||||
className="absolute inset-0 bg-black bg-opacity-50"
|
||||
onClick={() => setIsOpen(false)}
|
||||
/>
|
||||
|
||||
{/* 菜单内容 */}
|
||||
<div className="absolute right-0 top-0 h-full w-80 max-w-[85vw] bg-white shadow-xl mobile-safe-area">
|
||||
<div className="flex flex-col h-full">
|
||||
{/* 用户信息 */}
|
||||
<div className="p-6 border-b border-gray-200">
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="w-12 h-12 bg-gray-200 rounded-full flex items-center justify-center">
|
||||
<User className="w-6 h-6 text-gray-600" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-lg font-medium text-gray-900 truncate">
|
||||
{user?.full_name || user?.username}
|
||||
</p>
|
||||
<p className="text-sm text-gray-500 truncate">
|
||||
{user?.email}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 导航菜单 */}
|
||||
<div className="flex-1 p-6">
|
||||
<nav className="space-y-2">
|
||||
{navItems.map((item) => {
|
||||
const isActive = pathname === item.href;
|
||||
return (
|
||||
<Button
|
||||
key={item.id}
|
||||
variant={isActive ? "default" : "ghost"}
|
||||
onClick={() => handleNavClick(item.href)}
|
||||
className="w-full justify-start"
|
||||
>
|
||||
<item.icon className="w-5 h-5 mr-3" />
|
||||
{item.name}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* 底部操作 */}
|
||||
<div className="p-6 border-t border-gray-200 space-y-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => handleNavClick("/analytics")}
|
||||
className="w-full justify-start"
|
||||
>
|
||||
<TrendingUp className="w-5 h-5 mr-3" />
|
||||
学习进度
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => handleNavClick("/settings")}
|
||||
className="w-full justify-start"
|
||||
>
|
||||
<Settings className="w-5 h-5 mr-3" />
|
||||
设置
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={handleLogout}
|
||||
className="w-full justify-start text-red-600 hover:text-red-700 hover:bg-red-50"
|
||||
>
|
||||
<LogOut className="w-5 h-5 mr-3" />
|
||||
退出登录
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import React, { memo } from "react";
|
||||
|
||||
interface AuroraTextProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
colors?: string[];
|
||||
speed?: number;
|
||||
}
|
||||
|
||||
export const AuroraText = memo(
|
||||
({
|
||||
children,
|
||||
className = "",
|
||||
colors = ["#FF0080", "#7928CA", "#0070F3", "#38bdf8"],
|
||||
speed = 1,
|
||||
}: AuroraTextProps) => {
|
||||
const gradientStyle = {
|
||||
backgroundImage: `linear-gradient(135deg, ${colors.join(", ")}, ${
|
||||
colors[0]
|
||||
})`,
|
||||
WebkitBackgroundClip: "text",
|
||||
WebkitTextFillColor: "transparent",
|
||||
animationDuration: `${10 / speed}s`,
|
||||
};
|
||||
|
||||
return (
|
||||
<span className={`relative inline-block ${className}`}>
|
||||
<span className="sr-only">{children}</span>
|
||||
<span
|
||||
className="relative animate-aurora bg-[length:200%_auto] bg-clip-text text-transparent"
|
||||
style={gradientStyle}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
AuroraText.displayName = "AuroraText";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { ArrowRightIcon } from "@radix-ui/react-icons";
|
||||
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface BentoGridProps extends ComponentPropsWithoutRef<"div"> {
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
interface BentoCardProps extends ComponentPropsWithoutRef<"div"> {
|
||||
name: string;
|
||||
className: string;
|
||||
background?: ReactNode;
|
||||
Icon: React.ElementType;
|
||||
description: string;
|
||||
href: string;
|
||||
cta: string;
|
||||
}
|
||||
|
||||
const BentoGrid = ({ children, className, ...props }: BentoGridProps) => {
|
||||
return (
|
||||
<div
|
||||
className={cn("grid w-full auto-rows-auto grid-cols-2 gap-4", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const BentoCard = ({
|
||||
name,
|
||||
className,
|
||||
background,
|
||||
Icon,
|
||||
description,
|
||||
href,
|
||||
cta,
|
||||
...props
|
||||
}: BentoCardProps) => (
|
||||
<div
|
||||
key={name}
|
||||
className={cn(
|
||||
"group relative col-span-3 flex flex-col justify-between overflow-hidden rounded-xl",
|
||||
// light styles
|
||||
"bg-background [box-shadow:0_0_0_1px_rgba(0,0,0,.03),0_2px_4px_rgba(0,0,0,.05),0_12px_24px_rgba(0,0,0,.05)]",
|
||||
// dark styles
|
||||
"dark:bg-background transform-gpu dark:[box-shadow:0_-20px_80px_-20px_#ffffff1f_inset] dark:[border:1px_solid_rgba(255,255,255,.1)]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{background && <div>{background}</div>}
|
||||
<div className="z-10 flex transform-gpu flex-col gap-1 p-6 transition-all duration-300 group-hover:-translate-y-5">
|
||||
<Icon className="h-12 w-12 origin-left transform-gpu text-neutral-700 transition-all duration-300 ease-in-out group-hover:scale-75 dark:text-neutral-300" />
|
||||
<h3 className="text-xl font-semibold text-neutral-700 dark:text-neutral-300">
|
||||
{name}
|
||||
</h3>
|
||||
<p className="max-w-lg text-neutral-400">{description}</p>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"pointer-events-none absolute bottom-0 flex w-full translate-y-10 transform-gpu flex-row items-center p-4 opacity-0 transition-all duration-300 group-hover:translate-y-0 group-hover:opacity-100",
|
||||
)}
|
||||
>
|
||||
<Button variant="ghost" asChild size="sm" className="pointer-events-auto">
|
||||
<a href={href}>
|
||||
<span className="flex items-center">
|
||||
{cta}
|
||||
<ArrowRightIcon className="ms-2 h-4 w-4 rtl:rotate-180" />
|
||||
</span>
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
<div className="pointer-events-none absolute inset-0 transform-gpu transition-all duration-300 group-hover:bg-black/[.03] group-hover:dark:bg-neutral-800/10" />
|
||||
</div>
|
||||
);
|
||||
|
||||
export { BentoCard, BentoGrid };
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
"use client";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
interface FlickeringGridProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
squareSize?: number;
|
||||
gridGap?: number;
|
||||
flickerChance?: number;
|
||||
color?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
className?: string;
|
||||
maxOpacity?: number;
|
||||
}
|
||||
|
||||
export const FlickeringGrid: React.FC<FlickeringGridProps> = ({
|
||||
squareSize = 4,
|
||||
gridGap = 6,
|
||||
flickerChance = 0.3,
|
||||
color = "rgb(0, 0, 0)",
|
||||
width,
|
||||
height,
|
||||
className,
|
||||
maxOpacity = 0.3,
|
||||
...props
|
||||
}) => {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const [isInView, setIsInView] = useState(false);
|
||||
const [canvasSize, setCanvasSize] = useState({ width: 0, height: 0 });
|
||||
|
||||
const memoizedColor = useMemo(() => {
|
||||
const toRGBA = (color: string) => {
|
||||
if (typeof window === "undefined") {
|
||||
return `rgba(0, 0, 0,`;
|
||||
}
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = canvas.height = 1;
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return "rgba(255, 0, 0,";
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillRect(0, 0, 1, 1);
|
||||
const [r, g, b] = Array.from(ctx.getImageData(0, 0, 1, 1).data);
|
||||
return `rgba(${r}, ${g}, ${b},`;
|
||||
};
|
||||
return toRGBA(color);
|
||||
}, [color]);
|
||||
|
||||
const setupCanvas = useCallback(
|
||||
(canvas: HTMLCanvasElement, width: number, height: number) => {
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
canvas.width = width * dpr;
|
||||
canvas.height = height * dpr;
|
||||
canvas.style.width = `${width}px`;
|
||||
canvas.style.height = `${height}px`;
|
||||
const cols = Math.floor(width / (squareSize + gridGap));
|
||||
const rows = Math.floor(height / (squareSize + gridGap));
|
||||
|
||||
const squares = new Float32Array(cols * rows);
|
||||
for (let i = 0; i < squares.length; i++) {
|
||||
squares[i] = Math.random() * maxOpacity;
|
||||
}
|
||||
|
||||
return { cols, rows, squares, dpr };
|
||||
},
|
||||
[squareSize, gridGap, maxOpacity],
|
||||
);
|
||||
|
||||
const updateSquares = useCallback(
|
||||
(squares: Float32Array, deltaTime: number) => {
|
||||
for (let i = 0; i < squares.length; i++) {
|
||||
if (Math.random() < flickerChance * deltaTime) {
|
||||
squares[i] = Math.random() * maxOpacity;
|
||||
}
|
||||
}
|
||||
},
|
||||
[flickerChance, maxOpacity],
|
||||
);
|
||||
|
||||
const drawGrid = useCallback(
|
||||
(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
width: number,
|
||||
height: number,
|
||||
cols: number,
|
||||
rows: number,
|
||||
squares: Float32Array,
|
||||
dpr: number,
|
||||
) => {
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
ctx.fillStyle = "transparent";
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
|
||||
for (let i = 0; i < cols; i++) {
|
||||
for (let j = 0; j < rows; j++) {
|
||||
const opacity = squares[i * rows + j];
|
||||
ctx.fillStyle = `${memoizedColor}${opacity})`;
|
||||
ctx.fillRect(
|
||||
i * (squareSize + gridGap) * dpr,
|
||||
j * (squareSize + gridGap) * dpr,
|
||||
squareSize * dpr,
|
||||
squareSize * dpr,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
[memoizedColor, squareSize, gridGap],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
const container = containerRef.current;
|
||||
if (!canvas || !container) return;
|
||||
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
|
||||
let animationFrameId: number;
|
||||
let gridParams: ReturnType<typeof setupCanvas>;
|
||||
|
||||
const updateCanvasSize = () => {
|
||||
const newWidth = width || container.clientWidth;
|
||||
const newHeight = height || container.clientHeight;
|
||||
setCanvasSize({ width: newWidth, height: newHeight });
|
||||
gridParams = setupCanvas(canvas, newWidth, newHeight);
|
||||
};
|
||||
|
||||
updateCanvasSize();
|
||||
|
||||
let lastTime = 0;
|
||||
const animate = (time: number) => {
|
||||
if (!isInView) return;
|
||||
|
||||
const deltaTime = (time - lastTime) / 1000;
|
||||
lastTime = time;
|
||||
|
||||
updateSquares(gridParams.squares, deltaTime);
|
||||
drawGrid(
|
||||
ctx,
|
||||
canvas.width,
|
||||
canvas.height,
|
||||
gridParams.cols,
|
||||
gridParams.rows,
|
||||
gridParams.squares,
|
||||
gridParams.dpr,
|
||||
);
|
||||
animationFrameId = requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
updateCanvasSize();
|
||||
});
|
||||
|
||||
resizeObserver.observe(container);
|
||||
|
||||
const intersectionObserver = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
setIsInView(entry!.isIntersecting);
|
||||
},
|
||||
{ threshold: 0 },
|
||||
);
|
||||
|
||||
intersectionObserver.observe(canvas);
|
||||
|
||||
if (isInView) {
|
||||
animationFrameId = requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
resizeObserver.disconnect();
|
||||
intersectionObserver.disconnect();
|
||||
};
|
||||
}, [setupCanvas, updateSquares, drawGrid, width, height, isInView]);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={cn(`h-full w-full ${className}`)}
|
||||
{...props}
|
||||
>
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
className="pointer-events-none"
|
||||
style={{
|
||||
width: canvasSize.width,
|
||||
height: canvasSize.height,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"use client";
|
||||
|
||||
import { useInView, useMotionValue, useSpring } from "framer-motion";
|
||||
import { type ComponentPropsWithoutRef, useEffect, useRef } from "react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface NumberTickerProps extends ComponentPropsWithoutRef<"span"> {
|
||||
value: number;
|
||||
startValue?: number;
|
||||
direction?: "up" | "down";
|
||||
delay?: number;
|
||||
decimalPlaces?: number;
|
||||
}
|
||||
|
||||
export function NumberTicker({
|
||||
value,
|
||||
startValue = 0,
|
||||
direction = "up",
|
||||
delay = 0,
|
||||
className,
|
||||
decimalPlaces = 0,
|
||||
...props
|
||||
}: NumberTickerProps) {
|
||||
const ref = useRef<HTMLSpanElement>(null);
|
||||
const motionValue = useMotionValue(direction === "down" ? value : startValue);
|
||||
const springValue = useSpring(motionValue, {
|
||||
damping: 60,
|
||||
stiffness: 100,
|
||||
});
|
||||
const isInView = useInView(ref, { once: true, margin: "0px" });
|
||||
|
||||
useEffect(() => {
|
||||
if (isInView) {
|
||||
const timer = setTimeout(() => {
|
||||
motionValue.set(direction === "down" ? startValue : value);
|
||||
}, delay * 1000);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [motionValue, isInView, delay, value, direction, startValue]);
|
||||
|
||||
useEffect(
|
||||
() =>
|
||||
springValue.on("change", (latest) => {
|
||||
if (ref.current) {
|
||||
ref.current.textContent = Intl.NumberFormat("en-US", {
|
||||
minimumFractionDigits: decimalPlaces,
|
||||
maximumFractionDigits: decimalPlaces,
|
||||
}).format(Number(latest.toFixed(decimalPlaces)));
|
||||
}
|
||||
}),
|
||||
[springValue, decimalPlaces],
|
||||
);
|
||||
|
||||
return (
|
||||
<span
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-block tracking-wider tabular-nums",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{startValue}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
||||
import { ChevronDown } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Accordion = AccordionPrimitive.Root
|
||||
|
||||
const AccordionItem = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AccordionPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn("border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AccordionItem.displayName = "AccordionItem"
|
||||
|
||||
const AccordionTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
))
|
||||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
|
||||
|
||||
const AccordionContent = React.forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Content
|
||||
ref={ref}
|
||||
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pb-4 pt-0", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
))
|
||||
|
||||
AccordionContent.displayName = AccordionPrimitive.Content.displayName
|
||||
|
||||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import * as React from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const alertVariants = cva(
|
||||
"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-background text-foreground",
|
||||
destructive:
|
||||
"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const Alert = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
|
||||
>(({ className, variant, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
role="alert"
|
||||
className={cn(alertVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
Alert.displayName = "Alert";
|
||||
|
||||
const AlertTitle = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLHeadingElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<h5
|
||||
ref={ref}
|
||||
className={cn("mb-1 font-medium leading-none tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
AlertTitle.displayName = "AlertTitle";
|
||||
|
||||
const AlertDescription = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("text-sm [&_p]:leading-relaxed", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
AlertDescription.displayName = "AlertDescription";
|
||||
|
||||
export { Alert, AlertTitle, AlertDescription };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Avatar = React.forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Avatar.displayName = AvatarPrimitive.Root.displayName
|
||||
|
||||
const AvatarImage = React.forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Image>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Image
|
||||
ref={ref}
|
||||
className={cn("aspect-square h-full w-full", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AvatarImage.displayName = AvatarPrimitive.Image.displayName
|
||||
|
||||
const AvatarFallback = React.forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Fallback>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Fallback
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-full w-full items-center justify-center rounded-full bg-muted",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
|
||||
|
||||
export { Avatar, AvatarImage, AvatarFallback }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
|
||||
secondary:
|
||||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
destructive:
|
||||
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
|
||||
outline: "text-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
export interface BadgeProps
|
||||
extends React.HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof badgeVariants> {}
|
||||
|
||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||
return (
|
||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"mit-button inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "mit-button-primary",
|
||||
destructive:
|
||||
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||
outline:
|
||||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
||||
secondary: "mit-button-secondary",
|
||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-10 px-4 py-2",
|
||||
sm: "h-8 rounded-md px-3",
|
||||
lg: "h-11 rounded-md px-8",
|
||||
icon: "h-10 w-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, loading = false, disabled, children, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
if (asChild) {
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
disabled={disabled || loading}
|
||||
{...props}
|
||||
>
|
||||
{loading && (
|
||||
<svg
|
||||
className="mr-2 h-4 w-4 animate-spin"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
||||
@@ -0,0 +1,84 @@
|
||||
import * as React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Card = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"mit-card",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
Card.displayName = "Card";
|
||||
|
||||
const CardHeader = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardHeader.displayName = "CardHeader";
|
||||
|
||||
const CardTitle = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLHeadingElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<h3
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"text-xl font-semibold leading-none tracking-tight",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardTitle.displayName = "CardTitle";
|
||||
|
||||
const CardDescription = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<p
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardDescription.displayName = "CardDescription";
|
||||
|
||||
const CardContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
||||
));
|
||||
CardContent.displayName = "CardContent";
|
||||
|
||||
const CardFooter = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex items-center p-6 pt-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardFooter.displayName = "CardFooter";
|
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { X } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Dialog = DialogPrimitive.Root;
|
||||
|
||||
const DialogTrigger = DialogPrimitive.Trigger;
|
||||
|
||||
const DialogPortal = DialogPrimitive.Portal;
|
||||
|
||||
const DialogClose = DialogPrimitive.Close;
|
||||
|
||||
const DialogOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
));
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||
|
||||
const DialogHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-1.5 text-center sm:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DialogHeader.displayName = "DialogHeader";
|
||||
|
||||
const DialogFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
DialogFooter.displayName = "DialogFooter";
|
||||
|
||||
const DialogTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"text-lg font-semibold leading-none tracking-tight",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
||||
|
||||
const DialogDescription = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogPortal,
|
||||
DialogOverlay,
|
||||
DialogClose,
|
||||
DialogTrigger,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogFooter,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
||||
import { Check, ChevronRight, Circle } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const DropdownMenu = DropdownMenuPrimitive.Root;
|
||||
|
||||
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
||||
|
||||
const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
||||
|
||||
const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
||||
|
||||
const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
||||
|
||||
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
||||
|
||||
const DropdownMenuSubTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, children, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRight className="ml-auto h-4 w-4" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
));
|
||||
DropdownMenuSubTrigger.displayName =
|
||||
DropdownMenuPrimitive.SubTrigger.displayName;
|
||||
|
||||
const DropdownMenuSubContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuSubContent.displayName =
|
||||
DropdownMenuPrimitive.SubContent.displayName;
|
||||
|
||||
const DropdownMenuContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
));
|
||||
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
||||
|
||||
const DropdownMenuItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
||||
|
||||
const DropdownMenuCheckboxItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
||||
>(({ className, children, checked, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<Check className="h-4 w-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
));
|
||||
DropdownMenuCheckboxItem.displayName =
|
||||
DropdownMenuPrimitive.CheckboxItem.displayName;
|
||||
|
||||
const DropdownMenuRadioItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<Circle className="h-2 w-2 fill-current" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
));
|
||||
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
||||
|
||||
const DropdownMenuLabel = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-semibold",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
|
||||
|
||||
const DropdownMenuSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
|
||||
|
||||
const DropdownMenuShortcut = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
||||
return (
|
||||
<span
|
||||
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
DropdownMenuShortcut.displayName = "DropdownMenuShortcut";
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuRadioGroup,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import * as React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export interface InputProps
|
||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
Input.displayName = "Input";
|
||||
|
||||
export { Input };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as LabelPrimitive from "@radix-ui/react-label";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const labelVariants = cva(
|
||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||
);
|
||||
|
||||
const Label = React.forwardRef<
|
||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
||||
VariantProps<typeof labelVariants>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<LabelPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(labelVariants(), className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
Label.displayName = LabelPrimitive.Root.displayName;
|
||||
|
||||
export { Label };
|
||||
@@ -0,0 +1,48 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface LoadingSpinnerProps {
|
||||
size?: "sm" | "md" | "lg";
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function LoadingSpinner({
|
||||
size = "md",
|
||||
className
|
||||
}: LoadingSpinnerProps) {
|
||||
const sizeClasses = {
|
||||
sm: "h-4 w-4",
|
||||
md: "h-8 w-8",
|
||||
lg: "h-12 w-12",
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("flex items-center justify-center", className)}>
|
||||
<svg
|
||||
className={cn("animate-spin text-primary", sizeClasses[size])}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
|
||||
import { Circle } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const RadioGroup = React.forwardRef<
|
||||
React.ElementRef<typeof RadioGroupPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<RadioGroupPrimitive.Root
|
||||
className={cn("grid gap-2", className)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
/>
|
||||
);
|
||||
});
|
||||
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;
|
||||
|
||||
const RadioGroupItem = React.forwardRef<
|
||||
React.ElementRef<typeof RadioGroupPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => {
|
||||
return (
|
||||
<RadioGroupPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<RadioGroupPrimitive.Indicator className="flex items-center justify-center">
|
||||
<Circle className="h-2.5 w-2.5 fill-current text-current" />
|
||||
</RadioGroupPrimitive.Indicator>
|
||||
</RadioGroupPrimitive.Item>
|
||||
);
|
||||
});
|
||||
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;
|
||||
|
||||
export { RadioGroup, RadioGroupItem };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const ScrollArea = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn("relative overflow-hidden", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
))
|
||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
|
||||
|
||||
const ScrollBar = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
>(({ className, orientation = "vertical", ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
ref={ref}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none select-none transition-colors",
|
||||
orientation === "vertical" &&
|
||||
"h-full w-2.5 border-l border-l-transparent p-[1px]",
|
||||
orientation === "horizontal" &&
|
||||
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
))
|
||||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
@@ -0,0 +1,166 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SelectPrimitive from "@radix-ui/react-select"
|
||||
import { Check, ChevronDown, ChevronUp } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Select = SelectPrimitive.Root
|
||||
|
||||
const SelectGroup = SelectPrimitive.Group
|
||||
|
||||
const SelectValue = SelectPrimitive.Value
|
||||
|
||||
const SelectTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDown className="h-4 w-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
))
|
||||
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
|
||||
|
||||
const SelectScrollUpButton = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUp className="h-4 w-4" />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
))
|
||||
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName
|
||||
|
||||
const SelectScrollDownButton = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
))
|
||||
SelectScrollDownButton.displayName =
|
||||
SelectPrimitive.ScrollDownButton.displayName
|
||||
|
||||
const SelectContent = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
||||
>(({ className, children, position = "popper", ...props }, ref) => (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className
|
||||
)}
|
||||
position={position}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
))
|
||||
SelectContent.displayName = SelectPrimitive.Content.displayName
|
||||
|
||||
const SelectLabel = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SelectLabel.displayName = SelectPrimitive.Label.displayName
|
||||
|
||||
const SelectItem = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<Check className="h-4 w-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
))
|
||||
SelectItem.displayName = SelectPrimitive.Item.displayName
|
||||
|
||||
const SelectSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SelectSeparator.displayName = SelectPrimitive.Separator.displayName
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectGroup,
|
||||
SelectValue,
|
||||
SelectTrigger,
|
||||
SelectContent,
|
||||
SelectLabel,
|
||||
SelectItem,
|
||||
SelectSeparator,
|
||||
SelectScrollUpButton,
|
||||
SelectScrollDownButton,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Separator = React.forwardRef<
|
||||
React.ElementRef<typeof SeparatorPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
||||
>(
|
||||
(
|
||||
{ className, orientation = "horizontal", decorative = true, ...props },
|
||||
ref
|
||||
) => (
|
||||
<SeparatorPrimitive.Root
|
||||
ref={ref}
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"shrink-0 bg-border",
|
||||
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
)
|
||||
Separator.displayName = SeparatorPrimitive.Root.displayName
|
||||
|
||||
export { Separator }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SliderPrimitive from "@radix-ui/react-slider"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Slider = React.forwardRef<
|
||||
React.ElementRef<typeof SliderPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SliderPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex w-full touch-none select-none items-center",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SliderPrimitive.Track className="relative h-2 w-full grow overflow-hidden rounded-full bg-secondary">
|
||||
<SliderPrimitive.Range className="absolute h-full bg-primary" />
|
||||
</SliderPrimitive.Track>
|
||||
<SliderPrimitive.Thumb className="block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50" />
|
||||
</SliderPrimitive.Root>
|
||||
))
|
||||
Slider.displayName = SliderPrimitive.Root.displayName
|
||||
|
||||
export { Slider }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Table = React.forwardRef<
|
||||
HTMLTableElement,
|
||||
React.HTMLAttributes<HTMLTableElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div className="relative w-full overflow-auto">
|
||||
<table
|
||||
ref={ref}
|
||||
className={cn("w-full caption-bottom text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
Table.displayName = "Table"
|
||||
|
||||
const TableHeader = React.forwardRef<
|
||||
HTMLTableSectionElement,
|
||||
React.HTMLAttributes<HTMLTableSectionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
||||
))
|
||||
TableHeader.displayName = "TableHeader"
|
||||
|
||||
const TableBody = React.forwardRef<
|
||||
HTMLTableSectionElement,
|
||||
React.HTMLAttributes<HTMLTableSectionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<tbody
|
||||
ref={ref}
|
||||
className={cn("[&_tr:last-child]:border-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableBody.displayName = "TableBody"
|
||||
|
||||
const TableFooter = React.forwardRef<
|
||||
HTMLTableSectionElement,
|
||||
React.HTMLAttributes<HTMLTableSectionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<tfoot
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableFooter.displayName = "TableFooter"
|
||||
|
||||
const TableRow = React.forwardRef<
|
||||
HTMLTableRowElement,
|
||||
React.HTMLAttributes<HTMLTableRowElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<tr
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableRow.displayName = "TableRow"
|
||||
|
||||
const TableHead = React.forwardRef<
|
||||
HTMLTableCellElement,
|
||||
React.ThHTMLAttributes<HTMLTableCellElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<th
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableHead.displayName = "TableHead"
|
||||
|
||||
const TableCell = React.forwardRef<
|
||||
HTMLTableCellElement,
|
||||
React.TdHTMLAttributes<HTMLTableCellElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<td
|
||||
ref={ref}
|
||||
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableCell.displayName = "TableCell"
|
||||
|
||||
const TableCaption = React.forwardRef<
|
||||
HTMLTableCaptionElement,
|
||||
React.HTMLAttributes<HTMLTableCaptionElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<caption
|
||||
ref={ref}
|
||||
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TableCaption.displayName = "TableCaption"
|
||||
|
||||
export {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableFooter,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TableCell,
|
||||
TableCaption,
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const Tabs = TabsPrimitive.Root
|
||||
|
||||
const TabsList = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.List
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsList.displayName = TabsPrimitive.List.displayName
|
||||
|
||||
const TabsTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
|
||||
|
||||
const TabsContent = React.forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TabsContent.displayName = TabsPrimitive.Content.displayName
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
@@ -0,0 +1,30 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export interface TextareaProps
|
||||
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
|
||||
|
||||
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
({ className, ...props }, ref) => {
|
||||
return (
|
||||
<textarea
|
||||
className={cn(
|
||||
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Textarea.displayName = "Textarea"
|
||||
|
||||
export { Textarea }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { Moon, Sun } from "lucide-react";
|
||||
import { useTheme } from "next-themes";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function ThemeToggle() {
|
||||
const { theme, setTheme } = useTheme();
|
||||
const [mounted, setMounted] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
if (!mounted) {
|
||||
return (
|
||||
<Button variant="ghost" size="icon" className="w-9 h-9">
|
||||
<Sun className="h-4 w-4" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
|
||||
className="w-9 h-9"
|
||||
>
|
||||
{theme === "light" ? (
|
||||
<Moon className="h-4 w-4" />
|
||||
) : (
|
||||
<Sun className="h-4 w-4" />
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user