feat(shipping-notice): 新增发货批次和任务管理功能,支持批次创建与任务处理
This commit is contained in:
1 parent
457f0f4e5e
commit
634dee4b81
81 files changed
+9088
-3625
No files matched your search
@@ -1,15 +1,19 @@
|
||||
/**
|
||||
* 出货聊天:消息气泡动作按钮与菜单项点击分发。
|
||||
*
|
||||
* 按 action.id 路由到 API 调用、决策提交、文件选择器或 Dify 菜单消息。
|
||||
/**
|
||||
* features/chat/shipping/useChatShippingMenuHandler.ts
|
||||
* 用途:分发聊天气泡动作按钮点击,连接 API、决策处理、下载和文件选择器。
|
||||
* 依赖:shipping.api、shippingDownload、shipping 常量、chat.types。
|
||||
* 逻辑:由 useChatShipping 调用本文件;本文件根据 action.id 决定触发后端接口、本地消息落库或前端 UI 行为。
|
||||
*/
|
||||
import {
|
||||
generateWorkspaceShippingExcel,
|
||||
matchWorkspaceShippingInventory,
|
||||
type ShippingDecisionResponse,
|
||||
type ShippingMatchLineResult,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { SHIPPING_DECISION_ACTIONS } from '../constants/shipping';
|
||||
import { downloadWorkspaceShippingExcelFile } from './shippingDownload';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ShippingMatchResultPayload } from '../types/shipping.types';
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
export interface ShippingMenuHandlerContext {
|
||||
@@ -28,7 +32,39 @@ export interface ShippingMenuHandlerContext {
|
||||
t: (key: string) => string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发货通知动作菜单处理器。
|
||||
*
|
||||
* 核心逻辑:按 action.id 分流到生成 Excel、库存匹配、人工决策、手工上传确认等前后端动作。
|
||||
* @param ctx - 动作菜单上下文
|
||||
* @returns 菜单动作与按钮点击处理函数
|
||||
*/
|
||||
export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
const buildMatchResultPayload = (
|
||||
taskId: string,
|
||||
result: ShippingDecisionResponse & { action_buttons?: Array<{ id: string; label: string; message: string; variant?: 'primary' | 'secondary' | 'danger' }> },
|
||||
): ShippingMatchResultPayload => {
|
||||
const data = (result?.data && typeof result.data === 'object') ? result.data as Record<string, unknown> : {};
|
||||
const lineResults = Array.isArray(data.line_results)
|
||||
? data.line_results as ShippingMatchLineResult[]
|
||||
: [];
|
||||
const shortageRaw = data.shortage && typeof data.shortage === 'object'
|
||||
? data.shortage as { lines?: ShippingMatchLineResult[] }
|
||||
: null;
|
||||
return {
|
||||
taskId,
|
||||
match_status: typeof data.match_status === 'string' ? data.match_status : null,
|
||||
line_results: lineResults,
|
||||
shortage_lines: Array.isArray(shortageRaw?.lines) ? shortageRaw.lines : [],
|
||||
action_buttons: Array.isArray(result.action_buttons)
|
||||
? result.action_buttons.map((action) => ({
|
||||
...action,
|
||||
variant: action.variant || 'secondary',
|
||||
}))
|
||||
: [],
|
||||
};
|
||||
};
|
||||
|
||||
const handleShippingMenuAction = async (
|
||||
action: { id?: string; message: string },
|
||||
chatMsg?: ChatMessage & { shipping_actions_used?: boolean },
|
||||
@@ -71,11 +107,12 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
};
|
||||
const assistantMsg: ChatMessage = {
|
||||
role: 'assistant',
|
||||
type: 'text',
|
||||
type: 'shipping-match-result',
|
||||
content: [
|
||||
String(result.message || '').trim(),
|
||||
`任务编号:${taskId}`,
|
||||
].filter(Boolean).join('\n'),
|
||||
payload: buildMatchResultPayload(taskId, result),
|
||||
local_id: ctx.newLocalMessageId('shipping-assistant'),
|
||||
local_only: true,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user