领料出库扫描
This commit is contained in:
		
							parent
							
								
									008a19695f
								
							
						
					
					
						commit
						7772b9d805
					
				| 
						 | 
				
			
			@ -13,7 +13,7 @@ const scanQrCode = () => {
 | 
			
		|||
      console.log("扫一扫");
 | 
			
		||||
      console.log("window对象", window);
 | 
			
		||||
 | 
			
		||||
      // document.addEventListener("deviceready", onDeviceReady.bind(this), false);
 | 
			
		||||
      document.addEventListener("deviceready", onDeviceReady.bind(this), false);
 | 
			
		||||
 | 
			
		||||
      function onDeviceReady() {
 | 
			
		||||
        // Cordova is now initialized. Have fun!
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -444,7 +444,7 @@ const scanStart = () => {
 | 
			
		|||
 | 
			
		||||
// 处理扫描成功事件
 | 
			
		||||
const handleScanSuccess = (result) => {
 | 
			
		||||
    qrCodeScan.value = result
 | 
			
		||||
    qrCodeScan.value = result?.text || ''
 | 
			
		||||
    if (qrCodeScan.value === "") {
 | 
			
		||||
        uni.showToast({ title: '扫码识别失败', icon: 'none' })
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,13 @@
 | 
			
		|||
<template>
 | 
			
		||||
	<view class="page-container">
 | 
			
		||||
		<view>
 | 
			
		||||
		<!-- <view>
 | 
			
		||||
			<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"
 | 
			
		||||
				:zoom="true" :style="[{height: cameraHeight+'rpx' ,width:'750rpx'}]">
 | 
			
		||||
			</live-pusher>
 | 
			
		||||
		</view>
 | 
			
		||||
		</view> -->
 | 
			
		||||
		<view class="table-list-item">
 | 
			
		||||
		    <view class="scan-btn" @click="handleInstruct('shutter')">
 | 
			
		||||
		    <view class="scan-btn" @click="handleInstruct()">
 | 
			
		||||
					<text style="color: #FFF;">开始识别</text> 
 | 
			
		||||
			</view>
 | 
			
		||||
		</view>
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +72,7 @@
 | 
			
		|||
				queryCodeParams:{
 | 
			
		||||
					maCode:""
 | 
			
		||||
				},
 | 
			
		||||
				codeData:{}
 | 
			
		||||
				codeData:{},
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		onLoad(options) {
 | 
			
		||||
| 
						 | 
				
			
			@ -80,49 +80,204 @@
 | 
			
		|||
			this.queryCodeParams.typeId = this.queryParams.typeId;
 | 
			
		||||
		},
 | 
			
		||||
		onReady() { 
 | 
			
		||||
			this.cameraHeight = uni.getSystemInfoSync().screenHeight * 0.22
 | 
			
		||||
			console.log(this.cameraHeight) 
 | 
			
		||||
			this.init() 
 | 
			
		||||
			// this.cameraHeight = uni.getSystemInfoSync().screenHeight * 0.22
 | 
			
		||||
			// console.log(this.cameraHeight) 
 | 
			
		||||
			// this.init() 
 | 
			
		||||
		},
 | 
			
		||||
		methods: {
 | 
			
		||||
			//初始化相机
 | 
			
		||||
			init() { 
 | 
			
		||||
				this.livePusher = uni.createLivePusherContext('livePusher', this);
 | 
			
		||||
				console.log(this.livePusher)
 | 
			
		||||
				setTimeout(() => {
 | 
			
		||||
					this.startPreview()
 | 
			
		||||
				}, 1000)
 | 
			
		||||
			},
 | 
			
		||||
			// 开始相机
 | 
			
		||||
			startPreview() {
 | 
			
		||||
				this.livePusher.startPreview({
 | 
			
		||||
					success: () => {
 | 
			
		||||
						console.log('相机初始化成功');
 | 
			
		||||
						switch (plus.os.name) {
 | 
			
		||||
							case 'Android':
 | 
			
		||||
								break;
 | 
			
		||||
							case 'iOS':
 | 
			
		||||
								this.livePusher.switchCamera()
 | 
			
		||||
								break
 | 
			
		||||
			// init() { 
 | 
			
		||||
			// 	this.livePusher = uni.createLivePusherContext('livePusher', this);
 | 
			
		||||
			// 	console.log(this.livePusher)
 | 
			
		||||
			// 	setTimeout(() => {
 | 
			
		||||
			// 		this.startPreview()
 | 
			
		||||
			// 	}, 1000)
 | 
			
		||||
			// },
 | 
			
		||||
			// // 开始相机
 | 
			
		||||
			// startPreview() {
 | 
			
		||||
			// 	this.livePusher.startPreview({
 | 
			
		||||
			// 		success: () => {
 | 
			
		||||
			// 			console.log('相机初始化成功');
 | 
			
		||||
			// 			switch (plus.os.name) {
 | 
			
		||||
			// 				case 'Android':
 | 
			
		||||
			// 					break;
 | 
			
		||||
			// 				case 'iOS':
 | 
			
		||||
			// 					this.livePusher.switchCamera()
 | 
			
		||||
			// 					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) => {
 | 
			
		||||
						console.log(err)
 | 
			
		||||
					}
 | 
			
		||||
						console.error('操作菜单选择失败:', err);
 | 
			
		||||
					},
 | 
			
		||||
				});
 | 
			
		||||
			},
 | 
			
		||||
			//截屏
 | 
			
		||||
			handleInstruct(instruct) {
 | 
			
		||||
				if (this.ready) {
 | 
			
		||||
					this.ready = false
 | 
			
		||||
					this.livePusher.snapshot({
 | 
			
		||||
						success: (res) => {
 | 
			
		||||
							console.log(res)
 | 
			
		||||
							this.ready = true
 | 
			
		||||
							this.$emit('getImage', res.message.tempImagePath)
 | 
			
		||||
 | 
			
		||||
        imgToBase64(filePath) {
 | 
			
		||||
            return new Promise((resolve, reject) => {
 | 
			
		||||
                return new Promise((resolve, reject) => {
 | 
			
		||||
                    const xhr = new XMLHttpRequest();
 | 
			
		||||
                    xhr.open('GET', filePath, true);
 | 
			
		||||
                    xhr.responseType = 'blob';
 | 
			
		||||
                    xhr.onload = () => {
 | 
			
		||||
                        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(){ 
 | 
			
		||||
| 
						 | 
				
			
			@ -248,7 +403,7 @@
 | 
			
		|||
	.outbound-btn {
 | 
			
		||||
	    position: fixed;
 | 
			
		||||
	    bottom: 40rpx;
 | 
			
		||||
		left: 20%;
 | 
			
		||||
		left: 10%;
 | 
			
		||||
	   /* transform: translateX(-50%); */
 | 
			
		||||
	    /* width: 90%; */
 | 
			
		||||
	    height: 88rpx;
 | 
			
		||||
| 
						 | 
				
			
			@ -7,8 +7,8 @@ import { useMemberStore } from '@/stores'
 | 
			
		|||
 */
 | 
			
		||||
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://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' ? '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' ? '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' ? '/api' : '***'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue