/** * 共享相机 composable (H5 only) * * 用法: const { captured, errorMsg, startCamera, flipCamera, takePhoto, retake, confirm } = useCamera('my-video-id') * * - 自动在 onMounted 启动摄像头 * - 自动在 onBeforeUnmount 停止摄像头 * - 返回 ref 和方法,业务页只需负责 UI 布局 */ import { ref, onMounted, onBeforeUnmount } from 'vue' import { openCamera, stopCamera, captureFrame, captureFrameWithBlur, describeCameraError, type Facing, } from '@/utils/camera' import { uploadCameraPhoto } from '@/utils/upload' /** 条带高斯模糊配置 (签到表脱敏用): 对截图竖直 [start, end] 比例区间做高斯模糊 */ export type BlurConfig = { start: number end: number radius: number } export function useCamera(videoId: string, blur?: BlurConfig) { const facing = ref('environment') const captured = ref('') const blurred = ref('') const errorMsg = ref('') function getVideoEl(): HTMLVideoElement | null { const el = document.getElementById(videoId) as HTMLElement | null if (!el) return null // uni-app H5 把