"use client" import { useState, useEffect } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Label } from "@/components/ui/label" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" import { Switch } from "@/components/ui/switch" import { Slider } from "@/components/ui/slider" import { Textarea } from "@/components/ui/textarea" import { Badge } from "@/components/ui/badge" import { useStore } from "@/lib/store" import { Save, Settings, Users, DollarSign, UserCircle, Calendar, MapPin, BookOpen, Gift, X, Plus, Smartphone } from "lucide-react" export default function SettingsPage() { const { settings, updateSettings } = useStore() const [localSettings, setLocalSettings] = useState({ sectionPrice: settings.sectionPrice, baseBookPrice: settings.baseBookPrice, distributorShare: settings.distributorShare, authorInfo: { ...settings.authorInfo, startDate: settings.authorInfo?.startDate || "2025年10月15日", bio: settings.authorInfo?.bio || "连续创业者,私域运营专家,每天早上6-9点在Soul派对房分享真实商业故事", }, }) const [isSaving, setIsSaving] = useState(false) // 免费章节配置 const [freeChapters, setFreeChapters] = useState(['preface', 'epilogue', '1.1', 'appendix-1', 'appendix-2', 'appendix-3']) const [newFreeChapter, setNewFreeChapter] = useState('') // 小程序配置 const [mpConfig, setMpConfig] = useState({ appId: 'wxb8bbb2b10dec74aa', apiDomain: 'https://soul.quwanzhi.com', buyerDiscount: 5, // 购买者优惠比例 referralBindDays: 30, // 推荐绑定天数 minWithdraw: 10, // 最低提现金额 }) // 功能开关配置 const [featureConfig, setFeatureConfig] = useState({ matchEnabled: true, // 找伙伴功能开关(默认开启) referralEnabled: true, // 推广功能开关 searchEnabled: true, // 搜索功能开关 aboutEnabled: true // 关于页面开关 }) // 加载配置 useEffect(() => { const loadConfig = async () => { try { const res = await fetch('/api/db/config') if (res.ok) { const data = await res.json() if (data.freeChapters) setFreeChapters(data.freeChapters) if (data.mpConfig) setMpConfig(prev => ({ ...prev, ...data.mpConfig })) if (data.features) setFeatureConfig(prev => ({ ...prev, ...data.features })) } } catch (e) { console.log('Load config error:', e) } } loadConfig() }, []) useEffect(() => { setLocalSettings({ sectionPrice: settings.sectionPrice, baseBookPrice: settings.baseBookPrice, distributorShare: settings.distributorShare, authorInfo: { ...settings.authorInfo, startDate: settings.authorInfo?.startDate || "2025年10月15日", bio: settings.authorInfo?.bio || "连续创业者,私域运营专家,每天早上6-9点在Soul派对房分享真实商业故事", }, }) }, [settings]) const handleSave = async () => { setIsSaving(true) try { updateSettings(localSettings) // 同时保存到数据库 await fetch('/api/db/settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(localSettings) }) // 保存免费章节和小程序配置 const res1 = await fetch('/api/db/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ freeChapters, mpConfig }) }) const result1 = await res1.json() console.log('保存免费章节和小程序配置:', result1) // 保存功能开关配置 const res2 = await fetch('/api/db/config', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'feature_config', config: featureConfig, description: '功能开关配置' }) }) const result2 = await res2.json() console.log('保存功能开关配置:', result2) // 验证保存结果 const verifyRes = await fetch('/api/db/config') const verifyData = await verifyRes.json() console.log('验证保存结果:', verifyData.features) // 立即更新本地状态 if (verifyData.features) { setFeatureConfig(prev => ({ ...prev, ...verifyData.features })) } alert("设置已保存!\n\n找伙伴功能:" + (verifyData.features?.matchEnabled ? "✅ 开启" : "❌ 关闭")) } catch (error) { console.error('Save settings error:', error) alert("保存失败: " + (error as Error).message) } finally { setIsSaving(false) } } // 添加免费章节 const addFreeChapter = () => { if (newFreeChapter && !freeChapters.includes(newFreeChapter)) { setFreeChapters([...freeChapters, newFreeChapter]) setNewFreeChapter('') } } // 移除免费章节 const removeFreeChapter = (chapter: string) => { setFreeChapters(freeChapters.filter(c => c !== chapter)) } return (

系统设置

配置全站基础参数与开关

{/* 作者信息 - 重点增强 */} 关于作者 配置作者信息,将在"关于作者"页面显示
setLocalSettings((prev) => ({ ...prev, authorInfo: { ...prev.authorInfo, name: e.target.value }, })) } />
setLocalSettings((prev) => ({ ...prev, authorInfo: { ...prev.authorInfo, startDate: e.target.value }, })) } />
setLocalSettings((prev) => ({ ...prev, authorInfo: { ...prev.authorInfo, liveTime: e.target.value }, })) } />
setLocalSettings((prev) => ({ ...prev, authorInfo: { ...prev.authorInfo, platform: e.target.value }, })) } />
setLocalSettings((prev) => ({ ...prev, authorInfo: { ...prev.authorInfo, description: e.target.value }, })) } />