const copyText = (textToCopy) => {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard
.writeText(textToCopy)
.then(() => {
Message.success('复制成功')
})
.catch(() => {
Message.error('复制失败')
})
} else {
const textArea = document.createElement('textarea')
textArea.value = textToCopy
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
return new Promise((resolve, reject) => {
document.execCommand('copy') ? resolve() : reject(new Error('出错了'))
textArea.remove()
}).then(
() => {
Message.success('复制成功')
},
() => {
Message.error('复制失败')
},
)
}
}