8a48765a46
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
183 lines
5.1 KiB
React
183 lines
5.1 KiB
React
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: (
|
|
<div className='flex flex-col gap-2'>
|
|
<Text>{text.desc}</Text>
|
|
{row.overseas && (
|
|
<Alert
|
|
type='warning'
|
|
showIcon
|
|
title={t(
|
|
'该项涉及数据出境(发送到境外服务),可随时撤回,撤回后立即生效。',
|
|
)}
|
|
/>
|
|
)}
|
|
{mode === 'org' && (
|
|
<Text type='secondary' className='smart-router-sub'>
|
|
{t('授权后会覆盖企业「数据安全」「不用于训练」功能的默认保护。')}
|
|
</Text>
|
|
)}
|
|
</div>
|
|
),
|
|
onOk: doIt,
|
|
});
|
|
};
|
|
|
|
if (loading)
|
|
return (
|
|
<div className='smart-router-state'>
|
|
<Spin />
|
|
</div>
|
|
);
|
|
if (error)
|
|
return (
|
|
<Alert
|
|
type='error'
|
|
showIcon
|
|
title={error}
|
|
action={
|
|
<Button size='small' onClick={load}>
|
|
{t('重试')}
|
|
</Button>
|
|
}
|
|
/>
|
|
);
|
|
const available = rows.filter((r) => r.available);
|
|
if (available.length === 0)
|
|
return (
|
|
<Empty
|
|
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
description={t('平台暂未开放需要授权的智能路由功能')}
|
|
/>
|
|
);
|
|
|
|
return (
|
|
<div className='smart-router-stack'>
|
|
{!canWrite && (
|
|
<Alert
|
|
type='info'
|
|
showIcon
|
|
title={t('企业出境同意只能由企业所有者操作。')}
|
|
/>
|
|
)}
|
|
{available.map((r) => {
|
|
const text = kindText(t, r.kind);
|
|
return (
|
|
<div key={r.kind} className='smart-router-consent-row'>
|
|
<div className='min-w-0'>
|
|
<div className='smart-router-consent-head'>
|
|
<Text strong>{text.title}</Text>
|
|
{r.overseas && (
|
|
<Tag color='warning' variant='filled'>
|
|
{t('境外处理')}
|
|
</Tag>
|
|
)}
|
|
{r.valid ? (
|
|
<Tag color='success' variant='filled'>
|
|
{t('已生效')}
|
|
</Tag>
|
|
) : r.granted ? (
|
|
<Tag color='default' variant='filled'>
|
|
{t('文案已更新,需要重新授权')}
|
|
</Tag>
|
|
) : null}
|
|
</div>
|
|
<Text type='secondary' className='smart-router-sub'>
|
|
{text.desc}
|
|
</Text>
|
|
</div>
|
|
<Switch
|
|
size='small'
|
|
checked={r.valid}
|
|
disabled={!canWrite}
|
|
onChange={(v) => toggle(r, v)}
|
|
aria-label={text.title}
|
|
/>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ConsentPanel;
|