refactor(train_management): 优化人脸认证逻辑和首页功能
- 修改了 face_authentication 页面的返回逻辑- 优化了 index 页面的扫码功能和人脸认证提示 -移除了生成二维码的冗余请求hyx_2025-01-13_xgf2.0
							parent
							
								
									4934e79c45
								
							
						
					
					
						commit
						e348a2248f
					
				|  | @ -26,16 +26,9 @@ | |||
| 				</view> | ||||
| 			</view> | ||||
| 		</view> | ||||
| 		<u-modal | ||||
| 			:show="updateVersion.modalShow" | ||||
| 			title="温馨提示" | ||||
| 			:showConfirmButton="updateVersion.showConfirmButton" | ||||
| 			:showCancelButton="updateVersion.showCancelButton" | ||||
| 			:confirmText="updateVersion.confirmText" | ||||
| 			:cancelText="updateVersion.cancelText" | ||||
| 			@cancel="modalCancel" | ||||
| 			@confirm="modalConfirm" | ||||
| 		> | ||||
| 		<u-modal :show="updateVersion.modalShow" title="温馨提示" :showConfirmButton="updateVersion.showConfirmButton" | ||||
| 			:showCancelButton="updateVersion.showCancelButton" :confirmText="updateVersion.confirmText" | ||||
| 			:cancelText="updateVersion.cancelText" @cancel="modalCancel" @confirm="modalConfirm"> | ||||
| 			<view style="text-align: center; color: #606266"> | ||||
| 				<rich-text :nodes="updateVersion.modalContent"></rich-text> | ||||
| 			</view> | ||||
|  | @ -45,220 +38,254 @@ | |||
| </template> | ||||
| 
 | ||||
| <script> | ||||
| import updateVersion from '../../utils/updateVersion' | ||||
| import {setEntry, getIsUploadFace, getClassInfoByParams, getClassList} from '../../api' | ||||
| import { getStudentInfoApi, setEntryV1} from "../../api/api"; | ||||
| import store from "../../store"; | ||||
| 	import updateVersion from '../../utils/updateVersion' | ||||
| 	import { | ||||
| 		setEntry, | ||||
| 		getIsUploadFace, | ||||
| 		getClassInfoByParams, | ||||
| 		getClassList | ||||
| 	} from '../../api' | ||||
| 	import { | ||||
| 		getStudentInfoApi, | ||||
| 		setEntryV1 | ||||
| 	} from "../../api/api"; | ||||
| 	import store from "../../store"; | ||||
| 
 | ||||
