import { getWarehouseAreaSimpleList } from '#/api/mes/wm/warehouse/area';
|
import { getWarehouseSimpleList } from '#/api/mes/wm/warehouse';
|
import { getWarehouseLocationSimpleList } from '#/api/mes/wm/warehouse/location';
|
|
export interface WmLocationMaps {
|
warehouseNameMap: Record<number, string>;
|
locationNameMap: Record<number, string>;
|
areaNameMap: Record<number, string>;
|
}
|
|
let cached: WmLocationMaps | null = null;
|
|
/** 加载仓库/库区/库位 ID -> 名称映射(模块级缓存,仅首次加载) */
|
export async function getWmLocationMaps(): Promise<WmLocationMaps> {
|
if (cached) {
|
return cached;
|
}
|
const [warehouses, locations, areas] = await Promise.all([
|
getWarehouseSimpleList(),
|
getWarehouseLocationSimpleList(),
|
getWarehouseAreaSimpleList(),
|
]);
|
cached = {
|
warehouseNameMap: Object.fromEntries(
|
warehouses.map((w) => [w.id!, w.name || w.code || '']),
|
),
|
locationNameMap: Object.fromEntries(
|
locations.map((l) => [l.id!, l.name || l.code || '']),
|
),
|
areaNameMap: Object.fromEntries(
|
areas.map((a) => [a.id!, a.name || a.code || '']),
|
),
|
};
|
return cached;
|
}
|
|
/** 根据 ID 渲染 仓库/库区/库位 文本(ID 缺失时返回空串) */
|
export function formatWmLocation(
|
maps: WmLocationMaps,
|
warehouseId?: number,
|
locationId?: number,
|
areaId?: number,
|
): string {
|
return [
|
warehouseId ? maps.warehouseNameMap[warehouseId] : '',
|
locationId ? maps.locationNameMap[locationId] : '',
|
areaId ? maps.areaNameMap[areaId] : '',
|
]
|
.filter(Boolean)
|
.join(' / ');
|
}
|