提交 2cb1c171 authored 作者: 羊富学's avatar 羊富学

贝因美

上级 c8f5c84a
......@@ -9,45 +9,129 @@ Page({
* 页面的初始数据
*/
data: {
canvas: {
height: 100,
width: 100
},
src: 'https://res.wx.qq.com/wxdoc/dist/assets/img/draw-image.22401fa6.png',
height: 0,
width: 0,
showPage:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let flag = true
this.cameraContext = wx.createCameraContext()
this.cameraContext.setZoom({
zoom: 2
})
this.cameraFrame()
// this.cameraFrameApi()
},
// 视频流(后端校验二维码)
cameraFrameApi() {
let flag = true
const that = this
const listener = this.cameraContext.onCameraFrame((frame) => {
if (flag) {
flag = false
that.setData({
width: frame.width,
height: frame.height,
})
wx.canvasPutImageData({
canvasId: 'myCanvas',
width: frame.width,
height: frame.height,
data: new Uint8ClampedArray(frame.data),
success(rew) {
console.log(rew, 99);
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',
success(path) {
console.log(path.tempFilePath, 66);
const base = wx.getFileSystemManager().readFileSync(path.tempFilePath, 'base64')
that.setData({
src: 'data:image/jpeg;base64,' + base
})
wx.request({
url: 'https://ai.tj5.cc:35437/object/',
method: "POST",
data: {
base
},
success(g) {
console.log(g, 'cccc');
flag = true
}
})
},
fail(rr) {
console.log(rr, 5555);
}
})
},
fail(err) {
console.log(err);
}
})
}
})
listener.start()
},
// 视频流(前端判断二维码)
cameraFrame() {
let flag = true
const that = this
const listener = this.cameraContext.onCameraFrame((frame) => {
if (flag) {
flag = false
const data = new Uint8ClampedArray(frame.data);
const d = qrcode.decodefrank(frame.width, frame.height, data)
if (d) {
wx.showToast({
title:'通过'
})
this.cameraContext.takePhoto({
quality:'high',
success(res){
console.log(res,'ss');
quality: 'high',
selfieMirror: false,
success(res) {
// flag = true
const base = wx.getFileSystemManager().readFileSync(res.tempImagePath, 'base64')
console.log(base);
wx.request({
url:'https://www.7856.work:4433/api/Bym_classfily_post/',
method:'POST',
data:{
device_id:'50',
base:base
url: 'https://www.7856.work:4433/api/Bym_classfily_post/',
method: 'POST',
data: {
device_id: '50',
base: base
},
success(res){
console.log(res);
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){
fail(e) {
console.log(e);
}
})
......
<!--pages/beiyinmei/beiyinmei.wxml-->
<view style="height: 100vh;width: 100vw;position: relative;z-index: 99;">
<camera device-position="back" frame-size="large" flash="off" binderror="error" style="width: 100%; height: 100%;" mode="normal">
<view wx:if="{{!showPage}}" style="height: 100vh;width: 100vw;position: relative;z-index: 99;">
<camera device-position="back" frame-size="medium" flash="off" style="width: 100%; height: 100%;" mode="normal">
<view class="prompt">
<image src="/assets/imgs/拍照框.png" style="width: 40%;" mode="widthFix" />
<text>请把二维码放置拍照框内</text>
</view>
</camera>
</view>
<view wx:else 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>
<!-- <view style="position: fixed;top: 0px;left: 0px;z-index: 999;">
<image src="{{src}}" mode="widthFix"/>
</view> -->
\ No newline at end of file
/* pages/beiyinmei/beiyinmei.wxss */
.prompt {
position: absolute;
top: 50%;
......@@ -15,3 +18,77 @@
.prompt text {
margin-top: 50px;
}
.result-container {
position: relative;
width: 100vw;
height: 100vh;
box-sizing: border-box;
overflow: hidden;
}
.full {
position: relative;
width: 100%;
height: 100%;
box-sizing: border-box
}
.bg-img {
position: absolute;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
}
.btn {
width: 60%;
height: 80rpx;
line-height: 80rpx;
text-align: center;
border-radius: 20rpx;
}
.success-content,.error-content {
display: flex;
flex-direction: column;
}
.content-text {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.success-content .query-text {
margin: 40rpx 0;
display: flex;
flex-direction: column;
align-items: center;
}
.success-content .btn {
margin-top: 40rpx;
color: #008AF4;
border: 4rpx solid #008AF4;
}
.error-content .btns {
margin-top: 40rpx;
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
font-size: 34rpx;
}
.error-content .btns .btn:first-child {
background-color: #FFB44C;
}
.error-content .btns .btn:last-child {
margin-top: 20rpx;
color: #FFB44C;
border:4rpx solid #FFB44C;
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论