ocr查询

This commit is contained in:
hongchao 2025-06-30 18:06:37 +08:00
parent 287745de4e
commit 22b9b9ab6a
3 changed files with 273 additions and 59 deletions

View File

@ -19,13 +19,14 @@
>编码检索</view> >编码检索</view>
</uni-col> </uni-col>
</uni-row> </uni-row>
<div v-if="optionList.length > 1" class="select-container"> <div v-if="optionList.length > 1" >
<uni-data-select <uni-data-select
v-model="maId" v-model="maId"
:localdata="optionList" :localdata="optionList"
@change="changeTag" @change="changeTag"
placeholder="请选择相关联编号" placeholder="请选择相关联编号"
class="data-select" :searchable="false"
filterable
></uni-data-select> ></uni-data-select>
</div> </div>
</view> </view>
@ -203,6 +204,18 @@ const changeTag = async () => {
padding: 0 0; padding: 0 0;
border-top: 1px #eee solid; border-top: 1px #eee solid;
} }
.select-container :deep(.uni-select__input-text) {
white-space: nowrap;
text-overflow: clip;
overflow: visible;
}
.select-container :deep(.uni-select) {
width: auto;
min-width: 200px;
}
.page-container { .page-container {
display: flex; display: flex;
height: 100%; height: 100%;

View File

@ -1,11 +1,11 @@
<template> <template>
<view class="page-container"> <view class="page-container">
<view> <!-- <view>
<live-pusher v-once id="livePusher" ref="livePusher" class="livePusher" mode="FHD" beauty="0" whiteness="0" <live-pusher v-once id="livePusher" ref="livePusher" class="livePusher" mode="FHD" beauty="0" whiteness="0"
device-position="back" :auto-focus="false" :muted="true" :enable-camera="true" :enable-mic="true" device-position="back" :auto-focus="false" :muted="true" :enable-camera="true" :enable-mic="true"
:zoom="true" :style="[{height: '350rpx' ,width:'750rpx'}]"> :zoom="true" :style="[{height: '350rpx' ,width:'750rpx'}]">
</live-pusher> </live-pusher>
</view> </view> -->
<view class="table-list-item"> <view class="table-list-item">
<view class="scan-btn" @click="handleInstruct('shutter')"> <view class="scan-btn" @click="handleInstruct('shutter')">
<text style="color: #FFF;">开始识别</text> <text style="color: #FFF;">开始识别</text>
@ -28,6 +28,16 @@
</view> </view>
</uni-col> </uni-col>
</uni-row> </uni-row>
<div v-if="optionList.length > 1" class="select-container">
<uni-data-select
v-model="queryCodeParams.maId"
:localdata="optionList"
@change="changeTag"
placeholder="请选择相关联编号"
class="data-select"
:searchable="false"
></uni-data-select>
</div>
</view> </view>
<view class="table-list-item"> <view class="table-list-item">
<!-- <scroll-view class="scroll-view" scroll-y="true" style="height: 650rpx;"> --> <!-- <scroll-view class="scroll-view" scroll-y="true" style="height: 650rpx;"> -->
@ -86,47 +96,49 @@
coverImage: null, coverImage: null,
queryParams:{}, queryParams:{},
queryCodeParams:{ queryCodeParams:{
maCode:"" maCode:"",
maId:""
}, },
codeData:{} codeData:{},
optionList:[],
} }
}, },
onLoad(options) { onLoad(options) {
// this.queryParams = JSON.parse(options.queryParams) // this.queryParams = JSON.parse(options.queryParams)
// this.queryCodeParams.typeId = this.queryParams.typeId; // this.queryCodeParams.typeId = this.queryParams.typeId;
}, },
onReady() { // onReady() {
this.cameraHeight = uni.getSystemInfoSync().screenHeight * 0.22 // this.cameraHeight = uni.getSystemInfoSync().screenHeight * 0.22
console.log(this.cameraHeight) // console.log(this.cameraHeight)
this.init() // this.init()
}, // },
methods: { methods: {
//初始化相机 //初始化相机
init() { // init() {
this.livePusher = uni.createLivePusherContext('livePusher', this); // this.livePusher = uni.createLivePusherContext('livePusher', this);
console.log(this.livePusher) // console.log(this.livePusher)
setTimeout(() => { // setTimeout(() => {
this.startPreview() // this.startPreview()
}, 1000) // }, 1000)
}, // },
// 开始相机 // 开始相机
startPreview() { // startPreview() {
this.livePusher.startPreview({ // this.livePusher.startPreview({
success: () => { // success: () => {
console.log('相机初始化成功'); // console.log('相机初始化成功');
switch (plus.os.name) { // switch (plus.os.name) {
case 'Android': // case 'Android':
break; // break;
case 'iOS': // case 'iOS':
this.livePusher.switchCamera() // this.livePusher.switchCamera()
break // break
} // }
}, // },
fail: (err) => { // fail: (err) => {
console.log(err) // console.log(err)
} // }
}); // });
}, // },
//截屏 //截屏
handleInstruct(instruct) { handleInstruct(instruct) {
if (this.ready) { if (this.ready) {
@ -140,26 +152,109 @@
}) })
} }
}, },
handleInstruct() {
uni.showActionSheet({
itemList: ['拍照', '从相册选择'],
success: (res) => {
if (res.tapIndex === 0) {
this.getCamera()
} else if (res.tapIndex === 1) {
// 从相册选择
this.getPhoto()
}
},
fail: (err) => {
console.error('操作菜单选择失败:', err)
},
})
},
getCamera() {
console.log(1)
navigator.camera.getPicture(this.onCameraSuccess, this.onCameraError, {
quality: 50,
destinationType: window.Camera.DestinationType.DATA_URL,
sourceType: window.Camera.PictureSourceType.CAMERA,
})
},
getPhoto() {
console.log(2)
navigator.camera.getPicture(this.onCameraSuccess, this.onCameraError, {
quality: 50,
destinationType: window.Camera.DestinationType.DATA_URL,
sourceType: window.Camera.PictureSourceType.SAVEDPHOTOALBUM,
})
},
onCameraError(message) {
console.log(message)
},
onCameraSuccess(file) {
// const file1 = "data:image/jpeg;base64," + file;
const file1 = file
let params = {
image: file1,
jiju_type: '',
auth_lic:
'xIWDlaDVdijcBB4mjhGCPYk5Kvk8tHZJbUn+vW+ih15+MYx98e/PXyBmKL5gFcWMPznLgDA15QuSAnZQSLddwdy9HkZgtuQDEEZZ351Eyb1eiDUccUnyoSGIrNimbx5TooBNNPYqU4qJeFrPJXAqjBHzRrxoBxuR2CEGKQPgHC4=',
}
uni.request({
url: '/material/app/ocr/getOcrCode',
method: 'post',
data: params,
header: {
'Content-Type': 'application/json', // 根据后端要求设置请求头,常见的 POST 请求数据格式为 JSON
},
success: (res) => {
const { data: resData } = res
if (resData.data.data.result) {
// this.queryCodeParams.maCode = resData.data.data.result
this.queryCodeParams.maCode = resData.data.data.result
this.$nextTick(() => {
this.getCode();
})
} else {
uni.showToast({
title: '识别失败!' + resData.data.msg,
icon: 'none',
})
}
},
fail: (err) => {
uni.showToast({
title: '请求失败:' + err.errMsg,
icon: 'none',
})
},
})
},
//编码检索 //编码检索
async getCode(){ async getCode(){
let param = { let param = {
maCode: this.queryCodeParams.maCode, maCode: this.queryCodeParams.maCode,
typeId:this.queryCodeParams.typeId,
maStatus:1
} }
uni.request({ uni.request({
url: '/material/ma_machine/list', url: '/material/ma_machine/getHisByCode',
method: 'get', method: 'get',
data: param, data: param,
success: res => { success: response => {
res = res.data; response = response.data;
console.log(res) if (response.data && response.data.length !== 0) {
if(res.rows&&res.rows.length>0){ this.optionList = response.data.map(option => ({
this.codeData=res.rows[0]; value: option.maId,
text: option.maCode
}))
if(response.data.length === 1){
this.codeData = response.data[0]
}
}else{ }else{
uni.showToast({ uni.showToast({
title: '未检索到有效的设备编码!', title: '未查询到该编号信息',
icon: 'none', icon: 'none',
duration: 2000
}) })
} }
@ -168,12 +263,53 @@
console.log(err) console.log(err)
} }
}) })
},
changeTag(){
if (!this.queryCodeParams.maId) return
try {
let param = {
maId: this.queryCodeParams.maId,
}
uni.request({
url: '/material/ma_machine/getHisByCode',
method: 'get',
data: param,
success: response => {
response = response.data;
if (response.data && response.data.length !== 0) {
this.codeData = response.data[0]
}else{
uni.showToast({
title: '获取编号信息失败',
icon: 'none',
duration: 2000
})
}
},
fail: err => {
console.log(err)
}
})
} catch (error) {
console.error("获取编号信息失败", error)
uni.showToast({
title: '获取信息失败',
icon: 'none',
duration: 2000
})
}
} }
} }
} }
</script> </script>
<style> <style>
.page-container { .page-container {
display: flex; display: flex;
height: auto; height: auto;
@ -182,13 +318,78 @@
padding: 24rpx; padding: 24rpx;
} }
.table-list-item { .table-list-item {
margin-top: 10rpx;
background: #fff; background: #fff;
padding: 20rpx; padding: 32rpx;
border-radius: 20rpx; border-radius: 20rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06); box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
margin-bottom: 20rpx; margin-bottom: 24rpx;
:deep(.uni-forms) {
.uni-forms-item {
margin-bottom: 24rpx;
padding: 0;
&:last-child {
margin-bottom: 0;
}
.uni-forms-item__label {
color: #8c8c8c;
font-size: 28rpx;
font-weight: 500;
padding: 0;
line-height: 1.8;
}
.uni-forms-item__content {
display: flex;
align-items: center;
min-height: unset;
}
}
}
:deep(.uni-row) {
/* margin-bottom: 20rpx; */
&:last-child {
margin-bottom: 0;
}
.uni-col-6 {
color: #8c8c8c;
font-size: 28rpx;
font-weight: 500;
}
.cont {
color: #262626;
font-size: 28rpx;
font-weight: 500;
line-height: 1.8;
}
}
:deep(.uni-easyinput__content) {
background-color: #f7f8fa;
border: 2rpx solid #e8e8e8;
border-radius: 12rpx;
height: 75rpx;
transition: all 0.3s ease;
&:focus-within {
border-color: #3784fb;
box-shadow: 0 0 0 2rpx rgba(55, 132, 251, 0.1);
}
.uni-easyinput__content-input {
font-size: 28rpx;
color: #262626;
}
}
} }
.scan-btn { .scan-btn {
/* width: 100%; */ /* width: 100%; */

View File

@ -12,8 +12,8 @@
</view> </view>
</view> </view>
<view> 参数{{ testParams }} </view> <!-- <view> 参数{{ testParams }} </view>
<view> 返回{{ resData }} </view> <view> 返回{{ resData }} </view> -->
<view class="table-list-item"> <view class="table-list-item">
<uni-row :gutter="24" style="display: flex; align-items: center"> <uni-row :gutter="24" style="display: flex; align-items: center">
<uni-col :span="5"> <uni-col :span="5">