二维码

This commit is contained in:
jjLv 2024-11-29 12:13:36 +08:00
parent f521356c3c
commit c8f62074a3
3 changed files with 105 additions and 14 deletions

View File

@ -24,23 +24,20 @@
<uni-row :gutter="24">
<uni-col :span="6">接收方式</uni-col>
<uni-col :span="6">
<view class="coding-btn">编码识别</view>
<view class="coding-btn" @tap="onCodeIdentify1">编码识别</view>
</uni-col>
<uni-col :span="6">
<view class="coding-btn">编码识别</view>
</uni-col>
<uni-col :span="6">
<view class="coding-btn">二维码识别</view>
<view class="coding-btn" @tap="onCodeIdentify2">二维码识别</view>
</uni-col>
</uni-row>
</div>
<div class="card" style="margin-top: 20px;">
<div>扫码识别</div>
<!-- <div>扫码识别</div>
<div style="width: 94%;height: 120px;margin: 10px;border: 1px solid #ccc;">
</div>
</div> -->
<uni-row :gutter="24" style="display: flex; align-items: center;margin-bottom: 10px;">
@ -213,6 +210,67 @@ const uploadImg = () => {
})
}
const toBase64 = (path) => {
return new Promise((resolve, reject) => {
// #ifdef APP-PLUS
plus.io.resolveLocalFileSystemURL(path, (entry) => {
entry.file((file) => {
let fileReader = new plus.io.FileReader()
fileReader.readAsDataURL(file)
fileReader.onloadend = (evt) => {
let base64 = evt.target.result.split(",")[1]
resolve(base64)
}
})
})
})
}
//
const onCodeIdentify1 = () => {
console.log('编码识别--')
//
uni.chooseImage({
count: 1, //
sourceType: ['camera'], //
success: (res) => {
const tempFilePath = res.tempFilePaths[0];
toBase64(tempFilePath)
},
fail: (err) => {
console.error("选择图片失败", err);
}
});
};
// OCR API
const recognizeCode =((imagePath)=>{
// Base64
toBase64(imagePath).then(res=>{
callBaiduOcrApi(res);
}
)
})
const onCodeIdentify2 = () => {
console.log('二维码识别--')
//
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode', 'pdf417'],
success: function (res) {
console.log('条码类型:' + res.scanType)
console.log('条码内容:' + res)
maCode.value = res.result;
getMaInfo();
},
})
}
onLoad((options)=>{
console.log(options)
taskInfo.value = JSON.parse(options.taskInfo)

View File

@ -32,13 +32,10 @@
<uni-row :gutter="24">
<uni-col :span="6">出库方式</uni-col>
<uni-col :span="6">
<view class="coding-btn" @tap="onCodeIdentify">编码识别</view>
<view class="coding-btn" @tap="onCodeIdentify1">编码识别</view>
</uni-col>
<uni-col :span="6">
<view class="coding-btn" @tap="onCodeIdentify">编码识别</view>
</uni-col>
<uni-col :span="6">
<view class="coding-btn" @tap="onCodeIdentify">二维码识别</view>
<view class="coding-btn" @tap="onCodeIdentify2">二维码识别</view>
</uni-col>
</uni-row>
</view>
@ -170,13 +167,27 @@ const getCodeDeviceListData = async () => {
getCodeDeviceListData()
//
const onCodeIdentify = () => {
const onCodeIdentify1 = () => {
console.log('编码识别--')
//
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode', 'pdf417'],
scanType: ['qrCode'],
success: function (res) {
console.log('条码类型:' + res.scanType)
console.log('条码内容:' + res.result)
},
})
}
//
const onCodeIdentify2 = () => {
console.log('二维码识别--')
//
uni.scanCode({
onlyFromCamera: true,
success: function (res) {
console.log('条码类型:' + res.scanType)
console.log('条码内容:' + res.result)

View File

@ -40,6 +40,19 @@
</text>
</view>
</view>
<view class="new-purchase">
<view
class="purchase-item"
:key="index"
@tap="onNavigateTo(item.url)"
v-for="(item, index) in backList"
>
<image :src="item.iconSrc" mode="scaleToFill" />
<text>
{{ item.title }}
</text>
</view>
</view>
</view>
</template>
@ -82,6 +95,15 @@ const repairList = ref([
},
])
// 退
const backList = ref([
{
title: '退料',
url: '/pages/back/index',
iconSrc: '../../static/workbench/fix.png',
},
])
const onNavigateTo = (url) => {
uni.navigateTo({ url })
}