feat(i18n): 将前端用户可见中文硬编码改为四语言
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dce915ea30
commit
ac7b53a523
105 files changed
+2928
-647
No files matched your search
@@ -1,14 +1,30 @@
|
||||
/**
|
||||
* 请假:假种标签、时长/是否展示、余额数字格式化。
|
||||
* features/chat/leave/leaveDisplay.ts
|
||||
* 用途:请假假种标签、时长/是否展示、余额数字格式化。
|
||||
* 依赖:leave.ts 常量、leaveDateTime、vue-i18n t()。
|
||||
* 逻辑:由 LeaveMessageBlock / useChatLeave 在展示层调用;假别文案经 labelKey + t() 解析。
|
||||
*/
|
||||
import { LEAVE_TYPES } from '../constants/leave';
|
||||
import { LEAVE_TYPES, LEAVE_TYPE_LABEL_KEYS } 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;
|
||||
/**
|
||||
* 按 OA 假别编码解析本地化标签。
|
||||
* 核心逻辑:优先 LEAVE_TYPE_LABEL_KEYS;找不到则回退编码本身。
|
||||
* @param val - OA 假别编码
|
||||
* @param t - i18n t 函数
|
||||
* @returns 本地化假别名
|
||||
*/
|
||||
export function getLeaveTypeLabel(val: string, t: (key: string) => string): string {
|
||||
const key = LEAVE_TYPE_LABEL_KEYS[val] || LEAVE_TYPES.find((x) => x.value === val)?.labelKey;
|
||||
return key ? t(key) : val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按时长与假别计价单位格式化展示文案。
|
||||
* @param hours - 小时数
|
||||
* @param leaveType - 假别编码
|
||||
* @param t - i18n t 函数
|
||||
*/
|
||||
export function formatDurationLabel(
|
||||
hours: number,
|
||||
leaveType: string | undefined,
|
||||
@@ -22,12 +38,20 @@ export function formatDurationLabel(
|
||||
return `${hours} ${t('chat.hourUnit')}`;
|
||||
}
|
||||
|
||||
export function formatYesNoLabel(value: 0 | 1 | null): string {
|
||||
if (value === 0) return '是';
|
||||
if (value === 1) return '否';
|
||||
return '未选择';
|
||||
/**
|
||||
* 将 0/1 是否字段格式化为是/否/未选择。
|
||||
* @param value - OA 是否字段
|
||||
* @param t - i18n t 函数
|
||||
*/
|
||||
export function formatYesNoLabel(value: 0 | 1 | null, t: (key: string) => string): string {
|
||||
if (value === 0) return t('chat.yes');
|
||||
if (value === 1) return t('chat.no');
|
||||
return t('chat.notSelected');
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化假期余额数字;空值显示「暂无数据」。
|
||||
*/
|
||||
export function formatLeaveBalanceNumber(value: unknown, t: (key: string) => string): string {
|
||||
if (value === null || value === undefined) return t('chat.noData');
|
||||
const num = Number(value);
|
||||
|
||||
@@ -114,7 +114,7 @@ export function createLeaveFormApi(ctx: LeaveFormContext) {
|
||||
const unit = isByDay ? ctx.t('chat.dayUnit') : ctx.t('chat.hourUnit');
|
||||
const requestedDisplay = isByDay ? Math.round(requestedHours / 8) : requestedHours;
|
||||
const remainingDisplay = isByDay ? Math.round(balance.remaining_hours / 8) : balance.remaining_hours;
|
||||
const label = getLeaveTypeLabel(form.leaveType);
|
||||
const label = getLeaveTypeLabel(form.leaveType, ctx.t);
|
||||
ctx.msg.warning(ctx.t('chat.durationExceedsBalance', {
|
||||
label,
|
||||
requested: `${requestedDisplay}${unit}`,
|
||||
|
||||
Reference in new issue
Block a user