Files
FirstUI-vue/components/firstui/fui-clipboard/index.js
2023-08-17 21:28:49 +08:00

52 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 本文件由FirstUI授权予新疆天衡创新研究院有限公司手机号 18 6 14 0 725 4 9身份证尾号5A07X5专用请尊重知识产权勿私下传播违者追究法律责任。
/*!
* 剪贴板
*
* 官网地址https://firstui.cn/
* 文档地址https://doc.firstui.cn/
*/
// #ifdef H5
import ClipboardJS from "./clipboard.min.js"
// #endif
/**
* data 需要复制的数据
* callback 回调
* e 当用户点击后需要先请求接口再进行复制时需要传入此参数H5端
* **/
const getClipboardData = function(data, callback, e) {
// #ifdef APP-PLUS || MP
uni.setClipboardData({
data: data,
success(res) {
("function" == typeof callback) && callback(true)
},
fail(res) {
("function" == typeof callback) && callback(false)
}
})
// #endif
// #ifdef H5
let event =window.event || e || {}
let clipboard = new ClipboardJS("", {
text: () => data
})
clipboard.on('success', (e) => {
("function" == typeof callback) && callback(true)
clipboard.off('success')
clipboard.off('error')
clipboard.destroy()
});
clipboard.on('error', (e) => {
("function" == typeof callback) && callback(false)
clipboard.off('success')
clipboard.off('error')
clipboard.destroy()
});
clipboard.onClick(event)
// #endif
}
export default {
getClipboardData: getClipboardData
};