export function handleCopy(copyText: string) {
  const textarea = document.createElement('textarea');
  textarea.value = copyText; // 要复制的内容
  textarea.style.position = 'fixed'; // 避免页面滚动
  textarea.style.opacity = '0';     // 隐藏元素
  document.body.appendChild(textarea);

  textarea.select(); // 选中内容

  try {
    const successful = document.execCommand('copy'); // 执行复制命令
    if (successful) {
      ElMessage.info({
        dangerouslyUseHTMLString: true,
        message: `<div class="flex items-center">
                    <div class="font-medium text-ellipsis line-clamp-1" style="color: #1D2129; max-width: 300px">${ textarea.value }</div>
                    <div class="ml-2">已复制至剪切板</div>
                  </div>`,
        plain: true,
        icon: 'DocumentCopy'
      });
    } else {
      ElMessage.error({ message: '复制失败，请手动复制！', plain: true });
    }
  } catch (error) {
    ElMessage.error({ message: '复制失败，请重试！', plain: true });
    console.error('复制失败：', error);
  }

  document.body.removeChild(textarea); // 清理临时元素
}
