浏览代码

摄像头功能

wangxy 2 月之前
父节点
当前提交
9596bd455a

+ 14 - 3
components/zhuapaiConfirm/index.vue

@@ -1,7 +1,7 @@
 <template>
 <template>
 	<uni-popup ref="popupRef" type="dialog" :animation="false" :is-mask-click="false"
 	<uni-popup ref="popupRef" type="dialog" :animation="false" :is-mask-click="false"
 		mask-background-color="rgba(0, 0, 0, 0.4);">
 		mask-background-color="rgba(0, 0, 0, 0.4);">
-		<uni-popup-dialog mode="input" class="phone-camera my-dialog-cc" title="摄像头确认" :duration="2000" :before-close="true"
+		<uni-popup-dialog mode="input" class="phone-camera my-dialog-cc" :title="title" :duration="2000" :before-close="true"
 			@close="handleClose" @confirm="handleConfirm">
 			@close="handleClose" @confirm="handleConfirm">
 			<view class="phone-camera-box" style="overflow: hidden;">
 			<view class="phone-camera-box" style="overflow: hidden;">
 				<view v-show="!showConfirmBtn" class="sxt-tip-box" style="text-align: center;">摄像头正在初始化...</view>
 				<view v-show="!showConfirmBtn" class="sxt-tip-box" style="text-align: center;">摄像头正在初始化...</view>
@@ -29,6 +29,13 @@
 		useH5Camera
 		useH5Camera
 	} from "./useCamera.js"
 	} from "./useCamera.js"
 	
 	
+	defineProps({
+		title: {
+			type: String,
+			default: '摄像头确认'
+		}
+	})
+	
 	const emits = defineEmits(['success', 'error', 'cancel'])
 	const emits = defineEmits(['success', 'error', 'cancel'])
 	
 	
 	const popupRef = ref(null)
 	const popupRef = ref(null)
@@ -36,6 +43,7 @@
 	
 	
 	let zhuapaiFun = null;
 	let zhuapaiFun = null;
 	let stopCamera = null;
 	let stopCamera = null;
