uniapp实现扫码枪扫码

该博客分享了如何在uni-app中使用USB连接扫码枪进行扫码操作,提供了有效的代码示例。

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


USB连接扫码枪进行扫码,亲测有效

一、代码

代码如下(示例):

<template>
	<view class="">
		<view>
			
			<input type="text" :focus="isFocus" v-model="inputValue" @input="inputChange" confirm-type="done" @confirm="inputChangeconfirm()" placeholder="请扫描录入" >
		</view>
		<view @click="empty" v-if="inputValue!=''"></view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				inputValue:'',
			}
		},
		onLoad(options) {
			this.title=options.title
			plus.key.addEventListener('keydown',this.getkeyCodes())
		},

		onHide() {
		},
		methods: {


			getkeyCodes(event) {
				this.keyCodes = event.keyCode;
			},

			// 扫描录入的变化
			async inputChange(event) {
				if (this.keyCodes == 302 || this.keyCodes == 303) {
					let inputData = event.target.value;
					console.log(inputData == null, inputData == undefined, inputData == '')
					if (inputData == null || inputData == undefined || inputData == '') {
						return;
					}
					this.inputValue = inputData;
					this.checkWorkCardNo(this.inputValue);
				}
			},
			inputChangeconfirm() {
				if (this.inputValue == null || this.inputValue == undefined || this.inputValue == '') {
					return;
				}
				this.checkWorkCardNo(this.inputValue);
			},
			loading() {
				uni.showLoading({
					title: '加载中...'
				})
			},
			// 清空后自动聚焦
			empty() {
				this.inputValue = '';
				this.isFocus = false
				this.$nextTick(() => {
					this.isFocus = true
				})
			},
			checkWorkCardNo(inputValue) {
				console.log(inputValue, 'inputValue')
				this.loading();
				this.$http.binscan.checkWorkCardNo({
					work_card_no: inputValue,
					receipt_type: 2,
					position_house_id: this.userInfo.position_house_id,
					position_house_name: this.userInfo.select
				}).then(res => {

					this.keyCodes = null;
					uni.hideLoading();
					if (res.code == 200) {
						if (res.data.list <= 0) {

							return;
						}
						correct();

						this.disableds = false;
						this.workOrderData = res.data.list;
						this.goodsName = res.data.goods_name;
						this.qu = res.data.qu;
						this.work_card_no = this.inputValue;
					} else {
						this.isMask = true;
						this.content = res.msg;
						warning();

					}

				}).catch(err => {
						uni.hideLoading();
						this.keyCodes = null;
						this.isMask = true;
						this.content = err.msg;
						warning()


					})
					

				}
			},
			}
</script>


总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是酷酷吖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值