2022-05-02 02:52:07 +00:00
|
|
|
import Clipboard from 'clipboard'
|
|
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clipboardSuccess() {
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: '复制成功',
|
|
|
|
|
type: 'success',
|
|
|
|
|
duration: 1500
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clipboardError() {
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: '复制失败',
|
|
|
|
|
type: 'error'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function handleClipboard(text, event) {
|
2022-05-07 06:28:52 +00:00
|
|
|
const clipboard:any = new Clipboard(event.target, {
|
2022-05-02 02:52:07 +00:00
|
|
|
text: () => text
|
|
|
|
|
})
|
|
|
|
|
clipboard.on('success', () => {
|
|
|
|
|
clipboardSuccess()
|
|
|
|
|
clipboard.destroy()
|
|
|
|
|
})
|
|
|
|
|
clipboard.on('error', () => {
|
|
|
|
|
clipboardError()
|
|
|
|
|
clipboard.destroy()
|
|
|
|
|
})
|
|
|
|
|
clipboard.onClick(event)
|
2022-05-07 06:28:52 +00:00
|
|
|
}
|