Register type=dept on main app and oa-fc-host, with PC tree-select and
narrow drawer pickers storing {id,name} path snapshots; format dept values
in print and related-summary flatten.
Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
export type OaDeptValueItem = { id: string; name: string }
|
|
|
|
export function isDeptValueItem(v: unknown): v is OaDeptValueItem {
|
|
if (!v || typeof v !== 'object') return false
|
|
const o = v as Record<string, unknown>
|
|
return String(o.id || '').trim() !== '' && String(o.name || '').trim() !== ''
|
|
}
|
|
|
|
/** 单选 → item|null;多选 → items(容错把单对象包成数组) */
|
|
export function normalizeDeptModelValue(
|
|
raw: unknown,
|
|
multiple: boolean
|
|
): OaDeptValueItem | OaDeptValueItem[] | null {
|
|
if (multiple) {
|
|
if (Array.isArray(raw)) {
|
|
return raw.filter(isDeptValueItem).map((x) => ({
|
|
id: String(x.id).trim(),
|
|
name: String(x.name).trim()
|
|
}))
|
|
}
|
|
if (isDeptValueItem(raw)) {
|
|
return [{ id: String(raw.id).trim(), name: String(raw.name).trim() }]
|
|
}
|
|
return []
|
|
}
|
|
if (isDeptValueItem(raw)) {
|
|
return { id: String(raw.id).trim(), name: String(raw.name).trim() }
|
|
}
|
|
if (Array.isArray(raw) && raw.length === 1 && isDeptValueItem(raw[0])) {
|
|
return { id: String(raw[0].id).trim(), name: String(raw[0].name).trim() }
|
|
}
|
|
return null
|
|
}
|
|
|
|
export function formatDeptDisplay(raw: unknown): string {
|
|
if (Array.isArray(raw)) {
|
|
return raw
|
|
.filter(isDeptValueItem)
|
|
.map((x) => x.name)
|
|
.filter(Boolean)
|
|
.join('、')
|
|
}
|
|
if (isDeptValueItem(raw)) return raw.name
|
|
return ''
|
|
}
|