【PT.SCC实名制管理系统】24.10.01 -30天,考勤打卡小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

433 lines
9.5 KiB

7 months ago
7 months ago
6 months ago
6 months ago
7 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago
7 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago
6 months ago
6 months ago
6 months ago
7 months ago
6 months ago
7 months ago
6 months ago
6 months ago
7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
6 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
6 months ago
7 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. <!-- 人脸识别 -->
  2. <template>
  3. <view class="human-face">
  4. <!-- 自定义导航栏 -->
  5. <uni-nav-bar dark :fixed="true" shadow background-color="var(--main-color)" status-bar left-icon="left"
  6. title="人脸识别" @clickLeft="$utils.navigateBack" />
  7. <!-- 人脸识别说明标题 -->
  8. <view class="human-face-title">为保证本人操作请进行人脸验证</view>
  9. <!-- 人脸识别图片 -->
  10. <view class="human-face-img">
  11. <image v-if="!isPhoto"
  12. src="https://tennis-oss.xzaiyp.top/2024-10-22/508376c5-64b2-472f-8e25-a2469b632a39.png" mode="widthFix">
  13. </image>
  14. <image v-else-if="!!tempImg"
  15. :src="tempImg" mode="widthFix">
  16. </image>
  17. <camera
  18. v-else
  19. :device-position="devicePosition ?'front': 'back'"
  20. class="camera"
  21. flash="off"
  22. resolution='high' />
  23. </view>
  24. <!-- 人脸识别说明 -->
  25. <view class="human-face-desc"
  26. v-if="!isPhoto">
  27. 人脸认证仅能由<text class="name">{{ userInfo.auth.name }}</text>本人完成验证时请将镜头对准您的脸部
  28. </view>
  29. <view class="human-face-desc"
  30. v-else>
  31. {{ tipsText }}
  32. </view>
  33. <!-- 说明 -->
  34. <view class="desc">
  35. <view class="desc-item">
  36. <image src="https://tennis-oss.xzaiyp.top/2024-10-22/a0bf2da9-c25a-4d5c-8c77-7318bd86227d.png"
  37. mode="widthFix"></image>
  38. <view class="text">避免遮挡</view>
  39. </view>
  40. <view class="desc-item">
  41. <image src="https://tennis-oss.xzaiyp.top/2024-10-22/feb72bfb-8271-4e48-8081-d72811543918.png"
  42. mode="widthFix"></image>
  43. <view class="text">光线充足</view>
  44. </view>
  45. <view class="desc-item">
  46. <image src="https://tennis-oss.xzaiyp.top/2024-10-22/5fd8a6a7-a13e-44d6-acf1-a7ada94c699d.png"
  47. mode="widthFix"></image>
  48. <view class="text">正对充足</view>
  49. </view>
  50. </view>
  51. <!-- 实名认证 -->
  52. <view class="btn"
  53. @click="handleTakePhotoClick"
  54. v-if="tipsText == successText && type == 'auth'">
  55. 立即核验
  56. </view>
  57. <!-- 人脸核验 -->
  58. <view class="btn"
  59. v-else-if="tipsText == successText && !isVerifyFace"
  60. @click="handleTakePhotoClick">
  61. 立即核验
  62. </view>
  63. <view class="btn"
  64. v-else-if="tipsText == successText">
  65. <uv-upload
  66. multiple
  67. :maxCount="1"
  68. capture="camera"
  69. height="180rpx"
  70. @afterRead="afterRead">
  71. <view style="display: flex;justify-content: center;
  72. width: 600rpx;">
  73. 拍照打卡
  74. </view>
  75. </uv-upload>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import position from '@/utils/position.js'
  81. import {
  82. mapState
  83. } from 'vuex'
  84. export default {
  85. name: "HumanFace",
  86. data() {
  87. return {
  88. isPhoto: false,
  89. form : {
  90. pic : '',
  91. },
  92. isLocationSubmit : false,//定位完成时提交
  93. tipsText: '', // 错误文案提示
  94. tempImg: '', // 本地图片路径
  95. cameraEngine: null, // 相机引擎
  96. devicePosition: true, // 摄像头朝向
  97. isAuthCamera: true, // 是否拥有相机权限
  98. type : '',
  99. isVerifyFace : false,//人脸核验是否成功
  100. successText : '请保持不动',//成功文案
  101. }
  102. },
  103. computed: {
  104. ...mapState(['teamList', 'userInfo', 'authInfo']),
  105. },
  106. onLoad(args) {
  107. if(args.type){
  108. this.type = args.type
  109. }
  110. this.initData()
  111. },
  112. onShow() {
  113. let self = this
  114. position.getLocationDetail()
  115. .then(res => {
  116. console.log(res);
  117. self.form.lat = res.latitude
  118. self.form.lon = res.longitude
  119. self.form.address = res.address
  120. if(self.isLocationSubmit){
  121. self.submit()
  122. }
  123. })
  124. },
  125. methods: {
  126. afterRead(e) {
  127. let self = this
  128. e.file.forEach(file => {
  129. self.$Oss.ossUpload(file.url).then(url => {
  130. self.form.pic = url
  131. if(self.form.lat){
  132. self.submit()
  133. }else{
  134. uni.showLoading({
  135. title: '定位中...'
  136. })
  137. self.isLocationSubmit = true
  138. }
  139. })
  140. })
  141. },
  142. async submit(){
  143. if (this.$utils.verificationAll(this.form, {
  144. lat : '经纬度缺失,请打开GPS',
  145. lon : '经纬度缺失,请打开GPS',
  146. address : '获取地址失败',
  147. pic : '请拍照',
  148. })) {
  149. return
  150. }
  151. this.$api('clock', this.form, res => {
  152. if(res.code == 200){
  153. uni.showToast({
  154. title: '打卡成功',
  155. icon:'none'
  156. })
  157. setTimeout(uni.navigateBack, 1000, -1)
  158. }else{
  159. this.$nextTick(() => {
  160. this.form.image = ''
  161. this.tempImg = ''
  162. })
  163. }
  164. })
  165. },
  166. // 初始化相机引擎
  167. initData() {
  168. let createTime = new Date().getTime()
  169. let num = 0
  170. // #ifdef MP-WEIXIN
  171. // 1、初始化人脸识别
  172. wx.initFaceDetect()
  173. // 2、创建 camera 上下文 CameraContext 对象
  174. this.cameraEngine = wx.createCameraContext()
  175. // 3、获取 Camera 实时帧数据
  176. const listener = this.cameraEngine.onCameraFrame((frame) => {
  177. if (this.tempImg) {
  178. return;
  179. }
  180. // 4、人脸识别,使用前需要通过 wx.initFaceDetect 进行一次初始化,推荐使用相机接口返回的帧数据
  181. wx.faceDetect({
  182. frameBuffer: frame.data,
  183. width: frame.width,
  184. height: frame.height,
  185. enablePoint: true,
  186. enableConf: true,
  187. enableAngle: true,
  188. enableMultiFace: true,
  189. success: (faceData) => {
  190. let face = faceData.faceInfo[0]
  191. if (faceData.x == -1 || faceData.y == -1) {
  192. this.tipsText = '检测不到人'
  193. }
  194. if (faceData.faceInfo.length > 1) {
  195. this.tipsText = '请保证只有一个人'
  196. } else {
  197. const {
  198. pitch,
  199. roll,
  200. yaw
  201. } = face.angleArray;
  202. const standard = 0.5
  203. let faseP = 0.98
  204. if (Math.abs(pitch) >= standard || Math.abs(roll) >= standard ||
  205. Math.abs(yaw) >= standard) {
  206. this.tipsText = '请平视摄像头'
  207. } else if (face.confArray.global <= faseP || face.confArray.leftEye <=
  208. faseP || face.confArray.mouth <= faseP || face.confArray.nose <= faseP ||
  209. face.confArray.rightEye <= faseP) {
  210. this.tipsText = '请勿遮挡五官'
  211. } else {
  212. this.tipsText = this.successText
  213. // 这里可以写自己的逻辑了
  214. // this.handleTakePhotoClick()
  215. // if(num > 2){
  216. // uni.showToast({
  217. // title: '人脸核验'
  218. // })
  219. // return
  220. // }
  221. // if(createTime - new Date().getTime() > 2000){
  222. // }
  223. }
  224. }
  225. },
  226. fail: (err) => {
  227. if (err.x == -1 || err.y == -1) {
  228. this.tipsText = '检测不到人'
  229. } else {
  230. this.tipsText = err.errMsg || '网络错误,请退出页面重试'
  231. }
  232. },
  233. })
  234. })
  235. // 5、开始监听帧数据
  236. listener.start()
  237. this.isPhoto = true
  238. // #endif
  239. },
  240. // 拍照
  241. handleTakePhotoClick() {
  242. if (this.tipsText != ""
  243. && this.tipsText != this.successText
  244. && !this.tempImg) {
  245. return;
  246. }
  247. uni.getSetting({
  248. success: (res) => {
  249. if (!res.authSetting['scope.camera']) {
  250. this.isAuthCamera = false
  251. uni.openSetting({
  252. success: (res) => {
  253. if (res.authSetting['scope.camera']) {
  254. this.isAuthCamera = true;
  255. }
  256. }
  257. })
  258. }
  259. }
  260. })
  261. this.cameraEngine.takePhoto({
  262. quality: "high",
  263. success: ({
  264. tempImagePath
  265. }) => {
  266. this.tempImg = tempImagePath
  267. // 上传图片
  268. this.$Oss.ossUpload(tempImagePath).then(url => {
  269. // 实名认证,上传人脸
  270. if(this.type == 'auth'){
  271. let form = {
  272. ...this.authInfo,
  273. pic : url
  274. }
  275. this.$api('authApply', form, res => {
  276. if(res.code == 200){
  277. setTimeout(uni.reLaunch, 1000, {
  278. url: '/pages/index/index'
  279. })
  280. }else{
  281. setTimeout(uni.navigateBack, 1000, -1)
  282. }
  283. })
  284. return
  285. }
  286. this.form.image = url
  287. if(!this.isVerifyFace){
  288. this.clockVerifyFace()
  289. }
  290. })
  291. }
  292. })
  293. },
  294. // 人脸核验
  295. clockVerifyFace(){
  296. this.$api('clockVerifyFace',
  297. this.form, res => {
  298. if(res.code == 200){
  299. uni.showToast({
  300. title: '核验成功!',
  301. icon: 'icon'
  302. })
  303. this.isVerifyFace = true
  304. }else{
  305. uni.navigateBack(-1)
  306. }
  307. })
  308. },
  309. }
  310. }
  311. </script>
  312. <style lang="scss" scoped>
  313. .human-face {
  314. min-height: 100vh;
  315. background: white;
  316. // 人脸识别说明标题
  317. .human-face-title {
  318. font-size: 35rpx;
  319. font-weight: bold;
  320. margin: 60rpx 0rpx;
  321. text-align: center;
  322. }
  323. // 人脸识别图片
  324. .human-face-img {
  325. display: flex;
  326. justify-content: center;
  327. image {
  328. width: 500rpx;
  329. border-radius: 50%;
  330. }
  331. .camera{
  332. width: 500rpx;
  333. height: 500rpx;
  334. border-radius: 50%;
  335. }
  336. }
  337. // 人脸识别说明
  338. .human-face-desc {
  339. color: #707070;
  340. width: 55%;
  341. font-size: 30rpx;
  342. margin: 30rpx auto;
  343. text-align: center;
  344. .name {
  345. color: $main-color;
  346. }
  347. }
  348. // 说明
  349. .desc {
  350. width: 80%;
  351. display: flex;
  352. flex-wrap: wrap;
  353. margin: 100rpx auto;
  354. .desc-item {
  355. width: 33.33%;
  356. display: flex;
  357. flex-direction: column;
  358. align-items: center;
  359. justify-content: center;
  360. image {
  361. width: 50%;
  362. }
  363. .text {
  364. font-size: 30rpx;
  365. color: #707070;
  366. margin-top: 10rpx;
  367. }
  368. }
  369. }
  370. // 立即核验
  371. .btn {
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. width: 83%;
  376. background: $main-color;
  377. color: white;
  378. height: 100rpx;
  379. border-radius: 50rpx;
  380. margin: 0rpx auto;
  381. }
  382. }
  383. </style>