diff --git a/api/api.js b/api/api.js index 28754b3..2f41c6b 100644 --- a/api/api.js +++ b/api/api.js @@ -78,6 +78,23 @@ const config = { }, + // 打卡时间的接口 + clockTime: { + url: '/clock/time', + method: 'POST', + showLoading : true, + auth : true, + }, + // 人脸识别 + clockVerifyFace: { + url: '/clock/verify/face', + method: 'POST', + showLoading : true, + auth : true, + limit : 2000, + loadingTitle : '核验中', + }, + // 打卡 clock: { url: '/clock/in', diff --git a/pages/index/index.vue b/pages/index/index.vue index d53edc8..517e060 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -27,7 +27,7 @@ - + 拍照打卡 {{ date.format('YYYY-MM-DD HH:mm:ss') }} @@ -100,6 +100,22 @@ openBroadside() { this.$refs.broadside.open() }, + + toClock(){ + // 检查当前是否在打卡时间段内 + this.$api('clockTime', { + lon : this.longitude, + lat : this.latitude + }, res => { + //打卡(跳转人脸识别) + if(res.code == 200){ + uni.navigateTo({ + // url: "/pages/subPack/face/face" + url: "/pages/subPack/human/human" + }) + } + }) + }, //获取用户位置 getLocation() { @@ -109,20 +125,19 @@ success: function(res) { self.longitude = res.longitude; self.latitude = res.latitude; - self.covers.push({ - id: 1, - latitude: res.latitude, - longitude: res.longitude, - iconPath: 'https://tennis-oss.xzaiyp.top/2024-10-22/103fa1db-8524-45e6-8d00-c36a69977a5b.png', - width: 30, - height: 30 - }) + // self.covers.push({ + // id: 1, + // latitude: res.latitude, + // longitude: res.longitude, + // iconPath: 'https://tennis-oss.xzaiyp.top/2024-10-22/103fa1db-8524-45e6-8d00-c36a69977a5b.png', + // width: 30, + // height: 30 + // }) }, fail() { self.checkAndRequestLocationPermission() } }); - }, checkAndRequestLocationPermission() { @@ -166,14 +181,6 @@ } }); }, - - //打卡(跳转人脸识别) - callCard(){ - uni.navigateTo({ - // url: "/pages/subPack/face/face" - url: "/pages/subPack/human/human" - }) - } } } diff --git a/pages/subPack/autonym/autonym.vue b/pages/subPack/autonym/autonym.vue index 902df91..4ceadf7 100644 --- a/pages/subPack/autonym/autonym.vue +++ b/pages/subPack/autonym/autonym.vue @@ -58,7 +58,6 @@ ...mapState(['userInfo']), }, onShow() { - this.$store.commit('getUserInfo') this.getAuthInfo() }, methods: { @@ -95,6 +94,7 @@ if(res.result){ this.form.cardNo = res.result.cardNo this.form.name = res.result.name + this.$store.commit('getUserInfo') } }) }, diff --git a/pages/subPack/human/human.vue b/pages/subPack/human/human.vue index 79693ba..e38df22 100644 --- a/pages/subPack/human/human.vue +++ b/pages/subPack/human/human.vue @@ -58,16 +58,21 @@ -
+ v-if="tipsText == successText && type == 'auth'"> 立即核验 -
+
+ + + 立即核验 + -
+ - 立即核验 + 拍照打卡 -
+
@@ -109,6 +114,10 @@ isAuthCamera: true, // 是否拥有相机权限 type : '', + + isVerifyFace : false,//人脸核验是否成功 + + successText : '请保持不动',//成功文案 } }, computed: { @@ -125,8 +134,8 @@ position.getLocationDetail() .then(res => { console.log(res); - self.form.lat = res.position.latitude - self.form.lon = res.position.longitude + self.form.lat = res.latitude + self.form.lon = res.longitude self.form.address = res.address if(self.isLocationSubmit){ self.submit() @@ -150,39 +159,6 @@ }) }) }, - // 人脸认证通过后拍照 - photo() { - let self = this - uni.chooseImage({ - count: 1, //默认9 - sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有 - // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 - sourceType: ['camera '], //这要注意,camera掉拍照,album是打开手机相册 - success: function(res) { - console.log(JSON.stringify(res.tempFilePaths)); - //后续在这里上传文件 - - self.$Oss.ossUpload(res.tempFilePaths[0]).then(url => { - self.form.pic = url - - if(self.form.lat){ - self.submit() - }else{ - uni.showLoading({ - title: '定位中...' - }) - self.isLocationSubmit = true - } - - }) - - - // uni.navigateTo({ - // url: "/pages/subPack/punchCard/punchCard" - // }) - } - }); - }, async submit(){ if (this.$utils.verificationAll(this.form, { lat : '经纬度缺失,请打开GPS', @@ -212,6 +188,10 @@ }, // 初始化相机引擎 initData() { + + let createTime = new Date().getTime() + let num = 0 + // #ifdef MP-WEIXIN @@ -246,18 +226,33 @@ roll, yaw } = face.angleArray; + const standard = 0.5 + + let faseP = 0.98 + 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) { + } else if (face.confArray.global <= faseP || face.confArray.leftEye <= + faseP || face.confArray.mouth <= faseP || face.confArray.nose <= faseP || + face.confArray.rightEye <= faseP) { this.tipsText = '请勿遮挡五官' } else { - this.tipsText = '请拍照' + this.tipsText = this.successText // 这里可以写自己的逻辑了 // this.handleTakePhotoClick() + + // if(num > 2){ + // uni.showToast({ + // title: '人脸核验' + // }) + // return + // } + + // if(createTime - new Date().getTime() > 2000){ + + // } } } }, @@ -279,8 +274,8 @@ // 拍照 handleTakePhotoClick() { - if (this.tipsText != "" - && this.tipsText != "请拍照" + if (this.tipsText != "" + && this.tipsText != this.successText && !this.tempImg) { return; } @@ -329,7 +324,26 @@ this.form.image = url + if(!this.isVerifyFace){ + this.clockVerifyFace() + } + }) + } + }) + }, + + // 人脸核验 + clockVerifyFace(){ + this.$api('clockVerifyFace', + this.form, res => { + if(res.code == 200){ + uni.showToast({ + title: '核验成功!', + icon: 'icon' }) + this.isVerifyFace = true + }else{ + uni.navigateBack(-1) } }) }, diff --git a/store/store.js b/store/store.js index f50ebc6..61ed5e3 100644 --- a/store/store.js +++ b/store/store.js @@ -116,6 +116,9 @@ const store = new Vuex.Store({ setAuthInfo(state, data){ state.authInfo = data }, + getLocation(state){ + + }, }, actions: {}, }) diff --git a/utils/position.js b/utils/position.js index a5e46fc..1e00e87 100644 --- a/utils/position.js +++ b/utils/position.js @@ -32,11 +32,11 @@ function calculateDistance(lat1, lon1, lat2, lon2, fixed = 0) { //计算两点 } function getLocation(fn) { //获取用户经纬度 - wxGetLocation() //此方法只用于提示用户打开gps + // wxGetLocation() //此方法只用于提示用户打开gps uni.getLocation({ type: 'gcj02', isHighAccuracy: true, - highAccuracyExpireTime: 1000, + // highAccuracyExpireTime: 1000, success: function(position) { fn(position) }, @@ -50,15 +50,17 @@ function getLocation(fn) { //获取用户经纬度 } function getLocationDetail() { //获取用户详细地址 - wxGetLocation() + // wxGetLocation() return new Promise((resolve, reject) => { let key = config.mapKey; //腾讯地图key uni.getLocation({ type: 'gcj02', isHighAccuracy: true, - highAccuracyExpireTime: 1000, + // highAccuracyExpireTime: 1000, success: function(position) { getUserAddress(position.latitude, position.longitude, key).then(res => { + res.latitude = position.latitude + res.longitude = position.longitude resolve(res) }) },