【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.

427 lines
9.6 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
7 months ago
7 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
7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
7 months ago
6 months ago
7 months ago
7 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
  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. <div class="btn"
  53. @click="handleTakePhotoClick"
  54. v-if="tipsText == '请拍照' && type == 'auth'">
  55. 立即核验
  56. </div>
  57. <div class="btn"
  58. @click="handleTakePhotoClick"
  59. v-else-if="tipsText == '请拍照'">
  60. <uv-upload
  61. multiple
  62. :maxCount="1"
  63. capture="camera"
  64. height="180rpx"
  65. @afterRead="afterRead">
  66. <view style="display: flex;justify-content: center;
  67. width: 600rpx;">
  68. 立即核验
  69. </view>
  70. </uv-upload>
  71. </div>
  72. </view>
  73. </template>
  74. <script>
  75. import position from '@/utils/position.js'
  76. import {
  77. mapState
  78. } from 'vuex'
  79. export default {
  80. name: "HumanFace",
  81. data() {
  82. return {
  83. isPhoto: false,
  84. form : {
  85. pic : '',
  86. },
  87. isLocationSubmit : false,//定位完成时提交
  88. tipsText: '', // 错误文案提示
  89. tempImg: '', // 本地图片路径
  90. cameraEngine: null, // 相机引擎
  91. devicePosition: true, // 摄像头朝向
  92. isAuthCamera: true, // 是否拥有相机权限
  93. type : '',
  94. }
  95. },
  96. computed: {
  97. ...mapState(['teamList', 'userInfo', 'authInfo']),
  98. },
  99. onLoad(args) {
  100. if(args.type){
  101. this.type = args.type
  102. }
  103. this.initData()
  104. },
  105. onShow() {
  106. let self = this
  107. position.getLocationDetail()
  108. .then(res => {
  109. console.log(res);
  110. self.form.lat = res.position.latitude
  111. self.form.lon = res.position.longitude
  112. self.form.address = res.address
  113. if(self.isLocationSubmit){
  114. self.submit()
  115. }
  116. })
  117. },
  118. methods: {
  119. afterRead(e) {
  120. let self = this
  121. e.file.forEach(file => {
  122. self.$Oss.ossUpload(file.url).then(url => {
  123. self.form.pic = url
  124. if(self.form.lat){
  125. self.submit()
  126. }else{
  127. uni.showLoading({
  128. title: '定位中...'
  129. })
  130. self.isLocationSubmit = true
  131. }
  132. })
  133. })
  134. },
  135. // 人脸认证通过后拍照
  136. photo() {
  137. let self = this
  138. uni.chooseImage({
  139. count: 1, //默认9
  140. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  141. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  142. sourceType: ['camera '], //这要注意,camera掉拍照,album是打开手机相册
  143. success: function(res) {
  144. console.log(JSON.stringify(res.tempFilePaths));
  145. //后续在这里上传文件
  146. self.$Oss.ossUpload(res.tempFilePaths[0]).then(url => {
  147. self.form.pic = url
  148. if(self.form.lat){
  149. self.submit()
  150. }else{
  151. uni.showLoading({
  152. title: '定位中...'
  153. })
  154. self.isLocationSubmit = true
  155. }
  156. })
  157. // uni.navigateTo({
  158. // url: "/pages/subPack/punchCard/punchCard"
  159. // })
  160. }
  161. });
  162. },
  163. async submit(){
  164. if (this.$utils.verificationAll(this.form, {
  165. lat : '经纬度缺失,请打开GPS',
  166. lon : '经纬度缺失,请打开GPS',
  167. address : '获取地址失败',
  168. pic : '请拍照',
  169. })) {
  170. return
  171. }
  172. this.$api('clock', this.form, res => {
  173. if(res.code == 200){
  174. uni.showToast({
  175. title: '打卡成功',
  176. icon:'none'
  177. })
  178. setTimeout(uni.navigateBack, 1000, -1)
  179. }else{
  180. this.$nextTick(() => {
  181. this.form.image = ''
  182. this.tempImg = ''
  183. })
  184. }
  185. })
  186. },
  187. // 初始化相机引擎
  188. initData() {
  189. // #ifdef MP-WEIXIN
  190. // 1、初始化人脸识别
  191. wx.initFaceDetect()
  192. // 2、创建 camera 上下文 CameraContext 对象
  193. this.cameraEngine = wx.createCameraContext()
  194. // 3、获取 Camera 实时帧数据
  195. const listener = this.cameraEngine.onCameraFrame((frame) => {
  196. if (this.tempImg) {
  197. return;
  198. }
  199. // 4、人脸识别,使用前需要通过 wx.initFaceDetect 进行一次初始化,推荐使用相机接口返回的帧数据
  200. wx.faceDetect({
  201. frameBuffer: frame.data,
  202. width: frame.width,
  203. height: frame.height,
  204. enablePoint: true,
  205. enableConf: true,
  206. enableAngle: true,
  207. enableMultiFace: true,
  208. success: (faceData) => {
  209. let face = faceData.faceInfo[0]
  210. if (faceData.x == -1 || faceData.y == -1) {
  211. this.tipsText = '检测不到人'
  212. }
  213. if (faceData.faceInfo.length > 1) {
  214. this.tipsText = '请保证只有一个人'
  215. } else {
  216. const {
  217. pitch,
  218. roll,
  219. yaw
  220. } = face.angleArray;
  221. const standard = 0.5
  222. if (Math.abs(pitch) >= standard || Math.abs(roll) >= standard ||
  223. Math.abs(yaw) >= standard) {
  224. this.tipsText = '请平视摄像头'
  225. } else if (face.confArray.global <= 0.8 || face.confArray.leftEye <=
  226. 0.8 || face.confArray.mouth <= 0.8 || face.confArray.nose <= 0.8 ||
  227. face.confArray.rightEye <= 0.8) {
  228. this.tipsText = '请勿遮挡五官'
  229. } else {
  230. this.tipsText = '请拍照'
  231. // 这里可以写自己的逻辑了
  232. // this.handleTakePhotoClick()
  233. }
  234. }
  235. },
  236. fail: (err) => {
  237. if (err.x == -1 || err.y == -1) {
  238. this.tipsText = '检测不到人'
  239. } else {
  240. this.tipsText = err.errMsg || '网络错误,请退出页面重试'
  241. }
  242. },
  243. })
  244. })
  245. // 5、开始监听帧数据
  246. listener.start()
  247. this.isPhoto = true
  248. // #endif
  249. },
  250. // 拍照
  251. handleTakePhotoClick() {
  252. if (this.tipsText != ""
  253. && this.tipsText != "请拍照"
  254. && !this.tempImg) {
  255. return;
  256. }
  257. uni.getSetting({
  258. success: (res) => {
  259. if (!res.authSetting['scope.camera']) {
  260. this.isAuthCamera = false
  261. uni.openSetting({
  262. success: (res) => {
  263. if (res.authSetting['scope.camera']) {
  264. this.isAuthCamera = true;
  265. }
  266. }
  267. })
  268. }
  269. }
  270. })
  271. this.cameraEngine.takePhoto({
  272. quality: "high",
  273. success: ({
  274. tempImagePath
  275. }) => {
  276. this.tempImg = tempImagePath
  277. // 上传图片
  278. this.$Oss.ossUpload(tempImagePath).then(url => {
  279. // 实名认证,上传人脸
  280. if(this.type == 'auth'){
  281. let form = {
  282. ...this.authInfo,
  283. pic : url
  284. }
  285. this.$api('authApply', form, res => {
  286. if(res.code == 200){
  287. setTimeout(uni.reLaunch, 1000, {
  288. url: '/pages/index/index'
  289. })
  290. }else{
  291. setTimeout(uni.navigateBack, 1000, -1)
  292. }
  293. })
  294. return
  295. }
  296. this.form.image = url
  297. if(this.form.lat){
  298. this.submit()
  299. }else{
  300. uni.showLoading({
  301. title: '定位中...'
  302. })
  303. this.isLocationSubmit = true
  304. }
  305. })
  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>