uniapp T1Pro iData条码扫描顶部扫描

iData条码扫描插件

一定从上到下的流程操作

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

manifest.json

App.vue

<script>
	import * as utils from "@/common/util.js"
	// 同步获取设备信息
	let info = uni.getSystemInfoSync();
	if (!info.model) {
		info.model = ''
	} else if (info.model == 'T1Pro') {
		uni.setStorageSync("phoneModel", info.model)
	}
	console.log('设备型号:', info, info.model);
	let phoneModel = uni.getStorageSync('phoneModel') ? uni.getStorageSync('phoneModel') : false
	// #ifdef APP-PLUS
	const modal = uni.requireNativePlugin('modal');
	if (phoneModel) {
		//获取module
		var barcodeModel = uni.requireNativePlugin("iData-BarcodePlugin-BarcodeModule")
		//setScanKeyEnable(boolean enable, UniJSCallback callback)
		//enable为bool类型,true为启用扫描键扫码功能,false为禁用扫描键扫码功能,默认为true
		//当设置为false后,可以自行监听扫描按键,实现自定义功能
		barcodeModel.setScanKeyEnable(false, (ret) => {
			console.log(10, 'setScanKeyEnable', ret)
			// modal.toast({
			// 	message: ret,
			// 	duration: 1.5
			// });
		});
		// //页面监听event事件,建议在页面onLoad方法里调用
		// var globalEvent = uni.requireNativePlugin('globalEvent');

		// globalEvent.addEventListener('iDataBarcodeEvent', function(e) {
		// 	console.log(20, '扫码结果', JSON.stringify(e))
		// 	// modal.toast({
		// 	// 	//条码结果示例:{"barcode","条码数据"}
		// 	// 	message: "收到条码:" + JSON.stringify(e),
		// 	// 	duration: 1.5
		// 	// });
		// 	utils.toGetScanCode(e.barcode)
		// });
	}
	// #endif 
export default {

		onLoad() {
			// #ifdef APP-PLUS
			if (phoneModel) {
				// globalEvent.addEventListener('iDataBarcodeEvent', function(e) {
				// 		console.log(60, "addEventListener", ret)
				// 	// modal.toast({
				// 	// 	message: "1111111收到条码:" + JSON.stringify(e),
				// 	// 	duration: 1.5
				// 	// });
				// 	//连续扫描如果间隔时间比较短,会出现toast不提示的情况,数据可以正常接收到,建议查看控制台输出
				// 	console.log(157, JSON.stringify(e));
				// });
				barcodeModel.initScan((ret) => {
					console.log(60, "initScan", ret)
					// modal.toast({
					// 	message: ret,
					// 	duration: 1.5
					// });
				});
			}
			// #endif 
		},
		onUnload() {
			// #ifdef APP-PLUS
			if (phoneModel) {
				barcodeModel.closeScan((ret) => {
					console.log(60, "closeScan", ret)
					// modal.toast({
					// 	message: ret,
					// 	duration: 1.5
					// });
				});
				globalEvent.removeEventListener('iDataBarcodeEvent');
			}
			// #endif 
		},
}

index.vue


