解决合并冲突

This commit is contained in:
2025-12-10 14:20:24 +08:00
parent e1385cb3e6
commit 18f6a845e6
804 changed files with 61881 additions and 13577 deletions

View File

@@ -459,3 +459,46 @@ export async function selectPrinterAndPrint(data, template, showPrinterDialog, m
modal.msgError(error.message || '获取打印机列表失败');
}
}
// 分组标记处理
export function getGroupMarkers(tableData) {
// 初始化所有行的 groupIcon 为 null
tableData.forEach((item) => {
item.groupIcon = null;
});
// 创建一个映射来存储每个 groupId 对应的行索引
const groupMap = {};
// 遍历列表,按 groupId 分组(忽略无 groupId 的项)
tableData.forEach((item, index) => {
if (!item.groupId) {
return;
}
if (!groupMap[item.groupId]) {
groupMap[item.groupId] = [];
}
groupMap[item.groupId].push(index);
});
// 为每个组设置 groupIcon
Object.values(groupMap).forEach((indices) => {
// 只有当组内元素大于1个时才需要显示分组标记
if (indices.length > 1) {
indices.forEach((index, i) => {
if (i === 0) {
// 第一行
tableData[index].groupIcon = '┏';
} else if (i === indices.length - 1) {
// 最后一行
tableData[index].groupIcon = '┗';
} else {
// 中间行
tableData[index].groupIcon = '┃';
}
});
}
});
return tableData;
}

View File

