领料出库扫描

This commit is contained in:
hongchao 2025-05-16 09:07:40 +08:00
parent 008a19695f
commit 7772b9d805
4 changed files with 198 additions and 43 deletions

View File

@ -13,7 +13,7 @@ const scanQrCode = () => {
console.log("扫一扫"); console.log("扫一扫");
console.log("window对象", window); console.log("window对象", window);
// document.addEventListener("deviceready", onDeviceReady.bind(this), false); document.addEventListener("deviceready", onDeviceReady.bind(this), false);
function onDeviceReady() { function onDeviceReady() {
// Cordova is now initialized. Have fun! // Cordova is now initialized. Have fun!

View File

@ -444,7 +444,7 @@ const scanStart = () => {
// //
const handleScanSuccess = (result) => { const handleScanSuccess = (result) => {
qrCodeScan.value = result qrCodeScan.value = result?.text || ''
if (qrCodeScan.value === "") { if (qrCodeScan.value === "") {
uni.showToast({ title: '扫码识别失败', icon: 'none' }) uni.showToast({ title: '扫码识别失败', icon: 'none' })
} else { } else {

View File

@ -1,13 +1,13 @@
<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: cameraHeight+'rpx' ,width:'750rpx'}]"> :zoom="true" :style="[{height: cameraHeight+'rpx' ,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()">
<text style="color: #FFF;">开始识别</text> <text style="color: #FFF;">开始识别</text>
</view> </view>
</view> </view>
@ -72,7 +72,7 @@
queryCodeParams:{ queryCodeParams:{
maCode:"" maCode:""
}, },
codeData:{} codeData:{},
} }
}, },
onLoad(options) { onLoad(options) {
@ -80,49 +80,204 @@
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) => {
// console.log(err)
// }
// });
// },
//
handleInstruct() {
//
uni.showActionSheet({
itemList: ['拍照', '从相册选择'],
success: (res) => {
if (res.tapIndex === 0) {
this.getCamera()
} else if (res.tapIndex === 1) {
//
uni.chooseImage({
count: 1,
sourceType: ['album'],
success: async (res) => {
// ... ...
const tempFilePath = res.tempFilePaths[0];
console.log('选择的图片路径:', tempFilePath);
//
let base64 = await this.imgToBase64(tempFilePath); //
let params = {
image: base64,
jiju_type: '12231',
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) => {
console.log('88888888', res);
if (res.code == 200) {
uni.showToast({
title: '出库成功!',
icon: 'none',
});
} else {
uni.showToast({ title: '出库失败!', icon: 'none' }); //
}
},
fail: (err) => {
uni.showToast({
title: '请求失败:' + err.errMsg,
icon: 'none',
});
},
});
},
fail: (err) => {
console.error('选择图片失败:', err);
uni.showToast({
title: '选择图片失败',
icon: 'none',
});
}
});
} }
}, },
fail: (err) => { fail: (err) => {
console.log(err) console.error('操作菜单选择失败:', err);
} },
}); });
}, },
//
handleInstruct(instruct) { imgToBase64(filePath) {
if (this.ready) { return new Promise((resolve, reject) => {
this.ready = false return new Promise((resolve, reject) => {
this.livePusher.snapshot({ const xhr = new XMLHttpRequest();
success: (res) => { xhr.open('GET', filePath, true);
console.log(res) xhr.responseType = 'blob';
this.ready = true xhr.onload = () => {
this.$emit('getImage', res.message.tempImagePath) if (xhr.status === 200) {
const reader = new FileReader();
reader.onloadend = (evt) => {
// data:URL
const base64WithoutPrefix = evt.target.result.split(',')[1];
resolve(base64WithoutPrefix);
};
reader.onerror = reject;
reader.readAsDataURL(xhr.response);
} else {
reject(new Error(`请求图片失败,状态码: ${xhr.status}`));
}
};
xhr.onerror = reject;
xhr.send();
});
})
},
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=',
};
// this.$http
// .post("/dzqm/uploadSignature", {
// base64Str: file1,
// })
// .then((res) => {
// console.log(res);
// if (res.code == 200) {
// // this.src = file
// this.$set(this.obj, "src", file1);
// this.$toast("");
// this.PictureVisible = false;
// }
// });
uni.request({
url: '/material/app/ocr/getOcrCode',
method: 'post',
data: params,
header: {
'Content-Type': 'application/json', // POST JSON
},
success: (res) => {
console.log('88888888', res);
const resData = JSON.stringify(res, null, 2);
uni.showModal({
title: '返回数据',
content: resData,
showCancel: false, //
});
if (res.code == 200) {
uni.showToast({
title: '出库成功!',
icon: 'none',
});
} else {
uni.showToast({ title: '出库失败!', icon: 'none' }); //
} }
}) },
} fail: (err) => {
uni.showToast({
title: '请求失败:' + err.errMsg,
icon: 'none',
});
},
});
}, },
// //
async getCode(){ async getCode(){
@ -248,7 +403,7 @@
.outbound-btn { .outbound-btn {
position: fixed; position: fixed;
bottom: 40rpx; bottom: 40rpx;
left: 20%; left: 10%;
/* transform: translateX(-50%); */ /* transform: translateX(-50%); */
/* width: 90%; */ /* width: 90%; */
height: 88rpx; height: 88rpx;

View File

@ -7,8 +7,8 @@ import { useMemberStore } from '@/stores'
*/ */
const ENV = process.env.NODE_ENV const ENV = process.env.NODE_ENV
// export const baseURL = ENV === 'development' ? 'http://192.168.0.244:18580' : 'http://192.168.0.244:18580'//测试 // export const baseURL = ENV === 'development' ? 'http://192.168.0.244:18580' : 'http://192.168.0.244:18580'//测试
export const baseURL = ENV === 'development' ? 'http://sgwpdm.ah.sgcc.com.cn/iws/jiju-api/' : 'http://sgwpdm.ah.sgcc.com.cn/iws/jiju-api/'//生产 // export const baseURL = ENV === 'development' ? 'http://sgwpdm.ah.sgcc.com.cn/iws/jiju-api/' : 'http://sgwpdm.ah.sgcc.com.cn/iws/jiju-api/'//生产
// export const baseURL = ENV === 'development' ? '/api' : '/iws/jiju-api'; // 宏源服务 export const baseURL = ENV === 'development' ? '/api' : '/iws/jiju-api'; // 宏源服务
// export const baseURL = ENV === 'development' ? 'http://192.168.0.234:18080' : '***' // export const baseURL = ENV === 'development' ? 'http://192.168.0.234:18080' : '***'
// export const baseURL = ENV === 'development' ? 'http://192.168.2.27:18080' : 'http://192.168.2.27:18080'//马 // export const baseURL = ENV === 'development' ? 'http://192.168.2.27:18080' : 'http://192.168.2.27:18080'//马
// export const baseURL = ENV === 'development' ? '/api' : '***' // export const baseURL = ENV === 'development' ? '/api' : '***'