From c7d08d238c22353b92d095d050ee2a0d59ce43d0 Mon Sep 17 00:00:00 2001 From: zhangmanman <994797151@qq.com> Date: Wed, 29 Sep 2021 16:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=80=E8=AF=B7=E7=A0=81=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/index.js | 8 ++--- .../junyi-h5-copy/junyi-h5-copy.js | 18 +++++++++++ pages/user/code.vue | 28 ++++++++--------- pages/user/index.vue | 30 +++++++++---------- 4 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 js_sdk/junyi-h5-copy/junyi-h5-copy/junyi-h5-copy.js diff --git a/apis/index.js b/apis/index.js index 3bb3546..d21ddd5 100644 --- a/apis/index.js +++ b/apis/index.js @@ -9,11 +9,11 @@ import store from '@/store' // 基础配置 const config = { - apiUrl : 'https://oapi.lianshang.vip/api/', - apiUrls : 'https://oapi.lianshang.vip/', + // apiUrl : 'https://oapi.lianshang.vip/api/', + // apiUrls : 'https://oapi.lianshang.vip/', - // apiUrl : 'http://api.ahxh.shangkelian.cn/api/', - // apiUrls : 'http://api.ahxh.shangkelian.cn/', + apiUrl : 'http://api.ahxh.shangkelian.cn/api/', + apiUrls : 'http://api.ahxh.shangkelian.cn/', timeout : 60000 } diff --git a/js_sdk/junyi-h5-copy/junyi-h5-copy/junyi-h5-copy.js b/js_sdk/junyi-h5-copy/junyi-h5-copy/junyi-h5-copy.js new file mode 100644 index 0000000..91fff37 --- /dev/null +++ b/js_sdk/junyi-h5-copy/junyi-h5-copy/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/pages/user/code.vue b/pages/user/code.vue index b894e89..a8aba88 100644 --- a/pages/user/code.vue +++ b/pages/user/code.vue @@ -60,6 +60,7 @@ import { userInvite } from '@/apis/interfaces/user' import { saveImageToPhotosAlbum, showToast, downloadFile } from '@/uni_modules/sakura-canvas/js_sdk/util' import Draw from '@/uni_modules/sakura-canvas/js_sdk/draw' + import h5Copy from '@/js_sdk/junyi-h5-copy/junyi-h5-copy/junyi-h5-copy' let draw = null export default { data() { @@ -96,7 +97,7 @@ async coverCode(){ // let { img, title, price, head, tips } = this let img = this.inviteData[this.codeIndex].code - let back = this.defaultImg + let back = this.inviteData[this.codeIndex].cover let name = this.inviteData[this.codeIndex].user_info.nickname let invite = this.inviteData[this.codeIndex].invite let avatar = this.inviteData[this.codeIndex].user_info.avatar || '/static/user/user-portrait.png' @@ -270,20 +271,17 @@ // 复制邀请码 copyCenter(e) { let copyNo = e - uni.vibrateShort({ - success: () => { - uni.setClipboardData({ - data : copyNo, - success : res=> { - uni.showToast({ - title : '复制成功', - icon :'none', - duration: 3000 - }); - } - }) - } - }) + const result = h5Copy(copyNo) + if (result === false) { + uni.showToast({ + title:'不支持', + }) + } else { + uni.showToast({ + title:'复制成功', + icon:'none' + }) + } }, // 切换海报背景index diff --git a/pages/user/index.vue b/pages/user/index.vue index 73d57c1..7a07cd2 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -28,7 +28,7 @@ - + @@ -252,6 +252,7 @@