@@ -0,0 +1,293 @@
/**
* 打印工具类
* 集中管理所有打印相关功能
*/
// 打印模板映射表
const TEMPLATE_MAP = {
// CLINIC_CHARGE: () => import('@/views/charge/cliniccharge/components/template.json'),
// DISPOSAL: () => import('@/views/clinicmanagement/disposal/components/disposalTemplate.json'),
//处方签
PRESCRIPTION: () => import('@/components/Print/Prescription.json'),
//处置单
DISPOSAL: () => import('@/components/Print/Disposal.json'),
//门诊日结
DAY_END: () => import('@/components/Print/DailyOutpatientSettlement.json'),
WESTERN_MEDICINE: () =>
import('@/views/pharmacymanagement/westernmedicine/components/templateJson.json'),
IN_HOSPITAL_DISPENSING: () =>
import('@/views/drug/inHospitalDispensing/components/templateJson.json'),
//门诊挂号
OUTPATIENT_REGISTRATION: () => import('@/components/Print/OutpatientRegistration.json'),
//门诊收费
OUTPATIENT_CHARGE: () => import('@/components/Print/OutpatientBilling.json'),
};
/**
* 极简打印方法
* @param {string} templateName 打印模板名称(常量或字符串)
* @param {Array|Object} data 打印数据
* @param {string} printerName 打印机名称(可选)
* @param {Object} options 打印选项(可选)
* @returns {Promise} 打印结果Promise
*/
export async function simplePrint(templateName, data, printerName, options = {}) {
try {
// 获取模板
const template = await loadTemplate(templateName);
// 执行打印,业务名称默认为模板名称
return await executePrint(data, template, printerName, options, templateName);
} catch (error) {
console.error('打印失败:', error);
throw error;
}
}
/**
* 加载打印模板
* @param {string} templateName 模板名称
* @returns {Promise<Object>} 模板对象
*/
async function loadTemplate(templateName) {
// 如果是常量形式,获取实际的键名
const templateKey = typeof templateName === 'symbol' ? templateName.description : templateName;
if (!TEMPLATE_MAP[templateKey]) {
throw new Error(`未找到打印模板: ${templateKey}`);
}
try {
const templateModule = await TEMPLATE_MAP[templateKey]();
return templateModule.default || templateModule;
} catch (error) {
console.error(`加载模板 ${templateKey} 失败:`, error);
throw error;
}
}
/**
* 带打印机选择的极简打印方法
* @param {string} templateName 打印模板名称
* @param {Array|Object} data 打印数据
* @param {Function} showPrinterDialog 显示打印机选择对话框的函数
* @param {Object} modal 消息提示对象
* @param {Function} callback 打印完成后的回调函数(可选)
* @returns {Promise} 打印结果Promise
*/
export async function simplePrintWithDialog(
templateName,
data,
showPrinterDialog,
modal,
callback
) {
try {
// 获取模板
const template = await loadTemplate(templateName);
// 执行打印
await selectPrinterAndPrint(data, template, showPrinterDialog, modal, callback, templateName);
} catch (error) {
modal.msgError(error.message || '打印失败');
if (callback) callback(error);
}
}
// 导出模板名称常量
export const PRINT_TEMPLATE = {
// CLINIC_CHARGE: 'CLINIC_CHARGE',
DAY_END: 'DAY_END',
WESTERN_MEDICINE: 'WESTERN_MEDICINE',
IN_HOSPITAL_DISPENSING: 'IN_HOSPITAL_DISPENSING',
//门诊挂号
OUTPATIENT_REGISTRATION: 'OUTPATIENT_REGISTRATION',
//门诊收费
OUTPATIENT_CHARGE: 'OUTPATIENT_CHARGE',
//处方签
PRESCRIPTION: 'PRESCRIPTION',
//处置单
DISPOSAL: 'DISPOSAL',
};
/**
* 获取打印机列表
* @returns {Array} 打印机列表
*/
export function getPrinterList() {
try {
const printerList =
window.hiprint && window.hiprint.hiwebSocket
? window.hiprint.hiwebSocket.getPrinterList()
: [];
return printerList || [];
} catch (error) {
console.error('获取打印机列表失败:', error);
return [];
}
}
import useUserStore from '@/store/modules/user';
/**
* 获取当前登录用户ID
* @returns {string} 用户ID
*/
function getCurrentUserId() {
try {
// 从Pinia store中获取当前用户ID
const userStore = useUserStore();
return userStore.id || '';
} catch (e) {
console.error('获取用户ID失败:', e);
return '';
}
}
/**
* 生成打印机缓存键
* @param {string} businessName 打印业务名称
* @returns {string} 缓存键
*/
function getPrinterCacheKey(businessName) {
const userId = getCurrentUserId();
return `selectedPrinter_${businessName || 'default'}_${userId}`;
}
/**
* 从缓存获取上次选择的打印机
* @param {string} businessName 打印业务名称
* @returns {string} 打印机名称
*/
export function getCachedPrinter(businessName = 'default') {
const cacheKey = getPrinterCacheKey(businessName);
return localStorage.getItem(cacheKey) || '';
}
/**
* 保存打印机选择到缓存
* @param {string} printerName 打印机名称
* @param {string} businessName 打印业务名称
*/
export function savePrinterToCache(printerName, businessName = 'default') {
if (printerName) {
const cacheKey = getPrinterCacheKey(businessName);
localStorage.setItem(cacheKey, printerName);
}
}
/**
* 执行打印操作
* @param {Array} data 打印数据
* @param {Object} template 打印模板
* @param {string} printerName 打印机名称(可选)
* @param {Object} options 打印选项(可选)
* @param {string} businessName 打印业务名称(可选)
* @returns {Promise} 打印结果Promise
*/
export function executePrint(data, template, printerName, options = {}, businessName = 'default') {
return new Promise((resolve, reject) => {
try {
if (!window.hiprint) {
throw new Error('打印插件未加载');
}
const hiprintTemplate = new window.hiprint.PrintTemplate({ template });
const printOptions = {
title: '打印标题',
height: 210,
width: 148,
...options,
};
// 如果指定了打印机,添加到打印选项中
if (printerName) {
printOptions.printer = printerName;
// 保存到缓存
savePrinterToCache(printerName, businessName);
}
// 打印成功回调
hiprintTemplate.on('printSuccess', function (e) {
resolve({ success: true, event: e });
});
// 打印失败回调
hiprintTemplate.on('printError', function (e) {
reject({ success: false, event: e, message: '打印失败' });
});
// 执行打印
hiprintTemplate.print2(data, printOptions);
} catch (error) {
reject({ success: false, error: error, message: error.message || '打印过程中发生错误' });
}
});
}
/**
* 选择打印机并执行打印
* @param {Array} data 打印数据
* @param {Object} template 打印模板
* @param {Function} showPrinterDialog 显示打印机选择对话框的函数
* @param {Object} modal 消息提示对象
* @param {Function} callback 打印完成后的回调函数
* @param {string} businessName 打印业务名称(可选)
*/
export async function selectPrinterAndPrint(
data,
template,
showPrinterDialog,
modal,
callback,
businessName = 'default'
) {
try {
// 获取打印机列表
const printerList = getPrinterList();
if (printerList.length === 0) {
modal.msgWarning('未检测到可用打印机');
return;
}
// 获取缓存的打印机
const cachedPrinter = getCachedPrinter(businessName);
let selectedPrinter = '';
// 判断打印机选择逻辑
if (printerList.length === 1) {
selectedPrinter = printerList[0].name;
await executePrint(data, template, selectedPrinter, {}, businessName);
if (callback) callback();
} else if (cachedPrinter && printerList.some((printer) => printer.name === cachedPrinter)) {
selectedPrinter = cachedPrinter;
await executePrint(data, template, selectedPrinter, {}, businessName);
if (callback) callback();
} else {
// 调用显示打印机选择对话框的函数
showPrinterDialog(printerList, async (chosenPrinter) => {
try {
await executePrint(data, template, chosenPrinter, {}, businessName);
if (callback) callback();
} catch (error) {
modal.msgError(error.message || '打印失败');
}
});
}
} catch (error) {
modal.msgError(error.message || '获取打印机列表失败');
}
}
// 默认导出简化的打印方法
export default {
print: simplePrint,
printWithDialog: simplePrintWithDialog,
TEMPLATE: PRINT_TEMPLATE,
executePrint,
selectPrinterAndPrint,
getPrinterList,
getCachedPrinter,
savePrinterToCache,
};