优化展示

This commit is contained in:
2025-11-27 18:29:05 +08:00
parent aa50fdc9de
commit 1ddd3f8c90
2 changed files with 28 additions and 3 deletions

View File

@@ -14,7 +14,7 @@
</el-table-column> </el-table-column>
<el-table-column prop="last_operation_source_type" label="上次操作类型"> <el-table-column prop="last_operation_source_type" label="上次操作类型">
<template #default="scope"> <template #default="scope">
{{ StockLogSourceType[scope.row.last_operation_source_type] || '--' }} {{ getStockLogSourceTypeLabel(scope.row.last_operation_source_type) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="120"> <el-table-column label="操作" width="120">
@@ -40,7 +40,7 @@ import { ref, onMounted, watch } from 'vue';
import { InventoryApi } from '../../api/inventory'; import { InventoryApi } from '../../api/inventory';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import { formatRFC3339, formatWeight } from '../../utils/format'; import { formatRFC3339, formatWeight } from '../../utils/format';
import { StockLogSourceType } from '../../enums'; // 导入 StockLogSourceType import { getStockLogSourceTypeLabel } from '../../enums'; // 导入 getStockLogSourceTypeLabel
export default { export default {
name: 'StockListTable', name: 'StockListTable',
@@ -130,7 +130,7 @@ export default {
formatRFC3339, formatRFC3339,
formatWeight, formatWeight,
handleAdjust, handleAdjust,
StockLogSourceType, // 暴露 StockLogSourceType 给模板 getStockLogSourceTypeLabel, // 暴露辅助函数给模板
}; };
}, },
}; };

View File

@@ -79,6 +79,31 @@ export const StockLogSourceType = {
FERMENT_END: '发酵入库', // 发酵料产出,作为新原料计入库存 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} * @enum {string}