添加扫描二维码功能

This commit is contained in:
kron
2025-05-26 14:11:21 +08:00
parent 6931646737
commit 11171f66ec
2 changed files with 34 additions and 3 deletions

View File

@@ -59,6 +59,9 @@
"permission": { "permission": {
"scope.userInfo": { "scope.userInfo": {
"desc": "用于完善用户资料" "desc": "用于完善用户资料"
},
"scope.camera": {
"desc": "用于扫描二维码"
} }
} }
}, },

View File

@@ -1,8 +1,35 @@
<script setup> <script setup>
import Guide from "@/components/Guide.vue"; import Guide from "@/components/Guide.vue";
import BowTarget from "@/components/BowTarget.vue"; import BowTarget from "@/components/BowTarget.vue";
import Button from "@/components/SButton.vue"; import SButton from "@/components/SButton.vue";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
// 扫描二维码方法
const handleScan = () => {
console.log('开始扫码');
// 调用扫码API
uni.scanCode({
// 只支持扫码二维码
onlyFromCamera: true,
scanType: ['qrCode'],
success: (res) => {
// res.result 为二维码内容
console.log('扫码结果:', res.result);
uni.showToast({
title: '扫码成功',
icon: 'success'
});
// 这里可以处理扫码后的业务逻辑
},
fail: (err) => {
console.error('扫码失败:', err);
uni.showToast({
title: '扫码失败',
icon: 'error'
});
}
});
};
</script> </script>
<template> <template>
@@ -15,11 +42,12 @@ import Container from "@/components/Container.vue";
</Guide> </Guide>
<BowTarget <BowTarget
avatar="../static/avatar.png" avatar="../static/avatar.png"
power="45" :power="45"
tips="本次射程5.2米,已达距离要求" tips="本次射程5.2米,已达距离要求"
/> />
<view> <view>
<Button>准备好了直接开始</Button> <SButton>准备好了直接开始</SButton>
<SButton :onClick="handleScan">扫码</SButton>
</view> </view>
</Container> </Container>
</template> </template>