修改扫码页面

This commit is contained in:
2025-09-04 19:40:29 +08:00
parent a16d74cccd
commit 2d09878787
5 changed files with 464 additions and 476 deletions

View File

@@ -1,79 +1,75 @@
<template>
<view>
<!-- HTML -->
<mumu-get-qrcode @success='qrcodeSucess' @error="qrcodeError" :scanWidth="300"
:scanHeight="300"></mumu-get-qrcode>
</view>
</template>
<script>
import {
getInspectionManage
} from '@/api/inspection/inspectionManage.js'
// js
import mumuGetQrcode from '@/uni_modules/mumu-getQrcode/components/mumu-getQrcode/mumu-getQrcode.vue'
// 嫌路径长的话可以单独复制出来
export default {
created() {
this.requestCameraAuth()
components: {
mumuGetQrcode
},
methods: {
requestCameraAuth() {
const _this = this
uni.authorize({
scope: 'scope.camera', // 请求相机权限
success: (res) => {
_this.scanQRCode();
},
fail: (err) => {
// 用户拒绝授权
uni.showToast({
title: '您拒绝了授权',
icon: 'none'
});
}
});
qrcodeSucess(data) {
console.log("二维码数据", data)
this.handleScanResult(data);
},
scanQRCode() {
const _this = this
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
success(res) {
if (res.result) {
// 扫描成功,处理二维码内容
getInspectionManage(res.result).then(res => {
if (res.data.inspectionStatus === "1") {
let inspectionPoint = res.data.inspectionPoint
let inspectionRequirements = res.data.inspectionRequirements
// _this.$tab.redirectTo(
// `/pages/work/inspection/scanSign/index?inspectionPoint=${inspectionPoint}&inspectionRequirements=${inspectionRequirements}`
// )
uni.reLaunch({
url: `/pages/work/inspection/scanSign/index?inspectionPoint=${inspectionPoint}&inspectionRequirements=${inspectionRequirements}`
})
} else {
uni.reLaunch({
url: '/pages/work/index'
}).then(()=>{
// 扫描失败
uni.showToast({
title: '验证码已失效!!!',
icon: 'none'
});
})
}
qrcodeError(err) {
console.log(err)
let that = this;
uni.showModal({
title: '摄像头授权失败',
content: '摄像头授权失败,请检测当前浏览器是否有摄像头权限。',
success: () => {
that.redirectToWorkbench(); // 请求错误跳回工作台
}
})
},
handleScanResult(result) {
let that = this;
getInspectionManage(result)
.then(res => {
if (res.data.inspectionStatus === "1") {
let inspectionPoint = res.data.inspectionPoint;
let inspectionRequirements = res.data.inspectionRequirements;
let inspectionPointId = res.data.id
uni.reLaunch({
url: `/pages/work/inspection/scanSign/index?inspectionPoint=${inspectionPoint}&inspectionRequirements=${inspectionRequirements}&inspectionPointId=${inspectionPointId}`
});
} else {
// 扫描失败
uni.showToast({
title: '扫描失败',
title: '验证码已失效!',
icon: 'none'
});
that.redirectToWorkbench(); // 验证码失效跳回工作台
}
},
fail(res) {
})
.catch(err => {
console.log("请求错误", err);
uni.showToast({
title: '调用相机失败',
title: '服务器错误',
icon: 'none'
});
}
});
}
that.redirectToWorkbench(); // 请求错误跳回工作台
});
},
// 新增方法:跳转回工作台
redirectToWorkbench() {
setTimeout(() => {
uni.reLaunch({
url: '/pages/work/index'
});
}, 1500); // 1.5秒后跳转,让用户看到提示信息
},
}
}
</script>
<style>
</style>