+	let errorFunCompleteFn = null;
 
 
 	function startCamera() {
 	function startCamera() {
 		// 请求摄像头权限并获取流
 		// 请求摄像头权限并获取流
@@ -44,7 +52,8 @@
 		const {
 		const {
 			startH5Camera,
 			startH5Camera,
 			handlePaiZhao,
 			handlePaiZhao,
-			stopH5Camera
+			stopH5Camera,
+			errorFunComplete
 		} = useH5Camera({
 		} = useH5Camera({
 			elVideoId: '#videoConfirm',
 			elVideoId: '#videoConfirm',
 			elCanvasId: '#canvasConfirm',
 			elCanvasId: '#canvasConfirm',
@@ -54,6 +63,7 @@
 		startH5Camera();
 		startH5Camera();
 		zhuapaiFun = handlePaiZhao;
 		zhuapaiFun = handlePaiZhao;
 		stopCamera = stopH5Camera;
 		stopCamera = stopH5Camera;
+		errorFunCompleteFn = errorFunComplete;
 		// #endif
 		// #endif
 
 
 		// #ifdef APP-PLUS
 		// #ifdef APP-PLUS
@@ -70,9 +80,10 @@
 		showConfirmBtn.value = true;
 		showConfirmBtn.value = true;
 	}
 	}
 
 
-	function onVideoError() {
+	function onVideoError(e) {
 		showConfirmBtn.false = true;
 		showConfirmBtn.false = true;
 		emits('error')
 		emits('error')
+		errorFunCompleteFn && errorFunCompleteFn(e)
 	}
 	}
 
 
 	function showDialog() {
 	function showDialog() {

+ 54 - 21
components/zhuapaiConfirm/useCamera.js

@@ -27,7 +27,11 @@ function checkPlatform2() {
 		let match = test.exec(ua);
 		let match = test.exec(ua);
 		let version = match[1].split('.')[0];
 		let version = match[1].split('.')[0];
 		if (version < 9) {
 		if (version < 9) {
-			Toast.fail(errorMessage.ms10);
+			uni.showToast({
+				icon: 'error',
+				title: errorMessage.ms10
+			})
+			
 			return {
 			return {
 				data: false,
 				data: false,
 				waitCode: false
 				waitCode: false
@@ -36,10 +40,11 @@ function checkPlatform2() {
 		// 判断 浏览器 Android
 		// 判断 浏览器 Android
 		if (!checkAndroidForBrowser()) {
 		if (!checkAndroidForBrowser()) {
 			// 提示信息
 			// 提示信息
-			Toast.fail({
-				message: errorMessage.ms13,
-				duration: 5000
-			});
+			uni.showToast({
+				icon: 'error',
+				title: errorMessage.ms13
+			})
+			
 			return {
 			return {
 				data: true,
 				data: true,
 				waitCode: true
 				waitCode: true
@@ -66,10 +71,14 @@ function checkPlatform2() {
 		}
 		}
 
 
 		if (version < 14.3) {
 		if (version < 14.3) {
-			Toast.fail(errorMessage.ms11);
+			uni.showToast({
+				icon: 'error',
+				title: errorMessage.ms11
+			})
 			return {
 			return {
 				data: false,
 				data: false,
-				waitCode: false
+				waitCode: false,
+				duration: 3000
 			};
 			};
 		}
 		}
 
 
@@ -77,10 +86,11 @@ function checkPlatform2() {
 		// 判断 浏览器 Android
 		// 判断 浏览器 Android
 		if (!checkIosForBrowser()) {
 		if (!checkIosForBrowser()) {
 			// 提示信息
 			// 提示信息
-			Toast.fail({
-				message: errorMessage.ms12,
+			uni.showToast({
+				icon: 'error',
+				title: errorMessage.ms12,
 				duration: 5000
 				duration: 5000
-			});
+			})
 			return {
 			return {
 				data: true,
 				data: true,
 				waitCode: true
 				waitCode: true
@@ -202,18 +212,36 @@ function getBrowser() {
 export function errorFunComplete(e) {
 export function errorFunComplete(e) {
 	const name = e.name;
 	const name = e.name;
 	if (name === 'NotFoundError' || name === 'DevicesNotFoundError') {
 	if (name === 'NotFoundError' || name === 'DevicesNotFoundError') {
-		Toast.fail(errorMessage.ms4);
+		uni.showToast({
+			icon: 'error',
+			title: errorMessage.ms4,
+		})
 	}
 	}
 	if (name === 'NotReadableError' || name === 'TrackStartError') {
 	if (name === 'NotReadableError' || name === 'TrackStartError') {
-		Toast.fail(errorMessage.ms5);
+		uni.showToast({
+			icon: 'error',
+			title: errorMessage.ms5,
+		})
 	} else if (name === 'OverconstrainedError' || name === 'ConstraintNotSatisfiedError') {
 	} else if (name === 'OverconstrainedError' || name === 'ConstraintNotSatisfiedError') {
-		Toast.fail(errorMessage.ms6);
+		uni.showToast({
+			icon: 'error',
+			title: errorMessage.ms6,
+		})
 	} else if (name === 'NotAllowedError' || name === 'PermissionDeniedError') {
 	} else if (name === 'NotAllowedError' || name === 'PermissionDeniedError') {
-		Toast.fail(errorMessage.ms7);
+		uni.showToast({
+			icon: 'error',
+			title: errorMessage.ms7,
+		})
 	} else if (name === 'TypeError' || name === 'TypeError') {
 	} else if (name === 'TypeError' || name === 'TypeError') {
-		Toast.fail(errorMessage.ms8);
+		uni.showToast({
+			icon: 'error',
+			title: errorMessage.ms8,
+		})
 	} else {
 	} else {
-		Toast.fail(errorMessage.ms9);
+		uni.showToast({
+			icon: 'error',
+			title: errorMessage.ms9,
+		})
 	}
 	}
 }
 }
 
 
@@ -235,10 +263,11 @@ let constraints = {
 export function check(success, error, backFun) {
 export function check(success, error, backFun) {
 
 
 	if (!navigator) {
 	if (!navigator) {
-		Toast.fail({
-			message: errorMessage.ms1,
+		uni.showToast({
+			icon: 'error',
+			title: errorMessage.ms1,
 			duration: 5000
 			duration: 5000
-		});
+		})
 		// 当前浏览器版本 无媒体对象
 		// 当前浏览器版本 无媒体对象
 		backFun && backFun();
 		backFun && backFun();
 		return false;
 		return false;
@@ -267,7 +296,10 @@ export function check(success, error, backFun) {
 			//旧版API
 			//旧版API
 			navigator.getUserMedia(constraints, success, error);
 			navigator.getUserMedia(constraints, success, error);
 		} else {
 		} else {
-			Toast.fail(errorMessage.ms2);
+			uni.showToast({
+				icon: 'error',
+				title: errorMessage.ms2,
+			})
 			backFun && backFun();
 			backFun && backFun();
 		}
 		}
 	}, timeD);
 	}, timeD);
@@ -471,6 +503,7 @@ export function useH5Camera({
 	return {
 	return {
 		startH5Camera,
 		startH5Camera,
 		stopH5Camera,
 		stopH5Camera,
-		handlePaiZhao
+		handlePaiZhao,
+		errorFunComplete
 	}
 	}
 }
 }

+ 1 - 1
components/zhuapaiConfirm/zhuapai.vue

@@ -151,7 +151,7 @@
 	function onVideoSuccess() {
 	function onVideoSuccess() {
 		setTimeout(() => {
 		setTimeout(() => {
 			// 首次运行进行抓拍一次
 			// 首次运行进行抓拍一次
-			// handleZhua();
+			handleZhua();
 		}, 3000);
 		}, 3000);
 	}
 	}
 
 

+ 5 - 5
pages/client/Kaoshi/exam.vue

@@ -402,7 +402,7 @@
 
 
 	function zpError() {
 	function zpError() {
 		uni.showToast({
 		uni.showToast({
-			title: '摄像头唤起异常',
+			title: '抓拍图片异常',
 			icon: 'none'
 			icon: 'none'
 		})
 		})
 		uni.redirectTo({
 		uni.redirectTo({
@@ -417,10 +417,10 @@
 	}
 	}
 
 
 	function zpConfirmError() {
 	function zpConfirmError() {
-		uni.showToast({
-			title: '摄像头唤起异常',
-			icon: 'none'
-		})
+		// uni.showToast({
+		// 	title: '摄像头唤起异常',
+		// 	icon: 'none'
+		// })
 		uni.redirectTo({
 		uni.redirectTo({
 			url: '/pages/client/Kaoshi/list'
 			url: '/pages/client/Kaoshi/list'
 		})
 		})

+ 32 - 3
pages/client/my/index.vue

@@ -42,11 +42,11 @@
 				<icon class="list-icon score-icon"></icon>
 				<icon class="list-icon score-icon"></icon>
 				<text>我的成绩</text>
 				<text>我的成绩</text>
 			</view>
 			</view>
-			<view class="list-row">
+			<view class="list-row" @click="showZhuaPaiConfirm">
 				<icon class="list-icon sxtcs-icon"></icon>
 				<icon class="list-icon sxtcs-icon"></icon>
 				<text>摄像头测试</text>
 				<text>摄像头测试</text>
 			</view>
 			</view>
-			<view class="list-row">
+			<view class="list-row" @click="showMessageDl">
 				<icon class="list-icon sxtsm-icon"></icon>
 				<icon class="list-icon sxtsm-icon"></icon>
 				<text>摄像头说明</text>
 				<text>摄像头说明</text>
 			</view>
 			</view>
@@ -58,6 +58,10 @@
 		<!-- 底部区域 -->
 		<!-- 底部区域 -->
 		<customTabbarClient :currentTab="1"></customTabbarClient>
 		<customTabbarClient :currentTab="1"></customTabbarClient>
 		<common-dialog ref="commonDialogRef" :title="exitTitle" :content="exitContent"@confirm-btn="exitBtn"></common-dialog>
 		<common-dialog ref="commonDialogRef" :title="exitTitle" :content="exitContent"@confirm-btn="exitBtn"></common-dialog>
+		<shexiangDialogVue ref="shexiangRef" title="摄像头说明"></shexiangDialogVue>
+		
+		<!-- 摄像头确认 -->
+		<zhuapaiConfrimVue ref="zpRef" @error="zpConfirmError" title="摄像头测试"></zhuapaiConfrimVue>
 	</view>
 	</view>
 </template>
 </template>
 
 
@@ -69,6 +73,9 @@
 	import {reactive,ref} from "vue";
 	import {reactive,ref} from "vue";
 	import customTabbarClient from "@/components/custom-tabbar/custom-tabbar-client.vue"
 	import customTabbarClient from "@/components/custom-tabbar/custom-tabbar-client.vue"
 	import commonDialog from '@/components/dialog/commonDialog.vue';
 	import commonDialog from '@/components/dialog/commonDialog.vue';
+	import shexiangDialogVue from "@/components/dialog/shexiangDialog.vue";
+	import zhuapaiConfrimVue from "@/components/zhuapaiConfirm/index.vue";
+	
 	let myInfoData = reactive({
 	let myInfoData = reactive({
 		userImg: '',
 		userImg: '',
 		realName: '',
 		realName: '',
@@ -76,9 +83,11 @@
 		kaoshiCount: '',
 		kaoshiCount: '',
 		kechengCount: '',
 		kechengCount: '',
 		lianxiCount: '',
 		lianxiCount: '',
-    from:''
+		from:''
 	});
 	});
 	const commonDialogRef = ref(null);
 	const commonDialogRef = ref(null);
+	const shexiangRef = ref(null);
+	const zpRef = ref(null);
 	const exitContent = '你确定要执行这个操作吗?';
 	const exitContent = '你确定要执行这个操作吗?';
 	const exitTitle = '退出登录';
 	const exitTitle = '退出登录';
 	function getMyInit() {
 	function getMyInit() {
@@ -144,6 +153,26 @@
 			toast('退出登录失败,请稍后重试')
 			toast('退出登录失败,请稍后重试')
 		})
 		})
 	}
 	}
+	
+	function showMessageDl() {
+		console.log(shexiangRef.value)
+		shexiangRef.value.handleShow()
+	}
+	
+	function showZhuaPaiConfirm() {
+		zpRef.value.showDialog()
+	}
+	
+	function zpConfirmSuccess() {
+		zpRef.value.showDialog()
+	}
+	function zpConfirmError() {
+		uni.showToast({
+			title: '摄像头唤起异常',
+			icon: 'none'
+		})
+	}
+	
 	onLoad(() => {
 	onLoad(() => {
     
     
 	})
 	})