feat: 拆包工作台接入摄像头 OSD 字幕推送(扫单号/商品条码自动推送)
This commit is contained in:
parent
a241495afc
commit
558aacbae1
@ -6,8 +6,16 @@
|
|||||||
<div class="left-panel">
|
<div class="left-panel">
|
||||||
<div class="left-top">
|
<div class="left-top">
|
||||||
<span class="left-title">拆包工作台</span>
|
<span class="left-title">拆包工作台</span>
|
||||||
|
<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>
|
<el-button size="small" @click="openCameraSettings">摄像头设置</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<el-form label-width="70px" size="small" class="waybill-form">
|
<el-form label-width="70px" size="small" class="waybill-form">
|
||||||
<el-form-item label="运单号">
|
<el-form-item label="运单号">
|
||||||
<div class="waybill-row">
|
<div class="waybill-row">
|
||||||
@ -480,7 +488,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<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 { ElMessage } from 'element-plus'
|
||||||
import {
|
import {
|
||||||
returnUnpackCreate,
|
returnUnpackCreate,
|
||||||
@ -494,7 +502,7 @@ import {
|
|||||||
returnUnpackDetail,
|
returnUnpackDetail,
|
||||||
returnUnpackDetailList,
|
returnUnpackDetailList,
|
||||||
} from '@/api/returnunpack'
|
} 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 CameraLivePreview, { type CameraLiveItem } from './CameraLivePreview.vue'
|
||||||
import JsBarcode from 'jsbarcode'
|
import JsBarcode from 'jsbarcode'
|
||||||
import { CMD, CMD_LABEL, CMD_TAG_TYPE, SCAN_COMMANDS, resolveScanCommand } from './scan-commands'
|
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}`)
|
ElMessage.success(`拆包单创建成功,ID ${data.id}`)
|
||||||
// 保留输入的运单号显示在锁定的输入框中(创建后运单号置灰不可改)
|
// 保留输入的运单号显示在锁定的输入框中(创建后运单号置灰不可改)
|
||||||
|
lastScannedBarcode.value = ''
|
||||||
|
void pushOsdText()
|
||||||
loadUnpackList()
|
loadUnpackList()
|
||||||
loadDetailList()
|
loadDetailList()
|
||||||
loadOrderDetail()
|
loadOrderDetail()
|
||||||
@ -794,6 +804,8 @@ function saveCameraSettings() {
|
|||||||
cameraSettingsVisible.value = false
|
cameraSettingsVisible.value = false
|
||||||
ElMessage.success('摄像头设置已保存')
|
ElMessage.success('摄像头设置已保存')
|
||||||
persistCameraSelection()
|
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() {
|
function openAddDetail() {
|
||||||
@ -957,6 +1025,7 @@ async function findSameStockDetail(stockId: number, productStatus?: string): Pro
|
|||||||
async function quickAddDetail(item: any) {
|
async function quickAddDetail(item: any) {
|
||||||
const unpackId = createResult.value?.id
|
const unpackId = createResult.value?.id
|
||||||
if (!unpackId) return
|
if (!unpackId) return
|
||||||
|
const scannedBarcode = String(detailBarcode.value ?? '').trim()
|
||||||
// 兼容商品搜索行(item_id)与商品选择弹窗返回项(id)两种字段
|
// 兼容商品搜索行(item_id)与商品选择弹窗返回项(id)两种字段
|
||||||
const rawStockId = item?.item_id ?? item?.id
|
const rawStockId = item?.item_id ?? item?.id
|
||||||
const stockId = rawStockId != null ? Number(rawStockId) : null
|
const stockId = rawStockId != null ? Number(rawStockId) : null
|
||||||
@ -970,6 +1039,8 @@ async function quickAddDetail(item: any) {
|
|||||||
})
|
})
|
||||||
if (isOk(res)) {
|
if (isOk(res)) {
|
||||||
detailBarcode.value = ''
|
detailBarcode.value = ''
|
||||||
|
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||||
|
void pushOsdText()
|
||||||
ElMessage.success('相同商品数量已累加')
|
ElMessage.success('相同商品数量已累加')
|
||||||
loadDetailList()
|
loadDetailList()
|
||||||
focusTarget.value = 'barcode'
|
focusTarget.value = 'barcode'
|
||||||
@ -990,6 +1061,8 @@ async function quickAddDetail(item: any) {
|
|||||||
})
|
})
|
||||||
if (isOk(res)) {
|
if (isOk(res)) {
|
||||||
detailBarcode.value = ''
|
detailBarcode.value = ''
|
||||||
|
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||||
|
void pushOsdText()
|
||||||
ElMessage.success('明细添加成功')
|
ElMessage.success('明细添加成功')
|
||||||
loadDetailList()
|
loadDetailList()
|
||||||
focusTarget.value = 'barcode'
|
focusTarget.value = 'barcode'
|
||||||
@ -1165,6 +1238,8 @@ async function selectUnpack(row: any) {
|
|||||||
if (recordStoreId != null) {
|
if (recordStoreId != null) {
|
||||||
addStoreCandidate(recordStoreId, data.store_remark || row.store_remark || '')
|
addStoreCandidate(recordStoreId, data.store_remark || row.store_remark || '')
|
||||||
}
|
}
|
||||||
|
lastScannedBarcode.value = ''
|
||||||
|
void pushOsdText()
|
||||||
detailPagination.currentPage = 1
|
detailPagination.currentPage = 1
|
||||||
loadDetailList()
|
loadDetailList()
|
||||||
loadOrderDetail()
|
loadOrderDetail()
|
||||||
@ -1206,6 +1281,8 @@ function resetWorkState() {
|
|||||||
defaultProductStatus.value = 'normal'
|
defaultProductStatus.value = 'normal'
|
||||||
orderDetailData.value = null
|
orderDetailData.value = null
|
||||||
orderDetailItems.value = []
|
orderDetailItems.value = []
|
||||||
|
lastScannedBarcode.value = ''
|
||||||
|
void pushOsdText('')
|
||||||
focusTarget.value = 'waybill'
|
focusTarget.value = 'waybill'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1642,6 +1719,7 @@ onMounted(async () => {
|
|||||||
loadUnpackList()
|
loadUnpackList()
|
||||||
await loadCameraList()
|
await loadCameraList()
|
||||||
restoreCameraSelection()
|
restoreCameraSelection()
|
||||||
|
restoreOsdEnabled()
|
||||||
window.addEventListener('keydown', handleKeydown)
|
window.addEventListener('keydown', handleKeydown)
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
renderBarcodes()
|
renderBarcodes()
|
||||||
@ -1660,6 +1738,7 @@ async function submitDetailForm() {
|
|||||||
ElMessage.warning('请先创建拆包单')
|
ElMessage.warning('请先创建拆包单')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const scannedBarcode = String(detailForm.barcode ?? '').trim()
|
||||||
detailFormLoading.value = true
|
detailFormLoading.value = true
|
||||||
try {
|
try {
|
||||||
// 相同商品且相同产品状态才累加数量
|
// 相同商品且相同产品状态才累加数量
|
||||||
@ -1671,6 +1750,8 @@ async function submitDetailForm() {
|
|||||||
quantity: Number(existing.quantity || 0) + detailForm.quantity,
|
quantity: Number(existing.quantity || 0) + detailForm.quantity,
|
||||||
})
|
})
|
||||||
if (isOk(res)) {
|
if (isOk(res)) {
|
||||||
|
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||||
|
void pushOsdText()
|
||||||
ElMessage.success('相同商品数量已累加')
|
ElMessage.success('相同商品数量已累加')
|
||||||
detailFormVisible.value = false
|
detailFormVisible.value = false
|
||||||
loadDetailList()
|
loadDetailList()
|
||||||
@ -1688,6 +1769,8 @@ async function submitDetailForm() {
|
|||||||
remark: detailForm.remark ? detailForm.remark.trim() : undefined,
|
remark: detailForm.remark ? detailForm.remark.trim() : undefined,
|
||||||
})
|
})
|
||||||
if (isOk(res)) {
|
if (isOk(res)) {
|
||||||
|
if (scannedBarcode) lastScannedBarcode.value = scannedBarcode
|
||||||
|
void pushOsdText()
|
||||||
ElMessage.success('明细添加成功')
|
ElMessage.success('明细添加成功')
|
||||||
detailFormVisible.value = false
|
detailFormVisible.value = false
|
||||||
loadDetailList()
|
loadDetailList()
|
||||||
@ -1819,6 +1902,12 @@ async function confirmRemoveDetail() {
|
|||||||
color: #303133;
|
color: #303133;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.left-top-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
/* 键盘快捷键说明 */
|
/* 键盘快捷键说明 */
|
||||||
.shortcut-tips {
|
.shortcut-tips {
|
||||||
border-top: 1px dashed #e8eef7;
|
border-top: 1px dashed #e8eef7;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user