"use client" import { useState, useEffect, Suspense } from "react" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" import { Label } from "@/components/ui/label" import { Switch } from "@/components/ui/switch" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Badge } from "@/components/ui/badge" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog" import { Settings, Save, RefreshCw, Edit3, Plus, Trash2, Users, Zap, DollarSign } from "lucide-react" interface MatchType { id: string label: string matchLabel: string icon: string matchFromDB: boolean showJoinAfterMatch: boolean price: number enabled: boolean } interface MatchConfig { matchTypes: MatchType[] freeMatchLimit: number matchPrice: number settings: { enableFreeMatches: boolean enablePaidMatches: boolean maxMatchesPerDay: number } } const DEFAULT_CONFIG: MatchConfig = { matchTypes: [ { id: 'partner', label: '创业合伙', matchLabel: '创业伙伴', icon: '⭐', matchFromDB: true, showJoinAfterMatch: false, price: 1, enabled: true }, { id: 'investor', label: '资源对接', matchLabel: '资源对接', icon: '👥', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true }, { id: 'mentor', label: '导师顾问', matchLabel: '商业顾问', icon: '❤️', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true }, { id: 'team', label: '团队招募', matchLabel: '加入项目', icon: '🎮', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true } ], freeMatchLimit: 3, matchPrice: 1, settings: { enableFreeMatches: true, enablePaidMatches: true, maxMatchesPerDay: 10 } } function MatchConfigContent() { const [config, setConfig] = useState(DEFAULT_CONFIG) const [isLoading, setIsLoading] = useState(true) const [isSaving, setIsSaving] = useState(false) const [showTypeModal, setShowTypeModal] = useState(false) const [editingType, setEditingType] = useState(null) const [formData, setFormData] = useState({ id: '', label: '', matchLabel: '', icon: '⭐', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true }) // 加载配置 const loadConfig = async () => { setIsLoading(true) try { const res = await fetch('/api/db/config?key=match_config') const data = await res.json() if (data.success && data.config) { setConfig({ ...DEFAULT_CONFIG, ...data.config }) } } catch (error) { console.error('加载匹配配置失败:', error) } finally { setIsLoading(false) } } useEffect(() => { loadConfig() }, []) // 保存配置 const handleSave = async () => { setIsSaving(true) try { const res = await fetch('/api/db/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'match_config', config, description: '匹配功能配置' }) }) const data = await res.json() if (data.success) { alert('配置保存成功!') } else { alert('保存失败: ' + (data.error || '未知错误')) } } catch (error) { console.error('保存配置失败:', error) alert('保存失败') } finally { setIsSaving(false) } } // 编辑匹配类型 const handleEditType = (type: MatchType) => { setEditingType(type) setFormData({ id: type.id, label: type.label, matchLabel: type.matchLabel, icon: type.icon, matchFromDB: type.matchFromDB, showJoinAfterMatch: type.showJoinAfterMatch, price: type.price, enabled: type.enabled }) setShowTypeModal(true) } // 添加匹配类型 const handleAddType = () => { setEditingType(null) setFormData({ id: '', label: '', matchLabel: '', icon: '⭐', matchFromDB: false, showJoinAfterMatch: true, price: 1, enabled: true }) setShowTypeModal(true) } // 保存匹配类型 const handleSaveType = () => { if (!formData.id || !formData.label) { alert('请填写类型ID和名称') return } const newTypes = [...config.matchTypes] if (editingType) { // 更新 const index = newTypes.findIndex(t => t.id === editingType.id) if (index !== -1) { newTypes[index] = { ...formData } } } else { // 新增 if (newTypes.some(t => t.id === formData.id)) { alert('类型ID已存在') return } newTypes.push({ ...formData }) } setConfig({ ...config, matchTypes: newTypes }) setShowTypeModal(false) } // 删除匹配类型 const handleDeleteType = (typeId: string) => { if (!confirm('确定要删除这个匹配类型吗?')) return const newTypes = config.matchTypes.filter(t => t.id !== typeId) setConfig({ ...config, matchTypes: newTypes }) } // 切换类型启用状态 const handleToggleType = (typeId: string) => { const newTypes = config.matchTypes.map(t => t.id === typeId ? { ...t, enabled: !t.enabled } : t ) setConfig({ ...config, matchTypes: newTypes }) } const icons = ['⭐', '👥', '❤️', '🎮', '💼', '🚀', '💡', '🎯', '🔥', '✨'] return (
{/* 页面标题 */}

匹配功能配置

管理找伙伴功能的匹配类型和价格

{/* 基础设置 */} 基础设置 配置免费匹配次数和付费规则
{/* 每日免费次数 */}
setConfig({ ...config, freeMatchLimit: parseInt(e.target.value) || 0 })} />

用户每天可免费匹配的次数

{/* 付费匹配价格 */}
setConfig({ ...config, matchPrice: parseFloat(e.target.value) || 1 })} />

免费次数用完后的单次匹配价格

{/* 每日最大次数 */}
setConfig({ ...config, settings: { ...config.settings, maxMatchesPerDay: parseInt(e.target.value) || 10 } })} />

包含免费和付费的总次数

setConfig({ ...config, settings: { ...config.settings, enableFreeMatches: checked } })} />
setConfig({ ...config, settings: { ...config.settings, enablePaidMatches: checked } })} />
{/* 匹配类型管理 */}
匹配类型管理 配置不同的匹配类型及其价格
图标 类型ID 显示名称 匹配标签 价格 数据库匹配 状态 操作 {config.matchTypes.map((type) => ( {type.icon} {type.id} {type.label} {type.matchLabel} ¥{type.price} {type.matchFromDB ? ( ) : ( )} handleToggleType(type.id)} />
))}
{/* 编辑类型弹窗 */} {editingType ? : } {editingType ? '编辑匹配类型' : '添加匹配类型'}
setFormData({ ...formData, id: e.target.value })} disabled={!!editingType} />
{icons.map((icon) => ( ))}
setFormData({ ...formData, label: e.target.value })} />
setFormData({ ...formData, matchLabel: e.target.value })} />
setFormData({ ...formData, price: parseFloat(e.target.value) || 1 })} />
setFormData({ ...formData, matchFromDB: checked })} />
setFormData({ ...formData, showJoinAfterMatch: checked })} />
setFormData({ ...formData, enabled: checked })} />
) } export default function MatchConfigPage() { return ( ) }