-
-
-
- {{ getPreviewValue(item) }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ {{ getPreviewValue(item, page.data) }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+ {{ c.title }}
+ |
+
+
+
+
- {{ c.title }}
-
-
-
-
-
- |
- {{ detailItem[c.field_code] || '' }}
- |
-
-
-
-
-
-
-
+
+ {{ detailItem[c.field_code] || '' }}
+ |
+ |
+
+
+
+
+
+
+
+
+ {{ page.pageNo }} / {{ page.pageTotal }}
+
-
+
@@ -128,6 +134,7 @@ 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'
+import { paginatePrintTemplate, type PrintPageItem } from '@/utils/printPaginate'
type RowItem = {
id: string | number
@@ -169,6 +176,8 @@ const printing = ref(false)
const currentPrintIndex = ref(0)
const printStatusMap = ref
>({})
const printForm = reactive({})
+/** 当前单据按模板分页后的页面集合(第 1 页原样,第 2+ 页重复单据头) */
+const currentPages = ref([])
const printSettings = reactive({
businessType: 'RECEIPT',
station: '' as string | number,
@@ -230,11 +239,17 @@ const previewInfo = computed(() => {
return { width: t.page_width || 0, height: t.page_height || 0 }
})
-const previewObjects = computed(() => {
+/** 按当前模板 + 当前单据数据计算分页结果 */
+function refreshPages() {
const t = templateOptions.value.find((item: any) => item.id === printSettings.template)
- if (!t || !Array.isArray(t.template_content)) return []
- return t.template_content
-})
+ currentPages.value = paginatePrintTemplate(t || {}, printForm)
+}
+
+// 切换打印模板时重新分页
+watch(
+ () => printSettings.template,
+ () => refreshPages()
+)
const completedPrintCount = computed(() => {
return Object.values(printStatusMap.value).filter(s => s === 'done').length
@@ -315,19 +330,19 @@ function _fmtISODate(val: string): string {
}
}
-function getPreviewValue(item: any): string {
- // 有 field_code 时优先从 printForm 取值
+function getPreviewValue(item: any, data?: any): string {
+ const form = data ?? printForm
+ // 有 field_code 时优先从 form 取值
if (item.field_code) {
-
// 处理 suffix_fields:将主字段 + 后缀字段拼接
if (Array.isArray(item.suffix_fields) && item.suffix_fields.length > 0) {
const parts: string[] = []
- const mainVal = printForm[item.field_code]
+ const mainVal = form[item.field_code]
if (mainVal !== undefined && mainVal !== null && String(mainVal).trim() !== '') {
parts.push(String(mainVal).trim())
}
item.suffix_fields.forEach((sf: string) => {
- const sv = printForm[sf]
+ const sv = form[sf]
if (sv !== undefined && sv !== null && String(sv).trim() !== '') {
parts.push(String(sv).trim())
}
@@ -339,7 +354,7 @@ function getPreviewValue(item: any): string {
}
// 普通字段取值
- const raw = printForm[item.field_code]
+ const raw = form[item.field_code]
if (raw !== undefined && raw !== null && String(raw).trim() !== '') {
const val = String(raw)
// 时间字段自动格式化 ISO → YYYY-MM-DD HH:mm:ss
@@ -351,21 +366,20 @@ function getPreviewValue(item: any): string {
// express_code / waybill_code 为空时尝试多来源回退
if (item.field_code === 'express_code' || item.field_code === 'waybill_code') {
- // 1) 交叉回退:express_code ↔ waybill_code(两个字段在 printForm 顶层互换取值)
+ // 1) 交叉回退:express_code ↔ waybill_code(两个字段在 form 顶层互换取值)
const peerField = item.field_code === 'express_code' ? 'waybill_code' : 'express_code'
- const peerVal = printForm[peerField]
+ const peerVal = form[peerField]
if (peerVal !== undefined && peerVal !== null && String(peerVal).trim() !== '') {
return String(peerVal).trim()
}
- console.log("printForm",JSON.stringify(printForm));
// 2) 先试 expresses 数组
- const expresses = printForm.expresses
+ const expresses = form.expresses
if (Array.isArray(expresses) && expresses.length > 0) {
const code = expresses[0]?.waybill_code || expresses[0]?.express_code
if (code) return String(code)
}
// 3) 再试 details 中第一条的 expresses
- const details = printForm.details
+ const details = form.details
if (Array.isArray(details) && details.length > 0) {
const firstDetail = details[0]
if (firstDetail) {
@@ -452,6 +466,7 @@ async function loadPrintFormData(index: number) {
const formData = await props.fetchPrintData(mainRow, index)
Object.keys(printForm).forEach(key => delete printForm[key])
Object.assign(printForm, formData || {})
+ refreshPages()
} catch (e) {
console.error('加载打印数据失败', e)
Object.keys(printForm).forEach(key => delete printForm[key])
@@ -543,6 +558,7 @@ async function loadPrintFormData(index: number) {
Object.keys(printForm).forEach(key => delete printForm[key])
Object.assign(printForm, formData)
+ refreshPages()
}
async function loadPrintOptions() {
@@ -666,43 +682,60 @@ async function doPrint() {
try {
const selectedTemplateObj = templateOptions.value.find((item: any) => item.id === printSettings.template) || null
- const printPayload: PrintSendParams = {
- type: 'customize',
- computerId: String(printSettings.station),
- printer: printSettings.printer,
- template: (selectedTemplateObj || {}) as Record,
- data: { ...printForm } as Record,
- timestamp: String(Date.now()),
- count: 1
+ // 逐页发送:当前单据按模板分页,每页一个打印任务(第 2+ 页重复单据头)
+ const pages = currentPages.value.length > 0 ? currentPages.value : [
+ {
+ pageNo: 1,
+ pageTotal: 1,
+ templateContent: Array.isArray(selectedTemplateObj?.template_content) ? selectedTemplateObj.template_content : [],
+ data: { ...printForm },
+ detailStart: 0,
+ detailEnd: Array.isArray(printForm.details) ? printForm.details.length : 0
+ }
+ ]
+
+ for (const page of pages) {
+ const printPayload: PrintSendParams = {
+ type: 'customize',
+ computerId: String(printSettings.station),
+ printer: printSettings.printer,
+ template: {
+ ...(selectedTemplateObj || {}),
+ template_content: page.templateContent
+ } as Record,
+ data: { ...page.data } as Record,
+ timestamp: String(Date.now()),
+ count: 1
+ }
+ const res: any = await stationApi.sendPrint(printPayload)
+ if (!(res && (res.code === 0 || res.code === 200 || res.status === 'success' || res.flag === 'success'))) {
+ throw new Error(res?.msg || res?.message || `${props.documentLabel} ${getQueueNumber(currentRow)} 打印失败`)
+ }
}
- const res: any = await stationApi.sendPrint(printPayload)
- if (res && (res.code === 0 || res.code === 200 || res.status === 'success' || res.flag === 'success')) {
- printStatusMap.value[currentRow.id] = 'done'
- ElMessage.success(`${props.documentLabel} ${getQueueNumber(currentRow)} 打印成功`)
+ // 全部页打印成功
+ printStatusMap.value[currentRow.id] = 'done'
+ const pageTip = pages.length > 1 ? `(共 ${pages.length} 页)` : ''
+ ElMessage.success(`${props.documentLabel} ${getQueueNumber(currentRow)} 打印成功${pageTip}`)
- if (currentPrintIndex.value < props.selectionRows.length - 1) {
- currentPrintIndex.value++
- await loadPrintFormData(currentPrintIndex.value)
- } else {
- ElMessage.info('已完成所有选中单据的打印操作')
- }
+ if (currentPrintIndex.value < props.selectionRows.length - 1) {
+ currentPrintIndex.value++
+ await loadPrintFormData(currentPrintIndex.value)
} else {
- printStatusMap.value[currentRow.id] = 'error'
- ElMessage.error(res?.msg || res?.message || `${props.documentLabel} ${getQueueNumber(currentRow)} 打印失败`)
+ ElMessage.info('已完成所有选中单据的打印操作')
}
} catch (e) {
console.error('打印出错:', e)
printStatusMap.value[currentRow.id] = 'error'
- ElMessage.error('打印请求失败,请检查网络或打印台状态')
+ ElMessage.error((e as Error)?.message || '打印请求失败,请检查网络或打印台状态')
} finally {
printing.value = false
}
}
function browserPrint() {
- const previewEl = document.querySelector('.preview-page') as HTMLElement | null
- if (!previewEl) {
+ const previewEls = document.querySelectorAll('.preview-page') as NodeListOf
+ if (!previewEls.length) {
ElMessage.warning('暂无预览内容可打印')
return
}
@@ -715,12 +748,33 @@ function browserPrint() {
let styleHtml = ''
styles.forEach(s => { styleHtml += s.outerHTML })
+ // 拼接当前单据的所有分页(第 1..N 页),每页强制分页
+ const pagesHtml = Array.from(previewEls)
+ .map(el => el.outerHTML)
+ .join('')
+
printWindow.document.write(`
- 打印预览${styleHtml}
-
- ${previewEl.outerHTML}
+
+
+ 打印预览
+ ${styleHtml}
+
+
+
+ ${pagesHtml}
`)
@@ -853,8 +907,9 @@ function browserPrint() {
.print-canvas-area {
display: flex;
- justify-content: center;
- align-items: flex-start;
+ flex-direction: column;
+ align-items: center;
+ gap: 20px;
padding: 20px;
background-color: #f0f2f5;
@@ -863,6 +918,18 @@ function browserPrint() {
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
border: 1px solid #ddd;
flex-shrink: 0;
+
+ .preview-page-label {
+ position: absolute;
+ right: 4px;
+ top: 2px;
+ color: #c0c4cc;
+ font-size: 10px;
+ z-index: 99;
+ background: rgba(255, 255, 255, 0.8);
+ padding: 0 4px;
+ border-radius: 3px;
+ }
}
.preview-empty {
diff --git a/src/components/ScanBox/index.vue b/src/components/ScanBox/index.vue
index 06dbffcb..01283c66 100644
--- a/src/components/ScanBox/index.vue
+++ b/src/components/ScanBox/index.vue
@@ -477,6 +477,7 @@
+
{{ field.label }}
[10, 20, 50, 100, 200, 500, 1000],
+ default: () => [10, 20, 50, 100, 200, 500],
},
// 分页布局
paginationLayout: {
diff --git a/src/composables/useOrderAsyncExport.ts b/src/composables/useOrderAsyncExport.ts
index 20b6000a..2ab635b5 100644
--- a/src/composables/useOrderAsyncExport.ts
+++ b/src/composables/useOrderAsyncExport.ts
@@ -17,6 +17,9 @@ export type OrderAsyncExportPayload = {
sort?: Record
export_mode?: OrderExportMode
exportMode?: OrderExportMode
+ /** 导出表头字段白名单(中文表头字符串数组);不传或空数组时输出全部列 */
+ export_columns?: string[]
+ exportColumns?: string[]
}
export function useOrderAsyncExport(storageKey?: string) {
diff --git a/src/utils/printPaginate.ts b/src/utils/printPaginate.ts
new file mode 100644
index 00000000..fc695e0d
--- /dev/null
+++ b/src/utils/printPaginate.ts
@@ -0,0 +1,197 @@
+/**
+ * 打印模板分页工具
+ *
+ * 用于把一张单据的「商品明细」按模板布局拆分为多页:
+ * - 定位模板中的 table(商品明细)与下方「截止线」(默认取表格之后最近的 text 元素 top,即备注位置)
+ * - 按每行实际渲染高度(商品名称换行会抬高行高)动态切分,而非固定行数
+ * - 第 2+ 页重复单据头(top < tableTop 的元素)+ 重复表头 + 页码
+ *
+ * 打印台通道(print.send)与浏览器打印共用此逻辑,保证两通道分页一致。
+ */
+
+export interface PrintPageItem {
+ /** 第几页(从 1 开始) */
+ pageNo: number
+ /** 总页数 */
+ pageTotal: number
+ /** 该页模板内容(第 1 页为原模板;第 2+ 页为单头 + 表格 + 页码) */
+ templateContent: Record[]
+ /** 该页数据(单据头字段完整 + details 切片 + pageNo/pageTotal) */
+ data: Record
+ /** 该页明细在原始 details 中的起始下标(含) */
+ detailStart: number
+ /** 该页明细在原始 details 中的结束下标(不含) */
+ detailEnd: number
+}
+
+export interface PaginatePrintOptions {
+ /** 截止线(mm),默认自动取表格之后最近的 text 元素 top */
+ cutlineTop?: number
+ /** 单元格字号(mm),用于估算文本换行,默认 3 */
+ cellFontSizeMm?: number
+ /** 每行基准高度(mm),默认取 table.rowHeight || 6 */
+ perLineHeight?: number
+ /** 是否给第 2+ 页追加页码元素,默认 true */
+ appendPageLabel?: boolean
+}
+
+/** 中日韩/全角字符按 1 个宽度单位,其余按 0.5 个单位(近似) */
+function displayUnits(text: string): number {
+ let units = 0
+ for (const ch of String(text ?? '')) {
+ const code = ch.codePointAt(0) ?? 0
+ if (code >= 0x2e80 || code === 0x3000) {
+ units += 1
+ } else {
+ units += 0.5
+ }
+ }
+ return units
+}
+
+/**
+ * 估算单行实际高度:
+ * 对每一列,按「文本显示宽度 / 列宽」换行,取所有列的最大行数 × 基准行高。
+ */
+function estimateRowHeight(
+ detail: Record,
+ table: Record,
+ cellFontSizeMm: number,
+ perLineHeight: number
+): number {
+ const cols: any[] = Array.isArray(table.rows) ? table.rows : []
+ let maxLines = 1
+ for (const col of cols) {
+ const colWidth = Number(col.width) || 10
+ const value = detail?.[col.field_code]
+ if (value === undefined || value === null || String(value).trim() === '') continue
+ // 每行可容纳的「中文宽度单位」数:列宽 / 字号
+ const capacity = Math.max(1, colWidth / Math.max(0.1, cellFontSizeMm))
+ const lines = Math.max(1, Math.ceil(displayUnits(String(value)) / capacity))
+ maxLines = Math.max(maxLines, lines)
+ }
+ return maxLines * perLineHeight
+}
+
+/** 第 2+ 页追加的页码元素(自定义 text,无 field_code,content 直接显示) */
+function buildPageLabel(template: Record, pageNo: number, pageTotal: number) {
+ const pageWidth = Number(template?.page_width) || 148
+ const pageHeight = Number(template?.page_height) || 210
+ return {
+ id: `page_label_${pageNo}`,
+ top: Math.max(0, pageHeight - 8),
+ left: Math.max(0, pageWidth - 46),
+ type: 'text',
+ width: 42,
+ height: 6,
+ fontSize: 8,
+ content: `第 ${pageNo}/${pageTotal} 页`,
+ textAlign: 'right',
+ lineHeight: 6
+ }
+}
+
+/**
+ * 按模板布局把单据分页。
+ * - 模板中没有 table 或没有明细 → 返回单页原样,行为与现状一致。
+ * - 有 table 且明细溢出 → 自动拆分多页。
+ */
+export function paginatePrintTemplate(
+ template: Record,
+ formData: Record,
+ options: PaginatePrintOptions = {}
+): PrintPageItem[] {
+ const content: any[] = Array.isArray(template?.template_content) ? template.template_content : []
+ const table = content.find(el => el?.type === 'table')
+ const details: any[] = Array.isArray(formData?.details) ? formData.details : []
+
+ if (!table || details.length === 0) {
+ return [
+ {
+ pageNo: 1,
+ pageTotal: 1,
+ templateContent: content,
+ data: { ...formData, details, pageNo: 1, pageTotal: 1 },
+ detailStart: 0,
+ detailEnd: details.length
+ }
+ ]
+ }
+
+ const tableTop = Number(table.top) ?? 0
+ const headerH = Number(table.headerHeight ?? 4)
+ const perLineHeight = options.perLineHeight ?? Number(table.rowHeight ?? 6)
+ const cellFontSizeMm = options.cellFontSizeMm ?? 3
+
+ // 截止线:参数优先;否则取表格之后最近的 text 元素 top(如备注位置)
+ const optionCutline = options.cutlineTop
+ let cutlineTop: number
+ if (optionCutline === undefined || optionCutline === null) {
+ const afterTexts = content
+ .filter(el => el !== table && el?.type === 'text' && Number(el.top) > tableTop)
+ .map(el => Number(el.top))
+ .filter(n => Number.isFinite(n))
+ .sort((a, b) => a - b)
+ cutlineTop = afterTexts.length > 0 ? (afterTexts[0] as number) : tableTop + (Number(table.height) || 75)
+ } else {
+ cutlineTop = optionCutline
+ }
+
+ const usableH = cutlineTop - tableTop - headerH
+
+ // 第一遍:按实际行高动态切分(不按固定行数)
+ const pageRowSets: any[][] = []
+ let curRows: any[] = []
+ let curH = 0
+ for (const detail of details) {
+ const rowH = estimateRowHeight(detail, table, cellFontSizeMm, perLineHeight)
+ if (curRows.length > 0 && curH + rowH > usableH) {
+ pageRowSets.push(curRows)
+ curRows = []
+ curH = 0
+ }
+ curRows.push(detail)
+ curH += rowH
+ }
+ if (curRows.length > 0 || pageRowSets.length === 0) {
+ pageRowSets.push(curRows)
+ }
+
+ // 第二遍:生成每页模板内容与数据
+ const total = pageRowSets.length
+ const result: PrintPageItem[] = []
+ let idx = 0
+ pageRowSets.forEach((rows, i) => {
+ const pageNo = i + 1
+ const detailStart = idx
+ const detailEnd = idx + rows.length
+ idx = detailEnd
+
+ let pageContent = content
+ if (pageNo > 1) {
+ // 第 2+ 页:重复单据头(top < tableTop)+ 表格(重复表头)
+ const head = content.filter(el => Number(el.top) < tableTop)
+ pageContent = [...head, table]
+ }
+ // 多页时每页右下角都追加页码(第 1 页同样加,便于确认页序与批次)
+ if (total > 1 && options.appendPageLabel !== false) {
+ pageContent = [...pageContent, buildPageLabel(template, pageNo, total)]
+ }
+
+ result.push({
+ pageNo,
+ pageTotal: total,
+ templateContent: pageContent,
+ data: {
+ ...formData,
+ details: rows,
+ pageNo,
+ pageTotal: total
+ },
+ detailStart,
+ detailEnd
+ })
+ })
+
+ return result
+}
diff --git a/src/views/order/orderManagement/archiveOrder.vue b/src/views/order/orderManagement/archiveOrder.vue
index 7b4342ac..de0f3131 100644
--- a/src/views/order/orderManagement/archiveOrder.vue
+++ b/src/views/order/orderManagement/archiveOrder.vue
@@ -113,6 +113,14 @@
+