feat: 手机连续扫与出仓汇总表改用t-table并升至1.1.24

This commit is contained in:
2026-11-09 21:53:32 +08:00
parent fdbd06f5f5
commit 706fcda5b9
8 changed files with 495 additions and 28 deletions
+84 -2
View File
@@ -72,20 +72,63 @@ export default {
return configs.length ? configs[0] : null;
},
/** 停止手机连续扫码(含 Ba-Scanner) */
stopPhoneScanContinuous() {
this._phoneScanContinuousActive = false;
// #ifdef APP-PLUS
try {
const scanner = uni.requireNativePlugin('Ba-Scanner');
if (scanner && typeof scanner.onClose === 'function') {
scanner.onClose();
}
} catch (e) {
// 未购买/未打包原生插件时忽略
}
// #endif
},
/**
* 打开手机扫码
* @param {{ continuous?: boolean, callback?: Function, fail?: Function, scanType?: string[], hintText?: string, scanTimeSpace?: number }} options
* continuous=true 时优先用 Ba-Scanner 连续扫;无插件则扫完自动再开相机
*/
openPhoneScan(options = {}) {
const callback = options.callback || this._scanCallback;
const continuous = !!options.continuous;
this._phoneScanContinuousActive = continuous;
// #ifdef APP-PLUS
if (continuous && this.openBaScannerContinuous(options, callback)) {
return;
}
// #endif
// #ifdef APP-PLUS || MP-WEIXIN
uni.scanCode({
scanType: options.scanType || ['qrCode', 'barCode'],
success: (res) => {
this.handleScanResult(res.result, callback);
const result = this.handleScanResult(res.result, callback);
if (!continuous || !this._phoneScanContinuousActive) return;
Promise.resolve(result)
.catch(() => null)
.then(() => {
if (!this._phoneScanContinuousActive || !this.isPageActive) return;
setTimeout(() => {
if (!this._phoneScanContinuousActive || !this.isPageActive) return;
this.openPhoneScan(options);
}, Number(options.scanTimeSpace) > 0 ? Number(options.scanTimeSpace) : 400);
});
},
fail: (err) => {
console.error('手机扫码失败:', err);
this._phoneScanContinuousActive = false;
if (options.fail) {
options.fail(err);
return;
}
// 用户取消不打扰
const msg = (err && (err.errMsg || err.message)) || '';
if (/cancel|取消/i.test(msg)) return;
uni.showToast({
title: '扫码失败',
icon: 'none',
@@ -103,6 +146,41 @@ export default {
// #endif
},
/**
* Ba-Scanner 连续扫码(插件市场 id=9669)
* @returns {boolean} 是否已成功唤起原生连续扫
*/
openBaScannerContinuous(options = {}, callback) {
// #ifdef APP-PLUS
try {
const scanner = uni.requireNativePlugin('Ba-Scanner');
if (!scanner || typeof scanner.onScan !== 'function') return false;
scanner.onScan(
{
isContinuous: true,
scanTimeSpace: Number(options.scanTimeSpace) > 0 ? Number(options.scanTimeSpace) : 1500,
isShowVibrate: options.isShowVibrate !== false,
isShowBeep: !!options.isShowBeep,
isShowToast: false,
isShowPhotoAlbum: options.isShowPhotoAlbum !== false,
hintText: options.hintText || '扫二维码/条形码,可连续扫',
barcodeFormats: options.barcodeFormats || ['QR Code', 'Code 128', 'Code 39', 'EAN-13', 'EAN-8'],
},
(ret) => {
if (!ret || !ret.result) return;
if (!this._phoneScanContinuousActive) return;
this.handleScanResult(ret.result, callback);
},
);
return true;
} catch (e) {
console.warn('Ba-Scanner 不可用,回退 uni.scanCode', e);
return false;
}
// #endif
return false;
},
triggerScan() {
if (this.usePhoneScanFallback) {
this.openPhoneScan();
@@ -261,11 +339,12 @@ export default {
console.log("扫码结果:", cleanCode);
if (scanCallback) {
scanCallback(cleanCode);
return scanCallback(cleanCode);
}
} catch (error) {
console.error("处理扫码结果时出错:", error);
}
return undefined;
},
unregisterScanBroadcast() {
@@ -317,10 +396,13 @@ export default {
onHide() {
this.isPageActive = false;
// 不在 onHide 里关 Ba-Scanner:打开原生扫码页也会触发 hide,误关会打断连续扫
// 无插件回退模式靠 isPageActive 控制是否自动再开相机
},
onUnload() {
this.isPageActive = false;
this.stopPhoneScanContinuous();
this.unregisterScanBroadcast();
}
}
@@ -1,29 +1,52 @@
<template>
<view class="fabric-out-summary">
<scroll-view scroll-x class="fabric-out-summaryScroll">
<wyb-table
:headers="headers"
:contents="contents"
:width="tableWidth"
height="auto"
:font-size="[36, 36]"
:min-height="[100, 100]"
:padding="[16, 12]"
:first-line-fixed="false"
empty-string=""
@onCellClick="$emit('cell-click', $event)"
/>
<view class="fabric-out-summaryInner" :style="{ width: tableWidth }">
<t-table border="1" border-color="#e1e1e1">
<t-tr font-size="18" color="#3e3e3e" align="center">
<t-th
v-for="col in headers"
:key="col.key"
align="center"
>
<view class="fabric-out-th" :style="cellStyle(col)">{{ col.label }}</view>
</t-th>
</t-tr>
<t-tr
v-for="(row, rowIndex) in contents"
:key="row.group_key || rowIndex"
font-size="18"
color="#333"
align="center"
>
<t-td
v-for="col in headers"
:key="col.key"
align="center"
>
<view
class="fabric-out-td"
:style="cellStyle(col)"
@click="onCellClick(col.key, row)"
>{{ formatCell(row, col.key) }}</view>
</t-td>
</t-tr>
</t-table>
</view>
</scroll-view>
<view v-if="!contents.length" class="fabric-out-summaryEmpty">暂无数据~~</view>
</view>
</template>
<script>
import wybTable from '@/components/wyb-table/wyb-table.vue';
import tTable from '@/components/t-table/t-table.vue';
import tTr from '@/components/t-table/t-tr.vue';
import tTh from '@/components/t-table/t-th.vue';
import tTd from '@/components/t-table/t-td.vue';
import { SUMMARY_TABLE_COLUMNS } from '@/common/storeFabricBusinessOut';
export default {
components: { wybTable },
components: { tTable, tTr, tTh, tTd },
props: {
rows: { type: Array, default: () => [] },
},
@@ -47,10 +70,30 @@ export default {
}));
},
},
methods: {
cellStyle(col) {
const width = `${col.width || 160}rpx`;
return {
width,
minWidth: width,
maxWidth: width,
};
},
formatCell(row, key) {
const val = row[key];
if (val === 0) return '0';
return val != null && val !== '' ? val : '-';
},
onCellClick(key, row) {
this.$emit('cell-click', { key, lineData: row });
},
},
};
</script>
<style scoped lang="scss">
@import '@/common/pda-typography.scss';
.fabric-out-summary {
background: #fff;
margin-top: 16rpx;
@@ -58,16 +101,40 @@ export default {
.fabric-out-summaryScroll {
width: 100%;
}
.fabric-out-summary ::v-deep .wyb-table-scroll-view {
height: auto !important;
overflow-x: auto;
overflow-y: visible;
.fabric-out-summaryInner {
min-width: 100%;
}
.fabric-out-summary ::v-deep .t-table {
width: 100%;
}
.fabric-out-summary ::v-deep .t-th,
.fabric-out-summary ::v-deep .t-td {
flex: 0 0 auto;
width: auto;
padding: 0;
min-height: $pda-row-min-height;
box-sizing: border-box;
}
.fabric-out-th,
.fabric-out-td {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-height: $pda-row-min-height;
padding: 16rpx 12rpx;
font-size: $pda-font-body;
word-break: break-all;
text-align: center;
}
.fabric-out-th {
font-weight: bold;
}
.fabric-out-summaryEmpty {
text-align: center;
color: #999;
font-size: 36rpx;
line-height: 100rpx;
font-size: $pda-font-body;
line-height: $pda-row-min-height;
background: #fff;
}
</style>
+86
View File
@@ -0,0 +1,86 @@
<template>
<view class="t-table" :style="{ 'border-width': border + 'px', 'border-color': borderColor }">
<slot />
</view>
</template>
<script>
export default {
props: {
border: {
type: String,
default: '1'
},
borderColor: {
type: String,
default: '#d0dee5'
},
isCheck: {
type: Boolean,
default: false
}
},
provide() {
return {
table: this
};
},
data() {
return {};
},
created() {
this.childrens = [];
this.index = 0;
},
methods: {
fire(e, index, len) {
let childrens = this.childrens;
console.log(childrens);
// 全选
if (index === 0) {
childrens.map((vm, index) => {
vm.checkboxData.checked = e;
return vm;
});
} else {
let isAll = childrens.find((n, ids) => ids !== 0 && !n.checkboxData.checked);
childrens[0].checkboxData.checked = isAll ? false : true;
}
let fireArr = [];
for (let i = 0; i < childrens.length; i++) {
if (childrens[i].checkboxData.checked && i !== 0) {
fireArr.push(childrens[i].checkboxData.value - 1);
}
}
this.$emit('change', {
detail: fireArr
});
}
}
};
</script>
<style scoped>
.t-table {
width: 100%;
border: 1px #d0dee5 solid;
border-left: none;
border-top: none;
box-sizing: border-box;
}
.t-table>>>t-tr {
display: flex;
}
.t-table>>>t-tr:nth-child(2n) {
background: #f5f5f5;
}
/* #ifdef H5 */
.t-table>>>.t-tr:nth-child(2n) {
background: #f5f5f5;
}
/* #endif */
</style>
+71
View File
@@ -0,0 +1,71 @@
<template>
<view class="t-td" :style="{ 'border-width': thBorder + 'px','border-color':borderColor ,'font-size':fontSize+'px' ,'color':color,'justify-content':tdAlignCpd}">
<slot></slot>
</view>
</template>
<script>
export default {
props: {
align: String
},
data() {
return {
thBorder: '1',
borderColor: '#d0dee5',
fontSize: '14',
color: '#555c60',
tdAlign: 'center'
};
},
inject: ['table', 'tr'],
created() {
this.thBorder = this.table.border;
this.borderColor = this.table.borderColor;
this.fontSize = this.tr.fontSize;
this.color = this.tr.color;
if (this.align) {
this.tdAlign = this.align;
} else {
this.tdAlign = this.tr.align
}
},
computed: {
tdAlignCpd() {
let nameAlign = '';
switch (this.tdAlign) {
case 'left':
nameAlign = 'flex-start'
break;
case 'center':
nameAlign = 'center'
break;
case 'right':
nameAlign = 'flex-end'
break;
default:
nameAlign = 'center'
break;
}
return nameAlign
}
}
};
</script>
<style>
.t-td {
flex: 1;
display: flex;
align-items: center;
width: 100%;
padding: 14upx;
border-top: 1px #d0dee5 solid;
border-left: 1px #d0dee5 solid;
text-align: center;
color: #555c60;
font-size: 28upx;
}
</style>
+71
View File
@@ -0,0 +1,71 @@
<template>
<view class="t-th" :style="{ 'border-width': thBorder + 'px' ,'border-color':borderColor,'font-size':fontSize+'px' ,'color':color,'justify-content':thAlignCpd}">
<slot></slot>
</view>
</template>
<script>
export default {
props: {
align: String,
},
data() {
return {
thBorder: '1',
borderColor: '#d0dee5',
fontSize: '15',
color: '#3b4246',
thAlign: 'center'
};
},
inject: ['table', 'tr'],
created() {
this.thBorder = this.table.border;
this.borderColor = this.table.borderColor;
this.fontSize = this.tr.fontSize;
this.color = this.tr.color;
if (this.align) {
this.thAlign = this.align;
} else {
this.thAlign = this.tr.align
}
},
computed: {
thAlignCpd() {
let nameAlign = '';
switch (this.thAlign) {
case 'left':
nameAlign = 'flex-start'
break;
case 'center':
nameAlign = 'center'
break;
case 'right':
nameAlign = 'flex-end'
break;
default:
nameAlign = 'center'
break;
}
return nameAlign
}
}
};
</script>
<style>
.t-th {
flex: 1;
display: flex;
align-items: center;
font-size: 30upx;
font-weight: bold;
text-align: center;
color: #3b4246;
border-left: 1px #d0dee5 solid;
border-top: 1px #d0dee5 solid;
padding: 15upx;
}
</style>
+81
View File
@@ -0,0 +1,81 @@
<template>
<view class="t-tr">
<view v-if="isCheck" class="t-check-box" :style="{ 'border-width': thBorder + 'px' ,'border-color':borderColor}">
<checkbox-group @change="checkboxChange">
<checkbox :value="checkboxData.value + ''" :checked="checkboxData.checked" />
</checkbox-group>
</view>
<slot></slot>
</view>
</template>
<script>
export default {
props: {
fontSize: String,
color: String,
align: String
},
inject: ['table'],
provide() {
return {
tr: this
};
},
data() {
return {
isCheck: false,
checkboxData: {
value: 0,
checked: false
},
checked: false,
thBorder: '1',
borderColor: '#d0dee5'
};
},
created() {
this.thBorder = this.table.border;
this.borderColor = this.table.borderColor;
this.table.childrens.push(this);
this.checkboxData.value = this.table.index++;
this.isCheck = this.table.isCheck;
},
methods: {
checkboxChange(e) {
this.checkboxData.checked = !this.checkboxData.checked;
this.table.childrens[this.checkboxData.value] = this;
this.table.fire(e.detail.value[0] ? true : false, this.checkboxData.value, this.table.index);
}
}
};
</script>
<style>
.t-tr {
width: 100%;
display: flex;
}
.t-tr t-th,
.t-tr t-td {
display: flex;
flex: 1;
}
.t-tr .t-check-box {
flex-shrink: 0;
display: flex;
justify-content: center;
align-items: center;
width: 80upx;
color: #3b4246;
border-left: 1px #d0dee5 solid;
border-top: 1px #d0dee5 solid;
}
.t-tr .t-check-box checkbox {
transform: scale(0.8);
}
</style>
+2 -2
View File
@@ -2,8 +2,8 @@
"name" : "浩拓织厂",
"appid" : "__UNI__F79F300",
"description" : "周尚-浩拓织厂",
"versionName" : "1.1.23",
"versionCode" : 123,
"versionName" : "1.1.24",
"versionCode" : 124,
"transformPx" : false,
"app-plus" : {
"optimization" : {
@@ -120,7 +120,16 @@ export default {
},
methods: {
handlePhoneScan() {
this.openPhoneScan();
// 手机连续扫:优先 Ba-Scanner;无插件时扫完自动再开相机
this.openPhoneScan({
continuous: true,
hintText: '连续扫码出仓,扫完可继续下一条',
scanTimeSpace: 1200,
callback: (scanResult) => {
this.QRBarCode = String(scanResult || '').trim().replace(/[\r\n]/g, '');
return this.handleScan();
},
});
},
registerOrderScanBroadcast() {
this.registerScanBroadcast((scanResult) => {
@@ -314,14 +323,14 @@ export default {
if (!this.canScan || !this.orderId) {
this.showError('请先提交保存后再扫码');
this.QRBarCode = '';
return;
return Promise.resolve();
}
if (!code) {
this.QRBarCode = '';
return;
return Promise.resolve();
}
const scanType = this.BarCodeDelStatus ? 2 : 1;
this.doScanUpdate(code, scanType);
return this.doScanUpdate(code, scanType);
},
BarCodeDelChange(e) {
this.BarCodeDelStatus = (e.detail.value || []).length > 0;