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

This commit is contained in:
zhanjunhao
2026-11-02 11:06:28 +08:00
parent 5bd2b3405d
commit 21d64e43ce
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 { Button, Toast, Banner } from '@douyinfe/semi-ui';
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 copy = (val) => {
navigator.clipboard
.writeText(val)
.then(() => Toast.success(t('已复制到剪贴板')))
.catch(() => Toast.error(t('复制失败,请手动复制')));
const copy = async (val) => {
if (await copyText(val)) {
Toast.success(t('已复制到剪贴板'));
} else {
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.initial_password} mono />
</div>
<Button
size='large'
block
icon={<Copy size={14} />}
onClick={copyAll}
>
<Button size='large' block icon={<Copy size={14} />} onClick={copyAll}>
{t('复制全部凭证')}
</Button>
{onLogin && (
+15 -10
View File
@@ -104,28 +104,33 @@ export function getUserIdFromLocalStorage() {
}
export async function copy(text) {
let okay = true;
try {
await navigator.clipboard.writeText(text);
} catch (e) {
return true;
} catch {
let textarea;
const activeElement = document.activeElement;
try {
// 构建 textarea 执行复制命令,保留多行文本格式
const textarea = window.document.createElement('textarea');
textarea = window.document.createElement('textarea');
textarea.value = text;
textarea.setAttribute('readonly', '');
textarea.style.position = 'fixed';
textarea.style.left = '-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();
window.document.execCommand('copy');
window.document.body.removeChild(textarea);
} catch (e) {
okay = false;
console.error(e);
return window.document.execCommand('copy');
} catch {
return false;
} finally {
textarea?.remove();
activeElement?.focus({ preventScroll: true });
}
}
return okay;
}
// isMobile 函数已移除,请改用 useIsMobile Hook
+1
View File
@@ -1154,6 +1154,7 @@ const AdminOrganizations = () => {
confirmLoading={createLoading}
{...(createCredentialResult ? { footer: null } : {})}
bodyStyle={{
...(createCredentialResult ? { paddingBottom: 24 } : {}),
maxHeight: 'calc(100vh - 200px)',
overflowY: 'auto',
overscrollBehavior: 'contain',