fix(print): 修复处方打印功能并优化路由查询解析
- 使用全局用户存储替代代理访问医院名称 - 更改打印方法为浏览器打印预览方式,无需客户端连接 - 添加打印样式处理和回调函数 - 在主入口文件初始化hiprint并配置本地客户端连接 - 移除重复的路由查询解析逻辑,简化代码结构
This commit is contained in:
@@ -465,6 +465,9 @@ import {hiprint} from 'vue-plugin-hiprint';
|
||||
import templateJson from '@/components/Print/Pharmacy.json';
|
||||
import chineseMedicineTemplateJson from '@/components/Print/ChineseMedicinePrescription.json';
|
||||
import {formatInventory} from '../../../utils/his';
|
||||
import useUserStore from '@/store/modules/user';
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
const {proxy} = getCurrentInstance();
|
||||
const showSearch = ref(true);
|
||||
@@ -718,21 +721,18 @@ async function printPrescription() {
|
||||
// 根据药品分类选择对应的打印模板
|
||||
const template = tcmFlag.value === '1' ? chineseMedicineTemplateJson : templateJson;
|
||||
const printElements = JSON.parse(
|
||||
JSON.stringify(template).replace(/{{HOSPITAL_NAME}}/g, proxy.$store.useUserStore().hospitalName)
|
||||
JSON.stringify(template).replace(/{{HOSPITAL_NAME}}/g, userStore.hospitalName)
|
||||
);
|
||||
var hiprintTemplate = new hiprint.PrintTemplate({template: printElements}); // 定义模板
|
||||
hiprintTemplate.print2(result, {
|
||||
height: 210,
|
||||
width: 148,
|
||||
});
|
||||
// 发送任务到打印机成功
|
||||
hiprintTemplate.on('printSuccess', function (e) {
|
||||
console.log('打印成功');
|
||||
});
|
||||
// 发送任务到打印机失败
|
||||
hiprintTemplate.on('printError', function (e) {
|
||||
console.log('打印失败');
|
||||
proxy.$modal.msgError('打印失败,请检查打印机连接');
|
||||
|
||||
// 使用浏览器打印预览方式(不需要客户端连接)
|
||||
hiprintTemplate.print(result, {}, {
|
||||
styleHandler: () => {
|
||||
return '<style>@media print { @page { margin: 0; } }</style>';
|
||||
},
|
||||
callback: () => {
|
||||
console.log('打印窗口已打开');
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('处方打印失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user