提交 dff50832 编写于 作者: 北巷晴's avatar 北巷晴

h5复制功能

上级 1d17e18c
......@@ -6,52 +6,80 @@ Vue.mixin({
userInfo: {
nickname: "游客",
portrait: "/static/missing-face.png",
phone: "欢迎您!",
walletaddress:""
phone: "欢迎您!",
walletaddress: ""
},
}
},
methods: {
methods: {
//跳转
navTo(url) {
uni.navigateTo({
url
});
},
},
//返回带刷新
back() {
uni.$emit('refreshData');
uni.navigateBack({
delta: 1
})
},
// 复制功能
copyConnection(getData) {
var _this = this;
// #ifndef H5
uni.getClipboardData({
success: function(res) {
console.log(res.data);
}
})
uni.setClipboardData({
data: getData,
success: function() {
uni.showToast({
icon: 'success',
title: "复制成功",
duration: 2000,
});
}
})
// #endif
},
// 数字前面补零
seqid00000(num, length) {
for (var len = (num + "").length; len < length; len = num.length) {
num = "0" + num;
}
return num;
},
// 复制功能
copyConnection(getData) {
var _this = this;
// #ifndef H5
uni.getClipboardData({
success: function(res) {
console.log(res.data);
}
})
uni.setClipboardData({
data: getData,
success: function() {
uni.showToast({
icon: 'success',
title: "复制成功",
duration: 2000,
});
}
})
// #endif
//#ifdef H5
const result = this.h5Copy(getData)
if (result === false) {
uni.showToast({
title: '不支持',
})
} else {
uni.showToast({
title: '复制成功',
icon: 'none'
})
}
// #endif
},
// 数字前面补零
seqid00000(num, length) {
for (var len = (num + "").length; len < length; len = num.length) {
num = "0" + num;
}
return num;
},
h5Copy(content) {
if (!document.queryCommandSupported('copy')) {
// 不支持
return false
}
let textarea = document.createElement("textarea")
textarea.value = content
textarea.readOnly = "readOnly"
document.body.appendChild(textarea)
textarea.select() // 选择对象
textarea.setSelectionRange(0, content.length) //核心
let result = document.execCommand("copy") // 执行浏览器复制命令
textarea.remove()
return result
}
}
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册