年假限制优化
This commit is contained in:
1 parent
5eb36e53ae
commit
fabb96013c
2 files changed
+76
-19
No files matched your search
@@ -1266,6 +1266,7 @@ const messages = {
|
||||
leaveBalanceTableUsed: 'Used',
|
||||
leaveBalanceTableRemaining: 'Remaining',
|
||||
leaveBalanceContactHr: 'If needed, please contact HR to confirm leave data.',
|
||||
durationExceedsBalance: '{label}申请时长({requested})超出剩余额度({remaining}),无法提交。',
|
||||
leaveConfirmPrompt: 'Please confirm the following leave information before submitting to OA.',
|
||||
oaLeaveSubmitFailed: 'OA leave submission failed, please try again later.',
|
||||
leaveSubmitFailedPrefix: 'Leave submission failed: {error}',
|
||||
@@ -2699,6 +2700,7 @@ const messages = {
|
||||
leaveBalanceTableUsed: '已休',
|
||||
leaveBalanceTableRemaining: '当前剩余',
|
||||
leaveBalanceContactHr: '如有疑问,请联系人事部门确认假期数据。',
|
||||
durationExceedsBalance: '{label}申请时长({requested})超出剩余额度({remaining}),无法提交。',
|
||||
leaveConfirmPrompt: '请确认以下请假信息,确认无误后再提交到 OA。',
|
||||
oaLeaveSubmitFailed: 'OA 请假提交失败,请稍后重试。',
|
||||
leaveSubmitFailedPrefix: '请假单提交失败:{error}',
|
||||
@@ -3991,6 +3993,7 @@ const messages = {
|
||||
leaveBalanceTableUsed: '已休',
|
||||
leaveBalanceTableRemaining: '目前剩餘',
|
||||
leaveBalanceContactHr: '如有疑問,請聯繫人事部門確認假期資料。',
|
||||
durationExceedsBalance: '{label}申請時長({requested})超出剩餘額度({remaining}),無法提交。',
|
||||
leaveConfirmPrompt: '請確認以下請假資訊,確認無誤後再提交到 OA。',
|
||||
oaLeaveSubmitFailed: 'OA 請假提交失敗,請稍後重試。',
|
||||
leaveSubmitFailedPrefix: '請假單提交失敗:{error}',
|
||||
@@ -5200,6 +5203,7 @@ const messages = {
|
||||
leaveBalanceTableUsed: 'ใช้ไปแล้ว',
|
||||
leaveBalanceTableRemaining: 'คงเหลือปัจจุบัน',
|
||||
leaveBalanceContactHr: 'หากมีข้อสงสัย โปรดติดต่อฝ่ายบุคคลเพื่อตรวจสอบข้อมูลวันลา',
|
||||
durationExceedsBalance: '{label}ระยะเวลาที่ขอ({requested})เกินยอดคงเหลือ({remaining}) ไม่สามารถส่งได้',
|
||||
leaveConfirmPrompt: 'โปรดยืนยันข้อมูลการลาพนักงานก่อนส่งไปยัง OA',
|
||||
oaLeaveSubmitFailed: 'ส่งคำขอลา OA ไม่สำเร็จ กรุณาลองใหม่อีกครั้ง',
|
||||
leaveSubmitFailedPrefix: 'ส่งใบลาล้มเหลว: {error}',
|
||||
|
||||
@@ -937,7 +937,7 @@ const calculateDurationHours = (startTime: string, endTime: string) => {
|
||||
const formatDurationLabel = (hours: number, leaveType?: string) => {
|
||||
if (!hours) return `0 ${isLeaveTypeByDay(leaveType || '') ? t('chat.dayUnit') : t('chat.hourUnit')}`;
|
||||
if (isLeaveTypeByDay(leaveType || '')) {
|
||||
const days = Math.round(hours / 8 * 100) / 100;
|
||||
const days = Math.round(hours / 8);
|
||||
return `${days} ${t('chat.dayUnit')}`;
|
||||
}
|
||||
return `${hours} ${t('chat.hourUnit')}`;
|
||||
@@ -1077,7 +1077,18 @@ const extractLeaveInfoFromIntent = (content: string): ExtractedLeaveInfo | null
|
||||
}
|
||||
|
||||
if (startTime && endTime) {
|
||||
durationHours = durationHours || calculateDurationHours(startTime, endTime);
|
||||
if (isLeaveTypeByDay(leaveType)) {
|
||||
const s = parseDateTime(startTime);
|
||||
const e = parseDateTime(endTime);
|
||||
if (s && e && e.getTime() > s.getTime()) {
|
||||
const sd = new Date(s.getFullYear(), s.getMonth(), s.getDate());
|
||||
const ed = new Date(e.getFullYear(), e.getMonth(), e.getDate());
|
||||
const days = Math.max(1, Math.round((ed.getTime() - sd.getTime()) / (24 * 3600 * 1000)) + 1);
|
||||
durationHours = days * 8;
|
||||
}
|
||||
} else {
|
||||
durationHours = durationHours || calculateDurationHours(startTime, endTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (!leaveType && !startTime) return null;
|
||||
@@ -1101,18 +1112,19 @@ const createLeaveFormData = (content?: string, extractedInfo?: ExtractedLeaveInf
|
||||
const startTime = extractedInfo?.startTime || defaultStart;
|
||||
const endTime = extractedInfo?.endTime || defaultEnd;
|
||||
let durationHours: number;
|
||||
if (extractedInfo?.durationHours) {
|
||||
durationHours = extractedInfo.durationHours;
|
||||
} else if (isByDay) {
|
||||
if (isByDay) {
|
||||
const start = parseDateTime(startTime);
|
||||
const end = parseDateTime(endTime);
|
||||
if (start && end && end.getTime() > start.getTime()) {
|
||||
const diffMs = end.getTime() - start.getTime();
|
||||
const days = Math.ceil(diffMs / (24 * 3600 * 1000));
|
||||
const startDate = new Date(start.getFullYear(), start.getMonth(), start.getDate());
|
||||
const endDate = new Date(end.getFullYear(), end.getMonth(), end.getDate());
|
||||
const days = Math.max(1, Math.round((endDate.getTime() - startDate.getTime()) / (24 * 3600 * 1000)) + 1);
|
||||
durationHours = days * 8;
|
||||
} else {
|
||||
durationHours = 8;
|
||||
}
|
||||
} else if (extractedInfo?.durationHours) {
|
||||
durationHours = extractedInfo.durationHours;
|
||||
} else {
|
||||
durationHours = calculateDurationHours(startTime, endTime);
|
||||
}
|
||||
@@ -1147,8 +1159,9 @@ const syncLeaveDuration = (form: LeaveRequestFormData) => {
|
||||
form.durationHours = 0;
|
||||
return;
|
||||
}
|
||||
const diffMs = end.getTime() - start.getTime();
|
||||
const days = Math.ceil(diffMs / (24 * 3600 * 1000));
|
||||
const startDate = new Date(start.getFullYear(), start.getMonth(), start.getDate());
|
||||
const endDate = new Date(end.getFullYear(), end.getMonth(), end.getDate());
|
||||
const days = Math.max(1, Math.round((endDate.getTime() - startDate.getTime()) / (24 * 3600 * 1000)) + 1);
|
||||
form.durationHours = days * 8;
|
||||
} else {
|
||||
form.durationHours = calculateDurationHours(form.startTime, form.endTime);
|
||||
@@ -1647,8 +1660,8 @@ const validateLeaveForm = (form: LeaveRequestFormData) => {
|
||||
return '';
|
||||
};
|
||||
|
||||
const submitLeaveForm = (msg: any) => {
|
||||
const payload = getLeaveFormPayload(msg);
|
||||
const submitLeaveForm = async (chatMsg: any) => {
|
||||
const payload = getLeaveFormPayload(chatMsg);
|
||||
if (!payload) return;
|
||||
syncLeaveDuration(payload.form);
|
||||
const error = validateLeaveForm(payload.form);
|
||||
@@ -1657,6 +1670,26 @@ const submitLeaveForm = (msg: any) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NEED_BALANCE_CHECK_TYPES.has(payload.form.leaveType)) {
|
||||
const balance = await checkLeaveBalance(payload.form.leaveType);
|
||||
if (balance && balance.remaining_hours !== null && balance.remaining_hours !== undefined) {
|
||||
const requestedHours = payload.form.durationHours;
|
||||
if (requestedHours > balance.remaining_hours) {
|
||||
const isByDay = isLeaveTypeByDay(payload.form.leaveType);
|
||||
const unit = isByDay ? t('chat.dayUnit') : 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(payload.form.leaveType);
|
||||
msg.warning(t('chat.durationExceedsBalance', {
|
||||
label,
|
||||
requested: `${requestedDisplay}${unit}`,
|
||||
remaining: `${remainingDisplay}${unit}`,
|
||||
}));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const existingConfirmIndex = messages.value.findIndex((item: any) => item?.type === 'leave-confirmation' && item?.payload?.formId === payload.formId);
|
||||
if (existingConfirmIndex >= 0) {
|
||||
messages.value.splice(existingConfirmIndex, 1);
|
||||
@@ -1678,13 +1711,12 @@ const submitLeaveForm = (msg: any) => {
|
||||
};
|
||||
messages.value.push(confirmMsg);
|
||||
|
||||
// 保存更新后的表单消息和新的确认消息
|
||||
saveLocalMessageToBackend(msg);
|
||||
saveLocalMessageToBackend(chatMsg);
|
||||
saveLocalMessageToBackend(confirmMsg);
|
||||
};
|
||||
|
||||
const editLeaveConfirmation = (msg: any, index: number) => {
|
||||
const payload = getLeaveConfirmationPayload(msg);
|
||||
const editLeaveConfirmation = (chatMsg: any, index: number) => {
|
||||
const payload = getLeaveConfirmationPayload(chatMsg);
|
||||
if (!payload) return;
|
||||
const sourceIndex = findMessageIndexByLocalId(payload.formId);
|
||||
if (sourceIndex >= 0) {
|
||||
@@ -1702,9 +1734,30 @@ const editLeaveConfirmation = (msg: any, index: number) => {
|
||||
messages.value.splice(index, 1);
|
||||
};
|
||||
|
||||
const confirmLeaveSubmission = async (msg: any) => {
|
||||
const payload = getLeaveConfirmationPayload(msg);
|
||||
const confirmLeaveSubmission = async (chatMsg: any) => {
|
||||
const payload = getLeaveConfirmationPayload(chatMsg);
|
||||
if (!payload || payload.submitting) return;
|
||||
|
||||
if (NEED_BALANCE_CHECK_TYPES.has(payload.form.leaveType)) {
|
||||
const balance = await checkLeaveBalance(payload.form.leaveType);
|
||||
if (balance && balance.remaining_hours !== null && balance.remaining_hours !== undefined) {
|
||||
const requestedHours = payload.form.durationHours;
|
||||
if (requestedHours > balance.remaining_hours) {
|
||||
const isByDay = isLeaveTypeByDay(payload.form.leaveType);
|
||||
const unit = isByDay ? t('chat.dayUnit') : 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(payload.form.leaveType);
|
||||
msg.warning(t('chat.durationExceedsBalance', {
|
||||
label,
|
||||
requested: `${requestedDisplay}${unit}`,
|
||||
remaining: `${remainingDisplay}${unit}`,
|
||||
}));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
payload.submitting = true;
|
||||
|
||||
const sourceIndex = findMessageIndexByLocalId(payload.formId);
|
||||
@@ -1746,8 +1799,8 @@ const confirmLeaveSubmission = async (msg: any) => {
|
||||
};
|
||||
messages.value.push(resultMsg);
|
||||
payload.confirmed = true;
|
||||
payload.submitting = false; // Add this line to immediately clear submitting state on success
|
||||
saveLocalMessageToBackend(msg);
|
||||
payload.submitting = false;
|
||||
saveLocalMessageToBackend(chatMsg);
|
||||
saveLocalMessageToBackend(resultMsg);
|
||||
} catch (error: any) {
|
||||
const errorMessage = error?.message || t('chat.oaLeaveSubmitFailed');
|
||||
|
||||
Reference in new issue
Block a user