import { useState, useEffect } from 'react'; import { readYamlConfig, updateYamlConfig } from '../../utils/yamlHelper'; import Toast from "../toast.jsx"; import { ConfigToggle } from '../common/ConfigItem'; // 定义配置项 const TIKTOK_CONFIG = { textareas: [ { key: 'douyinCookie', label: 'Cookie', placeholder: '请输入抖音Cookie...', hint: '格式:odin_tt=xxx;passport_fe_beating_status=xxx;...' } ], toggles: [ { key: 'douyinCompression', label: '视频压缩', hint: '开启后使用压缩格式,加速视频发送' }, { key: 'douyinComments', label: '显示评论', hint: '是否显示视频评论' } ] }; // 默认配置 const DEFAULT_CONFIG = { douyinCookie: '', douyinCompression: true, douyinComments: false }; export default function Tiktok() { const [config, setConfig] = useState(DEFAULT_CONFIG); const [loading, setLoading] = useState(false); useEffect(() => { const loadConfig = async () => { const yamlConfig = await readYamlConfig(); if (yamlConfig) { const newConfig = {}; Object.keys(DEFAULT_CONFIG).forEach(key => { newConfig[key] = yamlConfig[key] ?? DEFAULT_CONFIG[key]; }); setConfig(newConfig); } }; loadConfig(); }, []); const handleSave = async () => { setLoading(true); try { const success = await updateYamlConfig(config); if (success) { document.getElementById('tiktok-toast-success').classList.remove('hidden'); setTimeout(() => { document.getElementById('tiktok-toast-success').classList.add('hidden'); }, 3000); } } catch (error) { console.error('保存配置失败:', error); } finally { setLoading(false); } }; const handleConfigChange = (key, value) => { setConfig(prev => ({ ...prev, [key]: value })); }; return (