优化++
This commit is contained in:
132
dist/index.d.ts
vendored
132
dist/index.d.ts
vendored
@@ -45,6 +45,58 @@ interface ScanConfigOptions {
|
||||
* 2. 结束扫码的方法名称为:stopScan
|
||||
*/
|
||||
bridgeName?: string,
|
||||
/**
|
||||
* 桥接扫码超时(毫秒),超时后回退 Web/图片识别,默认 5000
|
||||
*/
|
||||
bridgeScanTimeout?: number,
|
||||
/**
|
||||
* 是否允许 H5 摄像头扫码:true 强制开启(仍需有媒体 API),false 强制关闭
|
||||
*/
|
||||
webScanCameraEnabled?: boolean,
|
||||
/**
|
||||
* @deprecated 请用 webScanCameraEnabled;保留兼容
|
||||
*/
|
||||
webScanCameraInWechat?: boolean,
|
||||
/**
|
||||
* @deprecated 摄像头权限已后置到 startScan,请用 webScanVideoAccessTimeout
|
||||
*/
|
||||
webScanCameraProbeTimeout?: number,
|
||||
/**
|
||||
* startScan 走 Web 摄像头前是否展示权限说明弹窗,默认 true
|
||||
*/
|
||||
webScanCameraPermissionDialogEnabled?: boolean,
|
||||
/**
|
||||
* 摄像头权限说明弹窗标题
|
||||
*/
|
||||
webScanCameraPermissionTitle?: string,
|
||||
/**
|
||||
* 摄像头权限说明弹窗正文
|
||||
*/
|
||||
webScanCameraPermissionMessage?: string,
|
||||
/**
|
||||
* 摄像头权限说明弹窗确认按钮文案
|
||||
*/
|
||||
webScanCameraPermissionConfirmText?: string,
|
||||
/**
|
||||
* 摄像头权限说明弹窗取消按钮文案
|
||||
*/
|
||||
webScanCameraPermissionCancelText?: string,
|
||||
/**
|
||||
* 选图后延迟读取 file 对象(毫秒),微信/安卓 WebView 默认 100
|
||||
*/
|
||||
webScanFileReadDelay?: number,
|
||||
/**
|
||||
* 强制使用 WASM ponyfill 识别(微信/部分 WebView 建议开启,默认微信内自动开启)
|
||||
*/
|
||||
webScanPreferPonyfill?: boolean,
|
||||
/**
|
||||
* WASM 文件完整 URL;未配置时相对 SDK 脚本地址解析 lib/reader.wasm
|
||||
*/
|
||||
webScanWasmUrl?: string,
|
||||
/**
|
||||
* WASM 基准路径(SDK 脚本 URL 或目录);用于 async/defer 加载时修正 reader.wasm 路径
|
||||
*/
|
||||
webScanWasmBaseUrl?: string,
|
||||
/**
|
||||
* webScan是否启用,默认启用
|
||||
*/
|
||||
@@ -101,6 +153,41 @@ interface ScanConfigOptions {
|
||||
* 摄像头已打开但长时间无画面时触发图片回退(毫秒),默认 8000
|
||||
*/
|
||||
webScanVideoReadyTimeout?: number,
|
||||
/**
|
||||
* 图片/回退识别时 detect 超时(毫秒),默认 15000
|
||||
*/
|
||||
webScanDetectTimeout?: number,
|
||||
/**
|
||||
* 图片识别是否优先使用 ZXing ponyfill(原生 detect 在部分 WebView 可能卡住),默认 true
|
||||
*/
|
||||
webScanImagePreferPonyfill?: boolean,
|
||||
/**
|
||||
* 移动端图片回退是否使用 capture 拍照(false 为相册选图,兼容性更好),默认 false
|
||||
*/
|
||||
webScanImagePreferCapture?: boolean,
|
||||
/**
|
||||
* 图片识别是否优先 canvas 解码(安卓 WebView 建议开启),默认在安卓/微信内自动开启
|
||||
*/
|
||||
webScanImageDetectPreferCanvas?: boolean,
|
||||
/**
|
||||
* ZXing WASM 加载超时(毫秒),默认 20000
|
||||
*/
|
||||
webScanPrepareTimeout?: number,
|
||||
/**
|
||||
* 选图等待超时(毫秒),默认 120000
|
||||
*/
|
||||
webScanChooseImageTimeout?: number,
|
||||
/**
|
||||
* 选图方式:button=显示「选择图片」按钮(安卓/微信默认,需用户点击);auto=自动弹出系统选图
|
||||
*/
|
||||
webScanImagePickerMode?: 'auto' | 'button',
|
||||
webScanImagePickerTitle?: string,
|
||||
webScanImagePickerButtonText?: string,
|
||||
webScanImagePickerCancelText?: string,
|
||||
/**
|
||||
* 单次扫码会话超时(毫秒),超时后状态恢复 ready,默认 90000
|
||||
*/
|
||||
scanSessionTimeout?: number,
|
||||
/**
|
||||
* 扫码成功提示音地址,默认使用内置提示音;任意识别模式匹配成功时播放
|
||||
*/
|
||||
@@ -161,6 +248,16 @@ interface ScanResult {
|
||||
key: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码错误
|
||||
*/
|
||||
interface ScanErrorInfo {
|
||||
error: string,
|
||||
key: string,
|
||||
source?: string,
|
||||
cancel?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听key
|
||||
*/
|
||||
@@ -197,6 +294,22 @@ type ScanStatus = "scanning" | "ready";
|
||||
*/
|
||||
type ScanResultCallback = (result: ScanResult) => any;
|
||||
|
||||
/**
|
||||
* 监听扫码错误回调
|
||||
*/
|
||||
type ScanErrorCallback = (error: ScanErrorInfo) => any;
|
||||
|
||||
/**
|
||||
* 扫码错误监听信息
|
||||
*/
|
||||
interface ScanErrorListenerInfo {
|
||||
key?: string;
|
||||
match?: string;
|
||||
level?: number;
|
||||
listener: ScanErrorCallback;
|
||||
cancel: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听状态回调
|
||||
*/
|
||||
@@ -227,6 +340,19 @@ interface IScan {
|
||||
* @param callback 监听回调,或监听key
|
||||
*/
|
||||
offScanListener(callback: ScanResultCallback | string): void;
|
||||
/**
|
||||
* 添加监听扫码错误(如图片识别失败)
|
||||
* @param callback 错误回调
|
||||
* @param key 监听 key
|
||||
* @param match 可选正则,匹配 error 文本后回调
|
||||
* @param level 优先级
|
||||
*/
|
||||
onScanErrorListener(callback: ScanErrorCallback, key: string, match?: string, level?: number): ScanErrorListenerInfo;
|
||||
/**
|
||||
* 取消监听扫码错误
|
||||
* @param callback 监听回调,或监听 key
|
||||
*/
|
||||
offScanErrorListener(callback: ScanErrorCallback | string): void;
|
||||
/**
|
||||
* 获取扫码状态
|
||||
* @returns ScanStatus
|
||||
@@ -240,14 +366,12 @@ interface IScan {
|
||||
* 开启扫码
|
||||
*/
|
||||
startScan(): void;
|
||||
/**
|
||||
* 开启视频扫码
|
||||
*/
|
||||
scanVideo(): void;
|
||||
/**
|
||||
* 选择图片进行识别
|
||||
*/
|
||||
scanImage(): void;
|
||||
/** 由业务/原生传入已选图片 File 识别(WebView input.files 异常时使用) */
|
||||
scanImageFromFile(file: File | Blob): void;
|
||||
/**
|
||||
* 清除全部监听
|
||||
*/
|
||||
|
||||
7
dist/index.html
vendored
7
dist/index.html
vendored
@@ -161,7 +161,7 @@
|
||||
|
||||
section {
|
||||
margin-bottom: 16px;
|
||||
}</style></head><body><main class="page"><section class="hero"><h1>IScan 通用扫码SDK</h1><p>统一接入桥接扫码、微信小程序、微信 JSSDK 扫码、Web 摄像头扫码、图片识别和扫码枪输入。</p></section><section class="grid"><div class="card"><h2>功能说明</h2><ul class="feature-list"><li>支持桥接扫码、微信 JSSDK 扫码、Web 摄像头扫码、图片识别和扫码枪输入。</li><li>浏览器环境使用WASM库识别二维码和条形码。</li><li>扫码结果由监听规则统一回调,支持正则匹配和优先级排序。</li></ul></div><div class="card"><h2>当前状态</h2><p>SDK 状态:<span id="status" class="status">loading</span></p><p>运行环境:</p><pre id="output" class="panel"></pre></div></section><section class="card"><h2>操作</h2><p>点击开始后,会按桥接、微信、Web 摄像头、图片识别的顺序选择可用扫码方式。</p><div class="actions"><button onclick="startScan()" class="btn">开始扫码</button> <button onclick="scanVideo()" class="btn secondary">开启视频扫码</button> <button onclick="scanImage()" class="btn secondary">选择图片识别</button> <button onclick="stopScan()" class="btn secondary">停止扫码</button></div></section><section class="card"><h2>扫码结果</h2><pre id="result" class="panel result"></pre></section><section class="card"><h2>错误信息</h2><pre id="error" class="panel error"></pre><p style="color: #919191">错误信息可能来源于扫码结果、扫码过程、扫码初始化等。</p></section><section class="card code"><h2>接入方式</h2><pre>IScan.config({
|
||||
}</style></head><body><main class="page"><section class="hero"><h1>IScan 通用扫码SDK</h1><p>统一接入桥接扫码、微信小程序、微信 JSSDK 扫码、Web 摄像头扫码、图片识别和扫码枪输入。</p></section><section class="grid"><div class="card"><h2>功能说明</h2><ul class="feature-list"><li>支持桥接扫码、微信 JSSDK 扫码、Web 摄像头扫码、图片识别和扫码枪输入。</li><li>浏览器环境使用WASM库识别二维码和条形码。</li><li>扫码结果由监听规则统一回调,支持正则匹配和优先级排序。</li></ul></div><div class="card"><h2>当前状态</h2><p>SDK 状态:<span id="status" class="status">loading</span></p><p>运行环境:</p><pre id="output" class="panel"></pre></div></section><section class="card"><h2>操作</h2><p>点击开始后,会按桥接、微信、Web 摄像头、图片识别的顺序选择可用扫码方式。</p><div class="actions"><button onclick="startScan()" class="btn">开始扫码</button> <button onclick="scanImage()" class="btn secondary">选择图片识别</button> <button onclick="stopScan()" class="btn secondary">停止扫码</button></div></section><section class="card"><h2>扫码结果</h2><pre id="result" class="panel result"></pre></section><section class="card"><h2>错误信息</h2><pre id="error" class="panel error"></pre><p style="color: #919191">错误信息可能来源于扫码结果、扫码过程、扫码初始化等。</p></section><section class="card code"><h2>接入方式</h2><pre>IScan.config({
|
||||
webScanEnabled: true,
|
||||
webScanCanvasEnabled: true,
|
||||
webScanCloseButtonStyle: "background: rgba(27, 99, 244, 0.88);",
|
||||
@@ -182,7 +182,6 @@
|
||||
|
||||
IScan.startScan();
|
||||
IScan.scanImage();
|
||||
IScan.scanVideo();
|
||||
IScan.stopScan();</pre></section></main><script>(function () {
|
||||
output(window.navigator.userAgent);
|
||||
window.onerror = function (message, source, lineno, colno, err) {
|
||||
@@ -279,8 +278,4 @@ IScan.stopScan();</pre></section></main><script>(function () {
|
||||
IScan.scanImage();
|
||||
}
|
||||
|
||||
function scanVideo() {
|
||||
IScan.scanVideo();
|
||||
}
|
||||
|
||||
ready();</script><script src="index.js"></script></body></html>
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
16
dist/index.md
vendored
16
dist/index.md
vendored
@@ -61,9 +61,6 @@ IScan.config({
|
||||
// 自动选择可用扫码方式:桥接 -> 微信 -> Web 摄像头 -> 图片识别
|
||||
IScan.startScan();
|
||||
|
||||
// 仅打开 Web 视频扫码
|
||||
IScan.scanVideo();
|
||||
|
||||
// 仅选择图片识别
|
||||
IScan.scanImage();
|
||||
|
||||
@@ -126,6 +123,11 @@ interface ScanConfigOptions {
|
||||
| `webScanImageFallbackOnVideoError` | 摄像头不可用或打开失败时,是否自动弹出拍照/选图(适用于部分安卓内置浏览器) | `true` |
|
||||
| `webScanVideoAccessTimeout` | 打开摄像头超时(毫秒),超时后走图片回退 | `10000` |
|
||||
| `webScanVideoReadyTimeout` | 摄像头已开但无画面超时(毫秒),超时后走图片回退 | `8000` |
|
||||
| `webScanCameraPermissionDialogEnabled` | `startScan` 走 Web 摄像头前是否先展示权限说明弹窗 | `true` |
|
||||
| `webScanCameraPermissionTitle` | 权限说明弹窗标题 | `需要使用摄像头` |
|
||||
| `webScanCameraPermissionMessage` | 权限说明弹窗正文 | 见类型定义默认值 |
|
||||
| `webScanCameraPermissionConfirmText` | 确认按钮文案 | `继续` |
|
||||
| `webScanCameraPermissionCancelText` | 取消按钮文案 | `取消` |
|
||||
| `scanBeepAudio` | 扫码成功提示音地址(任意模式匹配成功时播放) | 内置提示音 |
|
||||
| `scanBeepEnabled` | 扫码成功是否播放提示音 | `true` |
|
||||
| `initWechatJssdk` | 微信 JSSDK 初始化配置,仅微信环境生效 | 无 |
|
||||
@@ -292,14 +294,6 @@ console.log(IScan.getStatus());
|
||||
IScan.startScan();
|
||||
```
|
||||
|
||||
### `scanVideo(): void`
|
||||
|
||||
直接开启 Web 摄像头扫码。扫码结果通过 `onScanListener` 回调。
|
||||
|
||||
```js
|
||||
IScan.scanVideo();
|
||||
```
|
||||
|
||||
### `scanImage(): void`
|
||||
|
||||
直接选择图片进行识别。识别结果通过 `onScanListener` 回调。
|
||||
|
||||
Reference in New Issue
Block a user