feat(scanner): 多厂商PDA扫码器兼容方案及扫码功能重构
- 采用策略模式及配置表驱动方式支持多品牌扫码器广播注册 - 实现扫码广播的统一注册和注销管理,支持并发多个扫码广播接收器 - 重构扫码处理逻辑,统一处理扫码结果,支持条码和二维码识别 - 移除原有单一品牌扫码注册,整合商米、新大陆等扫码头支持 - 调整扫码相关页面代码,集成scanMixin,实现扫码广播注册和注销自动化 - 优化扫码结果处理,支持删除模式及整缸扫描状态区分 - 修正多处界面文本格式与代码风格,提高代码一致性和可维护性 - 升级manifest版本号至1.1.3,标记此功能更新
This commit is contained in:
@@ -3,12 +3,7 @@
|
||||
<common-navbar title="工作台" :showBack="false">
|
||||
<template #right>
|
||||
<view class="scan_box">
|
||||
<u-icon
|
||||
name="scan"
|
||||
color="#333333"
|
||||
size="46"
|
||||
@click="handleScan"
|
||||
></u-icon>
|
||||
<u-icon name="scan" color="#333333" size="46" @click="handleScan"></u-icon>
|
||||
</view>
|
||||
</template>
|
||||
</common-navbar>
|
||||
@@ -21,10 +16,7 @@
|
||||
</view>
|
||||
<view class="grid-text">成品配布</view>
|
||||
</u-grid-item>
|
||||
<u-grid-item
|
||||
:index="1"
|
||||
@click="navTo('/pages/storegoods/QRBarCodeReview')"
|
||||
>
|
||||
<u-grid-item :index="1" @click="navTo('/pages/storegoods/QRBarCodeReview')">
|
||||
<view class="home-icon icon-color02">
|
||||
<i class="iconfont icon-mall-bag"></i>
|
||||
</view>
|
||||
@@ -35,44 +27,31 @@
|
||||
<view class="workbench-title">成品管理</view>
|
||||
<view class="toolbar">
|
||||
<u-grid class="grid" :col="4" :border="false">
|
||||
<u-grid-item
|
||||
:index="0"
|
||||
@click="navTo('/pages/storegoods/dyeworksDyeback')"
|
||||
>
|
||||
<u-grid-item :index="0" @click="navTo('/pages/storegoods/dyeworksDyeback')">
|
||||
<view class="home-icon icon-color04">
|
||||
<i class="iconfont icon-finance"></i>
|
||||
</view>
|
||||
<view class="grid-text">染整进仓</view>
|
||||
</u-grid-item>
|
||||
<u-grid-item
|
||||
:index="1"
|
||||
@click="navTo('/pages/storegoods/storeGoodsBusinessIn')"
|
||||
>
|
||||
<u-grid-item :index="1" @click="navTo('/pages/storegoods/storeGoodsBusinessIn')">
|
||||
<view class="home-icon icon-color03">
|
||||
<i class="iconfont icon-mall-bag"></i>
|
||||
</view>
|
||||
<view class="grid-text">成品进仓</view>
|
||||
</u-grid-item>
|
||||
<u-grid-item
|
||||
:index="2"
|
||||
@click="navTo('/pages/storegoods/storeGoodsBusinessOut')"
|
||||
>
|
||||
<u-grid-item :index="2" @click="navTo('/pages/storegoods/storeGoodsBusinessOut')">
|
||||
<view class="home-icon icon-color12">
|
||||
<i class="iconfont icon-baoxiaodan"></i>
|
||||
</view>
|
||||
<view class="grid-text">成品出仓</view>
|
||||
</u-grid-item>
|
||||
<u-grid-item
|
||||
@click="navTo('/pages/storegoods/storeGoodsBusinessCheck')"
|
||||
>
|
||||
<u-grid-item @click="navTo('/pages/storegoods/storeGoodsBusinessCheck')">
|
||||
<view class="home-icon icon-color04">
|
||||
<i class="iconfont icon-shenpi"></i>
|
||||
</view>
|
||||
<view class="grid-text">成品盘点</view>
|
||||
</u-grid-item>
|
||||
<u-grid-item
|
||||
@click="navTo('/pages/storegoods/storeGoodsBusinessStationMoveOnly')"
|
||||
>
|
||||
<u-grid-item @click="navTo('/pages/storegoods/storeGoodsBusinessStationMoveOnly')">
|
||||
<view class="home-icon icon-color04">
|
||||
<i class="iconfont icon-shenpi"></i>
|
||||
</view>
|
||||
@@ -151,6 +130,7 @@
|
||||
</template>
|
||||
<script>
|
||||
import CommonNavbar from "@/components/common-navbar/index";
|
||||
import scanMixin from '@/common/scanMixin.js';
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://aidex.vip All rights reserved.
|
||||
*/
|
||||
@@ -158,6 +138,7 @@ export default {
|
||||
components: {
|
||||
CommonNavbar,
|
||||
},
|
||||
mixins: [scanMixin],
|
||||
data() {
|
||||
return {
|
||||
show: false,
|
||||
@@ -168,34 +149,17 @@ export default {
|
||||
//{image: '/static/aidex/banner/banner03.png'}
|
||||
],
|
||||
todoCount: 3,
|
||||
scanReceiver: null,
|
||||
isPageActive: false,
|
||||
// scanReceiver 和 isPageActive 已由 scanMixin 提供
|
||||
};
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// #ifdef APP-PLUS
|
||||
this.isPageActive = true;
|
||||
this.registerScanBroadcast();
|
||||
// 使用 scanMixin 的方法注册扫码广播,传入自定义回调
|
||||
this.registerScanBroadcast(this.handleScanCode);
|
||||
// #endif
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
// #ifdef APP-PLUS
|
||||
this.isPageActive = false;
|
||||
this.unregisterBroadcast();
|
||||
// #endif
|
||||
},
|
||||
|
||||
onHide() {
|
||||
// 页面隐藏时
|
||||
this.isPageActive = false;
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// 页面显示时
|
||||
this.isPageActive = true;
|
||||
},
|
||||
// onUnload, onHide, onShow 已由 scanMixin 自动处理
|
||||
|
||||
computed: {
|
||||
contentStyle() {
|
||||
@@ -206,6 +170,15 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
// 自定义扫码处理回调 - 处理本页面特有的扫码逻辑
|
||||
handleScanCode(scanResult) {
|
||||
console.log('工作台-扫码结果:', scanResult);
|
||||
const cleanResult = scanResult.trim().replace(/[\r\n]/g, '');
|
||||
uni.navigateTo({
|
||||
url: '/pages/saleship/salepickscandetail?order_no=' + cleanResult
|
||||
});
|
||||
},
|
||||
|
||||
navTo(url) {
|
||||
uni.navigateTo({
|
||||
url: url,
|
||||
@@ -217,11 +190,11 @@ export default {
|
||||
itemClick(index) {
|
||||
console.log(index);
|
||||
},
|
||||
// 处理扫码
|
||||
// 处理扫码(手动点击扫码按钮)
|
||||
handleScan() {
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/saleship/salepickscandetail?order_no=FPD-PB-202412270196'
|
||||
// })
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/saleship/salepickscandetail?order_no=FPD-PB-202412270196'
|
||||
// })
|
||||
// return
|
||||
// #ifdef APP-PLUS || MP-WEIXIN
|
||||
uni.scanCode({
|
||||
@@ -229,9 +202,9 @@ export default {
|
||||
success: (res) => {
|
||||
console.log('扫码成功:', res);
|
||||
const cleanResult = res.result.trim().replace(/[\r\n]/g, '');
|
||||
uni.navigateTo({
|
||||
url: '/pages/saleship/salepickscandetail?order_no=' + cleanResult
|
||||
})
|
||||
uni.navigateTo({
|
||||
url: '/pages/saleship/salepickscandetail?order_no=' + cleanResult
|
||||
})
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('扫码失败:', err);
|
||||
@@ -275,99 +248,32 @@ export default {
|
||||
});
|
||||
}
|
||||
},
|
||||
// 注册扫码广播
|
||||
registerScanBroadcast() {
|
||||
try {
|
||||
console.log('开始注册扫码广播');
|
||||
const main = plus.android.runtimeMainActivity();
|
||||
|
||||
// 配置扫码枪广播
|
||||
try {
|
||||
const Intent = plus.android.importClass('android.content.Intent');
|
||||
const intent = new Intent('com.android.scanner.service_settings');
|
||||
intent.putExtra('action_barcode_broadcast', 'com.android.server.scannerservice.broadcast');
|
||||
intent.putExtra('key_barcode_broadcast', 'scannerdata');
|
||||
main.sendBroadcast(intent);
|
||||
console.log('扫码枪广播配置已发送');
|
||||
} catch (error) {
|
||||
console.error('配置扫码枪广播失败:', error);
|
||||
}
|
||||
|
||||
// 注册广播接收器
|
||||
const IntentFilter = plus.android.importClass('android.content.IntentFilter');
|
||||
const filter = new IntentFilter();
|
||||
filter.addAction('com.android.server.scannerservice.broadcast');
|
||||
|
||||
const receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
|
||||
onReceive: (context, intent) => {
|
||||
// 只有当页面活动时才处理广播
|
||||
if (!this.isPageActive) return;
|
||||
|
||||
try {
|
||||
console.log("Workbench intent:", intent);
|
||||
const scanResult = intent.getStringExtra('scannerdata');
|
||||
console.log('工作台-扫码结果:', scanResult);
|
||||
|
||||
if (scanResult) {
|
||||
this.$nextTick(() => {
|
||||
const cleanResult = scanResult.trim().replace(/[\r\n]/g, '');
|
||||
uni.navigateTo({
|
||||
url: '/pages/saleship/salepickscandetail?order_no=' + cleanResult
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('处理广播数据时出错:', error, error.stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 注册广播接收器
|
||||
main.registerReceiver(receiver, filter);
|
||||
this.scanReceiver = receiver;
|
||||
console.log('扫码广播注册成功,等待扫码...');
|
||||
|
||||
} catch (error) {
|
||||
console.error('注册扫码广播失败:', error);
|
||||
console.error('错误详情:', error.message);
|
||||
console.error('错误堆栈:', error.stack);
|
||||
}
|
||||
},
|
||||
|
||||
// 注销广播接收器
|
||||
unregisterBroadcast() {
|
||||
if (this.scanReceiver) {
|
||||
try {
|
||||
const main = plus.android.runtimeMainActivity();
|
||||
main.unregisterReceiver(this.scanReceiver);
|
||||
this.scanReceiver = null;
|
||||
console.log('扫码广播注销成功');
|
||||
} catch (error) {
|
||||
console.error('注销扫码广播失败:', error);
|
||||
}
|
||||
}
|
||||
},
|
||||
// registerScanBroadcast 和 unregisterScanBroadcast 已由 scanMixin 提供
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
@import "index.scss";
|
||||
|
||||
.scan_box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
.scan_text {
|
||||
font-size: 12px;
|
||||
color: #2979ff;
|
||||
}
|
||||
}
|
||||
|
||||
.banner-box {
|
||||
padding: 0 2%;
|
||||
width: 96%;
|
||||
height: 170rpx;
|
||||
margin: 30rpx 0 30rpx;
|
||||
}
|
||||
|
||||
.u-swiper-wrap {
|
||||
padding: 0 10px;
|
||||
}
|
||||
@@ -378,6 +284,7 @@ export default {
|
||||
display: inline-block;
|
||||
margin: 0 1.5%;
|
||||
}
|
||||
|
||||
.banner-pic image {
|
||||
width: 100%;
|
||||
height: 170rpx;
|
||||
@@ -394,12 +301,14 @@ export default {
|
||||
position: relative;
|
||||
top: -3px;
|
||||
}
|
||||
|
||||
.workbench-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
padding: 15px 30rpx;
|
||||
}
|
||||
|
||||
.home-icon i.icon-tongzhi {
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user