refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* features/chat/composables/useChatLeave.ts
|
||||
* 请假(OA)编排层:组合 leave/* 子模块,对外暴露 ChatView 所需 API。
|
||||
*
|
||||
* 消息类型约定(写入 messages 列表):
|
||||
* - leave-form:可编辑表单
|
||||
* - leave-confirmation:提交前确认
|
||||
* - leave-result:OA 提交结果
|
||||
*/
|
||||
import { computed, type ComputedRef, type Ref } from 'vue';
|
||||
import { getUserProfile } from '@/features/auth/api/user.api';
|
||||
import { LEAVE_FEATURE_AGENT_NAMES, LEAVE_TYPES } from '../constants/leave';
|
||||
import {
|
||||
createLeaveAgentPickerApi,
|
||||
createLeaveFlowApi,
|
||||
createLeaveFormApi,
|
||||
createLeaveLocalMessageApi,
|
||||
createLeaveOaLoginApi,
|
||||
formatDurationLabel,
|
||||
formatYesNoLabel,
|
||||
getLeaveAgentDisplayValue,
|
||||
getLeaveConfirmationPayload,
|
||||
getLeaveFormPayload,
|
||||
getLeaveResultPayload,
|
||||
syncLeaveDuration,
|
||||
} from '../leave';
|
||||
import { getLeaveTypeLabel } from '../leave/leaveDisplay';
|
||||
import type { ChatMessage, ChatSessionItem } from '../types/chat.types';
|
||||
import type { ChatDeps } from './chat.deps';
|
||||
|
||||
export interface UseChatLeaveOptions {
|
||||
deps: ChatDeps;
|
||||
currentAgent: Ref<{ name?: string } | null>;
|
||||
currentAgentId: ComputedRef<number>;
|
||||
currentUser: Ref<Record<string, unknown> | null>;
|
||||
currentUserDisplayName: ComputedRef<string>;
|
||||
currentUserEmployeeId: ComputedRef<string>;
|
||||
messages: Ref<ChatMessage[]>;
|
||||
conversationId: Ref<string | null>;
|
||||
isThinking: Ref<boolean>;
|
||||
history: Ref<ChatSessionItem[]>;
|
||||
loadHistory: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function useChatLeave(options: UseChatLeaveOptions) {
|
||||
const {
|
||||
deps: { t, msg },
|
||||
currentAgent,
|
||||
currentAgentId,
|
||||
currentUser,
|
||||
currentUserDisplayName,
|
||||
currentUserEmployeeId,
|
||||
messages,
|
||||
conversationId,
|
||||
isThinking,
|
||||
history,
|
||||
loadHistory,
|
||||
} = options;
|
||||
|
||||
const canUseLeaveFeature = computed(() =>
|
||||
LEAVE_FEATURE_AGENT_NAMES.has(String(currentAgent.value?.name || '').trim()),
|
||||
);
|
||||
|
||||
const { newLocalMessageId, saveLocalMessageToBackend } = createLeaveLocalMessageApi({
|
||||
conversationId,
|
||||
currentAgentId,
|
||||
});
|
||||
|
||||
const oaLogin = createLeaveOaLoginApi({
|
||||
currentUserEmployeeId,
|
||||
msg,
|
||||
t,
|
||||
});
|
||||
|
||||
const agentPicker = createLeaveAgentPickerApi({
|
||||
currentAgentId,
|
||||
messages,
|
||||
saveLocalMessageToBackend,
|
||||
});
|
||||
|
||||
const formApi = createLeaveFormApi({
|
||||
messages,
|
||||
currentUserDisplayName,
|
||||
currentUserEmployeeId,
|
||||
newLocalMessageId,
|
||||
saveLocalMessageToBackend,
|
||||
msg,
|
||||
t,
|
||||
});
|
||||
|
||||
const flowApi = createLeaveFlowApi({
|
||||
canUseLeaveFeature,
|
||||
isThinking,
|
||||
messages,
|
||||
conversationId,
|
||||
history,
|
||||
currentAgentId,
|
||||
loadHistory,
|
||||
newLocalMessageId,
|
||||
saveLocalMessageToBackend,
|
||||
createLeaveFormData: formApi.createLeaveFormData,
|
||||
checkLeaveBalance: formApi.checkLeaveBalance,
|
||||
formatLeaveBalanceNumber: formApi.formatLeaveBalanceNumber,
|
||||
msg,
|
||||
t,
|
||||
});
|
||||
|
||||
const syncCurrentUserProfile = async () => {
|
||||
if (currentUser.value?.real_name && String(currentUser.value.real_name).trim()) return;
|
||||
try {
|
||||
const data = await getUserProfile();
|
||||
currentUser.value = { ...currentUser.value, ...data };
|
||||
} catch (e) {
|
||||
console.error('Failed to load current user profile', e);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
LEAVE_TYPES,
|
||||
canUseLeaveFeature,
|
||||
...oaLogin,
|
||||
...agentPicker,
|
||||
getLeaveTypeLabel,
|
||||
formatDurationLabel: (hours: number, leaveType?: string) => formatDurationLabel(hours, leaveType, t),
|
||||
formatYesNoLabel,
|
||||
syncLeaveDuration,
|
||||
getLeaveFormPayload,
|
||||
getLeaveConfirmationPayload,
|
||||
getLeaveResultPayload,
|
||||
getLeaveAgentDisplayValue,
|
||||
submitLeaveForm: formApi.submitLeaveForm,
|
||||
editLeaveConfirmation: formApi.editLeaveConfirmation,
|
||||
confirmLeaveSubmission: formApi.confirmLeaveSubmission,
|
||||
tryHandleLeaveSend: flowApi.tryHandleLeaveSend,
|
||||
handleLeaveMarkdownClick: flowApi.handleLeaveMarkdownClick,
|
||||
syncCurrentUserProfile,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user