diff --git a/common/junyi-h5-copy.js b/common/junyi-h5-copy.js new file mode 100644 index 0000000..91fff37 --- /dev/null +++ b/common/junyi-h5-copy.js @@ -0,0 +1,18 @@ +export default function 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 + +} \ No newline at end of file diff --git a/common/mixin.js b/common/mixin.js index 167e151..aba9874 100644 --- a/common/mixin.js +++ b/common/mixin.js @@ -1,3 +1,4 @@ +import h5Copy from "@/common/junyi-h5-copy.js"; export default{ data(){ return { @@ -98,6 +99,22 @@ export default{ }else{ uni.switchTab({url:'/pages/index/index'}); } + }, + $copy(orderNumber){ + // #ifdef H5 + const result = h5Copy(orderNumber); + if (result === false) { + this.$msg('当前环境不支持复制'); + } else { + this.$msg('复制成功', {icon: 'success'}) + } + // #endif + + // #ifdef MP + uni.setClipboardData({ + data: orderNumber + }); + // #endif } } } \ No newline at end of file diff --git a/pages/my/exclusiveMatch.vue b/pages/my/exclusiveMatch.vue index d6018e8..2118c1c 100644 --- a/pages/my/exclusiveMatch.vue +++ b/pages/my/exclusiveMatch.vue @@ -55,9 +55,7 @@ // 点击复制 copy(text) { if(!text) return; - uni.setClipboardData({ - data: text - }); + this.$copy(text); } } } diff --git a/pages/my/memberDetails.vue b/pages/my/memberDetails.vue index d00082f..427bcf7 100644 --- a/pages/my/memberDetails.vue +++ b/pages/my/memberDetails.vue @@ -217,13 +217,9 @@ }) }, share(){ - this.$msg('复制链接成功!') - uni.setClipboardData({ - data: 'a', - complete: () => { - console.log("aaa") - } - }); + let text = `${this.API.CALLBACKURL}/pages/my/memberDetails?id=${this.number_id}`; + this.$copy(text); + this.$msg('复制链接成功!'); } } } diff --git a/pages/my/service.vue b/pages/my/service.vue index 9522e0e..71e565e 100644 --- a/pages/my/service.vue +++ b/pages/my/service.vue @@ -58,11 +58,8 @@ }, // 点击复制 copy(text) { - // TODO H5复制有问题??? if(!text) return; - uni.setClipboardData({ - data: text - }); + this.$copy(text); } } }