Skip to main content

复制文本

/** * 复制文本至剪切板 (兼容方案) * @param text */export function copyTextToClipboard(text: string) {  return new Promise((resolve, reject) => {    const textArea = document.createElement('textarea')    textArea.value = text    textArea.style.width = '0'    textArea.style.height = '0'    textArea.style.zIndex = '-1'    textArea.style.position = 'fixed' // 避免滚动到底部    document.body.appendChild(textArea)    textArea.focus()    textArea.select()
    try {      const successful = document.execCommand('copy')      if (successful) {        resolve(void 0)      } else {        reject()      }    } catch (err) {      reject()      console.error('Fallback: Oops, unable to copy', err)    }
    document.body.removeChild(textArea)  })}