| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <template>
- <view class="video-container-box">
- <view class="video-tip-box"> 摄像头初始化... </view>
- <camera class="zp-camera 88" device-position="front" flash="off" @initdone="onVideoSuccess"></camera>
- </view>
- </template>
- <script setup>
- import {
- ref,
- onUnmounted,
- onMounted,
- nextTick
- } from "vue"
- import {
- useH5Camera
- } from "./useCamera.js"
- const emits = defineEmits(['success', 'error', 'cancel'])
- const popupRef = ref(null)
- const showConfirmBtn = ref(false);
- const cameraContext = ref(null);
- let zhuapaiFun = null;
- let stopCamera = null;
- let errorFunCompleteFn = null;
- function startCamera() {
- // 请求摄像头权限并获取流
- cameraContext.value = uni.createCameraContext();
- }
- function handleZhua() {
- zhuapaiFun()
- }
- function onVideoSuccess() {
- }
- function onVideoError(e) {
- emits('error')
- errorFunCompleteFn && errorFunCompleteFn(e)
- }
- function showDialog() {
- setTimeout(() => {
- startCamera()
- },1000)
- }
- function handleClose() {
- emits('cancel')
- stopCamera && stopCamera()
- }
- function handleConfirm() {
- emits('success')
- stopCamera && stopCamera()
- }
- defineExpose({
- showDialog
- })
- onUnmounted(() => {
- // 组件销毁时停止摄像头
- stopCamera && stopCamera();
- })
- </script>
|