+
+
@@ -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)
+ }
+ })
+ },
}
}
@@ -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%;
}
}
diff --git a/utils/oss-upload/oss/index.js b/utils/oss-upload/oss/index.js
index 024eb80..91b7093 100644
--- a/utils/oss-upload/oss/index.js
+++ b/utils/oss-upload/oss/index.js
@@ -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
diff --git a/utils/oss-upload/oss/web.js b/utils/oss-upload/oss/web.js
index dfaab6e..9b419ae 100644
--- a/utils/oss-upload/oss/web.js
+++ b/utils/oss-upload/oss/web.js
@@ -1,5 +1,5 @@
// 此方法适用于web
-import OSS from "ali-oss"
+// import OSS from "ali-oss"
import config from '@/config.js'
/**