Browse Source

对接接口

master
前端-胡立永 3 months ago
parent
commit
17266dfc45
6 changed files with 572 additions and 18 deletions
  1. +6
    -0
      pages.json
  2. +5
    -1
      pages/index/index.vue
  3. +419
    -0
      pages/subPack/face/face.vue
  4. +141
    -6
      pages/subPack/human/human.vue
  5. +0
    -10
      utils/oss-upload/oss/index.js
  6. +1
    -1
      utils/oss-upload/oss/web.js

+ 6
- 0
pages.json View File

@ -57,6 +57,12 @@
"navigationBarTitleText": "人脸识别"
}
},
{
"path": "face/face",
"style": {
"navigationBarTitleText": "人脸验证"
}
},
{
"path": "team/team",
"style": {


+ 5
- 1
pages/index/index.vue View File

@ -16,7 +16,10 @@
</view>
</view>
<view class="map">
<map style="width: 100%; height: 100%" :latitude="latitude" :longitude="longitude" :markers="covers" :scale="14">
<map style="width: 100%; height: 100%"
:latitude="latitude"
:longitude="longitude"
:markers="covers" :scale="18">
</map>
</view>
</view>
@ -166,6 +169,7 @@
//()
callCard(){
uni.navigateTo({
// url: "/pages/subPack/face/face"
url: "/pages/subPack/human/human"
})
}


+ 419
- 0
pages/subPack/face/face.vue View File

@ -0,0 +1,419 @@
<template>
<view class="page-content">
<view class="containerV">
<view class="headerV">
<view class="top-tips1">
<view>请将正对手机头部匹配摄像区域</view>
</view>
<view class="top-tips2">
为了捍卫你的不要脸请拍摄本人头像
</view>
</view>
<view class="contentV">
<view class="mark"></view>
<image v-if="tempImg" mode="widthFix" :src="tempImg" />
<camera v-if='isAuthCamera' :device-position="devicePosition ?'front': 'back'" class="camera"
flash="off" resolution='high' />
<view v-show="!tempImg && tipsText" class="tipV">{{ tipsText }}</view>
</view>
<view class="footerV">
<view style="width: 100%;">
<view v-if="!tempImg" style="width: 100%;">
<view class="privacyV">
<view class="icon"></view>
<view class="text">
照片隐私<text @click="handleJumpSecurityClick">安全保障</text>
</view>
</view>
<view class="bottom-tips-2">该照片作为你不要脸的铁证</view>
<view class="take-photo-bgV">
<!-- 图片上传 -->
<view v-show="true" class="btn-change-upload" @click="handleChooseImage" />
<!--拍照-->
<view class="btn-take-photo" @click="handleTakePhotoClick" />
<!-- 切换镜头 -->
<view class="btn-change-camera" @click="handleChangeCameraClick" />
</view>
</view>
<view class="confirmV" v-else>
<view class="btn-cancel" @click="handleCancelClick">
取消
</view>
<view class="btn-ok" @click="handleOkClick">
确定
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'index',
components: {
},
data() {
return {
tipsText: '', //
tempImg: '', //
cameraEngine: null, //
devicePosition: true, //
isAuthCamera: true, //
}
},
onLoad(options) {
this.initData()
},
methods: {
//
initData() {
// #ifdef MP-WEIXIN
// 1
wx.initFaceDetect()
// 2 camera CameraContext
this.cameraEngine = wx.createCameraContext()
// 3 Camera
const listener = this.cameraEngine.onCameraFrame((frame) => {
if (this.tempImg) {
return;
}
// 4使 wx.initFaceDetect 使
wx.faceDetect({
frameBuffer: frame.data,
width: frame.width,
height: frame.height,
enablePoint: true,
enableConf: true,
enableAngle: true,
enableMultiFace: true,
success: (faceData) => {
let face = faceData.faceInfo[0]
if (faceData.x == -1 || faceData.y == -1) {
this.tipsText = '检测不到人'
}
if (faceData.faceInfo.length > 1) {
this.tipsText = '请保证只有一个人'
} else {
const {
pitch,
roll,
yaw
} = face.angleArray;
const standard = 0.5
if (Math.abs(pitch) >= standard || Math.abs(roll) >= standard ||
Math.abs(yaw) >= standard) {
this.tipsText = '请平视摄像头'
} else if (face.confArray.global <= 0.8 || face.confArray.leftEye <=
0.8 || face.confArray.mouth <= 0.8 || face.confArray.nose <= 0.8 ||
face.confArray.rightEye <= 0.8) {
this.tipsText = '请勿遮挡五官'
} else {
this.tipsText = '请拍照'
//
}
}
},
fail: (err) => {
if (err.x == -1 || err.y == -1) {
this.tipsText = '检测不到人'
} else {
this.tipsText = err.errMsg || '网络错误,请退出页面重试'
}
},
})
})
// 5
listener.start()
// #endif
},
//
handleChangeCameraClick() {
this.devicePosition = !this.devicePosition;
},
//
handleChooseImage() {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album'],
success: (res) => {
if (res.errMsg === 'chooseImage:ok') {
uni.showLoading({
title: '照片上传中...'
})
console.log("===========:", res.tempFilePaths[0])
this.handleOkClick()
}
},
fail: (res) => {
},
});
},
//
handleTakePhotoClick() {
if (this.tipsText != "" && this.tipsText != "请拍照") {
return;
}
uni.getSetting({
success: (res) => {
if (!res.authSetting['scope.camera']) {
this.isAuthCamera = false
uni.openSetting({
success: (res) => {
if (res.authSetting['scope.camera']) {
this.isAuthCamera = true;
}
}
})
}
}
})
this.cameraEngine.takePhoto({
quality: "high",
success: ({
tempImagePath
}) => {
this.tempImg = tempImagePath
console.log("=======tempImg:", this.tempImg)
}
})
},
//
handleOkClick() {
uni.showLoading({
mask: true,
title: '校验中...'
})
//
setTimeout(function() {
uni.hideLoading()
uni.showToast({
icon: "none",
title: "假装图片上传成功",
duration: 2000,
})
}, 3000);
},
// -
handleCancelClick() {
this.tempImg = ''
},
// -
handleJumpSecurityClick() {
uni.showToast({
icon: "none",
title: "假装跳转人脸安全保障",
duration: 2000,
})
},
}
}
</script>
<style lang="scss" scoped>
.page-content {
width: 100%;
height: 100%;
.containerV {
width: 100%;
height: 100%;
.headerV {
.top-tips1 {
margin-top: 60rpx;
color: #1C1C1C;
font-size: 36rpx;
text-align: center;
}
.top-tips2 {
margin-top: 20rpx;
color: #00AAFF;
font-size: 28rpx;
text-align: center;
}
}
.contentV {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 661rpx;
margin-top: 30rpx;
.tipV {
bottom: 30rpx;
position: absolute;
line-height: 90rpx;
padding-left: 24rpx;
padding-right: 24rpx;
max-width: calc(100vw - 50rpx * 2);
text-align: center;
font-size: 30rpx;
background: #000000;
opacity: 0.75;
color: #FFFFFF;
border-radius: 16rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
z-index: 5;
}
.camera {
width: 100%;
height: 100%;
}
.mark {
position: absolute;
left: 0;
top: 0;
z-index: 2;
width: 750rpx;
height: 100%;
// background: url("@/static/face/view_face_background.png") no-repeat center bottom;
background-size: 750rpx 661rpx;
}
image {
position: absolute;
width: 100%;
height: 100%;
z-index: 3;
}
}
.footerV {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
.privacyV {
padding-top: 30rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
.text {
font-size: 30rpx;
color: #1C1C1C;
text-align: center;
line-height: 42rpx;
margin-left: 15rpx;
text {
font-size: 30rpx;
color: #00AAFF;
text-align: center;
line-height: 42rpx;
}
}
.icon {
width: 40rpx;
height: 47rpx;
// background: url("@/static/face/icon_face_security.png") no-repeat;
background-size: 100% auto;
}
}
.bottom-tips-2 {
margin-top: 20rpx;
color: #999999;
text-align: center;
font-size: 26rpx;
}
.take-photo-bgV {
width: 100%;
margin-top: 30rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
.btn-take-photo {
// 便便
margin: 0rpx 80rpx 0rpx 80rpx;
width: 196rpx;
height: 196rpx;
// background: url("https://pro-file-qn.ztjy61.com/1003020211103145058685NNR9vlTm.png") no-repeat;
background-size: 100% auto;
}
.btn-change-upload {
left: 130rpx;
width: 80rpx;
height: 80rpx;
// background: url("@/static/face/icon_face_upload_picture.png") no-repeat;
background-size: 100% auto;
}
.btn-change-camera {
right: 130rpx;
width: 80rpx;
height: 80rpx;
// background: url("@/static/face/icon_face_switch_cameras.png") no-repeat;
background-size: 100% auto;
}
}
.confirmV {
margin: 200rpx 100rpx 0rpx 100rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
.btn-cancel {
font-size: 32rpx;
color: #1C1C1C;
}
.btn-ok {
font-size: 32rpx;
color: #00AAFF;
}
}
}
}
}
</style>

