GuDingZiChan/frontend/src/views/inventory/inventoryScopeSummary.ts
WuYongJie 0dc3c09315 feat(资产与打印): 提交近期借还盘点与打印助手源码
- 提交借用单缺失异常处理、扫码借还搜索与站内消息快捷处理源码
- 提交盘点范围、多终端打印、组织同步与认证模式相关源码
- 提交 .NET/Node 打印助手及版本清单源码
2026-03-27 20:18:31 +08:00

61 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { InventoryScopeEntity } from '@/types'
type InventoryScopeLike = {
scope_departments?: InventoryScopeEntity[] | null
scope_asset_types?: InventoryScopeEntity[] | null
scope_storage_locations?: InventoryScopeEntity[] | null
scope_department_name?: string | null
scope_asset_type_name?: string | null
}
const normalizeScopeEntities = (
values?: InventoryScopeEntity[] | null,
fallbackName?: string | null
) => {
if (Array.isArray(values) && values.length > 0) {
return values
}
if (fallbackName) {
return [
{
id: 0,
name: fallbackName
}
]
}
return []
}
const formatScopeSegment = (label: string, values: InventoryScopeEntity[]) => {
if (values.length === 0) {
return ''
}
if (values.length === 1) {
return `${label}:${values[0].name}`
}
return `${label}:已选 ${values.length} 项`
}
export const buildInventoryScopeLabel = (scope: InventoryScopeLike) => {
const segments = [
formatScopeSegment(
'部门',
normalizeScopeEntities(scope.scope_departments, scope.scope_department_name)
),
formatScopeSegment(
'资产类型',
normalizeScopeEntities(scope.scope_asset_types, scope.scope_asset_type_name)
),
formatScopeSegment(
'地区',
normalizeScopeEntities(scope.scope_storage_locations)
)
].filter(Boolean)
return segments.length > 0 ? segments.join(' / ') : '全量资产范围'
}