提交 80829ca8 authored 作者: 羊富学's avatar 羊富学

贝因美

上级 88418b24
......@@ -3,6 +3,8 @@ import qrcode, {
height
} from '../../utils/llqrcodefrankyin.js'
const base64js = require('base64-arraybuffer');
Page({
/**
......@@ -93,16 +95,37 @@ Page({
const listener = this.cameraContext.onCameraFrame(async (frame) => {
if (flag) {
flag = false
const data = new Uint8ClampedArray(frame.data);
// const nData = data.slice(data.length / 4, data.length / 4 * 3)
const qr_result = qrcode.decodefrank(frame.width, frame.height, data)
if (qr_result) {
// 文件系统
const fileSystem = wx.getFileSystemManager()
// 实时帧渲染到canvas
await wx.canvasPutImageData({
canvasId: 'myCanvas',
width: frame.width,
height: frame.height,
data: new Uint8ClampedArray(frame.data),
})
const fileData = await wx.canvasToTempFilePath({
canvasId: 'myCanvas',
x: frame.width / 2 - 150,
y: frame.height / 2 - 150,
width: 300,
height: 300,
destWidth: 300,
destHeight: 300,
quality: 'high',
fileType: 'jpg',
})
const base = fileSystem.readFileSync(fileData.tempFilePath, 'base64')
const qr_result = await that.handleCodeAnalysis(base)
// 前端校验取消
// const data = new Uint8ClampedArray(frame.data);
// // const nData = data.slice(data.length / 4, data.length / 4 * 3)
// const qr_result = qrcode.decodefrank(frame.width, frame.height, data)
if (qr_result?.codeinfo) {
that.setData({
height: frame.height,
width: frame.width
})
// 文件系统
const fileSystem = wx.getFileSystemManager()
// 原图(默认放大两倍)
const photo1 = await that.handleTakePoto()
// 放大图(四倍)
......@@ -117,13 +140,14 @@ Page({
Promise.all([that.handleApiCheck(base64_1), that.handleApiCheck(base64_2)])
.then(value => {
let pageType = 'error'
const result1 = value[0],result2 = value[1]
const result1 = value[0],
result2 = value[1]
// data.result == 2 为真
if (result1.data.result == 2 && result2.data.result == 2) {
pageType = 'success'
}
that.setData({
showPage:pageType
showPage: pageType
})
})
} else {
......@@ -135,6 +159,26 @@ Page({
listener.start()
},
// 后端接口解析二维码
handleCodeAnalysis(base64) {
return new Promise((resolve, reject) => {
wx.request({
url: 'https://www.7856.work:4433/api/Bym_upload/',
method: 'POST',
data: {
base: base64,
labelCodejson: 'BeiyinmeiAi'
},
success(res) {
resolve(res)
},
fail(err) {
reject(err)
}
})
})
},
// 视频流拍照
async handleTakePoto(context = this.cameraContext, zoom = 2, param) {
await context.setZoom({
......
......@@ -23,7 +23,6 @@
</view>
</view>
<!-- <view style="visibility: hidden;position: fixed;top: 9999px;left: 0px;">
<canvas canvas-id="myCanvas" id="myCanvas" style="width: {{width}}px;height: {{height}}px;" />
<canvas canvas-id="myCanvas2" id="myCanvas2" style="width: {{width}}px;height: {{height}}px;" />
</view> -->
<view style="visibility: hidden;position: fixed;top: 9999px;left: 0px;">
<canvas canvas-id="myCanvas" id="myCanvas" style="width:400px;height: 400px;" />
</view>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论