<template>
<div class="body">
<div class="livefater">
<div class="camera">
<live-pusher v-if="showPusher == true" id='livePusher' ref="livePusher" class="livePusher" url=""
mode="SD" :muted="true" :enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2"
aspect="1:1" @statechange="statechange" @netstatus="netstatus" @error="error"></live-pusher>
</div>
<!-- <cover-image src="/static/bg2.png" class="gaiimg" v-if="showPusher == true"></cover-image> -->
</div>
<view class="buttons">
<button @click="brush()" v-if="showPusher == false">打开人脸识别</button>
<button @click="snapshot()" v-else>验证</button>
</view>
</div>
</template>
<script>
export default {
data() {
return {
showPusher: false,
context: ''
}
},
mounted() {
},
onReady() {
// 注意:需要在onReady中 或 onLoad 延时
this.context = uni.createLivePusherContext("livePusher", this);
},
methods: {
// 打开摄像头
brush() {
this.startPreview()
},
switchCamera: function() {
this.context.switchCamera({
success: (a) => {
console.log("livePusher.switchCamera:" + JSON.stringify(a));
}
});
},
// 拍照事件
snapshot: function() {
console.log('拍照')
this.context.snapshot({
success: (e) => {
console.log(222)
console.log(JSON.stringify(e));
},
fail: (err) => {
console.log(111)
}
});
this.stopPreview();
},
// 开启摄像头
startPreview() {
var that = this
that.showPusher = true;
this.context.startPreview({
success: (a) => {
console.log("livePusher.startPreview:" + JSON.stringify(a));
},
fail(err) {
console.log(err);
}
});
},
getMinImage(imgPath) {
plus.zip.compressImage({
src: imgPath,
dst: imgPath,
overwrite: true,
quality: 40
},
zipRes => {
setTimeout(() => {
var reader = new plus.io.FileReader();
reader.onloadend = res => {
//获取图片base64
var speech = res.target.result; //base64图片
console.log(speech)
this.imgData = speech;
};
reader.readAsDataURL(plus.io.convertLocalFileSystemURL(zipRes.target));
}, 1000);
},
function(error) {
console.log('Compress error!', error);
}
);
},
// 关闭摄像头
stopPreview() {
var that = this
this.showPusher = false;
this.context.stopPreview({
success: (a) => {
console.log("livePusher.startPreview:" + JSON.stringify(a));
},
fail(err) {
console.log(err);
}
});
}
},
}
</script>
0 个回复