x-mlkit-scannig-u 扫码容器
页面内嵌扫码。实时出码、区域过滤、码点点击。全屏单例请用 x-mlkit-scannig-s。
微信走官方 camera 扫码,无码坐标,边框、码点点击、scanImage 不可用。
兼容性
| Harmony | IOS | Android | WEB | 小程序 |
|---|---|---|---|---|
| 支持 | 支持 | 支持 | 支持 | 支持(官方扫码) |
调用
vue
<x-mlkit-scannig-u
ref="scannerRef"
camera-position="back"
:continuous="false"
:scan-area="scanArea"
:auto-open="false"
:show-scan-area="true"
:show-code-points="true"
@ready="onReady"
@scan="onScan"
@clickCode="onCodeClick"
></x-mlkit-scannig-u>ts
const scanArea = { x: 0.1, y: 0.2, width: 0.8, height: 0.6 }
function onScan(result : XScanningResult) : void {
console.log(result.codes)
}
scannerRef.value?.open()
scannerRef.value?.close()参数
| 字段 | 说明 | 默认 |
|---|---|---|
| cameraPosition | front / back | back |
| torch | 闪光灯 | false |
| zoom | 倍率 | 1 |
| continuous | false 识别一批后暂停 | false |
| vibrate | 识别成功震动 | true |
| scanInterval | 最小识别间隔 ms | 300 |
| formats | 码制 | ["all"] |
| scanArea | 归一化扫描区 | 全预览 |
| autoOpen | 初始化后自动开相机 | true |
| showScanArea | 显示扫描框 | true |
| showCodePoints | 显示码标记 | true |
scanArea 相对组件预览,范围 0~1。只有码中心落在区域内才回调。
事件
| 名称 | 参数 | 说明 |
|---|---|---|
| ready | { state, cameraPosition, torchSupported, minZoom, maxZoom } | 相机就绪 |
| scan | XScanningResult:source、codes、texts、viewWidth / viewHeight、scanArea | 识别到一批码 |
| clickCode | { rawValue, displayValue, format, bounds, cornerPoints } | 点击页面上的码标记 |
| stop | { state, reason } | 暂停、关闭或销毁。reason 为 result / close / destroy / error |
| error | { errSubject, errCode, errMsg } | 打开或识别失败 |
方法
| 名称 | 需要 | 说明 |
|---|---|---|
| open | 可选 success / fail / complete | 打开或继续扫描 |
| close | 可选 success / fail / complete | 暂停扫描 |
| setTorch | enabled: boolean | 开关闪光灯 |
| setZoom | zoom: number | 设置倍率,超出设备范围会被夹住 |
| scanImage | tempFilePath: string | 识别本地图片。微信不可用 |
| chooseImage | 可选 success / fail / complete | 调相册选图并识别。微信不可用 |
| getState | 无 | 返回当前状态 |
兼容别名:openCamera = open,closeCamera = close,setFlashModel(enabled) = setTorch。
平台差异
- 微信无码坐标,扫描框和码点点击无效。
continuous=false时识别一批后暂停,再open继续。
版本
版权归https://xui.tmui.design你不得修改及二次开发,仅供TMUI4会员商用使用。不得转给非VIP会员使用,一经查实数倍赔偿,并追究法律责任。
更新日志
2.0.0(2026-07-31)
- 破坏性更新,统一为Dcloud函数式风格调用
- 所有端得到增强
- web也支持多码识别
1.1.2(2025-08-17)
- 针对旧 Web/微信实现调整浏览器内核属性。
1.1.0(2024-12-18)
- 增加闪光灯初始状态和
setFlashModel。
1.0.8(2024-08-31)
- 增加相册图片识别。
1.0.7(2024-08-11)
- 优化 Android/iOS 识别速率和嵌入尺寸适配。
1.0.0(2024-01-24)
- 首次发布。
