37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
/**
|
|
* 请假:假种标签、时长/是否展示、余额数字格式化。
|
|
*/
|
|
import { LEAVE_TYPES } from '../constants/leave';
|
|
import { isLeaveTypeByDay } from './leaveDateTime';
|
|
|
|
export function getLeaveTypeLabel(val: string): string {
|
|
const item = LEAVE_TYPES.find((x) => x.value === val);
|
|
return item ? item.label : val;
|
|
}
|
|
|
|
export function formatDurationLabel(
|
|
hours: number,
|
|
leaveType: string | undefined,
|
|
t: (key: string) => string,
|
|
): string {
|
|
if (!hours) return `0 ${isLeaveTypeByDay(leaveType || '') ? t('chat.dayUnit') : t('chat.hourUnit')}`;
|
|
if (isLeaveTypeByDay(leaveType || '')) {
|
|
const days = Math.round(hours / 8);
|
|
return `${days} ${t('chat.dayUnit')}`;
|
|
}
|
|
return `${hours} ${t('chat.hourUnit')}`;
|
|
}
|
|
|
|
export function formatYesNoLabel(value: 0 | 1 | null): string {
|
|
if (value === 0) return '是';
|
|
if (value === 1) return '否';
|
|
return '未选择';
|
|
}
|
|
|
|
export function formatLeaveBalanceNumber(value: unknown, t: (key: string) => string): string {
|
|
if (value === null || value === undefined) return t('chat.noData');
|
|
const num = Number(value);
|
|
if (Number.isNaN(num)) return String(value);
|
|
return Number.isInteger(num) ? String(num) : num.toFixed(2);
|
|
}
|