2024-08-20 17:44:53 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view>
|
|
|
|
|
|
<div v-if="isShow">
|
|
|
|
|
|
<div class="title">人脸识别扫描</div>
|
|
|
|
|
|
<div class="title-tip">请正对手机,确保光线充足</div>
|
|
|
|
|
|
<div class="face-scan">
|
2024-08-27 14:03:52 +08:00
|
|
|
|
<u-icon name="/static/images/face-recognition.png" size="180" />
|
2024-08-20 17:44:53 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="face-tip">人脸验证过程中仅能由本人完成</div>
|
|
|
|
|
|
<div class="tip-icon">
|
|
|
|
|
|
<div class="tip-item">
|
2024-08-27 14:03:52 +08:00
|
|
|
|
<u-icon name="/static/images/eye.png" size="40" />
|
2024-08-20 17:44:53 +08:00
|
|
|
|
<div>避免遮挡</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="tip-item">
|
2024-08-27 14:03:52 +08:00
|
|
|
|
<u-icon name="/static/images/well-lit.png" size="40" />
|
2024-08-20 17:44:53 +08:00
|
|
|
|
<div>光线充足</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="tip-item">
|
2024-08-27 14:03:52 +08:00
|
|
|
|
<u-icon name="/static/images/front-face-to-phone.png" size="40" />
|
2024-08-20 17:44:53 +08:00
|
|
|
|
<div>正对手机</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="btn"><u-button type="primary" shape="circle" text="开始录入" @click="openFaceScan" /></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-else>
|
|
|
|
|
|
<div class="img">
|
|
|
|
|
|
<u--image :src="url" width="180px" height="180px" shape="circle" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="img-title">您已完成人脸信息采集</div>
|
|
|
|
|
|
<div class="img-tip">温馨提示</div>
|
|
|
|
|
|
<div class="img-tip-content">收集您的信息,以实现在考试中检测是否是您本人操作,请务必录入您本人的面部信息</div>
|
|
|
|
|
|
<div class="btn">
|
|
|
|
|
|
<u-button type="primary" shape="circle" text="确定录入" @click="handleSubmit" />
|
|
|
|
|
|
<u-button type="" shape="circle" text="重新录入" @click="openFaceScan" style="margin: 20px 0" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-08-28 17:23:03 +08:00
|
|
|
|
import face from '@/uni_modules/mcc-face/index.js'
|
2024-08-23 16:00:43 +08:00
|
|
|
|
import config from 'config.js'
|
2024-08-20 17:44:53 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
isShow: true,
|
2024-08-23 16:00:43 +08:00
|
|
|
|
url: '',
|
|
|
|
|
|
facePath: '',
|
2024-08-26 21:46:08 +08:00
|
|
|
|
optMode: 'add',
|
2024-08-28 09:51:05 +08:00
|
|
|
|
token: uni.getStorageSync('access_token'),
|
2024-08-26 21:46:08 +08:00
|
|
|
|
userId: uni.getStorageSync('userId')
|
2024-08-20 17:44:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2024-08-26 21:46:08 +08:00
|
|
|
|
onLoad() {
|
|
|
|
|
|
console.log('🚀 ~ onLoad', this.token, this.userId)
|
|
|
|
|
|
this.url = uni.getStorageSync('facePath') || ''
|
|
|
|
|
|
this.optMode = uni.getStorageSync('facePath') ? 'replace' : 'add'
|
|
|
|
|
|
},
|
2024-08-23 16:00:43 +08:00
|
|
|
|
mounted() {
|
2024-08-26 21:46:08 +08:00
|
|
|
|
// console.log('🚀 ~ mounted', config)
|
2024-08-23 16:00:43 +08:00
|
|
|
|
},
|
2024-08-20 17:44:53 +08:00
|
|
|
|
methods: {
|
|
|
|
|
|
// 人脸识别
|
|
|
|
|
|
openFaceScan() {
|
|
|
|
|
|
this.url = ''
|
2024-08-26 21:46:08 +08:00
|
|
|
|
face.open(['a'], e => {
|
2024-08-20 17:44:53 +08:00
|
|
|
|
console.log('🚀 ~ e-人脸识别:', e)
|
|
|
|
|
|
this.url = e
|
|
|
|
|
|
this.isShow = false
|
|
|
|
|
|
face.close()
|
|
|
|
|
|
})
|
|
|
|
|
|
if (!this.url) this.isShow = true
|
|
|
|
|
|
},
|
|
|
|
|
|
// 确定录入
|
2024-08-23 16:00:43 +08:00
|
|
|
|
handleSubmit() {
|
|
|
|
|
|
// 上传文件
|
|
|
|
|
|
uni.uploadFile({
|
|
|
|
|
|
url: config.uploadUrl,
|
|
|
|
|
|
filePath: this.url,
|
|
|
|
|
|
name: 'data',
|
|
|
|
|
|
formData: {
|
|
|
|
|
|
photoType: 'face',
|
|
|
|
|
|
file: this.url
|
|
|
|
|
|
},
|
|
|
|
|
|
header: {
|
2024-08-26 21:46:08 +08:00
|
|
|
|
Authorization: this.token
|
2024-08-23 16:00:43 +08:00
|
|
|
|
},
|
|
|
|
|
|
success: res => {
|
|
|
|
|
|
console.log('🚀 ~ res:', res)
|
|
|
|
|
|
res = JSON.parse(res.data)
|
|
|
|
|
|
this.facePath = res.data.url
|
2024-08-26 21:46:08 +08:00
|
|
|
|
console.log('🚀 ~ handleSubmit ~ this.facePath:', this.facePath, this.optMode)
|
2024-08-23 16:00:43 +08:00
|
|
|
|
let params = {
|
2024-08-26 21:46:08 +08:00
|
|
|
|
userId: this.userId,
|
2024-08-23 16:00:43 +08:00
|
|
|
|
facePath: this.facePath,
|
|
|
|
|
|
optMode: this.optMode,
|
|
|
|
|
|
img: this.url
|
|
|
|
|
|
}
|
|
|
|
|
|
params = JSON.stringify(params)
|
|
|
|
|
|
uni.request({
|
2024-08-28 17:23:03 +08:00
|
|
|
|
url: config.baseUrl + '/exam-student/personalCenter/uploadFaceRecognition',
|
2024-08-23 16:00:43 +08:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: params,
|
|
|
|
|
|
header: {
|
2024-08-28 17:23:03 +08:00
|
|
|
|
'content-type': 'application/json',
|
|
|
|
|
|
Authorization: this.token
|
2024-08-23 16:00:43 +08:00
|
|
|
|
},
|
|
|
|
|
|
success: res => {
|
2024-08-28 17:23:03 +08:00
|
|
|
|
res = res.data
|
2024-08-29 08:58:38 +08:00
|
|
|
|
console.log('🚀 ~ this.uploadFaceRecognition ~ res上传成功:', res, res.code)
|
2024-08-28 17:23:03 +08:00
|
|
|
|
if (res.code == 200) {
|
2024-08-23 16:00:43 +08:00
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: '人脸信息录入成功',
|
|
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
2024-08-28 17:23:03 +08:00
|
|
|
|
uni.removeStorageSync('facePath')
|
|
|
|
|
|
uni.setStorageSync('facePath', this.facePath)
|
2024-08-29 08:58:38 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages/YNEduApp/user/user'
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 1000)
|
2024-08-23 16:00:43 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
uni.showToast({
|
2024-08-29 08:58:38 +08:00
|
|
|
|
title: res.msg,
|
2024-08-23 16:00:43 +08:00
|
|
|
|
icon: 'none'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: err => {
|
|
|
|
|
|
console.log('🚀 ~ this.uploadFaceRecognition ~ err:', err)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-08-26 21:46:08 +08:00
|
|
|
|
},
|
|
|
|
|
|
fail: err => {
|
|
|
|
|
|
console.log('🚀 ~ err:', err)
|
2024-08-23 16:00:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-08-20 17:44:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
.title {
|
|
|
|
|
|
padding: 80px 0 20px;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
font-size: 22px;
|
|
|
|
|
|
color: #000;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
.title-tip,
|
|
|
|
|
|
.face-tip {
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
color: #afaeae;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
.face-scan {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
padding: 25px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.tip-icon {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-around;
|
|
|
|
|
|
padding: 25px 40px;
|
|
|
|
|
|
|
|
|
|
|
|
.tip-item {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
2024-08-23 16:00:43 +08:00
|
|
|
|
:nth-child(2) {
|
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
|
color: #6b6b6b;
|
|
|
|
|
|
}
|
2024-08-20 17:44:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.btn {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
padding: 25px 40px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.img {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
padding: 105px 40px 35px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.img-title {
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
font-size: 19px;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
line-height: 18px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
.img-tip {
|
|
|
|
|
|
padding: 50px 40px 20px;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
font-size: 15px;
|
|
|
|
|
|
color: #6b6b6b;
|
|
|
|
|
|
line-height: 18px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.img-tip-content {
|
|
|
|
|
|
padding: 0 40px 50px;
|
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: #6b6b6b;
|
|
|
|
|
|
line-height: 18px;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|