| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <template>
- <view class="video-container">
- <camera class="zp-camera" 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>
- <style lang="scss">
- .video-container {
- position: relative;
- overflow: hidden;
-
- .zp-camera {
-
- }
- }
- </style>
|