wangguoyu před 1 měsícem
rodič
revize
cfc4e36337
3 změnil soubory, kde provedl 226 přidání a 78 odebrání
  1. 152 0
      components/dialog/cameraCommon.vue
  2. 64 73
      pages.json
  3. 10 5
      pages/my/index.vue

+ 152 - 0
components/dialog/cameraCommon.vue

@@ -0,0 +1,152 @@
+<template>
+	<uni-popup ref="commonPopup" :animation="false" :is-mask-click="false" mask-background-color="rgba(0, 0, 0, 0.4)">
+		<view class="phone-common-dialog">
+			<view class="common-body-box">
+				<view class="common-title">{{title}}</view>
+				<view class="common-content" :class="dialogContentClass">
+					<view v-if="showCamera" class="camera-modal">
+						<view class="mask" @click="closeCamera"></view>
+						<view class="modal-content">
+							<camera class="camera-view" device-position="front"></camera>
+							<button class="not-confirm-btn" @click="closeCamera">关闭</button>
+						</view>
+					</view>
+				</view>
+				<view class="common-btn-box">
+					<view class="not-confirm-btn" @click="handleClose">{{notBtn}}</view>
+					<view class="confirm-btn" @click="confirmBtn">{{okBtn}}</view>
+				</view>
+			</view>
+		</view>
+	</uni-popup>
+</template>
+
+<script setup>
+	import {
+		ref
+	} from 'vue';
+	const props = defineProps({
+		title: {
+			type: String,
+			default: ''
+		},
+		content: {
+			type: String,
+			require: true,
+			default: ''
+		},
+		dialogContentClass: {
+			type: String,
+			require: true,
+			default: 'content-center-class'
+		},
+		notBtn: {
+			type: String,
+			require: true,
+			default: '取消'
+		},
+		okBtn: {
+			type: String,
+			require: true,
+			default: '确认'
+		},
+	});
+	const commonPopup = ref(null);
+	let showCamera = ref(false)
+	let cameraContext = ref(null)
+	let listener = ref(null)
+	const $emit = defineEmits(['confirm-btn'])
+
+	function handleShow() {
+		commonPopup.value.open();
+		handleCheck()
+	}
+
+	function handleClose() {
+		commonPopup.value.close();
+		showCamera.value = false;
+	}
+
+	function confirmBtn() {
+		$emit('confirm-btn');
+		commonPopup.value.close();
+		showCamera.value = false;
+	}
+
+	function handleCheck() {
+		try {
+			const systemInfo = uni.getSystemInfo();
+			// if (!systemInfo.cameraAuthorized) {
+			// 	uni.showToast({
+			// 		title: '设备不支持摄像头',
+			// 		duration: 2000
+			// 	});
+			// }	
+			uni.getSetting({
+				success(res) {
+					const authSetting = res.authSetting || {}
+					if (!authSetting['scope.camera']) {
+						const {
+							errMsg
+						} = uni.authorize({
+							scope: 'scope.camera'
+						});
+						// if (errMsg !== 'authorize:ok') {
+						// 	throw new Error('权限被拒绝');
+						// }
+					}
+					showCamera.value = true;
+					setTimeout(() => {
+						cameraContext.value = uni.createCameraContext();
+						console.log('cameraContext.value', cameraContext.value);
+						listener.value = cameraContext.value.onCameraFrame((frame) => {
+							//  console.log(frame.data instanceof ArrayBuffer, frame.width, frame.height)
+						})
+						//	console.log('listener.value',listener.value);
+						listener.value.start()
+					}, 500)
+				},
+				fail(err) {
+					handleError(err)
+				}
+			})
+
+
+		} catch (err) {
+			handleError(err);
+		}
+	}
+
+	function closeCamera() {
+		if (listener.value) {
+			listener.value.stop();
+		}
+		showCamera.value = false;
+		handleClose()
+	}
+
+
+
+	function handleError(err) {
+		uni.showModal({
+			title: '权限验证失败',
+			content: err.message,
+			confirmText: '去设置',
+			success: (res) => {
+				if (res.confirm) {
+					// #ifdef MP-WEIXIN
+					wx.openSetting();
+					// #endif
+				}
+			}
+		});
+	}
+	defineExpose({
+		handleShow,
+		handleCheck,
+		handleClose
+	})
+</script>
+
+<style>
+</style>

+ 64 - 73
pages.json

