|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
<view class="home">
|
|
|
- <camera class="camera" device-position="front" flash="off"></camera>
|
|
|
+ <!-- <camera class="camera" device-position="front" flash="off"></camera> -->
|
|
|
<image v-if="tempImg" mode="widthFix" :src="tempImg" />
|
|
|
</view>
|
|
|
</template>
|
|
@@ -12,16 +12,15 @@
|
|
|
data() {
|
|
|
return {
|
|
|
cameraAuth: false,
|
|
|
+ locationAuth: false,
|
|
|
tempImg: '',
|
|
|
VKSession: null,
|
|
|
videoCtx: null,
|
|
|
listener: null
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
- mounted() {
|
|
|
- this.getAuth()
|
|
|
- this.initData()
|
|
|
+ onShow() {
|
|
|
+ this.getLocationAuth()
|
|
|
},
|
|
|
onUnload() {
|
|
|
this.VKSession?.destroy()
|
|
@@ -30,8 +29,21 @@
|
|
|
console.log('listener.stop', res)
|
|
|
}
|
|
|
})
|
|
|
+ this.VKSession = null
|
|
|
+ this.listener = null
|
|
|
},
|
|
|
methods: {
|
|
|
+ getMyLocation() {
|
|
|
+ console.log('getMyLocation:')
|
|
|
+ uni.getLocation({
|
|
|
+ success(res) {
|
|
|
+ console.log('位置信息', res)
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log('fail:', err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
async openSetting() {
|
|
|
const _this = this
|
|
|
let promise = new Promise((resolve, reject) => {
|
|
@@ -57,38 +69,72 @@
|
|
|
}
|
|
|
})
|
|
|
} else if (res.cancel) {
|
|
|
- setTimeout(() => {
|
|
|
- _this.openSetting().then((res) => {
|
|
|
- resolve(true)
|
|
|
- })
|
|
|
- }, 3000)
|
|
|
+ // setTimeout(() => {
|
|
|
+ // _this.openSetting().then((res) => {
|
|
|
+ // resolve(true)
|
|
|
+ // })
|
|
|
+ // }, 3000)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
return promise
|
|
|
},
|
|
|
- async getAuth() {
|
|
|
+ async getLocationAuth() {
|
|
|
+ const _this = this
|
|
|
+ uni.getSetting({
|
|
|
+ success(res) {
|
|
|
+ console.log('authSetting:', res.authSetting)
|
|
|
+
|
|
|
+ if (res.authSetting['scope.userLocation']) {
|
|
|
+ // 用户已经授权
|
|
|
+ _this.locationAuth = true
|
|
|
+ _this.getMyLocation()
|
|
|
+ } else {
|
|
|
+ uni.authorize({
|
|
|
+ scope: 'scope.userLocation',
|
|
|
+ success() {
|
|
|
+ // 用户同意授权
|
|
|
+ _this.locationAuth = true
|
|
|
+ _this.getMyLocation()
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ // 用户不同意授权
|
|
|
+ // _this.openSetting().then((res) => {
|
|
|
+ // console.log('终于授权了')
|
|
|
+ // _this.cameraAuth = true
|
|
|
+ // })
|
|
|
+ _this.locationAuth = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //获取摄像头权限,按需调用,如果该用户被配置为需要人脸打卡,再引导用户开启
|
|
|
+ getCameraAuth() {
|
|
|
const _this = this
|
|
|
uni.getSetting({
|
|
|
success(res) {
|
|
|
- console.log('sss', res.authSetting)
|
|
|
if (res.authSetting['scope.camera']) {
|
|
|
// 用户已经授权
|
|
|
_this.cameraAuth = true
|
|
|
+ _this.initFaceData()
|
|
|
} else {
|
|
|
uni.authorize({
|
|
|
scope: 'scope.camera',
|
|
|
success() {
|
|
|
// 用户同意授权
|
|
|
_this.cameraAuth = true
|
|
|
+ _this.initFaceData()
|
|
|
},
|
|
|
fail() {
|
|
|
// 用户不同意授权
|
|
|
- _this.openSetting().then((res) => {
|
|
|
- console.log('终于授权了')
|
|
|
- _this.cameraAuth = true
|
|
|
- })
|
|
|
+ // _this.openSetting().then((res) => {
|
|
|
+ // console.log('终于授权了')
|
|
|
+ // _this.cameraAuth = true
|
|
|
+ // })
|
|
|
+ _this.cameraAuth = false
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -105,7 +151,10 @@
|
|
|
modelMode: 1
|
|
|
})
|
|
|
},
|
|
|
- initData() {
|
|
|
+ initFaceData() {
|
|
|
+ if (this.VKSession && this.listener) {
|
|
|
+ return
|
|
|
+ }
|
|
|
this.videoCtx = wx.createCameraContext()
|
|
|
console.log('videoCtx:', this.videoCtx)
|
|
|
let count = 0
|