"use client"; import { useState, useEffect } from "react"; import { useToast } from "@/components/ui/toast"; import { Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; interface ExportConfig { untranslatedColor: string; secondPageHeader: boolean; orientation: "portrait" | "landscape"; } const defaultExportConfig: ExportConfig = { untranslatedColor: "CC0000", secondPageHeader: false, orientation: "landscape", }; export default function ExportPage() { const [config, setConfig] = useState(defaultExportConfig); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const { addToast } = useToast(); useEffect(() => { fetch("/api/config") .then((res) => res.json()) .then((result) => { if (result.success && result.data) { setConfig({ untranslatedColor: result.data.export?.untranslatedColor || defaultExportConfig.untranslatedColor, secondPageHeader: result.data.export?.secondPageHeader ?? defaultExportConfig.secondPageHeader, orientation: result.data.export?.orientation || defaultExportConfig.orientation, }); } }) .catch(console.error) .finally(() => setLoading(false)); }, []); const handleSave = async () => { setSaving(true); try { const response = await fetch("/api/config", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ export: config }), }); const result = await response.json(); if (result.success) { addToast({ type: "success", title: "导出设置已保存" }); } else { addToast({ type: "error", title: "保存失败", description: result.error }); } } catch { addToast({ type: "error", title: "保存失败" }); } finally { setSaving(false); } }; if (loading) { return (

导出设置

配置导出 Word 文档的格式

); } return (

导出设置

配置导出 Word 文档的格式

{/* 未翻译文本颜色 */}

文本颜色

setConfig({ ...config, untranslatedColor: e.target.value.toUpperCase() })} className="h-10 w-20 cursor-pointer rounded-md border border-input" /> { const val = e.target.value.toUpperCase(); if (/^[0-9A-Fa-f]{0,6}$/.test(val)) { setConfig({ ...config, untranslatedColor: val }); } }} className="w-24 rounded-md border border-input bg-background px-3 py-2 text-sm font-mono" placeholder="CC0000" /> HEX 颜色值(如 CC0000)
{/* 页面设置 */}

页面设置

启用后,如果内容超过一页,第二页及后续页面会在顶部显示表头行

{/* 预览 */}

预览

未翻译示例: 宫保鸡丁
页面方向: {config.orientation === "landscape" ? "横向 (Landscape)" : "纵向 (Portrait)"}
第二页表头: {config.secondPageHeader ? "启用" : "禁用"}
); }