UNPKG

3.23 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3interface CameraProps extends StandardProps {
4 /** 模式,有效值为normal, scanCode
5 * @default "normal"
6 * @supported weapp, alipay, tt, qq, jd, rn
7 */
8 mode?: keyof CameraProps.Mode
9 /** 分辨率,不支持动态修改
10 * @default "medium"
11 * @supported weapp, tt
12 */
13 resolution?: keyof CameraProps.Resolution
14 /** 摄像头朝向
15 * @default "back"
16 * @supported weapp, alipay, swan, tt, qq, jd, rn
17 */
18 devicePosition?: keyof CameraProps.DevicePosition
19 /** 闪光灯
20 * @default "auto"
21 * @supported weapp, alipay, swan, tt, qq, jd, rn
22 */
23 flash?: keyof CameraProps.Flash
24 /** 指定期望的相机帧数据尺寸
25 * @default "medium"
26 * @supported weapp, alipay, tt
27 */
28 frameSize?: keyof CameraProps.FrameSize
29 /** 相机拍照,录制的分辨率。
30 * @supported alipay
31 * @default "720P"
32 */
33 outputDimension?: '360P' | '540P' | '720P' | '1080P' | 'max'
34 /** 摄像头在非正常终止时触发,
35 * 如退出后台等情况
36 * @supported weapp, alipay, swan, tt, qq, jd, rn
37 */
38 onStop?: CommonEventFunction
39 /** 用户不允许使用摄像头时触发
40 * @supported weapp, alipay, swan, tt, qq, jd, rn
41 */
42 onError?: CommonEventFunction
43 /** 相机初始化完成时触发
44 * @supported weapp, tt, rn
45 */
46 onInitDone?: CommonEventFunction<CameraProps.onInitDoneEventDetail>
47 /** 相机初始化成功时触发。
48 * @supported alipay
49 */
50 onReady?: CommonEventFunction<CameraProps.onInitDoneEventDetail>
51 /** 在成功识别到一维码时触发,
52 * 仅在 mode="scanCode" 时生效
53 * @supported weapp, alipay, tt, qq, rn
54 */
55 onScanCode?: CommonEventFunction<CameraProps.onScanCodeEventDetail>
56}
57declare namespace CameraProps {
58 /** mode 的合法值 */
59 interface Mode {
60 /** 相机模式 */
61 normal
62 /** 扫码模式 */
63 scanCode
64 }
65 /** resolution 的合法值 */
66 interface Resolution {
67 /** 低 */
68 low
69 /** 中 */
70 medium
71 /** 高 */
72 high
73 }
74 /** device-position 的合法值 */
75 interface DevicePosition {
76 /** 前置 */
77 front
78 /** 后置 */
79 back
80 }
81 /** flash 的合法值 */
82 interface Flash {
83 /** 自动 */
84 auto
85 /** 打开 */
86 on
87 /** 关闭 */
88 off
89 /** 常亮 */
90 torch
91 }
92 /** frame-size 的合法值 */
93 interface FrameSize {
94 /** 小尺寸帧数据 */
95 small
96 /** 中尺寸帧数据 */
97 medium
98 /** 大尺寸帧数据 */
99 large
100 }
101 interface onInitDoneEventDetail {
102 /** 最大变焦 */
103 maxZoom: number
104 }
105 interface onScanCodeEventDetail {
106 /** 字符集 */
107 charSet: string
108 /** 原始数据
109 * @supported weapp
110 */
111 rawData: string
112 /** 码类型 */
113 type: string
114 /** 识别结果 */
115 result: string
116 /** 识别结果(完整)
117 * @supported alipay
118 */
119 fullResult: string
120 }
121}
122/** 系统相机
123 * @classification media
124 * @supported weapp, alipay, swan, tt, qq, jd, rn, harmony
125 * @see https://developers.weixin.qq.com/miniprogram/dev/component/camera.html
126 */
127declare const Camera: ComponentType<CameraProps>
128export { Camera, CameraProps }