| | |
| | | import { $t } from '@/locales' |
| | | |
| | | function escapeHtml(value) { |
| | | return String(value ?? '') |
| | | .replaceAll('&', '&') |
| | |
| | | |
| | | function getMetaItems(meta = {}) { |
| | | return [ |
| | | { key: 'reportDate', label: '报表日期', value: meta.reportDate ?? '--' }, |
| | | { key: 'operator', label: '打印人', value: meta.operator ?? '--' }, |
| | | { key: 'printedAt', label: '打印时间', value: meta.printedAt ?? '--' }, |
| | | { key: 'count', label: '记录数', value: meta.count ?? '--' } |
| | | { key: 'reportDate', label: $t('print.reportDate'), value: meta.reportDate ?? '--' }, |
| | | { key: 'operator', label: $t('print.operator'), value: meta.operator ?? '--' }, |
| | | { key: 'printedAt', label: $t('print.printedAt'), value: meta.printedAt ?? '--' }, |
| | | { key: 'count', label: $t('print.count'), value: meta.count ?? '--' } |
| | | ] |
| | | } |
| | | |
| | |
| | | return alignMap[column.align] ?? alignMap.left |
| | | } |
| | | |
| | | export function buildPrintDocumentHtml({ title = '报表', meta = {}, rows = [], columns = [] } = {}) { |
| | | export function buildPrintDocumentHtml({ title = '', meta = {}, rows = [], columns = [] } = {}) { |
| | | const reportStyle = getReportStyle(meta) |
| | | const reportTitle = meta.reportTitle || title |
| | | const reportTitle = meta.reportTitle || title || $t('print.defaultReportTitle') |
| | | const titleClass = `${getTitleAlignClass(reportStyle.titleAlign)} ${getTitleLevelClass(reportStyle.titleLevel)}` |
| | | const orientation = getPageOrientation(reportStyle) |
| | | const showBorder = reportStyle.showBorder !== false |
| | |
| | | return `<tr>${cells}</tr>` |
| | | }) |
| | | .join('') |
| | | : `<tr><td colspan="${Math.max(columns.length, 1)}" class="empty-cell">暂无打印数据</td></tr>` |
| | | : `<tr><td colspan="${Math.max(columns.length, 1)}" class="empty-cell">${escapeHtml($t('print.noData'))}</td></tr>` |
| | | |
| | | const metaHtml = metaItems |
| | | .map( |