refactor(backend): 重构后端代码 wave 3

This commit is contained in:
sophie committed 2026-07-29 19:12:49 +08:00
1 parent affe139bf9
commit 8415653365
97 files changed
+4673 -6164

No files matched your search

@@ -4,7 +4,7 @@
*/
import { computed, ref, watch, type ComputedRef } from 'vue';
import { BusinessError } from '@/shared/api/client';
import { getUserAgent, listUserAgents } from '@/features/auth/api/user.api';
import { getUserAgent, listUserAgents } from '@/features/user';
import { setLastChatAgentId } from '@/shared/utils/lastChatAgent';
import { sortAgentsByCategory } from '@/shared/utils/agent-category.utils';
import {
@@ -51,31 +51,33 @@ export interface UseChatAgentOptions {
chatGuides: Pick<UseChatGuidesReturn, 'loadGuides' | 'clearGuides'>;
}
type ChatAgentOption = AgentRegistryFields & {
id: number;
name: string;
description: string;
icon_url?: string;
dify_app_type?: 'chatflow' | 'workflow';
category?: string | null;
sub_category?: string | null;
sort_order?: number;
is_aggregate?: boolean;
directory_members?: Array<AgentRegistryFields & {
id: number;
name: string;
description?: string | null;
icon_url?: string;
category?: string | null;
sub_category?: string | null;
sort_order?: number;
}>;
};
export function useChatAgent(options: UseChatAgentOptions) {
const { deps, currentAgentId, currentUser, chatGuides } = options;
const { t, msg, router } = deps;
const currentAgent = ref<AgentRegistryFields | null>(null);
const userAgents = ref<Array<AgentRegistryFields & {
id: number;
name: string;
description: string;
icon_url?: string;
dify_app_type?: 'chatflow' | 'workflow';
category?: string | null;
sub_category?: string | null;
sort_order?: number;
is_aggregate?: boolean;
directory_members?: Array<AgentRegistryFields & {
id: number;
name: string;
description?: string | null;
icon_url?: string;
category?: string | null;
sub_category?: string | null;
sort_order?: number;
}>;
}>>([]);
const userAgents = ref<ChatAgentOption[]>([]);
const showAgentPanel = ref(true);
const selectedKb = ref(DEFAULT_KB);
const kbOptions = [DEFAULT_KB, ERP_KB];
@@ -162,7 +164,7 @@ export function useChatAgent(options: UseChatAgentOptions) {
const loadAgent = async () => {
try {
currentAgent.value = await getUserAgent(currentAgentId.value);
currentAgent.value = await getUserAgent<AgentRegistryFields>(currentAgentId.value);
await chatGuides.loadGuides();
} catch (e) {
if (e instanceof BusinessError && e.status === 403) {
@@ -178,9 +180,9 @@ export function useChatAgent(options: UseChatAgentOptions) {
const loadUserAgents = async () => {
try {
const agents = await listUserAgents();
const agents = await listUserAgents<ChatAgentOption>();
const filtered = Array.isArray(agents)
? agents.filter((a: any) => (a.dify_app_type || 'chatflow') === 'chatflow')
? agents.filter((agent) => (agent.dify_app_type || 'chatflow') === 'chatflow')
: [];
userAgents.value = sortAgentsByCategory(filtered);
showAgentPanel.value = userAgents.value.length > 0;
@@ -3,7 +3,7 @@
* Agent 学习之窗:指南列表加载与弹窗状态。
*/
import { computed, ref, type ComputedRef } from 'vue';
import { listAgentGuides } from '@/features/auth/api/user.api';
import { listAgentGuides } from '@/features/user';
export interface AgentGuide {
id: number;
@@ -8,7 +8,7 @@
* - leave-result:OA 提交结果
*/
import { computed, type ComputedRef, type Ref } from 'vue';
import { getUserProfile } from '@/features/auth/api/user.api';
import { getUserProfile } from '@/features/user';
import { canUseLeaveFeature as resolveLeaveFeatureEnabled } from '@/shared/utils/agent-registry.utils';
import type { AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
import { LEAVE_TYPES } from '../constants/leave';
@@ -1,4 +1,5 @@
/** 请假(leave)子模块 barrel:纯函数 + handler 工厂 */
export * from './leave.api';
export * from './leaveDateTime';
export * from './leaveDisplay';
export * from './leaveIntent';
@@ -0,0 +1,39 @@
/**
* features/chat/leave/leave.api.ts
* 用途:封装聊天请假流程的余额查询与 OA 工作流提交请求。
* 依赖:shared/utils/auth、shared/api/client。
* 逻辑:聊天请假表单调用本模块;后端暂保留 /api/user/leave-* 路径以兼容既有接口。
*/
import { requestJson } from '@/shared/api/client';
import { getAuthHeaders } from '@/shared/utils/auth';
import type { LeaveRequestFormData } from '../types/leave.types';
const auth = () => ({ headers: getAuthHeaders() });
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
export interface LeaveBalanceResult {
has_balance: boolean;
leave_type_label: string;
year: number;
total_hours: number | null;
used_hours: number | null;
remaining_hours: number | null;
}
/** 查询当前用户指定假别的可用余额。 */
export const getLeaveBalance = (leaveType: string) =>
requestJson<LeaveBalanceResult>(`/api/user/leave-balance?leave_type=${encodeURIComponent(leaveType)}`, auth());
export interface LeaveWorkflowSubmitResult {
request_id?: string;
submitted_at?: string;
request_name?: string;
}
/** 将聊天内确认后的请假表单提交至 OA 工作流。 */
export const submitLeaveWorkflow = (form: LeaveRequestFormData) =>
requestJson<LeaveWorkflowSubmitResult>('/api/user/leave-workflow/submit', {
method: 'POST',
...jsonAuth(),
body: JSON.stringify(form),
});
@@ -1,7 +1,7 @@
/**
* 请假:表单初始数据、校验、余额断言、确认与 OA 提交。
*/
import { getLeaveBalance, submitLeaveWorkflow } from '@/features/auth/api/user.api';
import { getLeaveBalance, submitLeaveWorkflow } from './leave.api';
import { NEED_BALANCE_CHECK_TYPES } from '../constants/leave';
import { formatLeaveBalanceNumber, getLeaveTypeLabel } from './leaveDisplay';
import {