| export default { | ||||
| 	mixins: [updateVersion], | ||||
| 	data() { | ||||
| 		return { | ||||
| 			baseList: [ | ||||
| 				{ | ||||
| 					img: require('../../static/icon-apps/app_icons.png'), | ||||
| 					title: '电子工牌', | ||||
| 					url: '/pages/electronic_work_card/index' | ||||
| 				}, | ||||
| 				{ | ||||
| 					img: require('../../static/icon-apps/app_icons2.png'), | ||||
| 					title: '服务单位 管理', | ||||
| 					url: '/pages/service_unit_management/index' | ||||
| 				}, | ||||
| 				{ | ||||
| 					img: require('../../static/icon-apps/app_icons3.png'), | ||||
| 					title: '我的信息', | ||||
| 					url: '/pages/mine/information/index' | ||||
| 				}, | ||||
| 				{ | ||||
| 					img: require('../../static/icon-apps/app_icons4.png'), | ||||
| 					title: '证书信息', | ||||
| 					url: '/pages/certificate_information/index' | ||||
| 				}, | ||||
| 				{ | ||||
| 					img: require('../../static/icon-apps/app_icons5.png'), | ||||
| 					title: '就职单位', | ||||
| 					url: '/pages/employed_by/index' | ||||
| 				}, | ||||
| 				{ | ||||
| 					img: require('../../static/icon-apps/app_icons7.png'), | ||||
| 					title: '高危作业', | ||||
| 					url: '/pages/eight_assignments/index' | ||||
| 				}, | ||||
| 				{ | ||||
| 					img: require('../../static/icon-apps/app_icons8.png'), | ||||
| 					title: '培训管理', | ||||
| 					url: '/pages/train_management/index' | ||||
| 				} | ||||
| 			] | ||||
| 		} | ||||
| 	}, | ||||
| 	computed: { | ||||
| 		userInfo() { | ||||
| 			return this.$store.getters.getUserInfo | ||||
| 		} | ||||
| 	}, | ||||
|   onLoad() { | ||||
|     if (this.$store.getters.getUserInfo.USER_ID) { | ||||
|       // 获取系统版本号, 其函数主体在 /utils/updateVersion.js 文件内查找 | ||||
|       this.fnUpdateVersion(false) | ||||
|       this.getUserFaceCompleted() | ||||
|     } | ||||
|   }, | ||||
| 	methods: { | ||||
| 		handleGetClassInfoByParams(classId) { | ||||
| 			return new Promise(async (resolve, reject) => { | ||||
| 				const userInfo = store.getters.getUserInfo | ||||
| 				await getClassInfoByParams({ | ||||
| 					classId, | ||||
| 					userId: userInfo.USER_ID | ||||
| 				}) | ||||
| 					.then((resData) => { | ||||
| 						resolve(resData.classInfo) | ||||
| 					}) | ||||
| 					.catch(() => { | ||||
| 						uni.$u.toast('网络开小差了,请稍后尝试') | ||||
| 						reject() | ||||
| 					}) | ||||
| 			}) | ||||
| 	export default { | ||||
| 		mixins: [updateVersion], | ||||
| 		data() { | ||||
| 			return { | ||||
| 				baseList: [{ | ||||
| 						img: require('../../static/icon-apps/app_icons.png'), | ||||
| 						title: '电子工牌', | ||||
| 						url: '/pages/electronic_work_card/index' | ||||
| 					}, | ||||
| 					{ | ||||
| 						img: require('../../static/icon-apps/app_icons2.png'), | ||||
| 						title: '服务单位 管理', | ||||
| 						url: '/pages/service_unit_management/index' | ||||
| 					}, | ||||
| 					{ | ||||
| 						img: require('../../static/icon-apps/app_icons3.png'), | ||||
| 						title: '我的信息', | ||||
| 						url: '/pages/mine/information/index' | ||||
| 					}, | ||||
| 					{ | ||||
| 						img: require('../../static/icon-apps/app_icons4.png'), | ||||
| 						title: '证书信息', | ||||
| 						url: '/pages/certificate_information/index' | ||||
| 					}, | ||||
| 					{ | ||||
| 						img: require('../../static/icon-apps/app_icons5.png'), | ||||
| 						title: '就职单位', | ||||
| 						url: '/pages/employed_by/index' | ||||
| 					}, | ||||
| 					{ | ||||
| 						img: require('../../static/icon-apps/app_icons7.png'), | ||||
| 						title: '高危作业', | ||||
| 						url: '/pages/eight_assignments/index' | ||||
| 					}, | ||||
| 					{ | ||||
| 						img: require('../../static/icon-apps/app_icons8.png'), | ||||
| 						title: '培训管理', | ||||
| 						url: '/pages/train_management/index' | ||||
| 					} | ||||
| 				] | ||||
| 			} | ||||
| 		}, | ||||
| 		async fnScan() { | ||||
| 			uni.scanCode({ | ||||
| 				success: async (res) => { | ||||
| 					// let obj = JSON.parse(res.result) | ||||
| 					// let type = obj[0].CODE_TYPE | ||||
| 					const { classId, type, RELEVANT_UNIT_NAME } = JSON.parse(res.result) | ||||
| 					const classInfo = await this.handleGetClassInfoByParams(classId); | ||||
|           const resData = await getStudentInfoApi({classId:classInfo.classId}) | ||||
|           await this.$store.dispatch('setStudentInfo', resData.studentInfo) | ||||
| 					switch(type) { | ||||
| 						case "0": { | ||||
| 							let info = await setEntryV1({ | ||||
| 							userId: this.userInfo.USER_ID, | ||||
| 							// corpinfoId: obj[0].CORPINFO_ID, | ||||
| 							RELEVANT_UNIT_NAME: RELEVANT_UNIT_NAME, | ||||
| 							postMethod: 'application/json' | ||||
| 		computed: { | ||||
| 			userInfo() { | ||||
| 				return this.$store.getters.getUserInfo | ||||
| 			} | ||||
| 		}, | ||||
| 		onLoad() { | ||||
| 			if (this.$store.getters.getUserInfo.USER_ID) { | ||||
| 				// 获取系统版本号, 其函数主体在 /utils/updateVersion.js 文件内查找 | ||||
| 				this.fnUpdateVersion(false) | ||||
| 				this.getUserFaceCompleted() | ||||
| 			} | ||||
| 		}, | ||||
| 		methods: { | ||||
| 			handleGetClassInfoByParams(classId) { | ||||
| 				return new Promise(async (resolve, reject) => { | ||||
| 					const userInfo = store.getters.getUserInfo | ||||
| 					await getClassInfoByParams({ | ||||
| 							classId, | ||||
| 							userId: userInfo.USER_ID | ||||
| 						}) | ||||
| 							if (info.code === 200) { | ||||
| 								uni.$u.toast('入职成功') | ||||
| 							} else { | ||||
| 								uni.$u.toast('入职失败,请联系管理员') | ||||
| 							} | ||||
| 							break; | ||||
| 						}; | ||||
| 						// case "1": { | ||||
| 						// 	// type=1时跳转电子工牌页面 | ||||
| 						// 	uni.$u.route({ | ||||
| 						// 		url: '/pages/electronic_work_card/index', | ||||
| 						// 		params: { | ||||
| 						// 			USER_ID: obj[0].USER_ID, | ||||
| 						// 			CODE_TYPE: obj[0].CODE_TYPE | ||||
| 						// 		} | ||||
| 						// 	}) | ||||
| 						// 	break; | ||||
| 						// }; | ||||
| 						case "2": { | ||||
| 							// 签到二维码方式进入, [type: 2 --> 签到二维码方式进入] | ||||
|               if (store.getters.getVerification === '0') { | ||||
|                 uni.showModal({ | ||||
|                   title: '温馨提示', | ||||
|                   content: '检测到您还未完成人脸信息读取,请先完成人脸信息认证!', | ||||
|                   success: function (res) { | ||||
|                     if (res.confirm) { | ||||
|                       uni.$u.route({ | ||||
|                         url: '/pages/train_management/face_authentication', | ||||
|                         params: { | ||||
|                           type: 'facial_input' | ||||
|                         } | ||||
|                       }) | ||||
|                     } | ||||
|                     if (res.cancel) { | ||||
|                       uni.navigateBack({ delta: 1 }) | ||||
|                     } | ||||
|                   } | ||||
| 						.then((resData) => { | ||||
| 							resolve(resData.classInfo) | ||||
| 						}) | ||||
| 						.catch(() => { | ||||
| 							uni.$u.toast('网络开小差了,请稍后尝试') | ||||
| 							reject() | ||||
| 						}) | ||||
| 				}) | ||||
| 			}, | ||||
| 			async fnScan() { | ||||
| 				uni.scanCode({ | ||||
| 					success: async (res) => { | ||||
| 						// let obj = JSON.parse(res.result) | ||||
| 						// let type = obj[0].CODE_TYPE | ||||
| 						const { | ||||
| 							classId, | ||||
| 							stageexampaperinputId, | ||||
| 							type, | ||||
|               CORPINFO_ID, | ||||
| 							RELEVANT_UNIT_NAME | ||||
| 						} = JSON.parse(res.result); | ||||
| 						if (type !== '0') { | ||||
| 							const classInfo = await this.handleGetClassInfoByParams(classId); | ||||
| 							const resData = await getStudentInfoApi({ | ||||
| 								classId: classInfo.classId | ||||
| 							}) | ||||
| 							await this.$store.dispatch('setStudentInfo', resData.studentInfo) | ||||
| 						} | ||||
| 						switch (type) { | ||||
| 							case "0": { | ||||
|                 let info = await setEntryV1({ | ||||
|                   userId: this.userInfo.USER_ID, | ||||
|                   corpinfoId: CORPINFO_ID, | ||||
|                   RELEVANT_UNIT_NAME: RELEVANT_UNIT_NAME, | ||||
|                   postMethod: 'application/json' | ||||
|                 }) | ||||
|               } | ||||
| 							if (classInfo) { | ||||
| 								uni.$u.route({ | ||||
| 									url: '/pages/train_management/realname_info_auth', | ||||
| 									params: { | ||||
| 										type: 'scan_face', | ||||
| 										classId | ||||
| 									} | ||||
| 								}) | ||||
| 							} else { | ||||
| 								uni.$u.toast('您未在培训计划内,无法入班签到,请联系教师') | ||||
|                 if (info.code === 200) { | ||||
|                   uni.$u.toast('入职成功') | ||||
|                 } else { | ||||
|                   uni.$u.toast('入职失败,请联系管理员') | ||||
|                 } | ||||
| 								break; | ||||
| 							} | ||||
| 							break; | ||||
| 						}; | ||||
| 						case "3": { | ||||
| 							// 考试二维码方式进入 [type: 3 --> 考试二维码方式进入] | ||||
| 							if (classInfo) { | ||||
| 							// case "1": { | ||||
| 							// 	// type=1时跳转电子工牌页面 | ||||
| 							// 	uni.$u.route({ | ||||
| 							// 		url: '/pages/electronic_work_card/index', | ||||
| 							// 		params: { | ||||
| 							// 			USER_ID: obj[0].USER_ID, | ||||
| 							// 			CODE_TYPE: obj[0].CODE_TYPE | ||||
| 							// 		} | ||||
| 							// 	}) | ||||
| 							// 	break; | ||||
| 							// }; | ||||
| 							case "2": { | ||||
| 								// 签到二维码方式进入, [type: 2 --> 签到二维码方式进入] | ||||
| 								if (store.getters.getVerification === '0') { | ||||
| 									uni.showModal({ | ||||
| 										title: '温馨提示', | ||||
| 										content: '检测到您还未完成人脸信息读取,请先完成人脸信息认证!', | ||||
| 										success: function(res) { | ||||
| 											if (res.confirm) { | ||||
| 												uni.$u.route({ | ||||
| 													url: '/pages/train_management/face_authentication', | ||||
| 													params: { | ||||
| 														type: 'facial_input' | ||||
| 													} | ||||
| 												}) | ||||
| 											} | ||||
| 											if (res.cancel) { | ||||
| 												uni.navigateBack({ | ||||
| 													delta: 1 | ||||
| 												}) | ||||
| 											} | ||||
| 										} | ||||
| 									}) | ||||
| 								} | ||||
| 								if (store.getters.getVerification === '1') { | ||||
| 									if (classInfo) { | ||||
| 										if (classInfo.studystate === "3") { | ||||
| 											uni.$u.toast("您已经入班签到,无需再次签到!") | ||||
| 											return; | ||||
| 										} | ||||
| 										uni.$u.route({ | ||||
| 											url: '/pages/train_management/realname_info_auth', | ||||
| 											params: { | ||||
| 												type: 'scan_face', | ||||
| 												classId | ||||
| 											} | ||||
| 										}) | ||||
| 									} else { | ||||
| 										uni.$u.toast('您未在培训计划内,无法入班签到,请联系教师') | ||||
| 									} | ||||
| 								} else { | ||||
| 									uni.$u.toast('您还未完成人脸信息读取,请先完成人脸信息认证!') | ||||
| 								} | ||||
| 								break; | ||||
| 							}; | ||||
| 							case "3": { | ||||
| 								// 考试二维码方式进入 [type: 3 --> 考试二维码方式进入] | ||||
| 								if (store.getters.getVerification === '1') { | ||||
| 									if (classInfo) { | ||||
| 
 | ||||
| 											uni.$u.route({ | ||||
| 												url: '/pages/train_management/face_authentication', | ||||
| 												params: { | ||||
| 													type: 'learning_certification', | ||||
| 													stageexampaperinputId, | ||||
| 													classId, | ||||
| 												} | ||||
| 											}) | ||||
| 
 | ||||
| 									} else { | ||||
| 										uni.$u.toast('您未在培训计划内,无法进行考试,请联系教师') | ||||
| 									} | ||||
| 								} else { | ||||
| 									uni.$u.toast('您还未完成人脸信息读取,请先完成人脸信息认证!') | ||||
| 								} | ||||
| 								break; | ||||
| 							} | ||||
| 							default: { | ||||
| 								break; | ||||
| 							}; | ||||
| 						} | ||||
| 					} | ||||
| 				}) | ||||
| 			}, | ||||
| 			fnIsShow(index) { | ||||
| 				if (index === 5) return !!this.userInfo.CORPINFO_ID | ||||
| 				return true | ||||
| 			}, | ||||
| 			fnNavigator(e) { | ||||
| 				uni.$u.route({ | ||||
| 					url: this.baseList[e].url | ||||
| 				}) | ||||
| 			}, | ||||
| 			/** | ||||
| 			 * 获取是否已经完成上传人脸信息 | ||||
| 			 */ | ||||
| 			async getUserFaceCompleted() { | ||||
| 				const userFaceData = await getIsUploadFace() | ||||
| 				// userFaceData.authentication --> 0: 未完成人脸认证 | ||||
| 				// userFaceData.authentication --> 1: 已完成人脸认证 | ||||
| 				this.$store.dispatch('setVerification', userFaceData.authentication ? userFaceData.authentication : | ||||
| 					"0"); // 设置本地存储人脸检测验证状态 | ||||
| 				const isPassedVerification = userFaceData.authentication === '0' | ||||
| 				if (isPassedVerification) { | ||||
| 					uni.showModal({ | ||||
| 						title: '温馨提示', | ||||
| 						content: '为了能够得到更好的体验,我们会获取您个人信息,请完成人脸信息认证!', | ||||
| 						success: function(res) { | ||||
| 							if (res.confirm) { | ||||
| 								uni.$u.route({ | ||||
| 									url: '/pages/train_management/face_authentication', | ||||
| 									params: { | ||||
| 										type: 'learning_certification', | ||||
| 										stageexampaperinputId, | ||||
| 										classId, | ||||
| 										type: 'facial_input' | ||||
| 									} | ||||
| 								}) | ||||
| 							} else { | ||||
| 								uni.$u.toast('您未在培训计划内,无法进行考试,请联系教师') | ||||
| 							} | ||||
| 							break; | ||||
| 							if (res.cancel) { | ||||
| 								uni.$u.toast("您可进入[我的]-[人脸认证]完成信息认证") | ||||
| 							} | ||||
| 						} | ||||
| 						default: { | ||||
| 							break; | ||||
| 						}; | ||||
| 					} | ||||
| 					}) | ||||
| 				} | ||||
| 			}) | ||||
| 		}, | ||||
| 		fnIsShow(index) { | ||||
| 			if (index === 5) return !!this.userInfo.CORPINFO_ID | ||||
| 			return true | ||||
| 		}, | ||||
| 		fnNavigator(e) { | ||||
| 			uni.$u.route({ | ||||
| 				url: this.baseList[e].url | ||||
| 			}) | ||||
| 		}, | ||||
| 		/** | ||||
| 		 * 获取是否已经完成上传人脸信息 | ||||
| 		 */ | ||||
| 		async getUserFaceCompleted() { | ||||
| 			const userFaceData = await getIsUploadFace() | ||||
| 			// userFaceData.authentication --> 0: 未完成人脸认证 | ||||
| 			// userFaceData.authentication --> 1: 已完成人脸认证 | ||||
| 			this.$store.dispatch('setVerification', userFaceData.authentication ? userFaceData.authentication : "0"); // 设置本地存储人脸检测验证状态 | ||||
| 			const isPassedVerification = userFaceData.authentication === '0' | ||||
| 			if (isPassedVerification) { | ||||
| 				uni.showModal({ | ||||
| 					title: '温馨提示', | ||||
| 					content: '为了能够得到更好的体验,我们会获取您个人信息,请完成人脸信息认证!', | ||||
| 					success: function (res) { | ||||
| 						if (res.confirm) { | ||||
| 							uni.$u.route({ | ||||
| 								url: '/pages/train_management/face_authentication', | ||||
| 								params: { | ||||
| 									type: 'facial_input' | ||||
| 								} | ||||
| 							}) | ||||
| 						} | ||||
| 						if (res.cancel) { | ||||
|               uni.$u.toast("您可进入[我的]-[人脸认证]完成信息认证") | ||||
| 						} | ||||
| 					} | ||||
| 				}) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| </script> | ||||
| 
 | ||||
| <style lang="scss" scoped> | ||||
| .page { | ||||
| 	background-color: #f7f9ff; | ||||
| 	min-height: 100vh; | ||||
| } | ||||
| 	.page { | ||||
| 		background-color: #f7f9ff; | ||||
| 		min-height: 100vh; | ||||
| 	} | ||||
| </style> | ||||
|  |  | |||
|  | @ -43,6 +43,7 @@ | |||
| 			}, 1000) | ||||
| 		}, | ||||
| 		onLoad(query) { | ||||
| 			console.log('query: >> ', query) | ||||
| 			// facial_input 人脸认证    isFirst 1 第一次登录添加人脸 | ||||
| 			// scan_face  扫码 | ||||
| 			// update_facial_input 更新人脸 | ||||
|  | @ -61,25 +62,18 @@ | |||
| 			// this.showButton = query.showButton || "yes"; | ||||
| 			this.routeQueryparams = query ?? {} | ||||
| 		}, | ||||
| 		onBackPress(event) { | ||||
| 			// if (event.from === 'backbutton') { | ||||
| 			// 	if ((this.type === 'scan_face' && this.isFirst === '1') || this.type === 'learning_certification' || this.type === 'facial_input') { | ||||
| 			// 		uni.$u.toast('请完成人脸验证') | ||||
| 			// 		return true | ||||
| 			// 	} | ||||
| 			// } | ||||
| 			if (this.type === 'facial_input') { | ||||
| 				uni.$u.route({ | ||||
| 					type: 'redirect', | ||||
| 					url: '/pages/index/index', | ||||
| 				}) | ||||
| 			} | ||||
| 			return false | ||||
| 		}, | ||||
| 		// onBackPress(event) { | ||||
| 		// 	return false | ||||
| 		// }, | ||||
| 		onUnload() { | ||||
| 			this.startPreviewTimer && clearInterval(this.startPreviewTimer) | ||||
| 		}, | ||||
| 		methods: { | ||||
| 			handleBack() { | ||||
| 				uni.navigateBack({ | ||||
| 					delta: 2, | ||||
| 				}) | ||||
| 			}, | ||||
| 			snapshot() { | ||||
| 				uni.showLoading({ | ||||
| 					title: '加载中' | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue