提交 7959679d authored 作者: 羊富学's avatar 羊富学

贝因美接口调试

上级 31d8ff98
...@@ -9,9 +9,6 @@ Page({ ...@@ -9,9 +9,6 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
img: 'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',
setHeight: '',
setWidth: '',
canvas: { canvas: {
height: 100, height: 100,
width: 100 width: 100
...@@ -22,136 +19,40 @@ Page({ ...@@ -22,136 +19,40 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
const that = this let flag = true
this.cameraContext = wx.createCameraContext() this.cameraContext = wx.createCameraContext()
//系统基本信息
const systemInfo = wx.getSystemInfoSync();
this.setData({
setHeight: systemInfo.windowWidth,
setWidth: systemInfo.windowHeight
})
let n = 1,
flag = true
// const ctx = wx.createCanvasContext('myCanvas');
// wx.chooseImage({
// success: function(res){
// console.log(res);
// ctx.drawImage(res.tempFilePaths[0], (400-50)/2, (300-50)/2, 50,50,0,0,200,200)
// // ctx.drawImage(res.tempFilePaths[0], 0, 0, 150, 150)
// ctx.draw()
// }
// })
// setInterval(() => {
// this.cameraContext.takePhoto({
// success: (res) => {
// console.log(888,res);
// this.checkPictureCode(res.tempImagePath)
// },
// fail(e){
// console.log(e,555);
// }
// })
// },0)
// return
const listener = this.cameraContext.onCameraFrame((frame) => { const listener = this.cameraContext.onCameraFrame((frame) => {
if (n % 25 == 0 && flag) { if (flag) {
flag = false flag = false
// this.setData({
// canvas: {
// height: frame.height,
// width: frame.width,
// flag: false
// }
// })
// console.log(frame.data)
// const base64 = wx.arrayBufferToBase64(frame.data)
// console.log(base64);
// that.setData({
// src: 'data:image/jpg;base64,' + base64
// });
const data = new Uint8ClampedArray(frame.data); const data = new Uint8ClampedArray(frame.data);
const d = qrcode.decodefrank(frame.width, frame.height, data) const d = qrcode.decodefrank(frame.width, frame.height, data)
console.log(d);
if (d) { if (d) {
this.cameraContext.takePhoto({ wx.showToast({
success: (res) => { title:'通过'
this.setData({
src: res.tempImagePath
}) })
console.log(888, res); const base64 = wx.arrayBufferToBase64(frame.data)
wx.request({
url:'https://www.7856.work:4433/api/Bym_classfily_post/',
method:'POST',
data:{
device_id:'50',
base:base64
}, },
fail(e) { success(res){
console.log(e, 555); console.log(res);
},
fail(e){
console.log(e);
} }
}) })
flag = false } else {
}
else{
flag = true flag = true
} }
console.log(d)
return
const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({
node: true,
size: true
})
.exec((res) => {
const canvas = res[0].node
const ctx = canvas.getContext('2d')
const imgData = canvas.createImageData(data, frame.height, frame.width)
console.log(imgData)
ctx.putImageData(imgData, 0, 0)
//flag = true
console.log(imgData, 4444);
})
} }
n++
}) })
listener.start() listener.start()
}, },
onScanCode(e) {
console.log(e)
},
checkPictureCode(imagePath) {
const that = this
wx.getImageInfo({
src: imagePath,
success(result) {
console.log(result, 222);
const w = result.width;
const h = result.height;
const canvasContent = wx.createCanvasContext('myCanvas');
canvasContent.drawImage(imagePath, (w - 200) / 2, (h - 200) / 2 - 50, 200, 200, 0, 0, 200, 200)
canvasContent.draw()
console.log();
wx.canvasGetImageData({
canvasId: 'myCanvas',
x: parseInt(0),
y: parseInt(0),
width: 200,
height: 200,
success(data) {
let d = qrcode.decodefrank(200, 200, data.data)
console.log('d', d, 55555);
}
})
that.setData({
img: result.path
})
}
})
},
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
......
<!--pages/beiyinmei/beiyinmei.wxml--> <!--pages/beiyinmei/beiyinmei.wxml-->
<view style="height: 100vh;width: 100vw;position: relative;z-index: 99;"> <view style="height: 100vh;width: 100vw;position: relative;z-index: 99;">
<camera device-position="back" frame-size="medium" flash="off" binderror="error" style="width: 100%; height: 300px;" mode="normal" bindscancode="onScanCode"> <camera device-position="back" frame-size="small" flash="off" binderror="error" style="width: 100%; height: 100%;" mode="normal">
<view class="prompt"> <view class="prompt">
<image src="/assets/imgs/拍照框.png" style="width: 40%;" mode="widthFix" /> <image src="/assets/imgs/拍照框.png" style="width: 60%;" mode="widthFix" />
<text>请把二维码放置拍照框内</text> <text>请把二维码放置拍照框内</text>
</view> </view>
</camera> </camera>
<canvas type="2d" id="myCanvas" canvas-id="myCanvas" style="height:200px;width: 200px;"></canvas>
<image src="{{src}}" mode="widthFix" style="position: fixed; bottom: 100px; width: 100%;" />
</view> </view>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论