139 lines
3.3 KiB
Plaintext
139 lines
3.3 KiB
Plaintext
<template>
|
|
<view class="container">
|
|
<view class="fat">
|
|
<text class="fatt">请将人脸置于方框内</text>
|
|
</view>
|
|
<view class="livefater">
|
|
<view style="width: 700upx; height: 700upx; border-radius: 700upx; overflow: hidden">
|
|
<live-pusher id="livePusher" ref="livePusher" class="livePusher" url="" mode="SD" :muted="true"
|
|
:enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2" aspect="1:1" />
|
|
</view>
|
|
<cover-image src="/static/images/gaiz.png" class="gaiimg"></cover-image>
|
|
</view>
|
|
|
|
<view style="margin: 0 100upx">
|
|
<u-button :text="btnTextStr" type="primary" @click="snapshot" />
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import {
|
|
submitEditUserFace,
|
|
compareUserFaceCertify,
|
|
compareUserExamFaceCertify
|
|
} from '@/api';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
startPreviewTimer: null, // 开始预览计时器实例
|
|
btnTextStr: '拍照'
|
|
}
|
|
},
|
|
onReady() {
|
|
this.context = uni.createLivePusherContext('livePusher', this)
|
|
this.startPreviewTimer = setInterval(() => {
|
|
this.startPreview()
|
|
}, 1000)
|
|
},
|
|
onUnload() {
|
|
this.startPreviewTimer && clearInterval(this.startPreviewTimer)
|
|
},
|
|
methods: {
|
|
snapshot() {
|
|
uni.showLoading({
|
|
title: '加载中'
|
|
})
|
|
this.context.snapshot({
|
|
success: (e) => {
|
|
this.getMinImage(e.message.tempImagePath)
|
|
}
|
|
})
|
|
},
|
|
startPreview() {
|
|
this.context.stopPreview()
|
|
this.context.startPreview({
|
|
success: () => {
|
|
this.startPreviewTimer && clearInterval(this.startPreviewTimer)
|
|
}
|
|
})
|
|
},
|
|
getMinImage(imgPath) {
|
|
plus.zip.compressImage({
|
|
src: imgPath,
|
|
dst: imgPath,
|
|
overwrite: true,
|
|
quality: 40
|
|
},
|
|
(zipRes) => {
|
|
setTimeout(() => {
|
|
const reader = new plus.io.FileReader()
|
|
reader.onloadend = async (res) => {
|
|
const speech = res.target.result
|
|
// 获取 base 64 图片编码的前缀
|
|
const USERAVATARPREFIX = speech.substring(0, speech.indexOf(
|
|
'base64,') + 7)
|
|
// 获取 base 64 图片的二进制到文本
|
|
const USERAVATARURL = speech.substring(speech.indexOf('base64,') + 7)
|
|
try {
|
|
// TODO USERAVATARPREFIX USERAVATARURL
|
|
// 调用 API 提交人脸图片
|
|
const fullBase64 = USERAVATARPREFIX + USERAVATARURL;
|
|
console.log(fullBase64)
|
|
console.log(this.$store.getters.getUserInfo.USER_ID)
|
|
const res = await submitEditUserFace({ faceData: fullBase64, userId: this.$store.getters.getUserInfo.USER_ID });
|
|
uni.hideLoading();
|
|
uni.$u.toast('上传成功');
|
|
uni.navigateBack({ delta: 1 });
|
|
} catch (e) {
|
|
if (e && e.msg) {
|
|
uni.$u.toast(e.msg)
|
|
}
|
|
}
|
|
}
|
|
reader.readAsDataURL(plus.io.convertLocalFileSystemURL(zipRes.target))
|
|
}, 4000)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.container {
|
|
background-color: #fff;
|
|
}
|
|
|
|
.livePusher {
|
|
width: 700upx;
|
|
height: 700upx;
|
|
}
|
|
|
|
.livefater {
|
|
display: flex;
|
|
justify-content: center;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
margin-bottom: 100upx;
|
|
height: 700upx;
|
|
}
|
|
|
|
.fat {
|
|
margin: 100upx;
|
|
}
|
|
|
|
.fatt {
|
|
text-align: center;
|
|
font-size: 36upx;
|
|
font-weight: 800;
|
|
}
|
|
|
|
.gaiimg {
|
|
width: 700upx;
|
|
height: 700upx;
|
|
margin-top: -700upx;
|
|
}
|
|
</style>
|