From 65b78ebdaa7a05d24bc7aba11e637b3dfb90d37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E7=8E=B2?= <8702040+cai-ling@user.noreply.gitee.com> Date: Thu, 5 Dec 2024 16:30:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SearchBox.vue | 44 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/components/SearchBox.vue b/components/SearchBox.vue index 59ea49f..faddd80 100644 --- a/components/SearchBox.vue +++ b/components/SearchBox.vue @@ -11,7 +11,7 @@ @confirm="handleSend"> - + @@ -50,7 +50,49 @@ if (e.target.value.length) { this.$emit('handleChange', e.target.value) } + }, + async toScan() { + // #ifdef APP-PLUS + let status = await this.checkPermission(); + if (status !== 1) { + return; + } + // #endif + uni.scanCode({ + success: (res) => { + this.$emit('input', res.result) + this.$emit('handleChange', res.result) + }, + fail: (err) => { + // uni.showToast({ + // title: '出错', + // icon: 'none' + // }) + } + }); } + // #ifdef APP-PLUS + , + async checkPermission(code) { + let status = permision.isIOS ? await permision.requestIOS('camera') : + await permision.requestAndroid('android.permission.CAMERA'); + + if (status === null || status === 1) { + status = 1; + } else { + uni.showModal({ + content: "需要相机权限", + confirmText: "设置", + success: function(res) { + if (res.confirm) { + permision.gotoAppSetting(); + } + } + }) + } + return status; + } + // #endif } }