2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
107 lines
3.5 KiB
React
107 lines
3.5 KiB
React
import { Copy as ActionCopy } from '@/components/common/icons/ActionIcons';
|
||
import React from 'react';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { Button, Toast, Banner } from '@/components/ui';
|
||
import { copy as copyText } from '../../helpers/utils';
|
||
|
||
/**
|
||
* 企业建号一次性凭证展示面板(注册自助建号 / 管理员建号复用)。
|
||
* props:
|
||
* creds: { status?, org_code, org_name, owner_login_name, initial_password }
|
||
* onLogin?: () => void 存在时展示「立即登录」按钮
|
||
*/
|
||
const OrgCredentialResult = ({ creds, onLogin }) => {
|
||
const { t } = useTranslation();
|
||
if (!creds) return null;
|
||
|
||
const isPending = creds.status === 'pending';
|
||
|
||
// 走公共 copy:HTTP 部署下 navigator.clipboard 为 undefined,直接调用会同步抛错、点了无反应
|
||
const copy = async (val) => {
|
||
if (await copyText(val)) {
|
||
Toast.success(t('已复制到剪贴板'));
|
||
} else {
|
||
Toast.error(t('复制失败,请手动复制'));
|
||
}
|
||
};
|
||
|
||
// 四项凭证拼成带标签的文本块一次复制,避免逐项复制的遗漏(如只记了密码没记企业代码)
|
||
const copyAll = () => {
|
||
copy(
|
||
[
|
||
`${t('企业代码')}: ${creds.org_code}`,
|
||
`${t('企业名称')}: ${creds.org_name}`,
|
||
`${t('登录名')}: ${creds.owner_login_name}`,
|
||
`${t('初始密码')}: ${creds.initial_password}`,
|
||
].join('\n'),
|
||
);
|
||
};
|
||
|
||
const Row = ({ label, value, mono }) => (
|
||
<div className='flex items-center justify-between gap-2 py-2 border-b border-gray-100 dark:border-white/[0.06] last:border-0'>
|
||
<span className='text-xs text-gray-500 dark:text-gray-400 shrink-0'>
|
||
{label}
|
||
</span>
|
||
<div className='flex items-center gap-1.5 min-w-0'>
|
||
<span
|
||
className={`truncate text-sm text-gray-800 dark:text-gray-100 ${mono ? 'font-mono' : ''}`}
|
||
>
|
||
{value}
|
||
</span>
|
||
<Button
|
||
size='small'
|
||
theme='borderless'
|
||
icon={<ActionCopy size={14} />}
|
||
onClick={() => copy(value)}
|
||
aria-label={t('复制')}
|
||
/>
|
||
</div>
|
||
</div>
|
||
);
|
||
|
||
return (
|
||
<div className='flex flex-col gap-3'>
|
||
<Banner
|
||
type={isPending ? 'info' : 'warning'}
|
||
closeIcon={null}
|
||
description={
|
||
isPending
|
||
? t(
|
||
'企业已提交,待平台审核通过后即可用以下凭证登录。请立即保存初始密码,此信息仅显示一次。',
|
||
)
|
||
: t(
|
||
'请立即保存以下凭证并交付管理员。初始密码仅显示一次,关闭后无法再次查看。',
|
||
)
|
||
}
|
||
/>
|
||
<div className='rounded-xl border border-gray-200/80 dark:border-white/[0.1] bg-white/60 dark:bg-white/[0.04] px-4'>
|
||
<Row label={t('企业代码')} value={creds.org_code} mono />
|
||
<Row label={t('企业名称')} value={creds.org_name} />
|
||
<Row label={t('登录名')} value={creds.owner_login_name} mono />
|
||
<Row label={t('初始密码')} value={creds.initial_password} mono />
|
||
</div>
|
||
<Button
|
||
size='large'
|
||
block
|
||
icon={<ActionCopy size={14} />}
|
||
onClick={copyAll}
|
||
>
|
||
{t('复制全部凭证')}
|
||
</Button>
|
||
{onLogin && (
|
||
<Button
|
||
theme='solid'
|
||
size='large'
|
||
block
|
||
onClick={onLogin}
|
||
disabled={isPending}
|
||
>
|
||
{isPending ? t('待审核通过后可登录') : t('立即登录')}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default OrgCredentialResult;
|