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

贝因美

上级 88418b24
...@@ -3,6 +3,8 @@ import qrcode, { ...@@ -3,6 +3,8 @@ import qrcode, {
height height
} from '../../utils/llqrcodefrankyin.js' } from '../../utils/llqrcodefrankyin.js'
const base64js = require('base64-arraybuffer');
Page({ Page({
/** /**
...@@ -93,16 +95,37 @@ Page({ ...@@ -93,16 +95,37 @@ Page({
const listener = this.cameraContext.onCameraFrame(async (frame) => { const listener = this.cameraContext.onCameraFrame(async (frame) => {
if (flag) { if (flag) {
flag = false flag = false
const data = new Uint8ClampedArray(frame.data); // 文件系统
// const nData = data.slice(data.length / 4, data.length / 4 * 3) const fileSystem = wx.getFileSystemManager()
const qr_result = qrcode.decodefrank(frame.width, frame.height, data) // 实时帧渲染到canvas
if (qr_result) { 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({ that.setData({
height: frame.height, height: frame.height,
width: frame.width width: frame.width
}) })
// 文件系统
const fileSystem = wx.getFileSystemManager()
// 原图(默认放大两倍) // 原图(默认放大两倍)
const photo1 = await that.handleTakePoto() const photo1 = await that.handleTakePoto()
// 放大图(四倍) // 放大图(四倍)
...@@ -117,13 +140,14 @@ Page({ ...@@ -117,13 +140,14 @@ Page({
Promise.all([that.handleApiCheck(base64_1), that.handleApiCheck(base64_2)]) Promise.all([that.handleApiCheck(base64_1), that.handleApiCheck(base64_2)])
.then(value => { .then(value => {
let pageType = 'error' let pageType = 'error'
const result1 = value[0],result2 = value[1] const result1 = value[0],
result2 = value[1]
// data.result == 2 为真 // data.result == 2 为真
if (result1.data.result == 2 && result2.data.result == 2) { if (result1.data.result == 2 && result2.data.result == 2) {
pageType = 'success' pageType = 'success'
} }
that.setData({ that.setData({
showPage:pageType showPage: pageType
}) })
}) })
} else { } else {
...@@ -135,6 +159,26 @@ Page({ ...@@ -135,6 +159,26 @@ Page({
listener.start() 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) { async handleTakePoto(context = this.cameraContext, zoom = 2, param) {
await context.setZoom({ await context.setZoom({
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
</view> </view>
</view> </view>
<!-- <view style="visibility: hidden;position: fixed;top: 9999px;left: 0px;"> <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="myCanvas" id="myCanvas" style="width:400px;height: 400px;" />
<canvas canvas-id="myCanvas2" id="myCanvas2" style="width: {{width}}px;height: {{height}}px;" /> </view>
</view> -->
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论