更新记录
1.0.12(2026-10-10)
- UTS 插件同时兼容 uni-app 与 uni-app x
- Android / iOS 基于华为 ScanKit,支持默认扫码、多码、图片识码、生成二维码
- HarmonyOS 基于系统 ScanKit
- H5 / Web 基于 BarcodeDetector 兼容扫码与识码
- 支持微信小程序
平台兼容性
uni-app(3.96)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | × | 5.0 | 12 | 12 |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | √ | √ | - | × | × | × | √ | × | × | × | × |
uni-app x(4.0)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| √ | √ | 5.0 | 12 | 12 | - |
其他
| 多语言 | 暗黑模式 | 宽屏模式 | 蒸汽模式 |
|---|---|---|---|
| × | × | × | √ |
try-scankit
基于华为统一扫码 ScanKit 的 UTS 插件,兼容 uni-app 与 uni-app x。
插件 ID:try-scankit(符合 插件市场命名规范:作者 ID + 英文名)。
将本目录放到项目 uni_modules/try-scankit(Vue3 Vite 工程多为 src/uni_modules/try-scankit)即可。
| 能力 | Android | iOS | HarmonyOS | H5 / Web | 微信等小程序 |
|---|---|---|---|---|---|
| 默认扫码 | ScanKit Default View | ScanKit Default View | @kit.ScanKit |
BarcodeDetector | uni.scanCode |
| 多码扫描 | RemoteView | Customized View | enableMultiMode |
连续识别 | 系统扫码(单次) |
| 图片识码 | decodeWithBitmap |
HmsBitMap |
detectBarcode |
BarcodeDetector | 请用 startScan({ album: true }) |
| 生成码 | ScanUtil.buildBitmap |
ScanKit / CIFilter | generateBarcode |
不支持 | 不支持 |
要不要单独写 scankit.ts?
不需要。 分流和 Promise 封装已在插件内:
| 工程 | 引入 |
|---|---|
| uni-app Vue2 / Vue3(H5 / 小程序 / App) | @/uni_modules/try-scankit/uni-app |
| uni-app x / uvue / App UTS | @/uni_modules/try-scankit |
不要在 H5、小程序里直接 import '@/uni_modules/try-scankit'(那是 UTS 入口,小程序编不过)。
调用
uni-app(Vue)
import { startScan, scanCode } from '@/uni_modules/try-scankit/uni-app'
startScan({
album: true,
scanTypes: ['QR', 'EAN-13'],
success(res) {
console.log(res.result)
console.log(res.results)
},
fail(err) {
if (err.errCode !== 801) {
uni.showToast({ title: err.errMsg, icon: 'none' })
}
},
})
const res = await scanCode({ album: true })
Promise:scanCode / scanMultiCode / scanImage / createQrCode。
示例页:把插件内 example.vue 拷到自己的 pages 并在 pages.json 注册。
uni-app x
import { startScan } from '@/uni_modules/try-scankit'
startScan({
album: true,
success: (res) => {
uni.showToast({ title: res.result, icon: 'none' })
},
})
示例:插件内 example.uvue。
API
startScan(options?)
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| album | boolean | true | 相册入口 |
| multiMode | boolean | false | 多码 |
| isSelectOne | boolean | true | 多码是否只返回一个 |
| scanTitle | string | 扫码 | 标题 |
| scanTypes | string[] | 全部 | 码制式 |
| isSound | boolean | true | 成功音效/震动 |
| success / fail / complete | function | 回调 |
isSelectOne = false 时连续扫码,点「完成」返回全部结果。
startMultiScan(options?)
等价于 startScan({ multiMode: true, ... })。
decodeImage(options)
不打开相机。image 支持本地路径、file://、https://、base64。
generateCode(options)
仅 App(Android / iOS / HarmonyOS)。返回 { tempFilePath, base64 }。
stopScan() / setFlashlight(enable)
关闭 H5 扫码层或自定义扫码页;开关手电筒。
码制式
QR Aztec DataMatrix PDF417 Code128 Code39 Code93 Codabar EAN-13 EAN-8 ITF14 UPC-A UPC-E
错误码
| errCode | 含义 |
|---|---|
| 401 | 无相机权限 |
| 801 | 用户取消 |
| 9010001 | 图片为空或加载失败 |
| 9010002 | 未识别到码 |
| 9010003 | 生码失败 |
| 9010004 | 当前端不支持 |
| 9010005 | 参数错误 |
平台与打包
Android
- Maven:
com.huawei.hms:scanplus:2.12.0.301(见utssdk/app-android/config.json) - 需 自定义基座或云打包,标准基座没有 ScanKit
- 请用真机
iOS
- CocoaPods:
ScanKitFrameWork 1.1.2.305 - iOS 12+
- 相机/相册文案在插件
utssdk/app-ios/info.plist
HarmonyOS NEXT
@kit.ScanKit,API 12+
H5
BarcodeDetector,需 HTTPS 或 localhost
微信 / 支付宝 / 百度 / 抖音 / QQ 小程序
uni.scanCode,单次一条- 不支持
decodeImage(指定路径)、generateCode、setFlashlight
上架插件市场
按 制作和发布插件指南:
- 本插件为 uni_modules + UTS,在 HBuilderX 中对
uni_modules/try-scankit右键 → 上传/更新插件。 - 不要带上
unpackage、node_modules、.git。 - 三方库走仓储(Android Maven / iOS CocoaPods),不要把 SDK 打进插件包。
- 上传时补全:分类选 UTS 插件、截图、隐私声明(已在
package.json→dcloudext.declaration)。 - UTS 插件提交的是源码,一般 免审核即可上架。
权限
扫码需要相机;相册识码需要相册。请在项目 manifest.json 勾选对应权限。

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 1
赞赏 0
下载 12670014
赞赏 1955
赞赏
京公网安备:11010802035340号