"use client"; import { useState, useEffect, useCallback } from "react"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { cloudDocConfigApi, type CloudDocConfigRead, type CloudDocConfigUpdate, } from "@/lib/api/client"; import { Loader2, Save, FileStack } from "lucide-react"; import { toast } from "sonner"; export default function SettingsCloudDocConfigPage() { const [config, setConfig] = useState(null); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [form, setForm] = useState({ feishu: { app_id: "", app_secret: "" }, yuque: { token: "", default_repo: "" }, tencent: { client_id: "", client_secret: "" }, }); const load = useCallback(async () => { setLoading(true); try { const data = await cloudDocConfigApi.get(); setConfig(data); setForm({ feishu: { app_id: data.feishu.app_id, app_secret: "" }, yuque: { token: "", default_repo: data.yuque.default_repo }, tencent: { client_id: data.tencent.client_id, client_secret: "" }, }); } catch { toast.error("加载云文档配置失败"); } finally { setLoading(false); } }, []); useEffect(() => { load(); }, [load]); const handleSave = async () => { setSaving(true); try { const payload: CloudDocConfigUpdate = {}; if (form.feishu?.app_id !== undefined) payload.feishu = { app_id: form.feishu.app_id }; if (form.feishu?.app_secret !== undefined && form.feishu.app_secret !== "") payload.feishu = { ...payload.feishu, app_secret: form.feishu.app_secret }; if (form.yuque?.token !== undefined && form.yuque.token !== "") payload.yuque = { token: form.yuque.token }; if (form.yuque?.default_repo !== undefined) payload.yuque = { ...payload.yuque, default_repo: form.yuque.default_repo }; if (form.tencent?.client_id !== undefined) payload.tencent = { client_id: form.tencent.client_id }; if (form.tencent?.client_secret !== undefined && form.tencent.client_secret !== "") payload.tencent = { ...payload.tencent, client_secret: form.tencent.client_secret }; await cloudDocConfigApi.update(payload); toast.success("已保存"); await load(); } catch (e) { toast.error(e instanceof Error ? e.message : "保存失败"); } finally { setSaving(false); } }; if (loading) { return (
加载中…
); } return (
← 设置
云文档配置

配置飞书、语雀、腾讯文档的 API 凭证,用于在工作台「推送到云文档」时创建/更新在线文档。

{/* 飞书 */}

飞书 (Feishu)

setForm((f) => ({ ...f, feishu: { ...f.feishu, app_id: e.target.value }, })) } placeholder="在飞书开放平台创建应用后获取" />
setForm((f) => ({ ...f, feishu: { ...f.feishu, app_secret: e.target.value }, })) } placeholder={config?.feishu?.app_secret_configured ? "已配置,留空不修改" : "必填"} />
{/* 语雀 */}

语雀 (Yuque)

setForm((f) => ({ ...f, yuque: { ...f.yuque, token: e.target.value }, })) } placeholder={config?.yuque?.token_configured ? "已配置,留空不修改" : "在语雀 设置 → Token 中创建"} />
setForm((f) => ({ ...f, yuque: { ...f.yuque, default_repo: e.target.value }, })) } placeholder="如:your_username/repo" />
{/* 腾讯文档 */}

腾讯文档 (Tencent)

腾讯文档需 OAuth 用户授权,当前版本仅保留配置项,推送功能请先用飞书或语雀。

setForm((f) => ({ ...f, tencent: { ...f.tencent, client_id: e.target.value }, })) } placeholder="开放平台应用 Client ID" />
setForm((f) => ({ ...f, tencent: { ...f.tencent, client_secret: e.target.value }, })) } placeholder={config?.tencent?.client_secret_configured ? "已配置,留空不修改" : "选填"} />
); }