123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /**
- * 复制文本 兼容H5
- * 来自 ThorUI www.thorui.cn | 文档地址: www.donarui.com
- * @author echo.
- * @version 1.0.0
- **/
- // #ifdef H5
- import ClipboardJS from "@/lib/clipboard.min.js"
- // #endif
- const thorui = {
- getClipboardData: function(data, callback) {
- // #ifdef APP-PLUS || MP
- uni.setClipboardData({
- data: data,
- success(res) {
- uni.getClipboardData({
- success(res) {
- ("function" == typeof callback) && callback(true)
- uni.showToast({title:'复制成功',icon:'none'})
- },
- fail(res) {
- ("function" == typeof callback) && callback(false)
- uni.showToast({title:'复制失败',icon:'none'})
- }
- })
- },
- fail(res) {
- ("function" == typeof callback) && callback(false)
- }
- })
- // #endif
- // #ifdef H5
- let event = window.event || {}
- 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
- }
- };
- module.exports = {
- getClipboardData: thorui.getClipboardData
- };
|