import { CheckCircle2, Circle, Clock, Hash, Info, XCircle } from 'lucide-react' import { useEffect, useState } from 'react' import { Alert, AlertDescription } from '@/components/ui/alert' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Switch } from '@/components/ui/switch' import { useToast } from '@/hooks/use-toast' import { cn } from '@/lib/utils' import { createExpression, updateExpression } from '@/lib/expression-api' import type { Expression, ExpressionCreateRequest, ExpressionUpdateRequest, ChatInfo } from '@/types/expression' /** * 表达方式详情对话框 */ export function ExpressionDetailDialog({ expression, open, onOpenChange, chatNameMap, }: { expression: Expression | null open: boolean onOpenChange: (open: boolean) => void chatNameMap: Map }) { if (!expression) return null const formatTime = (timestamp: number | null) => { if (!timestamp) return '-' return new Date(timestamp * 1000).toLocaleString('zh-CN') } const getChatName = (chatId: string): string => { return chatNameMap.get(chatId) || chatId } return ( 表达方式详情 查看表达方式的完整信息
{/* 状态标记 */}
{expression.checked ? ( ) : ( )}

已检查

{expression.checked ? "已通过审核" : "未审核"}

{expression.rejected ? ( ) : ( )}

已拒绝

{expression.rejected ? "不会被使用" : "正常"}

) } /** * 信息项组件 */ function InfoItem({ icon: Icon, label, value, mono = false, }: { icon?: typeof Hash label: string value: string | null | undefined mono?: boolean }) { return (
{value || '-'}
) } /** * 表达方式创建对话框 */ export function ExpressionCreateDialog({ open, onOpenChange, chatList, onSuccess, }: { open: boolean onOpenChange: (open: boolean) => void chatList: ChatInfo[] onSuccess: () => void }) { const [formData, setFormData] = useState({ situation: '', style: '', chat_id: '', }) const [saving, setSaving] = useState(false) const { toast } = useToast() const handleCreate = async () => { if (!formData.situation || !formData.style || !formData.chat_id) { toast({ title: '验证失败', description: '请填写必填字段:情境、风格和聚天', variant: 'destructive', }) return } try { setSaving(true) const result = await createExpression(formData) if (result.success) { toast({ title: '创建成功', description: '表达方式已创建', }) setFormData({ situation: '', style: '', chat_id: '', }) onSuccess() } else { toast({ title: '创建失败', description: result.error, variant: 'destructive', }) } } catch (error) { toast({ title: '创建失败', description: error instanceof Error ? error.message : '无法创建表达方式', variant: 'destructive', }) } finally { setSaving(false) } } return ( 新增表达方式 创建新的表达方式记录
setFormData({ ...formData, situation: e.target.value })} placeholder="描述使用场景" />
setFormData({ ...formData, style: e.target.value })} placeholder="描述表达风格" />
) } /** * 表达方式编辑对话框 */ export function ExpressionEditDialog({ expression, open, onOpenChange, chatList, onSuccess, }: { expression: Expression | null open: boolean onOpenChange: (open: boolean) => void chatList: ChatInfo[] onSuccess: () => void }) { const [formData, setFormData] = useState({}) const [saving, setSaving] = useState(false) const { toast } = useToast() useEffect(() => { if (expression) { setFormData({ situation: expression.situation, style: expression.style, chat_id: expression.chat_id, checked: expression.checked, rejected: expression.rejected, }) } }, [expression]) const handleSave = async () => { if (!expression) return try { setSaving(true) const result = await updateExpression(expression.id, formData) if (result.success) { toast({ title: '保存成功', description: '表达方式已更新', }) onSuccess() } else { toast({ title: '保存失败', description: result.error, variant: 'destructive', }) } } catch (error) { toast({ title: '保存失败', description: error instanceof Error ? error.message : '无法更新表达方式', variant: 'destructive', }) } finally { setSaving(false) } } if (!expression) return null return ( 编辑表达方式 修改表达方式的信息
setFormData({ ...formData, situation: e.target.value })} placeholder="描述使用场景" />
setFormData({ ...formData, style: e.target.value })} placeholder="描述表达风格" />
{/* 状态标记 */}

状态标记说明:

• 已检查:表示该表达方式已通过审核(可由AI自动检查或人工审核)

• 已拒绝:表示该表达方式被标记为不合适,将永远不会被使用

根据配置中"仅使用已审核通过的表达方式"设置:
• 开启时:只有通过审核(已检查)的项目会被使用
• 关闭时:未审核的项目也会被使用

已通过审核

setFormData({ ...formData, checked })} />

不会被使用

setFormData({ ...formData, rejected })} />
) } /** * 批量删除确认对话框 */ export function BatchDeleteConfirmDialog({ open, onOpenChange, onConfirm, count, }: { open: boolean onOpenChange: (open: boolean) => void onConfirm: () => void count: number }) { return ( 确认批量删除 您即将删除 {count} 个表达方式,此操作无法撤销。确定要继续吗? 取消 确认删除 ) } /** * 单个删除确认对话框 */ export function DeleteConfirmDialog({ expression, open, onOpenChange, onConfirm, }: { expression: Expression | null open: boolean onOpenChange: (open: boolean) => void onConfirm: () => Promise }) { return ( 确认删除 确定要删除表达方式 "{expression?.situation}" 吗? 此操作不可撤销。 取消 删除 ) }