feat: 拆包工作台接入摄像头 OSD 字幕推送(扫单号/商品条码自动推送)
This commit is contained in:
parent
a241495afc
commit
558aacbae1
@ -6,7 +6,15 @@
|
||||
<div class="left-panel">
|
||||
<div class="left-top">
|
||||
<span class="left-title">拆包工作台</span>
|
||||
<el-button size="small" @click="openCameraSettings">摄像头设置</el-button>
|
||||
<div class="left-top-actions">
|
||||
<el-switch
|
||||
v-model="osdEnabled"
|
||||
size="small"
|
||||
active-text="字幕推送"
|
||||
:title="osdEnabled ? '拆包扫码时自动推送 OSD 字幕到已选摄像头' : '开启后扫码自动推送 OSD 字幕到已选摄像头'"
|
||||
/>
|
||||
<el-button size="small" @click="openCameraSettings">摄像头设置</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-form label-width="70px" size="small" class="waybill-form">
|
||||
<el-form-item label="运单号">
|
||||
@ -480,7 +488,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import { computed, nextTick, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {
|
||||
returnUnpackCreate,
|
||||
@ -494,7 +502,7 @@ import {
|
||||
returnUnpackDetail,
|
||||
returnUnpackDetailList,
|
||||
} from '@/api/returnunpack'
|
||||
import { list as cameraList } from '@/api/camera/camera'
|
||||
import { list as cameraList, setOsd } from '@/api/camera/camera'
|
||||
import CameraLivePreview, { type CameraLiveItem } from './CameraLivePreview.vue'
|
||||
import JsBarcode from 'jsbarcode'
|
||||
import { CMD, CMD_LABEL, CMD_TAG_TYPE, SCAN_COMMANDS, resolveScanCommand } from './scan-commands'
|
||||
@ -739,6 +747,8 @@ async function handleCreate(barcode?: string) {
|
||||
}
|
||||
ElMessage.success(`拆包单创建成功,ID ${data.id}`)
|
||||
// 保留输入的运单号显示在锁定的输入框中(创建后运单号置灰不可改)
|
||||
lastScannedBarcode.value = ''
|
||||
void pushOsdText()
|
||||
loadUnpackList()
|
||||
loadDetailList()
|
||||
loadOrderDetail()
|
||||
@ -794,6 +804,8 @@ function saveCameraSettings() {
|
||||
cameraSettingsVisible.value = false
|
||||
ElMessage.success('摄像头设置已保存')
|
||||
persistCameraSelection()
|
||||
// 摄像头选择变化后,向新选中的摄像头重新推送当前字幕
|
||||
void pushOsdText(undefined, true)
|
||||
}
|
||||
|
||||
// ==================== 摄像头选择持久化 ====================
|
||||
@ -835,6 +847,62 @@ function restoreCameraSelection() {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== OSD 字幕推送 ====================
|
||||
// 拆包扫码时把「单号 + 商品条码」通过 camera.setOsd 推送到已选摄像头,叠加到监控画面
|
||||
const OSD_ENABLED_STORAGE_KEY = 'returnUnpackWork:osdEnabled'
|
||||
const osdEnabled = ref(false)
|
||||
const lastScannedBarcode = ref('')
|
||||
const osdPushing = ref(false)
|
||||
let lastOsdText: string | null = null
|
||||
|
||||
/** 当前应推送的字幕文本:单号:xxx(扫到商品条码后追加 商品条码:xxx) */
|
||||
function buildOsdText(): string {
|
||||
const waybill = String(createResult.value?.record?.waybill_code ?? waybillCode.value ?? '').trim()
|
||||
if (!waybill) return ''
|
||||
return lastScannedBarcode.value
|
||||
? `单号:${waybill} 商品条码:${lastScannedBarcode.value}`
|
||||
: `单号:${waybill}`
|
||||
}
|
||||
|
||||
/** 推送 OSD 字幕到所有已选摄像头(失败静默:请求层已提示;全部失败则允许下次重试) */
|
||||
async function pushOsdText(text?: string, force = false) {
|
||||
if (!osdEnabled.value) return
|
||||
const cameras = selectedCameras.value
|
||||
if (!cameras.length) return
|
||||
const t = String(text ?? buildOsdText()).trim()
|
||||
// 从未推过字幕时不主动推空文本(避免无意义请求)
|
||||
if (t === '' && (lastOsdText == null || lastOsdText === '')) return
|
||||
if (!force && t === lastOsdText) return
|
||||
lastOsdText = t
|
||||
osdPushing.value = true
|
||||
try {
|
||||
const results = await Promise.allSettled(
|
||||
cameras.map((c) => setOsd({ id: c.id, text: t, x: -0.9, y: 0.8 }))
|
||||
)
|
||||
const okCount = results.filter((r) => r.status === 'fulfilled' && isOk(r.value)).length
|
||||
if (okCount === 0) lastOsdText = null
|
||||
} finally {
|
||||
osdPushing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function restoreOsdEnabled() {
|
||||
try {
|
||||
const raw = localStorage.getItem(OSD_ENABLED_STORAGE_KEY)
|
||||
if (raw != null) osdEnabled.value = raw === '1' || raw === 'true'
|
||||
} catch {
|
||||
// 读取失败忽略
|
||||
}
|
||||
}
|
||||
|
||||
watch(osdEnabled, (v) => {
|
||||
try {
|
||||
localStorage.setItem(OSD_ENABLED_STORAGE_KEY, v ? '1' : '0')
|
||||
} catch {
|
||||
// 存储失败忽略
|
||||
}
|
||||
})
|
||||
|
||||
// ==================== 明细操作 ====================
|
||||
|
||||
function openAddDetail() {
|
||||
@ -957,6 +1025,7 @@ async function findSameStockDetail(stockId: number, productStatus?: string): Pro
|
||||
async function quickAddDetail(item: any) {
|
||||
const unpackId = createResult.value?.id
|
||||
if (!unpackId) return
|
||||
const scannedBarcode = String(detailBarcode.value ?? '').trim()
|
||||
// 兼容商品搜索行(item_id)与商品选择弹窗返回项(id)两种字段
|
||||
const rawStockId = item?.item_id ?? item?.id
|
||||
const stockId = rawStockId != null ? Number(rawStockId) : null
|
||||
@ -970,6 +1039,8 @@ async function quickAddDetail(item: any) {
|
||||
})
|
||||
if (isOk(res)) {
|
||||
detailBarcode.value = ''
|
||||
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||
void pushOsdText()
|
||||
ElMessage.success('相同商品数量已累加')
|
||||
loadDetailList()
|
||||
focusTarget.value = 'barcode'
|
||||
@ -990,6 +1061,8 @@ async function quickAddDetail(item: any) {
|
||||
})
|
||||
if (isOk(res)) {
|
||||
detailBarcode.value = ''
|
||||
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||
void pushOsdText()
|
||||
ElMessage.success('明细添加成功')
|
||||
loadDetailList()
|
||||
focusTarget.value = 'barcode'
|
||||
@ -1165,6 +1238,8 @@ async function selectUnpack(row: any) {
|
||||
if (recordStoreId != null) {
|
||||
addStoreCandidate(recordStoreId, data.store_remark || row.store_remark || '')
|
||||
}
|
||||
lastScannedBarcode.value = ''
|
||||
void pushOsdText()
|
||||
detailPagination.currentPage = 1
|
||||
loadDetailList()
|
||||
loadOrderDetail()
|
||||
@ -1206,6 +1281,8 @@ function resetWorkState() {
|
||||
defaultProductStatus.value = 'normal'
|
||||
orderDetailData.value = null
|
||||
orderDetailItems.value = []
|
||||
lastScannedBarcode.value = ''
|
||||
void pushOsdText('')
|
||||
focusTarget.value = 'waybill'
|
||||
}
|
||||
|
||||
@ -1642,6 +1719,7 @@ onMounted(async () => {
|
||||
loadUnpackList()
|
||||
await loadCameraList()
|
||||
restoreCameraSelection()
|
||||
restoreOsdEnabled()
|
||||
window.addEventListener('keydown', handleKeydown)
|
||||
nextTick(() => {
|
||||
renderBarcodes()
|
||||
@ -1660,6 +1738,7 @@ async function submitDetailForm() {
|
||||
ElMessage.warning('请先创建拆包单')
|
||||
return
|
||||
}
|
||||
const scannedBarcode = String(detailForm.barcode ?? '').trim()
|
||||
detailFormLoading.value = true
|
||||
try {
|
||||
// 相同商品且相同产品状态才累加数量
|
||||
@ -1671,6 +1750,8 @@ async function submitDetailForm() {
|
||||
quantity: Number(existing.quantity || 0) + detailForm.quantity,
|
||||
})
|
||||
if (isOk(res)) {
|
||||
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||
void pushOsdText()
|
||||
ElMessage.success('相同商品数量已累加')
|
||||
detailFormVisible.value = false
|
||||
loadDetailList()
|
||||
@ -1688,6 +1769,8 @@ async function submitDetailForm() {
|
||||
remark: detailForm.remark ? detailForm.remark.trim() : undefined,
|
||||
})
|
||||
if (isOk(res)) {
|
||||
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||
void pushOsdText()
|
||||
ElMessage.success('明细添加成功')
|
||||
detailFormVisible.value = false
|
||||
loadDetailList()
|
||||
@ -1819,6 +1902,12 @@ async function confirmRemoveDetail() {
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.left-top-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
/* 键盘快捷键说明 */
|
||||
.shortcut-tips {
|
||||
border-top: 1px dashed #e8eef7;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user