Files
syops/frontend/src/features/chat/leave/leavePayload.ts
T

35 lines
1.4 KiB
TypeScript

/**
* 请假:leave-form / leave-confirmation / leave-result payload 读取。
*/
import type { ChatMessage } from '../types/chat.types';
import type {
LeaveConfirmationPayload,
LeaveFormPayload,
LeaveRequestFormData,
LeaveResultPayload,
} from '../types/leave.types';
import type { Ref } from 'vue';
export function getLeaveFormPayload(chatMsg: ChatMessage): LeaveFormPayload | null {
return chatMsg?.type === 'leave-form' && chatMsg?.payload ? chatMsg.payload as LeaveFormPayload : null;
}
export function getLeaveConfirmationPayload(chatMsg: ChatMessage): LeaveConfirmationPayload | null {
return chatMsg?.type === 'leave-confirmation' && chatMsg?.payload ? chatMsg.payload as LeaveConfirmationPayload : null;
}
export function getLeaveResultPayload(chatMsg: ChatMessage): LeaveResultPayload | null {
return chatMsg?.type === 'leave-result' && chatMsg?.payload ? chatMsg.payload as LeaveResultPayload : null;
}
export function findMessageIndexByLocalId(messages: Ref<ChatMessage[]>, localId: string): number {
return messages.value.findIndex((m) => m?.local_id === localId || (m?.payload as LeaveFormPayload | undefined)?.formId === localId);
}
export function getLeaveAgentDisplayValue(form: LeaveRequestFormData): string {
if (!form.agentName) return '';
const parts = [form.agentName];
if (form.agentEmployeeId) parts.push(form.agentEmployeeId);
return parts.join(' / ');
}