From 7cfcc51296157bab92dc79979b812f41a725ff1a Mon Sep 17 00:00:00 2001
From: zhanjunhao <642307404@qq.com>
Date: Mon, 2 Nov 2026 11:06:28 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E4=BC=81=E4=B8=9A?=
=?UTF-8?q?=E5=87=AD=E8=AF=81=E5=A4=8D=E5=88=B6=E5=B9=B6=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E5=BC=B9=E7=AA=97=E5=BA=95=E9=83=A8=E9=97=B4=E8=B7=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/auth/OrgCredentialResult.jsx | 19 +++++++---------
src/helpers/utils.jsx | 25 ++++++++++++---------
src/pages/AdminOrganizations/index.jsx | 1 +
3 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/src/components/auth/OrgCredentialResult.jsx b/src/components/auth/OrgCredentialResult.jsx
index bf2b504e..de60bbe9 100644
--- a/src/components/auth/OrgCredentialResult.jsx
+++ b/src/components/auth/OrgCredentialResult.jsx
@@ -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 }) => {
- }
- onClick={copyAll}
- >
+ } onClick={copyAll}>
{t('复制全部凭证')}
{onLogin && (
diff --git a/src/helpers/utils.jsx b/src/helpers/utils.jsx
index b1c97d35..a4f1ca68 100644
--- a/src/helpers/utils.jsx
+++ b/src/helpers/utils.jsx
@@ -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
diff --git a/src/pages/AdminOrganizations/index.jsx b/src/pages/AdminOrganizations/index.jsx
index 8636ec44..c1769725 100644
--- a/src/pages/AdminOrganizations/index.jsx
+++ b/src/pages/AdminOrganizations/index.jsx
@@ -1154,6 +1154,7 @@ const AdminOrganizations = () => {
confirmLoading={createLoading}
{...(createCredentialResult ? { footer: null } : {})}
bodyStyle={{
+ ...(createCredentialResult ? { paddingBottom: 24 } : {}),
maxHeight: 'calc(100vh - 200px)',
overflowY: 'auto',
overscrollBehavior: 'contain',