/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ // 系统设置 →「WeyAi」→「版本说明」:每个 WeyAi 桌面版本的更新概要(Markdown)。 // 发布后,WeyAi 的「关于」页显示当前版本和历史版本的说明,发现新版本时的更新卡片 // 也会带上这里写的内容。客户端读公开接口 GET /api/weyai/desktop/release-notes, // 未登录也能看到;草稿只在这里可见。root 和被下放了「WeyAi」页签的管理员都能用。 import React, { useCallback, useEffect, useState } from 'react'; import { Banner, Button, DatePicker, Empty, Input, Modal, Popconfirm, Space, Switch, Table, TabPane, Tabs, Tag, TextArea, Typography, } from '@/components/ui'; import { useTranslation } from 'react-i18next'; import { API, showError, showSuccess } from '../../../helpers'; import MarkdownRenderer from '../../../components/common/markdown/MarkdownRenderer'; const { Text } = Typography; const BASE = '/api/admin/weyai/release-notes'; const EMPTY_DRAFT = { id: 0, version: '', title: '', content: '', prerelease: false, released_at: 0, }; const contentPlaceholder = (t) => `### ${t('新功能')} - ### ${t('改进')} - ### ${t('修复')} - `; const formatDate = (sec) => sec ? new Date(sec * 1000).toLocaleDateString() : ''; const SettingsWeyAiReleaseNotes = () => { const { t } = useTranslation(); const [notes, setNotes] = useState([]); const [loading, setLoading] = useState(false); const [busyId, setBusyId] = useState(0); const [draft, setDraft] = useState(null); const [saving, setSaving] = useState(false); const load = useCallback(async () => { const res = await API.get(BASE, { skipErrorHandler: true }); if (!res?.data?.success) { throw new Error(res?.data?.message || t('加载失败,请重试')); } setNotes(res.data.data || []); }, [t]); useEffect(() => { setLoading(true); load() .catch((e) => showError(e.message)) .finally(() => setLoading(false)); }, [load]); const call = async (id, request, successText) => { setBusyId(id); try { const res = await request(); if (!res?.data?.success) { showError(res?.data?.message || t('操作失败,请重试')); return; } showSuccess(successText); await load(); } catch (err) { showError(err?.response?.data?.message || t('操作失败,请重试')); } finally { setBusyId(0); } }; const setStatus = (note, status) => call( note.id, () => API.post( `${BASE}/${note.id}/status`, { status }, { skipErrorHandler: true }, ), status === 'published' ? t('已发布') : t('已撤回为草稿'), ); const remove = (note) => call( note.id, () => API.delete(`${BASE}/${note.id}`, { skipErrorHandler: true }), t('已删除'), ); const save = async () => { if (!draft) return; setSaving(true); try { const body = { version: draft.version, title: draft.title, content: draft.content, prerelease: draft.prerelease, released_at: draft.released_at, }; const res = draft.id ? await API.put(`${BASE}/${draft.id}`, body, { skipErrorHandler: true }) : await API.post(BASE, body, { skipErrorHandler: true }); if (!res?.data?.success) { showError(res?.data?.message || t('保存失败,请重试')); return; } showSuccess( draft.id ? t('保存成功') : t('已保存为草稿,确认无误后点「发布」'), ); setDraft(null); await load(); } catch (err) { showError(err?.response?.data?.message || t('保存失败,请重试')); } finally { setSaving(false); } }; const columns = [ { title: t('版本'), width: 160, render: (_, note) => ( v{note.version} {note.prerelease && ( {t('预发布')} )} ), }, { title: t('标题'), render: (_, note) => note.title || —, }, { title: t('状态'), width: 100, render: (_, note) => note.status === 'published' ? ( {t('已发布')} ) : ( {t('草稿')} ), }, { title: t('发布日期'), width: 130, render: (_, note) => formatDate(note.released_at) || —, }, { title: t('操作'), width: 240, render: (_, note) => ( {note.status === 'published' ? ( ) : ( )} remove(note)} > ), }, ]; return (
} /> setDraft(null)} onOk={save} okText={t('保存')} confirmLoading={saving} maskClosable={false} > {draft && (
setDraft({ ...draft, version, // 1.2.3-beta.1 → 1.2.3: the pre-release mark came from the suffix, drop it prerelease: draft.version.includes('-') && !version.includes('-') ? false : draft.prerelease, }) } /> setDraft({ ...draft, // Local noon: the same calendar day in every time zone within ±12 h. released_at: date ? Math.floor(new Date(date).setHours(12, 0, 0, 0) / 1000) : 0, }) } /> setDraft({ ...draft, prerelease })} /> {t('预发布版本')}
setDraft({ ...draft, title })} />