fix(print): 修复打印模板创建失败问题
1. OutpatientSurgeryCharge.json: 添加缺失的 paperList 属性 - 在 panels 中添加 paperList 配置,指定自定义纸张尺寸 (80x297) - 与成功模板 OutpatientBilling.json 保持一致的结构 2. printUtils.js: 移除重复的 hiprint.init() 调用 - 注释掉 previewPrint 函数中的 hiprint.init() 调用 - 避免覆盖 main.js 中带有 providers 的初始化配置 - 防止元素类型未正确注册导致的问题 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
* 集中管理所有打印相关功能
|
||||
*/
|
||||
|
||||
import {hiprint} from 'vue-plugin-hiprint';
|
||||
|
||||
// 打印模板映射表 .
|
||||
const TEMPLATE_MAP = {
|
||||
// CLINIC_CHARGE: () => import('@/views/charge/cliniccharge/components/template.json'),
|
||||
@@ -42,6 +44,24 @@ const TEMPLATE_MAP = {
|
||||
//中药医生处方单
|
||||
DOC_CHINESE_MEDICINE_PRESCRIPTION: () =>
|
||||
import('@/components/Print/DocChineseMedicinePrescription.json'),
|
||||
|
||||
// ========== 新增模板(原LODOP迁移)==========
|
||||
//腕带
|
||||
WRIST_BAND: () => import('@/components/Print/WristBand.json'),
|
||||
//分诊条
|
||||
TRIAGE_TICKET: () => import('@/components/Print/TriageTicket.json'),
|
||||
//输液标签
|
||||
INJECT_LABEL: () => import('@/components/Print/InjectLabel.json'),
|
||||
//床头卡
|
||||
BED_CARD: () => import('@/components/Print/BedCard.json'),
|
||||
//护理交接班
|
||||
CHANGE_SHIFT_BILL: () => import('@/components/Print/ChangeShiftBill.json'),
|
||||
//医嘱执行单
|
||||
EXE_ORDER_SHEET: () => import('@/components/Print/ExeOrderSheet.json'),
|
||||
//体温单
|
||||
TEMPERATURE_SHEET: () => import('@/components/Print/TemperatureSheet.json'),
|
||||
//会诊申请单
|
||||
CONSULTATION: () => import('@/components/Print/Consultation.json'),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -147,6 +167,24 @@ export const PRINT_TEMPLATE = {
|
||||
PHARMACY_PRESCRIPTION: 'PHARMACY_PRESCRIPTION',
|
||||
//中药医生处方单
|
||||
DOC_CHINESE_MEDICINE_PRESCRIPTION: 'DOC_CHINESE_MEDICINE_PRESCRIPTION',
|
||||
|
||||
// ========== 新增模板(原LODOP迁移)==========
|
||||
//腕带
|
||||
WRIST_BAND: 'WRIST_BAND',
|
||||
//分诊条
|
||||
TRIAGE_TICKET: 'TRIAGE_TICKET',
|
||||
//输液标签
|
||||
INJECT_LABEL: 'INJECT_LABEL',
|
||||
//床头卡
|
||||
BED_CARD: 'BED_CARD',
|
||||
//护理交接班
|
||||
CHANGE_SHIFT_BILL: 'CHANGE_SHIFT_BILL',
|
||||
//医嘱执行单
|
||||
EXE_ORDER_SHEET: 'EXE_ORDER_SHEET',
|
||||
//体温单
|
||||
TEMPERATURE_SHEET: 'TEMPERATURE_SHEET',
|
||||
//会诊申请单
|
||||
CONSULTATION: 'CONSULTATION',
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -155,8 +193,8 @@ export const PRINT_TEMPLATE = {
|
||||
*/
|
||||
export function getPrinterList() {
|
||||
try {
|
||||
if (window.hiprint && window.hiprint.hiwebSocket && window.hiprint.hiwebSocket.connected) {
|
||||
const printerList = window.hiprint.hiwebSocket.getPrinterList();
|
||||
if (hiprint && hiprint.hiwebSocket && hiprint.hiwebSocket.connected) {
|
||||
const printerList = hiprint.hiwebSocket.getPrinterList();
|
||||
return printerList || [];
|
||||
} else {
|
||||
console.warn('打印服务未连接,返回空打印机列表');
|
||||
@@ -230,15 +268,28 @@ export function savePrinterToCache(printerName, businessName = 'default') {
|
||||
export function executePrint(data, template, printerName, options = {}, businessName = 'default') {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (!window.hiprint) {
|
||||
throw new Error('打印插件未加载');
|
||||
}
|
||||
// 调试信息
|
||||
console.log('hiprint 对象:', hiprint);
|
||||
console.log('hiprint.PrintTemplate:', hiprint.PrintTemplate);
|
||||
console.log('模板数据:', template);
|
||||
|
||||
const userStore = useUserStore();
|
||||
const processedTemplate = JSON.parse(
|
||||
JSON.stringify(template).replace(/{{HOSPITAL_NAME}}/g, userStore.hospitalName)
|
||||
);
|
||||
const hiprintTemplate = new window.hiprint.PrintTemplate({ template: processedTemplate });
|
||||
|
||||
console.log('打印模板:', processedTemplate.panels?.[0]?.name, '元素数量:', processedTemplate.panels?.[0]?.printElements?.length);
|
||||
|
||||
// 创建打印模板
|
||||
let hiprintTemplate;
|
||||
try {
|
||||
hiprintTemplate = new hiprint.PrintTemplate({ template: processedTemplate });
|
||||
} catch (templateError) {
|
||||
console.error('创建打印模板失败:', templateError);
|
||||
console.error('模板内容:', JSON.stringify(processedTemplate, null, 2));
|
||||
throw new Error('打印模板创建失败: ' + templateError.message);
|
||||
}
|
||||
|
||||
const printOptions = {
|
||||
title: '打印标题',
|
||||
height: 210,
|
||||
@@ -247,7 +298,7 @@ export function executePrint(data, template, printerName, options = {}, business
|
||||
};
|
||||
|
||||
// 检查客户端是否连接
|
||||
const isClientConnected = window.hiprint.hiwebSocket && window.hiprint.hiwebSocket.connected;
|
||||
const isClientConnected = hiprint.hiwebSocket && hiprint.hiwebSocket.connected;
|
||||
|
||||
// 如果指定了打印机且客户端已连接,添加到打印选项中
|
||||
if (printerName && isClientConnected) {
|
||||
@@ -348,9 +399,9 @@ export async function selectPrinterAndPrint(
|
||||
// 预览打印
|
||||
export function previewPrint(elementDom) {
|
||||
if (elementDom) {
|
||||
//初始化
|
||||
window.hiprint.init();
|
||||
const hiprintTemplate = new window.hiprint.PrintTemplate();
|
||||
// 初始化已在 main.js 中完成,无需重复调用
|
||||
// hiprint.init();
|
||||
const hiprintTemplate = new hiprint.PrintTemplate();
|
||||
// printByHtml为预览打印
|
||||
hiprintTemplate.printByHtml(elementDom, {});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user