sync: 同步 monkey-ai@weiyuan(ddc5b9443) 的 web/ 到 ui-optimization
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user