diff --git a/openhis-ui-vue3/src/layout/components/Sidebar/SidebarItem.vue b/openhis-ui-vue3/src/layout/components/Sidebar/SidebarItem.vue index c174a983..3ec9c783 100644 --- a/openhis-ui-vue3/src/layout/components/Sidebar/SidebarItem.vue +++ b/openhis-ui-vue3/src/layout/components/Sidebar/SidebarItem.vue @@ -96,27 +96,6 @@ function resolvePath(routePath, routeQuery) { return { path: getNormalPath(props.basePath + '/' + routePath), query: query } } catch (e) { // 如果解析失败,将其作为普通字符串处理 - console.warn('Failed to parse routeQuery as JSON:', routeQuery, e); - return getNormalPath(props.basePath + '/' + routePath) - } - try { - let query = JSON.parse(routeQuery); - return { path: getNormalPath(props.basePath + '/' + routePath), query: query } - } catch (e) { - console.error('Failed to parse routeQuery:', routeQuery, e); - return getNormalPath(props.basePath + '/' + routePath) - } - try { - // 检查 routeQuery 是否已经是对象 - if (typeof routeQuery === 'object') { - return { path: getNormalPath(props.basePath + '/' + routePath), query: routeQuery } - } - // 尝试解析 JSON 字符串 - let query = JSON.parse(routeQuery); - return { path: getNormalPath(props.basePath + '/' + routePath), query: query } - } catch (e) { - // 如果解析失败,将其作为普通字符串处理 - console.warn('Failed to parse routeQuery as JSON:', routeQuery, e); return getNormalPath(props.basePath + '/' + routePath) } } diff --git a/openhis-ui-vue3/src/main.js b/openhis-ui-vue3/src/main.js index 4b846eee..c38a7016 100644 --- a/openhis-ui-vue3/src/main.js +++ b/openhis-ui-vue3/src/main.js @@ -3,7 +3,7 @@ import {createApp} from 'vue'; import Cookies from 'js-cookie'; // 导入 hiprint 并挂载到全局 window 对象 -import {hiprint} from 'vue-plugin-hiprint'; +import {hiprint, autoConnect, disAutoConnect} from 'vue-plugin-hiprint'; import ElementPlus, {ElDialog, ElMessage} from 'element-plus'; import zhCn from 'element-plus/es/locale/lang/zh-cn'; @@ -52,6 +52,32 @@ import {registerComponents} from './template'; window.hiprint = hiprint; +// 初始化 hiprint 并连接本地客户端 +hiprint.init({ + providers: [] +}); + +// 延迟连接,确保 hiwebSocket 已初始化 +setTimeout(() => { + if (hiprint.hiwebSocket) { + // 设置连接地址和 token + hiprint.hiwebSocket.setHost('http://localhost:17521', 'hiprint-test'); + console.log('hiprint 连接地址:', hiprint.hiwebSocket.host); + + // 等待连接建立 + setTimeout(() => { + console.log('hiprint 连接状态:', hiprint.hiwebSocket.connected); + if (hiprint.hiwebSocket.connected) { + console.log('hiprint 客户端连接成功'); + } else { + console.warn('hiprint 客户端未连接,请检查客户端是否运行'); + } + }, 2000); + } else { + console.warn('hiprint.hiwebSocket 未初始化'); + } +}, 500); + const app = createApp(App); if (chrome.webview !== undefined) { diff --git a/openhis-ui-vue3/src/views/pharmacymanagement/westernmedicine/index.vue b/openhis-ui-vue3/src/views/pharmacymanagement/westernmedicine/index.vue index 3e570880..d5f94e95 100644 --- a/openhis-ui-vue3/src/views/pharmacymanagement/westernmedicine/index.vue +++ b/openhis-ui-vue3/src/views/pharmacymanagement/westernmedicine/index.vue @@ -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 ''; + }, + callback: () => { + console.log('打印窗口已打开'); + } }); } catch (error) { console.error('处方打印失败:', error);