feat: 修复企业凭证复制并优化弹窗底部间距

This commit is contained in:
zhanjunhao
2026-11-02 11:06:28 +08:00
parent d14a517fdc
commit 399a3d7907
3 changed files with 24 additions and 21 deletions
+8 -11
View File
@@ -21,6 +21,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Button, Toast, Banner } from '@douyinfe/semi-ui'; import { Button, Toast, Banner } from '@douyinfe/semi-ui';
import { Copy } from 'lucide-react'; import { Copy } from 'lucide-react';
import { copy as copyText } from '../../helpers/utils';
/** /**
* 企业建号一次性凭证展示面板(注册自助建号 / 管理员建号复用)。 * 企业建号一次性凭证展示面板(注册自助建号 / 管理员建号复用)。
@@ -34,11 +35,12 @@ const OrgCredentialResult = ({ creds, onLogin }) => {
const isPending = creds.status === 'pending'; const isPending = creds.status === 'pending';
const copy = (val) => { const copy = async (val) => {
navigator.clipboard if (await copyText(val)) {
.writeText(val) Toast.success(t('已复制到剪贴板'));
.then(() => Toast.success(t('已复制到剪贴板'))) } else {
.catch(() => Toast.error(t('复制失败,请手动复制'))); Toast.error(t('复制失败,请手动复制'));
}
}; };
// 四项凭证拼成带标签的文本块一次复制,避免逐项复制的遗漏(如只记了密码没记企业代码) // 四项凭证拼成带标签的文本块一次复制,避免逐项复制的遗漏(如只记了密码没记企业代码)
@@ -96,12 +98,7 @@ const OrgCredentialResult = ({ creds, onLogin }) => {
<Row label={t('登录名')} value={creds.owner_login_name} mono /> <Row label={t('登录名')} value={creds.owner_login_name} mono />
<Row label={t('初始密码')} value={creds.initial_password} mono /> <Row label={t('初始密码')} value={creds.initial_password} mono />
</div> </div>
<Button <Button size='large' block icon={<Copy size={14} />} onClick={copyAll}>
size='large'
block
icon={<Copy size={14} />}
onClick={copyAll}
>
{t('复制全部凭证')} {t('复制全部凭证')}
</Button> </Button>
{onLogin && ( {onLogin && (
+15 -10
View File
@@ -104,28 +104,33 @@ export function getUserIdFromLocalStorage() {
} }
export async function copy(text) { export async function copy(text) {
let okay = true;
try { try {
await navigator.clipboard.writeText(text); await navigator.clipboard.writeText(text);
} catch (e) { return true;
} catch {
let textarea;
const activeElement = document.activeElement;
try { try {
// 构建 textarea 执行复制命令,保留多行文本格式 // 构建 textarea 执行复制命令,保留多行文本格式
const textarea = window.document.createElement('textarea'); textarea = window.document.createElement('textarea');
textarea.value = text; textarea.value = text;
textarea.setAttribute('readonly', ''); textarea.setAttribute('readonly', '');
textarea.style.position = 'fixed'; textarea.style.position = 'fixed';
textarea.style.left = '-9999px'; textarea.style.left = '-9999px';
textarea.style.top = '-9999px'; textarea.style.top = '-9999px';
window.document.body.appendChild(textarea); // Keep the selection inside a modal's focus trap when copying credentials.
const container =
activeElement?.closest('[role="dialog"]') || document.body;
container.appendChild(textarea);
textarea.select(); textarea.select();
window.document.execCommand('copy'); return window.document.execCommand('copy');
window.document.body.removeChild(textarea); } catch {
} catch (e) { return false;
okay = false; } finally {
console.error(e); textarea?.remove();
activeElement?.focus({ preventScroll: true });
} }
} }
return okay;
} }
// isMobile 函数已移除,请改用 useIsMobile Hook // isMobile 函数已移除,请改用 useIsMobile Hook
+1
View File
@@ -1154,6 +1154,7 @@ const AdminOrganizations = () => {
confirmLoading={createLoading} confirmLoading={createLoading}
{...(createCredentialResult ? { footer: null } : {})} {...(createCredentialResult ? { footer: null } : {})}
bodyStyle={{ bodyStyle={{
...(createCredentialResult ? { paddingBottom: 24 } : {}),
maxHeight: 'calc(100vh - 200px)', maxHeight: 'calc(100vh - 200px)',
overflowY: 'auto', overflowY: 'auto',
overscrollBehavior: 'contain', overscrollBehavior: 'contain',