<script>
	let phoneModel = uni.getStorageSync('phoneModel') ? uni.getStorageSync('phoneModel') : false
	// #ifdef APP-PLUS
	const modal = uni.requireNativePlugin('modal');
	if (phoneModel) {
		//获取module
		var barcodeModel = uni.requireNativePlugin("iData-BarcodePlugin-BarcodeModule")

		var globalEvent = uni.requireNativePlugin('globalEvent');
	}
	// #endif  
	import person from '@/pages/user/person/person.vue'
	import workbench from '@/pages/workbench/workbench.vue'
	// import apps from '@/pages/apps/apps.vue'
	import UpdateProcess from '@/pages/common/updateProcess.vue'
	
	export default {
		components: {
			person,
			workbench,
			UpdateProcess
			// apps
		},
		data() {
			return {
				PageCur: 'workbench',
				// 设备型号
				phoneModel: uni.getStorageSync('phoneModel') ? uni.getStorageSync('phoneModel') : false,
				updateApp: false,

			}
		},
		onLoad(option) {
			if (option && option.PageCur) {
				this.PageCur = option.PageCur
			}
			uni.setStorageSync("scanIndex", 'Index')
		
			// #ifdef APP-PLUS
			if (phoneModel) {
				let that = this
				globalEvent.addEventListener('iDataBarcodeEvent', function(e) {
					console.log(151, "addEventListener", JSON.stringify(e))
					// modal.toast({
					// 	message: "1111111收到条码:" + JSON.stringify(e),
					// 	duration: 1.5
					// });
					//连续扫描如果间隔时间比较短,会出现toast不提示的情况,数据可以正常接收到,建议查看控制台输出
					that.$utils.toGetScanCode(e.barcode)
				});
				barcodeModel.initScan((ret) => {
					console.log(151, "initScan", ret)
					// modal.toast({
					// 	message: ret,
					// 	duration: 1.5
					// });
				});
				this.setLockScanKeyFunc()
				this.continueScanFunc()
			}
			// #endif  
			// #ifdef APP-PLUS
			setTimeout(() => {
				this.updateApp = true
			}, 1000);
			// #endif
		},
		// onUnload() {
		// 	// #ifdef APP-PLUS
		// 	if (phoneModel) {
		// 		barcodeModel.closeScan((ret) => {
		// 			console.log(151, "closeScan", ret)
		// 			// modal.toast({
		// 			// 	message: ret,
		// 			// 	duration: 1.5
		// 			// });
		// 		});
		// 		globalEvent.removeEventListener('iDataBarcodeEvent');
		// 	}
		// 	// #endif  
		// },
		methods: {
			scanStartFunc() {
				// #ifdef APP-PLUS
				if (phoneModel) {
					barcodeModel.scanStart((ret) => {
						console.log(151, "scanStart", ret)
						// modal.toast({
						// 	message: ret,
						// 	duration: 1.5
						// });
					});
				}
				// #endif  
			},
			// #ifdef APP-PLUS
			closeUpdateProcess(bool) {
				this.updateApp = bool
			},
			// #endif
			setLockScanKeyFunc() {
				// #ifdef APP-PLUS
				if (phoneModel) {
					//启用扫码按键扫码功能,启用后按扫描键会自动触发扫码功能
					barcodeModel.setScanKeyEnable(true, (ret) => {
						console.log(151, "setScanKeyEnable", ret)
						// modal.toast({
						// 	message: ret,
						// 	duration: 1.5
						// });
					});
				}
				// #endif  
			},
			setUnLockScanKeyFunc() {
				// #ifdef APP-PLUS
				if (phoneModel) {
					//禁用扫码按键扫码功能,禁用后按扫描键不会自动触发扫码功能,支持自行监听按键触发功能
					barcodeModel.setScanKeyEnable(false, (ret) => {
						console.log(151, "setScanKeyEnable", ret)
						// modal.toast({
						// 	message: ret,
						// 	duration: 1.5
						// });
					});
				}
				// #endif  
			},
			// 连续扫描开启
			continueScanFunc(enable) {
				// #ifdef APP-PLUS
				if (phoneModel) {
					// 连续扫描设置:先设置扫描间隔时间,然后开启扫描开关
					if (enable) {
						//设置连续扫描间隔时间
						barcodeModel.intervalSet("500",
							(ret) => {
								console.log(151, "intervalSet", ret)
								// modal.toast({
								// 	message: ret,
								// 	duration: 1.5
								// });
							});
					}

					//设置连续扫描
					barcodeModel.continueScan(enable,
						(ret) => {
							console.log(151, "continueScan", ret)
							// modal.toast({
							// 	message: ret,
							// 	duration: 1.5
							// });
						});
				}
				// #endif  
			},
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			}
		}
	}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值