function FallbackCopyTextToClipboard(text) {
return new Promise((resolve, reject) => {
const textArea = document.createElement('textarea');
// 设置样式确保不可见但可选中
textArea.style.position = 'fixed';
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = '0';
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
textArea.style.opacity = '0';
textArea.value = text;
document.body.appendChild(textArea);
// 选中文本
textArea.select();
textArea.setSelectionRange(0, textArea.value.length);
try {
// 尝试执行复制命令
const successful = document.execCommand('copy');
document.body.removeChild(textArea);
if (successful) {
resolve(true);
} else {
reject(new Error('复制失败'));
}
} catch (err) {
document.body.removeChild(textArea);
reject(err);
}
});
}