feat: 修复企业凭证复制并优化弹窗底部间距
This commit is contained in:
+15
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user