+ 141
- 6
pages/subPack/human/human.vue View File

@ -13,12 +13,29 @@
<image v-if="!isPhoto"
src="https://tennis-oss.xzaiyp.top/2024-10-22/508376c5-64b2-472f-8e25-a2469b632a39.png" mode="widthFix">
</image>
<image v-else-if="!!tempImg"
:src="tempImg" mode="widthFix">
</image>
<camera
v-else
:device-position="devicePosition ?'front': 'back'"
class="camera"
flash="off"
resolution='high' />
</view>
<!-- 人脸识别说明 -->
<view class="human-face-desc">
<view class="human-face-desc"
v-if="!isPhoto">
人脸认证仅能由<text class="name">{{ userInfo.auth.name }}</text>本人完成验证时请将镜头对准您的脸部
</view>
<view class="human-face-desc"
v-else>
{{ tipsText }}{{ tempImg }}
</view>
<!-- 说明 -->
<view class="desc">
@ -40,7 +57,9 @@
</view>
<div class="btn">
<div class="btn"
@click="handleTakePhotoClick"
v-if="tipsText == '请拍照'">
<uv-upload
multiple
:maxCount="1"
@ -53,6 +72,7 @@
</view>
</uv-upload>
</div>
</view>
</template>
@ -70,12 +90,23 @@
form : {
pic : '',
},
isLocationSubmit : false,
isLocationSubmit : false,//
tipsText: '', //
tempImg: '', //
cameraEngine: null, //
devicePosition: true, //
isAuthCamera: true, //
}
},
computed: {
...mapState(['teamList', 'userInfo']),
},
onLoad() {
this.initData()
},
onShow() {
let self = this
position.getLocationDetail()
@ -139,7 +170,7 @@
}
});
},
submit(){
async submit(){
if (this.$utils.verificationAll(this.form, {
lat : '经纬度缺失,请打开GPS',
lon : '经纬度缺失,请打开GPS',
@ -161,6 +192,105 @@
}
})
},
//
initData() {
// #ifdef MP-WEIXIN
// 1
wx.initFaceDetect()
// 2 camera CameraContext
this.cameraEngine = wx.createCameraContext()
// 3 Camera
const listener = this.cameraEngine.onCameraFrame((frame) => {
if (this.tempImg) {
return;
}
// 4使 wx.initFaceDetect 使
wx.faceDetect({
frameBuffer: frame.data,
width: frame.width,
height: frame.height,
enablePoint: true,
enableConf: true,
enableAngle: true,
enableMultiFace: true,
success: (faceData) => {
let face = faceData.faceInfo[0]
if (faceData.x == -1 || faceData.y == -1) {
this.tipsText = '检测不到人'
}
if (faceData.faceInfo.length > 1) {
this.tipsText = '请保证只有一个人'
} else {
const {
pitch,
roll,
yaw
} = face.angleArray;
const standard = 0.5
if (Math.abs(pitch) >= standard || Math.abs(roll) >= standard ||
Math.abs(yaw) >= standard) {
this.tipsText = '请平视摄像头'
} else if (face.confArray.global <= 0.8 || face.confArray.leftEye <=
0.8 || face.confArray.mouth <= 0.8 || face.confArray.nose <= 0.8 ||
face.confArray.rightEye <= 0.8) {
this.tipsText = '请勿遮挡五官'
} else {
this.tipsText = '请拍照'
//
// this.handleTakePhotoClick()
}
}
},
fail: (err) => {
if (err.x == -1 || err.y == -1) {
this.tipsText = '检测不到人'
} else {
this.tipsText = err.errMsg || '网络错误,请退出页面重试'
}
},
})
})
// 5
listener.start()
this.isPhoto = true
// #endif
},
//
handleTakePhotoClick() {
if (this.tipsText != ""
&& this.tipsText != "请拍照"
&& !this.tempImg) {
return;
}
uni.getSetting({
success: (res) => {
if (!res.authSetting['scope.camera']) {
this.isAuthCamera = false
uni.openSetting({
success: (res) => {
if (res.authSetting['scope.camera']) {
this.isAuthCamera = true;
}
}
})
}
}
})
this.cameraEngine.takePhoto({
quality: "high",
success: ({
tempImagePath
}) => {
this.tempImg = tempImagePath
console.log("=======tempImg:", this.tempImg)
}
})
},
}
}
</script>
@ -182,9 +312,14 @@
.human-face-img {
display: flex;
justify-content: center;
image {
width: 70%;
width: 500rpx;
border-radius: 50%;
}
.camera{
width: 500rpx;
height: 500rpx;
border-radius: 50%;
}
}


+ 0
- 10
utils/oss-upload/oss/index.js View File

@ -2,10 +2,6 @@
* 阿里云OSS工具类
*/
import OSSConfig from "@/utils/oss-upload/oss/OSSConfig.js"
//支持web端
import {
uploadFileToOSS
} from '@/utils/oss-upload/oss/web.js'
import ossConfig from '@/config.js'
/**
@ -93,9 +89,6 @@ export function ossUploadImage({
count: 1,
sizeType,
success(res) {
// #ifdef H5
return uploadFileToOSS(res.tempFiles[0]).then(success).catch(fail)
// #endif
ossUpload(res.tempFilePaths[0], key, folder).then(success).catch(fail)
},
fail
@ -123,9 +116,6 @@ export function ossUploadVideo({
maxDuration,
camera,
success(res) {
// #ifdef H5
return uploadFileToOSS(res.tempFile).then(success).catch(fail)
// #endif
ossUpload(res.tempFilePath, key, folder).then(success).catch(fail)
},
fail


+ 1
- 1
utils/oss-upload/oss/web.js View File

@ -1,5 +1,5 @@
// 此方法适用于web
import OSS from "ali-oss"
// import OSS from "ali-oss"
import config from '@/config.js'
/**


Loading…
Cancel
Save