diff --git a/dist.tar.gz b/dist.tar.gz index 5622b8e2..b5553129 100644 Binary files a/dist.tar.gz and b/dist.tar.gz differ diff --git a/src/api/print/print.ts b/src/api/print/print.ts index e48df997..6b9e4e20 100644 --- a/src/api/print/print.ts +++ b/src/api/print/print.ts @@ -102,7 +102,12 @@ function normalizeDelIds(ids: unknown[]): number[] { return ids.map((i) => Number(i)).filter((n) => Number.isFinite(n)) } +/** print.del:ids 必填且须为非空数组(见 print 模块 module.json) */ export function delItems(ids: Array) { + const normalized = normalizeDelIds(ids) + if (!normalized.length) { + return Promise.reject(new Error('print.del:ids 必须为非空数组')) + } return request({ url: '/system', method: 'post', @@ -111,7 +116,7 @@ export function delItems(ids: Array) { v, timestamp: stamp() }, - data: { ids: normalizeDelIds(ids) } + data: { ids: normalized } }) } @@ -169,15 +174,17 @@ export function getPrintRecordItem(id: string | number) { }) } -/** print.send 请求体(与 print 模块接口一致) */ +/** print.send 请求体(与 print 模块 module.json 一致:template 仅 customize 必填,express 可不传) */ export type PrintSendParams = { computerId: string count?: number data: Record printer: string - template: Record + /** customize 时必填且宜含 page_width、page_height、template_content;express 可不传 */ + template?: Record /** 业务时间戳,可选;接口类型为 string */ timestamp?: string + /** 当前实现支持 customize、express */ type: string } @@ -189,18 +196,17 @@ export type PrintSendResult = { printId?: number } -export function savePrinters(data: { +/** print.savePrinters:defaultPrinter、express、print_station_id 均为必填(见 print 模块 module.json) */ +export type PrintSavePrintersParams = { defaultPrinter: string - express?: Array> - print_station_id?: number -}) { - const body: Record = { - defaultPrinter: data.defaultPrinter, - express: data.express ?? [] - } - if (data.print_station_id !== undefined && data.print_station_id !== null) { - const n = Number(data.print_station_id) - if (Number.isFinite(n)) body.print_station_id = n + express: Array> + print_station_id: number +} + +export function savePrinters(data: PrintSavePrintersParams) { + const sid = Number(data.print_station_id) + if (!Number.isFinite(sid)) { + return Promise.reject(new Error('print.savePrinters:print_station_id 无效')) } return request({ url: '/system', @@ -210,14 +216,29 @@ export function savePrinters(data: { v, timestamp: stamp() }, - data: body + data: { + defaultPrinter: data.defaultPrinter, + express: Array.isArray(data.express) ? data.express : [], + print_station_id: sid + } }) } export function sendPrint(data: PrintSendParams) { - const body: PrintSendParams = { ...data } - if (body.timestamp !== undefined && body.timestamp !== null && typeof body.timestamp !== 'string') { - body.timestamp = String(body.timestamp) + const body: Record = { + computerId: data.computerId, + data: data.data, + printer: data.printer, + type: data.type + } + if (data.count !== undefined && data.count !== null) { + body.count = data.count + } + if (data.timestamp !== undefined && data.timestamp !== null) { + body.timestamp = typeof data.timestamp === 'string' ? data.timestamp : String(data.timestamp) + } + if (data.template !== undefined && data.template !== null) { + body.template = data.template } return request({ url: '/system', diff --git a/src/components/BatchReceivingPrintDialog.vue b/src/components/BatchReceivingPrintDialog.vue index a4a6b296..d044bc2b 100644 --- a/src/components/BatchReceivingPrintDialog.vue +++ b/src/components/BatchReceivingPrintDialog.vue @@ -136,6 +136,7 @@ import JsBarcode from 'jsbarcode' import * as receivingApi from '@/api/storage_receiving/receiving' import * as templateApi from '@/api/setting.printtemplate/printTemplate' import * as stationApi from '@/api/print/print' +import type { PrintSendParams } from '@/api/print/print' import { printFormConfig } from '@/views/storage/receiving/receiving-config' type RowItem = { @@ -545,7 +546,7 @@ async function doPrint() { try { const selectedTemplateObj = templateOptions.value.find((item: any) => item.id === printSettings.template) || null - const printPayload = { + const printPayload: PrintSendParams = { type: 'customize', computerId: String(printSettings.station), printer: printSettings.printer, diff --git a/src/views/order/waveOrder/component/WavePlatformPrintPreviewDialog.vue b/src/views/order/waveOrder/component/WavePlatformPrintPreviewDialog.vue index 76db1737..7f388b35 100644 --- a/src/views/order/waveOrder/component/WavePlatformPrintPreviewDialog.vue +++ b/src/views/order/waveOrder/component/WavePlatformPrintPreviewDialog.vue @@ -57,6 +57,10 @@
+ {{ + platform.sys_logistics_name + }} + | {{ platform.platform_name }} {{ platform.platform }}
@@ -74,7 +78,14 @@ @@ -85,6 +96,7 @@ import { computed, reactive, ref, watch } from 'vue' import { ElMessage } from 'element-plus' import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint' import * as stationApi from '@/api/print/print' +import type { PrintSendParams } from '@/api/print/print' const WAVE_PRINT_STATION_STORAGE_KEY = 'wave_platform_print_station_id' @@ -93,6 +105,8 @@ type WaveGroupPlatform = { platformKey: string platform: string platform_name: string + /** 快递 / 物流公司名称(与波次列表 sys_logistics_name 一致) */ + sys_logistics_name: string order_count: number } type WaveGroupView = { @@ -115,11 +129,18 @@ const emit = defineEmits<{ }>() const printRootRef = ref(null) -const stationOptions = ref([]) +type StationOption = { + id: string | number + computer_id: string + name: string + default_printer_name: string +} + +const stationOptions = ref([]) const stationLoading = ref(false) const stationPrinting = ref(false) const printSettings = reactive({ - station: '' as string | number + station: '' as string }) const visibleProxy = computed({ @@ -152,10 +173,15 @@ const waveGroupList = computed(() => { const platform = rawPlatform as AnyRecord const platformCode = toText(platform.platform, `platform-${platformIndex + 1}`) const platformName = toText(platform.platform_name, platformCode) + const logisticsRaw = + platform.sys_logistics_name ?? platform.logistics_name ?? platform.express_name ?? platform.logisticsName + const sys_logistics_name = + logisticsRaw != null && String(logisticsRaw).trim() !== '' ? String(logisticsRaw).trim() : '' return { platformKey: `${wave_id}-${platformCode}-${platformIndex}`, platform: platformCode, platform_name: platformName, + sys_logistics_name, order_count: toNum(platform.order_count, 0) } }) @@ -185,7 +211,53 @@ function toNum(v: unknown, fallback = 0): number { } function isApiSuccess(res: any) { - return !!res && (res.code === 0 || res.code === 200) + const c = res?.code + return !!res && (c === 0 || c === 200 || c === 1 || c === 20000) +} + +/** print.getList:兼容 data.list 与 data.data.list(及 records) */ +function extractPrintStationRows(res: any): any[] { + const root = res?.data + if (Array.isArray(root)) return root + if (!root || typeof root !== 'object') return [] + if (Array.isArray(root.list)) return root.list + if (Array.isArray(root.records)) return root.records + if (Array.isArray(root.items)) return root.items + const inner = root.data + if (Array.isArray(inner)) return inner + if (inner && typeof inner === 'object') { + if (Array.isArray(inner.list)) return inner.list + if (Array.isArray(inner.records)) return inner.records + } + return [] +} + +/** 与 printStation info 表单一致:列表行上名称、默认打印机字段别名 */ +function mapStationRow(item: Record): StationOption { + const rawCid = item.computer_id ?? item.computerId ?? item.id + const computer_id = rawCid != null && String(rawCid).trim() !== '' ? String(rawCid) : '' + const nameRaw = + item.name ?? + item.station_name ?? + item.print_station_name ?? + item.printName ?? + item.stationName ?? + item.label ?? + '' + const name = nameRaw != null && String(nameRaw).trim() !== '' ? String(nameRaw).trim() : computer_id + const defPrinter = + item.default_printer_name ?? + item.defaultPrinterName ?? + item.printer_name ?? + item.default_printer ?? + '' + const default_printer_name = String(defPrinter ?? '').trim() + return { + id: item.id ?? rawCid ?? computer_id, + computer_id, + name, + default_printer_name + } } async function loadStationOptions() { @@ -194,21 +266,18 @@ async function loadStationOptions() { const stations: any = await stationApi.getList({ page: 1, pageSize: 100, where: {} }) if (!isApiSuccess(stations)) { stationOptions.value = [] + printSettings.station = '' ElMessage.warning('加载打印台列表失败') return } - const rawList: any[] = stations.data?.list || stations.data || [] - stationOptions.value = rawList.map((item: any) => ({ - id: item.id ?? item.computer_id, - computer_id: item.computer_id ?? item.computerId ?? item.id, - name: item.name || item.label || String(item.computer_id ?? item.computerId ?? item.id) - })) + const rawList = extractPrintStationRows(stations) + stationOptions.value = rawList.filter((x) => x && typeof x === 'object').map((item: any) => mapStationRow(item)) // 初始化默认打印台:优先本地存储,其次当前值,最后回退到首项 const savedStation = getSavedStationId() const currentStationId = String(printSettings.station || '').trim() - const hasSaved = !!savedStation && stationOptions.value.some((item) => String(item.computer_id) === savedStation) - const hasCurrent = !!currentStationId && stationOptions.value.some((item) => String(item.computer_id) === currentStationId) + const hasSaved = !!savedStation && stationOptions.value.some((item) => item.computer_id === savedStation) + const hasCurrent = !!currentStationId && stationOptions.value.some((item) => item.computer_id === currentStationId) if (!stationOptions.value.length) { printSettings.station = '' @@ -218,25 +287,25 @@ async function loadStationOptions() { if (hasSaved) { printSettings.station = savedStation - return - } - if (hasCurrent) { + } else if (hasCurrent) { saveStationId(String(currentStationId)) - return + } else { + const first = stationOptions.value[0] + if (first) { + printSettings.station = first.computer_id + saveStationId(first.computer_id) + } } - - const fallbackStation = String(stationOptions.value[0].computer_id) - printSettings.station = fallbackStation - saveStationId(fallbackStation) } catch { stationOptions.value = [] + printSettings.station = '' ElMessage.warning('加载打印台列表失败') } finally { stationLoading.value = false } } -async function handleStationChange(val: string | number) { +function handleStationChange(val: string | number) { const stationId = String(val || '').trim() if (!stationId) { clearSavedStationId() @@ -255,11 +324,16 @@ async function printToStation() { return } + const sid = String(printSettings.station).trim() + const stationRow = stationOptions.value.find((s) => s.computer_id === sid) + const printer = stationRow?.default_printer_name ?? '' + stationPrinting.value = true try { - const printPayload = { + const printPayload: PrintSendParams = { type: 'express', - computerId: String(printSettings.station), + computerId: sid, + printer, data: { waveGroups: props.payload.waveGroups || [], wave_ids: props.payload.wave_ids || [], @@ -269,7 +343,7 @@ async function printToStation() { timestamp: String(Date.now()), count: 1 } - const res: any = await stationApi.sendPrint(printPayload as any) + const res: any = await stationApi.sendPrint(printPayload) if (res && (res.code === 0 || res.code === 200 || res.flag === 'success' || res.status === 'success')) { ElMessage.success(res?.message || '已发送到打印台') return @@ -469,6 +543,17 @@ function escapeHtml(s: string) { font-weight: 500; } + &__logistics { + font-weight: 600; + color: #303133; + } + + &__sep-inline { + color: #c0c4cc; + margin: 0 6px; + font-weight: 400; + } + &__code { margin-left: 6px; color: #909399; diff --git a/src/views/order/waveOrder/config/wave-config.ts b/src/views/order/waveOrder/config/wave-config.ts index bac4b3fa..317a095c 100644 --- a/src/views/order/waveOrder/config/wave-config.ts +++ b/src/views/order/waveOrder/config/wave-config.ts @@ -430,6 +430,8 @@ export function unwrapWavePlatformPrintPayload(res: unknown): WavePlatformPrintD return { platform: platformObj.platform, platform_name: platformObj.platform_name, + sys_logistics_name: platformObj.sys_logistics_name, + logistics_name: platformObj.logistics_name, order_count: platformObj.order_count, orders: toOrderList(platformObj.orders) } diff --git a/src/views/storage/inventory/index.vue b/src/views/storage/inventory/index.vue index 97b4dc72..ef85a098 100644 --- a/src/views/storage/inventory/index.vue +++ b/src/views/storage/inventory/index.vue @@ -185,6 +185,7 @@ const columns = computed(() => { const expiryIdx = cols.findIndex((x: any) => x.prop === 'expiry_date') for (let i = warningColumns.length - 1; i >= 0; i--) { const c = warningColumns[i] + if (!c) continue if (cols.find((x: any) => x.prop === c.prop)) continue if (expiryIdx >= 0) cols.splice(expiryIdx + 1, 0, c) else cols.push(c) diff --git a/src/views/system/setting/printStation/components/add.vue b/src/views/system/setting/printStation/components/add.vue index db84c9c1..c8557d0a 100644 --- a/src/views/system/setting/printStation/components/add.vue +++ b/src/views/system/setting/printStation/components/add.vue @@ -1,29 +1,130 @@