59 行
1.8 KiB
TypeScript
59 行
1.8 KiB
TypeScript
import { isUuidLike } from "./reimbursementDisplay";
|
|
|
|
export type BusinessEntityType = "reimbursement" | "leave" | "attendance_correction" | "purchase_request" | "travel_request" | string | null | undefined;
|
|
|
|
const ENTITY_NOUN_LABELS: Record<string, string> = {
|
|
reimbursement: "报销单",
|
|
leave: "请假",
|
|
attendance_correction: "考勤修正",
|
|
purchase_request: "采购单",
|
|
travel_request: "差旅单",
|
|
};
|
|
|
|
const ENTITY_SHORT_LABELS: Record<string, string> = {
|
|
reimbursement: "报销",
|
|
leave: "请假",
|
|
attendance_correction: "考勤",
|
|
purchase_request: "采购",
|
|
travel_request: "差旅",
|
|
};
|
|
|
|
export function businessEntityLabel(entityType: BusinessEntityType, options: { noun?: boolean } = {}) {
|
|
if (!entityType) {
|
|
return options.noun ? "业务单据" : "业务";
|
|
}
|
|
const labels = options.noun ? ENTITY_NOUN_LABELS : ENTITY_SHORT_LABELS;
|
|
return labels[entityType] ?? String(entityType);
|
|
}
|
|
|
|
export function compactBusinessReference(value: string | null | undefined) {
|
|
const trimmed = value?.trim();
|
|
if (!trimmed || isUuidLike(trimmed)) {
|
|
return null;
|
|
}
|
|
return trimmed;
|
|
}
|
|
|
|
export function businessPrimaryLabel(input: {
|
|
entityType: BusinessEntityType;
|
|
reference?: string | null;
|
|
title?: string | null;
|
|
fallback?: string;
|
|
}) {
|
|
const reference = compactBusinessReference(input.reference);
|
|
if (reference) {
|
|
return `${businessEntityLabel(input.entityType, { noun: true })} ${reference}`;
|
|
}
|
|
|
|
const title = input.title?.trim();
|
|
if (title && !isUuidLike(title)) {
|
|
return title;
|
|
}
|
|
|
|
return input.fallback ?? businessEntityLabel(input.entityType, { noun: true });
|
|
}
|
|
|
|
export function joinBusinessMeta(items: Array<string | null | undefined>) {
|
|
return items.map((item) => item?.trim()).filter((item): item is string => Boolean(item)).join(" · ");
|
|
}
|