import React, { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Alert, Button, Empty, Modal, Spin, Switch, Tag, Typography, } from 'antd'; import { showError, showSuccess } from '../../helpers'; import { getConsents, updateConsent } from './api'; const { Text } = Typography; const kindText = (t, kind) => ({ judge: { title: t('智能判定'), desc: t( '把脱敏、截断后的请求片段发送给境外判定服务(Jev),用于选择合适的模型。', ), }, eval: { title: t('质量打分'), desc: t( '把脱敏、截断后的请求与回答片段发送给境外判定服务,用于质量评估。', ), }, shadow: { title: t('影子评审'), desc: t('把正式脱敏后的请求发送给基线模型和评审模型,用于对比质量。'), }, replay: { title: t('回放留存'), desc: t('把脱敏后的请求加密留存最多 90 天,用于离线评估。'), }, })[kind] || { title: kind, desc: '' }; // 同意记录(§9.5)。企业同意只能由真实的企业所有者操作。 // onChange:授权状态变化后回调最新列表(企业中心"仅授权模式"据此刷新入口) const ConsentPanel = ({ mode, orgId, canWrite = true, onChange }) => { const { t } = useTranslation(); const [rows, setRows] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const load = useCallback(async () => { setLoading(true); setError(''); try { setRows((await getConsents(mode, orgId)) || []); } catch (e) { setError(e?.message || t('加载失败')); } finally { setLoading(false); } }, [mode, orgId, t]); useEffect(() => { load(); }, [load]); const toggle = (row, granted) => { const text = kindText(t, row.kind); const doIt = async () => { try { const next = await updateConsent(mode, orgId, row.kind, granted); setRows(next); onChange?.(next); showSuccess(granted ? t('已授权') : t('已撤回')); } catch (e) { if (e?.message) showError(e.message); load(); // 写入可能已成功、只是回读失败:重新拉取,避免开关停在旧状态 } }; if (!granted) return doIt(); Modal.confirm({ title: `${t('确认授权')} · ${text.title}`, content: (