Files
syops/frontend/src/features/chat/page/useChatPageHandlerBundles.ts
T

124 lines
5.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 对话页:子组件 inject 用的 handlers 对象打包(请假表单、发货消息、消息气泡)。
*/
import type { LeaveMessageHandlers } from '../components/messages/LeaveMessageBlock.vue';
import type { ShippingMessageHandlers } from '../components/messages/shippingMessageHandlers';
import type { TrainingHandlers } from '../components/messages/TrainingExamQuestionMessage.vue';
import type { useChatLeave } from '../composables/useChatLeave';
import type { useChatShipping } from '../composables/useChatShipping';
import type { useTrainingWorkspace } from '../composables/useTrainingWorkspace';
import type { Ref } from 'vue';
type LeaveHandlerSource = Pick<
ReturnType<typeof useChatLeave>,
| 'getLeaveFormPayload'
| 'getLeaveConfirmationPayload'
| 'getLeaveResultPayload'
| 'getLeaveAgentDisplayValue'
| 'getLeaveTypeLabel'
| 'formatDurationLabel'
| 'formatYesNoLabel'
| 'syncLeaveDuration'
| 'openLeaveAgentDialog'
| 'openOALeaveRequestDirectly'
| 'openOARequestDirectly'
| 'submitLeaveForm'
| 'editLeaveConfirmation'
| 'confirmLeaveSubmission'
>;
type ShippingHandlerSource = Pick<
ReturnType<typeof useChatShipping>,
| 'getShippingParseReviewPayload'
| 'getShippingMatchResultPayload'
| 'updateShippingParseReviewHeader'
| 'updateShippingParseReviewLine'
| 'addShippingParseReviewLine'
| 'removeShippingParseReviewLine'
| 'retryOrderExtractionRun'
| 'reparseOrderExtractionRun'
| 'setShippingCandidateSelected'
| 'updateShippingCandidateSummary'
| 'resolveShippingCandidateDuplicate'
>;
type TrainingHandlerSource = ReturnType<typeof useTrainingWorkspace>;
/** 请假消息块 handlers(LeaveMessageBlock) */
export function createLeaveMessageHandlers(leave: LeaveHandlerSource): LeaveMessageHandlers {
return {
getLeaveFormPayload: leave.getLeaveFormPayload,
getLeaveConfirmationPayload: leave.getLeaveConfirmationPayload,
getLeaveResultPayload: leave.getLeaveResultPayload,
getLeaveAgentDisplayValue: leave.getLeaveAgentDisplayValue,
getLeaveTypeLabel: leave.getLeaveTypeLabel,
formatDurationLabel: leave.formatDurationLabel,
formatYesNoLabel: leave.formatYesNoLabel,
syncLeaveDuration: leave.syncLeaveDuration,
openLeaveAgentDialog: leave.openLeaveAgentDialog,
openOALeaveRequestDirectly: leave.openOALeaveRequestDirectly,
openOARequestDirectly: leave.openOARequestDirectly,
submitLeaveForm: leave.submitLeaveForm,
editLeaveConfirmation: leave.editLeaveConfirmation,
confirmLeaveSubmission: leave.confirmLeaveSubmission,
};
}
/** 发货通知订单复核与匹配消息 handlers。 */
export function createShippingMessageHandlers(shipping: ShippingHandlerSource): ShippingMessageHandlers {
return {
getParseReviewPayload: shipping.getShippingParseReviewPayload,
getMatchResultPayload: shipping.getShippingMatchResultPayload,
updateHeader: shipping.updateShippingParseReviewHeader,
updateLine: shipping.updateShippingParseReviewLine,
addLine: shipping.addShippingParseReviewLine,
removeLine: shipping.removeShippingParseReviewLine,
retryOrderExtractionRun: shipping.retryOrderExtractionRun,
reparseOrderExtractionRun: shipping.reparseOrderExtractionRun,
selectCandidate: shipping.setShippingCandidateSelected,
updateCandidate: shipping.updateShippingCandidateSummary,
resolveCandidateDuplicate: shipping.resolveShippingCandidateDuplicate,
};
}
/** 培训答题块 handlers(TrainingExamQuestionMessage) */
export function createTrainingHandlers(workspace: TrainingHandlerSource): TrainingHandlers {
return {
getQuestion: () => workspace.currentQuestion.value,
getCurrentQuestionIndex: () => workspace.currentQuestionIndex.value,
getAnsweredCount: () => workspace.answeredCount.value,
getTotalCount: () => workspace.totalQuestionCount.value,
getPassScore: () => workspace.passScore.value,
getScore: () => workspace.score.value,
getSelectedOptionId: () => workspace.selectedOptionId.value,
getAnswerLocked: () => workspace.answerLocked.value,
getFeedbackCorrect: () => workspace.currentFeedbackCorrect.value,
getAnswerLabel: () => {
const q = workspace.currentQuestion.value;
if (!q) return '';
return q.options?.find((o) => o.id === workspace.selectedOptionId.value)?.label || '';
},
getLatestExamFeedback: () => workspace.latestExamFeedback.value,
onSelect: workspace.selectAnswer,
onNext: workspace.moveToNextQuestion,
onPlayVideo: () => {
// 通过 DOM 事件或状态传递触发视频播放,这里我们直接让 workspace 标记视频模态框展示
// 注意:这里需要确保 TrainingWorkspacePanel 监听了对应的状态
workspace.showVideoModal.value = true;
},
onStartExam: workspace.startExam,
onRestartExam: workspace.restartExam,
getCorrectCount: () => workspace.latestSettledResult.value?.correctCount ?? workspace.correctCount.value,
getWrongCount: () => workspace.latestSettledResult.value?.wrongCount ?? workspace.wrongCount.value,
getResultScore: () => workspace.latestSettledResult.value?.score ?? workspace.score.value,
getResultPassed: () => workspace.latestSettledResult.value?.isPassed ?? workspace.isPassed.value,
getSummaryPoints: () => workspace.summaryPoints.value,
getSummaryChecklist: () => workspace.summaryChecklist.value,
};
}
/** 隐藏 file input ref 包裹,避免 template 自动解包 Ref */
export function createShippingPickerRefHolder(pickerRef: Ref<HTMLInputElement | null>) {
return { pickerRef };
}