更新记录
1.0.0(2024-05-13)
一、优化版本适配uniappx
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 3.8.0,Android:5.0,iOS:不支持,HarmonyNext:不确定 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
华为ScanKit统一扫码插件目前支持仅Android
请先试用。
代码示例
<template>
<view class="content">
<text class="hd-btn" @click="selectScanMode('defaultMode')">开启扫码</text>
<text class="hd-btn" @click="selectScanMode('customMode')">开启扫码「 扫描框 」</text>
<text class="hd-btn" @click="selectScanMode('multiMode')">开启扫码「 多图 」</text>
<text class="result_view" v-if="result">扫描结果:{{result}}</text>
</view>
</template>
<script>
// #ifdef UNI-APP-X
import { hwscanManager } from '@/uni_modules/hdx-hw-scankit';
import { ScanCodeManager, ScanOption, ScanCallbackOptions, ScanResult, CodeResult, InfoOptions, QRCodeOptions } from "@/uni_modules/hdx-hw-scankit/utssdk/interface.uts"
const scanCodeManager = hwscanManager() as ScanCodeManager;
// #endif
export default {
data() {
return {
title: 'Hello',
result: ''
}
},
onUnload() {
// scanMode 为 "customMode" "multiMode" 时 调用
// scanCodeManager.unregisterReceiver()
},
methods: {
// 选择扫描类型
selectScanMode(scanMode : string) {
scanCodeManager.config({ scanMode } as ScanOption)
let that = this
scanCodeManager.scanCode({
success: function (res : object) {
let result = res as ScanResult
that.result = JSON.stringify(result);
console.log("扫描结果:" + result.result);
uni.showToast({
title: result.result as string,
icon: 'none',
duration: 1500
})
}
} as ScanCallbackOptions);
}
}
}
</script>
<style>
.content {
display: flex;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-bottom: 50rpx;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
.hd-btn {
background: #4239ff;
color: #fff;
padding: 20rpx 20rpx;
border-radius: 6rpx;
text-align: center;
margin: 20rpx;
font-size: 32rpx;
width: 70%;
}
.result_view {
display: flex;
justify-content: center;
padding: 10rpx 20rpx;
box-sizing: border-box;
}
</style>
开发文档
UTS 语法
UTS API插件
UTS 组件插件
Hello UTS