提交 88418b24 authored 作者: 羊富学's avatar 羊富学

贝因美代码优化

上级 2cb1c171
......@@ -9,10 +9,9 @@ Page({
* 页面的初始数据
*/
data: {
src: 'https://res.wx.qq.com/wxdoc/dist/assets/img/draw-image.22401fa6.png',
height: 0,
width: 0,
showPage:false
showPage: '' // '' 为拍照 ,'error'为不通过,'success' 为通过
},
/**
......@@ -91,60 +90,82 @@ Page({
cameraFrame() {
let flag = true
const that = this
const listener = this.cameraContext.onCameraFrame((frame) => {
const listener = this.cameraContext.onCameraFrame(async (frame) => {
if (flag) {
flag = false
const data = new Uint8ClampedArray(frame.data);
const d = qrcode.decodefrank(frame.width, frame.height, data)
if (d) {
this.cameraContext.takePhoto({
quality: 'high',
selfieMirror: false,
success(res) {
// flag = true
const base = wx.getFileSystemManager().readFileSync(res.tempImagePath, 'base64')
wx.request({
url: 'https://www.7856.work:4433/api/Bym_classfily_post/',
method: 'POST',
data: {
device_id: '50',
base: base
},
success(rs) {
// console.log(rs,9999,rs.data.result,555);
// wx.showToast({
// title: 'dddd过',
// })
if (rs.data.result == 2) {
wx.showToast({
title: '通过',
icon:'success'
})
that.setData({
showPage:true
})
} else {
wx.showToast({
title: '未通过',
icon:'error'
})
flag = true
}
},
fail(e) {
console.log(e);
}
})
}
// const nData = data.slice(data.length / 4, data.length / 4 * 3)
const qr_result = qrcode.decodefrank(frame.width, frame.height, data)
if (qr_result) {
that.setData({
height: frame.height,
width: frame.width
})
// 文件系统
const fileSystem = wx.getFileSystemManager()
// 原图(默认放大两倍)
const photo1 = await that.handleTakePoto()
// 放大图(四倍)
const photo2 = await that.handleTakePoto(that.cameraContext, 4)
// 原图base64
const base64_1 = fileSystem.readFileSync(photo1.tempImagePath, 'base64')
// 放大四倍图 base64
const base64_2 = fileSystem.readFileSync(photo2.tempImagePath, 'base64')
// 请求接口
Promise.all([that.handleApiCheck(base64_1), that.handleApiCheck(base64_2)])
.then(value => {
let pageType = 'error'
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
})
})
} else {
flag = true
}
}
})
listener.start()
},
// 视频流拍照
async handleTakePoto(context = this.cameraContext, zoom = 2, param) {
await context.setZoom({
zoom
})
return await context.takePhoto({
quality: param?.quality || 'high',
selfieMirror: param?.selfieMirror || false,
})
},
// 接口请求
handleApiCheck(base64) {
return new Promise((resolve, reject) => {
wx.request({
url: 'https://www.7856.work:4433/api/Bym_classfily_post/',
method: 'POST',
data: {
device_id: '50',
base: base64
},
success(res) {
resolve(res)
},
fail(err) {
reject(err)
}
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
......
......@@ -8,21 +8,22 @@
</camera>
</view>
<view wx:else class="success-content full">
<view wx:if="{{showPage == 'success'}}" class="success-content full">
<view class="content-text">
<image src="/assets/imgs/成功.png" mode="widthFix" style="width: 40%;" />
<image src="/assets/imgs/通过.png" mode="widthFix" style="width: 50%;" />
<!-- <view class="btn" bind:tap="handleBack">返回主页面</view> -->
<!-- <navigator class="btn" open-type="exit" target="miniProgram">点击按钮返回主页</navigator> -->
</view>
</view>
<view style="visibility: hidden;position: fixed;top: 999px;left: 0px;">
<canvas canvas-id="myCanvas" id="myCanvas" style="width: 400px;height: 400px;" />
<view wx:if="{{showPage == 'error'}}" class="success-content full">
<view class="content-text" style="padding-top: 40rpx;">
<!-- <image src="/assets/imgs/成功.png" mode="widthFix" style="width: 40%;" /> -->
<image src="/assets/imgs/未通过.png" mode="widthFix" style="width: 30%;" />
<view style="color: #FFAF38;margin-top: 24rpx;">认证未通过,请扫描实物标签重新认证</view>
</view>
</view>
<!-- <view style="position: fixed;top: 0px;left: 0px;z-index: 999;">
<image src="{{src}}" mode="widthFix"/>
</view> -->
\ No newline at end of file
<!-- <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> -->
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论