43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
// +----------------------------------------------------------------------
|
||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
// +----------------------------------------------------------------------
|
||
// | Author: CRMEB Team <admin@crmeb.com>
|
||
// +----------------------------------------------------------------------
|
||
|
||
import Vue from 'vue'
|
||
import Clipboard from 'clipboard'
|
||
|
||
function clipboardSuccess() {
|
||
Vue.prototype.$message({
|
||
message: 'Copy successfully',
|
||
type: 'success',
|
||
duration: 1500
|
||
})
|
||
}
|
||
|
||
function clipboardError() {
|
||
Vue.prototype.$message({
|
||
message: 'Copy failed',
|
||
type: 'error'
|
||
})
|
||
}
|
||
|
||
export default function handleClipboard(text, event) {
|
||
const clipboard = new Clipboard(event.target, {
|
||
text: () => text
|
||
})
|
||
clipboard.on('success', () => {
|
||
clipboardSuccess()
|
||
clipboard.destroy()
|
||
})
|
||
clipboard.on('error', () => {
|
||
clipboardError()
|
||
clipboard.destroy()
|
||
})
|
||
clipboard.onClick(event)
|
||
}
|