// pages/takephoto/takephoto.js
import wxRequest from '../../../utils/wxRequest'
import regeneratorRuntime from '../../../utils/regenerator'
const { $Message } = require('../../../dist/iview/base/index')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
imageHost: app.globalData.imageHost,
count: 0, // 设置 计数器 初始为0
countTimer: null, // 设置 定时器 初始为null
complete: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
onReady: function () {
if (wx.createCameraContext()) {
this.cameraContext = wx.createCameraContext('myCamera')
this.drawProgressbg();
// this.drawCircle();
this.countInterval();
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
// this.bindChooiceProduct()
},
takePhoto() {
const ctx = wx.createCameraContext()
var that = this
ctx.takePhoto({
quality: 'high',
success: (res) => {
console.log(res.tempImagePath)
var imgbase64Url = wx.getFileSystemManager().readFileSync(res.tempImagePath, "base64");
// data:image/png;base64,
// console.log(imgbase64Url)
// that.uploadImg(encodeURIComponent(imgbase64Url))
// 识别成功之后跳转
$Message({
content: '正在识别,请稍后......',
type: 'success'
});
setTimeout(function () {
wx.redirectTo({
url: '../completeFetch/completeFetch'
})
}, 2000)
}
})
},
error(e) {
console.log(e.detail)
},
startdrawCanvas(){
console.log('相机初始化成功')
},
//添加Banner
bindChooiceProduct: function () {
var that = this;
wx.chooseImage({
count: 3, //最多可以选择的图片总数
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
console.log(tempFilePaths)
//启动上传等待中...
var url = wx.getFileSystemManager().readFileSync(tempFilePaths[0], "base64")
console.log(encodeURIComponent(url))
that.uploadImg(encodeURIComponent(url))
}
});
},
async uploadImg(url){
var res = await wxRequest.post('http://10.18.31.67:8881/face/byte/api/search?imgByte=' + url, {
imgByte: url
})
console.log(res)
if(res.code == 200){
if (res.data.faceMsg == 'pic not has face'){
this.goBack('未捕获到人脸,请重新录入!')
} else if (res.data.faceMsg == 'liveness check fail') {
this.goBack('人脸匹配失败,请重新录入!')
} else {
$Message({
content: '正在跳转',
type: 'success'
});
wx.navigateTo({
url: '../completeFetch/completeFetch'
})
}
}else{
this.goBack('网络错误,请重新录入!')
}
},
goBack(info){
$Message({
content: info,
type: 'error'
});
setTimeout(function(){
wx.navigateBack();
},2000)
},
drawProgressbg: function () {
// 使用 wx.createContext 获取绘图上下文 context
var ctx = wx.createCanvasContext('canvasProgressbg')
ctx.setLineWidth(5); // 设置圆环的宽度
ctx.setStrokeStyle('#a9a9a9'); // 设置圆环的颜色
ctx.setLineCap('round') // 设置圆环端点的形状
ctx.beginPath(); //开始一个新的路径
ctx.arc(110, 110, 100, 0, 2 * Math.PI, false);
//设置一个原点(100,100),半径为90的圆的路径到当前路径
ctx.stroke(); //对当前路径进行描边
ctx.draw();
},
drawCircle: function (step) {
var context = wx.createCanvasContext('canvasProgress');
// 设置渐变
var gradient = context.createLinearGradient(200, 100, 100, 200);
gradient.addColorStop("0", "#2661DD");
gradient.addColorStop("0.5", "#2661DD");
gradient.addColorStop("1.0", "#2661DD");
context.setLineWidth(5);
context.setStrokeStyle(gradient);
context.setLineCap('round')
context.beginPath();
// 参数step 为绘制的圆环周长,从0到2为一周 。 -Math.PI / 2 将起始角设在12点钟位置 ,结束角 通过改变 step 的值确定
context.arc(110, 110, 100, -Math.PI / 2, step * Math.PI - Math.PI / 2, false);
context.stroke();
context.draw()
},
countInterval: function () {
// 设置倒计时 定时器 每100毫秒执行一次,计数器count+1 ,耗时6秒绘一圈
this.countTimer = setInterval(() => {
if (this.data.count <= 60) {
/* 绘制彩色圆环进度条
注意此处 传参 step 取值范围是0到2,
所以 计数器 最大值 60 对应 2 做处理,计数器count=60的时候step=2
*/
this.drawCircle(this.data.count / (60 / 2))
this.data.count++;
} else {
this.setData({
complete: true
});
clearInterval(this.countTimer);
}
}, 100)
},
complateDis(){
this.takePhoto()
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
faceDistinguish.zip (16个子文件)
faceDistinguish
takephoto
takephoto.wxss 892B
takephoto.wxml 802B
takephoto.js 6KB
takephoto.json 141B
facedistinguish.png 91KB
facesuccess.png 20KB
distinguishing.png 17KB
startFetch
startFetch.wxss 462B
startFetch.js 995B
startFetch.json 29B
startFetch.wxml 368B
circle.png 16KB
completeFetch
completeFetch.json 87B
completeFetch.wxml 188B
completeFetch.js 1KB
completeFetch.wxss 301B
共 16 条
- 1
资源评论
- 李小斌962020-09-24这个所需的C币是人家自己涨的,我也很无奈。 链接:https://pan.baidu.com/s/1Hp0zwf2b45mryuzYp48Tzg 提取码:b9qu
李小斌96
- 粉丝: 190
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功