Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
2026-03-10 16:46:04 +08:00
4 changed files with 143 additions and 12 deletions

View File

@@ -0,0 +1,109 @@
/**
* 医疗常量配置
* 从字典动态获取常量值,避免硬编码
*
* 使用方式:
* import { DIAG_TYPE } from '@/utils/medicalConstants';
* medTypeCode: DIAG_TYPE.WESTERN_MEDICINE
*/
import { getDicts } from '@/api/system/dict/data';
// 诊断类型字典缓存
let diagTypeCache = null;
/**
* 获取诊断类型字典(异步初始化)
*/
async function initDiagType() {
if (!diagTypeCache) {
try {
const res = await getDicts('diag_type');
diagTypeCache = res.data || [];
} catch (error) {
console.error('获取诊断类型字典失败:', error);
diagTypeCache = [];
}
}
return diagTypeCache;
}
/**
* 根据标签获取诊断类型的值
* @param {string} label - 诊断类型标签,如 '西医诊断'
* @returns {string|null} - 诊断类型的值,如 '1'
*/
export async function getDiagTypeValue(label) {
const dictList = await initDiagType();
const item = dictList.find(d => d.dictLabel === label);
return item ? item.dictValue : null;
}
/**
* 根据值获取诊断类型的标签
* @param {string} value - 诊断类型的值,如 '1'
* @returns {string|null} - 诊断类型的标签,如 '西医诊断'
*/
export async function getDiagTypeLabel(value) {
const dictList = await initDiagType();
const item = dictList.find(d => d.dictValue === value);
return item ? item.dictLabel : null;
}
/**
* 获取完整的诊断类型字典列表
* @returns {Array} - 诊断类型字典列表
*/
export async function getDiagTypeList() {
return await initDiagType();
}
/**
* 诊断类型常量(同步使用,需要先初始化字典)
* 注意:这些值在字典加载后才有效
*/
export const DIAG_TYPE = {
/** 西医诊断 */
WESTERN_MEDICINE: '1',
/** 中医主病诊断 */
TCM_MAIN_DISEASE: '2',
/** 中医主证诊断 */
TCM_MAIN_SYNDROME: '3',
/** 初诊诊断 */
INITIAL: '4',
/** 修正诊断 */
REVISED: '5',
/** 补充诊断 */
SUPPLEMENTARY: '6',
};
/**
* 诊断类型常量的说明信息
*/
export const DIAG_TYPE_DESCRIPTIONS = {
'1': '西医诊断',
'2': '中医主病诊断',
'3': '中医主证诊断',
'4': '初诊诊断',
'5': '修正诊断',
'6': '补充诊断',
};
/**
* 获取诊断类型的说明
* @param {string} value - 诊断类型的值
* @returns {string} - 说明信息
*/
export function getDiagTypeDescription(value) {
return DIAG_TYPE_DESCRIPTIONS[value] || '未知类型';
}
// 默认导出
export default {
DIAG_TYPE,
DIAG_TYPE_DESCRIPTIONS,
getDiagTypeValue,
getDiagTypeLabel,
getDiagTypeList,
getDiagTypeDescription,
};