e7a7541b2b
补齐历史缺译并统一整句插值。九语覆盖 100%,静态检查及 713 项单测通过。
215 lines
7.5 KiB
React
215 lines
7.5 KiB
React
/*
|
|
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 { Trans } from 'react-i18next';
|
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
import { Button, Card, Empty, Tag, Typography } from 'antd';
|
|
import { Cable, LockKeyhole } from 'lucide-react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { API } from '../../helpers/api';
|
|
import {
|
|
usePageGuide,
|
|
PageGuideDrawer,
|
|
PageGuideTrigger,
|
|
} from '../../components/common/PageGuide';
|
|
import OrgPageHeader from './components/OrgPageHeader';
|
|
import './org-my-capabilities.css';
|
|
|
|
const confirmationLabels = {
|
|
never: '无需确认',
|
|
write: '写操作前确认',
|
|
always: '每次调用都确认',
|
|
};
|
|
|
|
const OrgMyConnectors = ({ orgId }) => {
|
|
const { t } = useTranslation();
|
|
const headers = useMemo(() => ({ 'X-Org-Id': String(orgId) }), [orgId]);
|
|
const [items, setItems] = useState([]);
|
|
const [loadError, setLoadError] = useState('');
|
|
|
|
useEffect(() => {
|
|
let active = true;
|
|
API.get('/api/org/connectors/mine', { headers, skipErrorHandler: true })
|
|
.then((response) => {
|
|
if (!active) return;
|
|
if (response.data?.success) {
|
|
setItems(response.data.data || []);
|
|
setLoadError('');
|
|
} else {
|
|
// A failed load must not masquerade as "no authorizations".
|
|
setLoadError(response.data?.message || t('授权列表加载失败'));
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
if (active)
|
|
setLoadError(
|
|
error?.response?.data?.message ||
|
|
error?.message ||
|
|
t('授权列表加载失败'),
|
|
);
|
|
});
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, [headers, t]);
|
|
|
|
// 使用指引:成员视角的阅读式说明(无上手流程,不出进度胶囊)。
|
|
const guide = usePageGuide({
|
|
guideKey: 'org-my-connectors',
|
|
title: t('我的业务系统授权 · 使用指引'),
|
|
intro: t('这里列出专家在任务中可以代表你调用的业务系统与边界'),
|
|
steps: [
|
|
{
|
|
title: t('看懂授权卡片'),
|
|
detail: t('一张卡片对应一个已授权的业务系统连接器'),
|
|
points: [
|
|
t('右上角标签是访问级别:read 只读,write 可执行写操作'),
|
|
t('卡片中的标签列出专家可调用的具体方法'),
|
|
],
|
|
},
|
|
{
|
|
title: t('理解确认策略'),
|
|
detail: t('确认策略决定哪些调用执行前需要你亲自确认'),
|
|
points: [
|
|
t('never 无需确认;write 写操作前确认;always 每次调用都确认'),
|
|
],
|
|
},
|
|
{
|
|
title: t('任务中的确认操作'),
|
|
detail: t('确认动作发生在云端大脑的任务详情页'),
|
|
points: [
|
|
t('专家发起调用时任务会停在「等待操作确认」'),
|
|
t('展开「查看冻结参数」核对操作内容,填写原因后确认或拒绝'),
|
|
t('长时间不处理会确认超时,任务按已发生用量结算'),
|
|
],
|
|
},
|
|
{
|
|
title: t('需要调整授权'),
|
|
detail: t('授权由企业管理员统一发布与撤销'),
|
|
points: [t('缺少某个系统的授权或范围不足时,请联系企业管理员')],
|
|
},
|
|
],
|
|
faq: [
|
|
{
|
|
q: t('列表是空的?'),
|
|
a: t('管理员发布授权并覆盖到你之后才会显示,请联系企业管理员'),
|
|
},
|
|
{
|
|
q: t('「企业服务账号由管理员管理」是什么意思?'),
|
|
a: t('该连接器以企业级凭据运行,个人无法自行撤销'),
|
|
},
|
|
],
|
|
});
|
|
return (
|
|
<main className='uc-page org-capabilities-page'>
|
|
<OrgPageHeader
|
|
title={t('我的业务系统授权')}
|
|
subtitle={t('查看专家在任务中可代表你调用的业务系统、方法和确认策略。')}
|
|
actions={<PageGuideTrigger guide={guide} />}
|
|
/>
|
|
<PageGuideDrawer guide={guide} />
|
|
{loadError ? (
|
|
<Card>
|
|
<Empty
|
|
description={
|
|
<>
|
|
<Typography.Text>{t('授权列表加载失败')}</Typography.Text>
|
|
<Typography.Paragraph type='secondary'>
|
|
{loadError}
|
|
</Typography.Paragraph>
|
|
</>
|
|
}
|
|
/>
|
|
</Card>
|
|
) : items.length === 0 ? (
|
|
<Card>
|
|
<Empty
|
|
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
description={
|
|
<>
|
|
<Typography.Text>
|
|
{t('当前没有 Connector 授权')}
|
|
</Typography.Text>
|
|
<Typography.Paragraph type='secondary'>
|
|
{t('管理员发布授权并覆盖到你后会显示在这里。')}
|
|
</Typography.Paragraph>
|
|
</>
|
|
}
|
|
/>
|
|
</Card>
|
|
) : (
|
|
<section className='org-capability-grid'>
|
|
{items.map((item) => (
|
|
<Card className='org-capability-card' key={item.grant.id}>
|
|
<div className='org-capability-card-head'>
|
|
<span className='org-capability-icon'>
|
|
<Cable size={20} />
|
|
</span>
|
|
<div className='org-capability-card-name'>
|
|
<Typography.Title level={5}>
|
|
{item.connector_name}
|
|
</Typography.Title>
|
|
<Typography.Text type='secondary'>
|
|
{item.definition_name}
|
|
</Typography.Text>
|
|
</div>
|
|
<Tag
|
|
color={
|
|
item.grant.access_level === 'write' ? 'orange' : 'green'
|
|
}
|
|
>
|
|
{item.grant.access_level}
|
|
</Tag>
|
|
</div>
|
|
<div className='org-capability-methods'>
|
|
{item.methods.map((method) => (
|
|
<Tag key={method}>{method}</Tag>
|
|
))}
|
|
</div>
|
|
<div className='org-capability-confirmation'>
|
|
<LockKeyhole size={14} aria-hidden='true' />
|
|
<Typography.Text type='secondary'>
|
|
<Trans
|
|
t={t}
|
|
i18nKey='确认策略: {{label}}'
|
|
values={{
|
|
label: t(
|
|
confirmationLabels[item.grant.confirmation_policy] ||
|
|
item.grant.confirmation_policy,
|
|
),
|
|
}}
|
|
/>
|
|
</Typography.Text>
|
|
</div>
|
|
<div className='org-capability-card-footer'>
|
|
<Button disabled={!item.revocable}>
|
|
{item.revocable
|
|
? t('撤销个人委托')
|
|
: t('企业服务账号由管理员管理')}
|
|
</Button>
|
|
</div>
|
|
</Card>
|
|
))}
|
|
</section>
|
|
)}
|
|
</main>
|
|
);
|
|
};
|
|
|
|
export default OrgMyConnectors;
|