@@ -13,104 +13,95 @@
 			}
 		},
 		{
-			"path" : "pages/exam/index",
-			"style" :
-			{
-				"navigationBarTitleText" : "考试"
+			"path": "pages/exam/index",
+			"style": {
+				"navigationBarTitleText": "考试"
 			}
 		},
 		{
-			"path" : "pages/my/index",
-			"style" :
-			{
-				"navigationBarTitleText" : "我的"
+			"path": "pages/my/index",
+			"style": {
+				"navigationBarTitleText": "我的"
 			}
 		},
-			{
-			"path" : "pages/my/zhengshu",
-			"style" :
-			{
-				"navigationBarTitleText" : "证书"
+		{
+			"path": "pages/my/zhengshu",
+			"style": {
+				"navigationBarTitleText": "证书"
 			}
 		},
 		{
-			"path" : "pages/my/setting",
-			"style" :
-			{
-				"navigationBarTitleText" : "设置"
+			"path": "pages/my/setting",
+			"style": {
+				"navigationBarTitleText": "设置"
 			}
 		},
 		{
-			"path" : "pages/demo/index",
-			"style" :
-			{
-				"navigationBarTitleText" : "demo"
+			"path": "pages/demo/index",
+			"style": {
+				"navigationBarTitleText": "demo"
 			}
 		},
 		{
-			"path" : "pages/course/index",
-			"style" :
-			{
-				"navigationBarTitleText" : "课程"
+			"path": "pages/course/index",
+			"style": {
+				"navigationBarTitleText": "课程"
 			}
 		},
-			{
-			"path" : "pages/course/kechengInfo",
-			"style" :
-			{
-				"navigationBarTitleText" : "课程详情"
+		{
+			"path": "pages/course/kechengInfo",
+			"style": {
+				"navigationBarTitleText": "课程详情"
 			}
 		},
 		{
-			"path" : "pages/score/index",
-			"style" :
-			{
-				"navigationBarTitleText" : "成绩"
+			"path": "pages/score/index",
+			"style": {
+				"navigationBarTitleText": "成绩"
 			}
 		},
 		{
-			"path" : "pages/exam/exam",
-			"style" : 
-			{
-				"navigationBarTitleText" : ""
+			"path": "pages/exam/exam",
+			"style": {
+				"navigationBarTitleText": ""
 			}
 		}
 	],
 	"tabBar": {
-			"color": "#565656",
-			"selectedColor": "#0856E6",
-			"borderStyle": "black",
-			"backgroundColor": "#ffffff",
-			"fontSize": "13px",
-			"iconWidth": "28px",
-			"spacing": "0px",
-			"list": [{
-				"pagePath": "pages/index/index",
-				"iconPath": "static/images/tabbar/unselect/index-sj.png",
-				"selectedIconPath": "static/images/tabbar/select/index-sj.png",
-				"text": "首页"
-			}, {
-				"pagePath": "pages/exam/index",
-				"iconPath": "static/images/tabbar/unselect/exam-sj.png",
-				"selectedIconPath": "static/images/tabbar/select/exam-sj.png",
-				"text": "考试"
-			}, {
-				"pagePath": "pages/course/index",
-				"iconPath": "static/images/tabbar/unselect/kecheng-sj.png",
-				"selectedIconPath": "static/images/tabbar/select/kecheng-sj.png",
-				"text": "课程"
-			}, {
-				"pagePath": "pages/score/index",
-				"iconPath": "static/images/tabbar/unselect/score-sj.png",
-				"selectedIconPath": "static/images/tabbar/select/score-sj.png",
-				"text": "成绩"
-			}, {
-				"pagePath": "pages/my/index",
-				"iconPath": "static/images/tabbar/unselect/my-sj.png",
-				"selectedIconPath": "static/images/tabbar/select/my-sj.png",
-				"text": "我的"
-			}]
-		},
+		"color": "#565656",
+		"selectedColor": "#0856E6",
+		"borderStyle": "black",
+		"backgroundColor": "#ffffff",
+		"fontSize": "13px",
+		"iconWidth": "28px",
+		"spacing": "0px",
+		"list": [{
+			"pagePath": "pages/index/index",
+			"iconPath": "static/images/tabbar/unselect/index-sj.png",
+			"selectedIconPath": "static/images/tabbar/select/index-sj.png",
+			"text": "首页"
+		}, {
+			"pagePath": "pages/exam/index",
+			"iconPath": "static/images/tabbar/unselect/exam-sj.png",
+			"selectedIconPath": "static/images/tabbar/select/exam-sj.png",
+			"text": "考试"
+		}, {
+			"pagePath": "pages/course/index",
+			"iconPath": "static/images/tabbar/unselect/kecheng-sj.png",
+			"selectedIconPath": "static/images/tabbar/select/kecheng-sj.png",
+			"text": "课程"
+		}, {
+			"pagePath": "pages/score/index",
+			"iconPath": "static/images/tabbar/unselect/score-sj.png",
+			"selectedIconPath": "static/images/tabbar/select/score-sj.png",
+			"text": "成绩"
+		}, {
+			"pagePath": "pages/my/index",
+			"iconPath": "static/images/tabbar/unselect/my-sj.png",
+			"selectedIconPath": "static/images/tabbar/select/my-sj.png",
+			"text": "我的"
+		}]
+	},
 	"globalStyle": {
 		"navigationBarTextStyle": "black",
 		"navigationBarTitleText": "麦塔软件",
@@ -118,4 +109,4 @@
 	},
 
 	"uniIdRouter": {}
-}
+}

+ 10 - 5
pages/my/index.vue

@@ -54,6 +54,10 @@
 				<text>设置</text>
 			</view>
 		</view>
+		
+		<view>
+			<cameraCommon ref="cameraCommonRef"></cameraCommon>
+		</view>
 	</view>
 </template>
 
@@ -62,7 +66,7 @@
 	import {toast} from "@/utils/common";
 	import {getMineInfo} from '@/api/my.js'
 	import {onLoad,onShow} from '@dcloudio/uni-app';
-	
+	import cameraCommon from "@/components/dialog/cameraCommon.vue";
 	let myInfoData = reactive({
 		userImg: '',
 		realName: '',
@@ -74,7 +78,7 @@
 		countNotice:'',
 
 	});
-	
+	const cameraCommonRef = ref(null)
 	onLoad(() => {})
 	
 	onShow(() => {getMyInit()})
@@ -135,9 +139,10 @@
 			
 			// 摄像头测试
 			case 'sxtcs':
-			    uni.navigateTo({
-			    	url:'/pages/admin/my/myInfo?from=my'
-			    })
+			cameraCommonRef.value.handleShow()
+			    // uni.navigateTo({
+			    // 	url:'/pages/admin/my/myInfo?from=my'
+			    // })
 			break;
 			
 			// 摄像头说明