From 1ddd3f8c9045f8dfd1dffe1d21ff9037ba206253 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Thu, 27 Nov 2025 18:29:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/inventory/StockListTable.vue | 6 ++--- src/enums.js | 25 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/inventory/StockListTable.vue b/src/components/inventory/StockListTable.vue index c515cd99..a68fd1ae 100644 --- a/src/components/inventory/StockListTable.vue +++ b/src/components/inventory/StockListTable.vue @@ -14,7 +14,7 @@ @@ -40,7 +40,7 @@ import { ref, onMounted, watch } from 'vue'; import { InventoryApi } from '../../api/inventory'; import { ElMessage } from 'element-plus'; import { formatRFC3339, formatWeight } from '../../utils/format'; -import { StockLogSourceType } from '../../enums'; // 导入 StockLogSourceType +import { getStockLogSourceTypeLabel } from '../../enums'; // 导入 getStockLogSourceTypeLabel export default { name: 'StockListTable', @@ -130,7 +130,7 @@ export default { formatRFC3339, formatWeight, handleAdjust, - StockLogSourceType, // 暴露 StockLogSourceType 给模板 + getStockLogSourceTypeLabel, // 暴露辅助函数给模板 }; }, }; diff --git a/src/enums.js b/src/enums.js index 947a9600..2bc7b1ea 100644 --- a/src/enums.js +++ b/src/enums.js @@ -79,6 +79,31 @@ export const StockLogSourceType = { FERMENT_END: '发酵入库', // 发酵料产出,作为新原料计入库存 }; +/** + * 根据库存变动来源的键或值获取其对应的中文标签。 + * @param {string} sourceTypeKeyOrValue - 库存变动来源的键 (如 "PURCHASE") 或值 (如 "采购入库")。 + * @returns {string} 对应的中文标签,如果未找到则返回 '--'。 + */ +export function getStockLogSourceTypeLabel(sourceTypeKeyOrValue) { + if (!sourceTypeKeyOrValue) { + return '--'; + } + + // 尝试直接通过键查找 + if (StockLogSourceType[sourceTypeKeyOrValue]) { + return StockLogSourceType[sourceTypeKeyOrValue]; + } + + // 尝试通过值反向查找 + for (const key in StockLogSourceType) { + if (StockLogSourceType[key] === sourceTypeKeyOrValue) { + return StockLogSourceType[key]; + } + } + + return '--'; +} + /** * 用药原因 * @enum {string}