From dab4fb54bfc9390d3207f3ca3a48f962344e4f88 Mon Sep 17 00:00:00 2001 From: Christ Date: Thu, 20 Aug 2026 23:24:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E5=BF=AB=E6=8D=B7=E5=9B=9E=E5=A4=8D=E4=B8=8E?= =?UTF-8?q?=E4=B9=B0=E5=AE=B6=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/openapi.yaml | 153 +++++++ frontend/app/features/chat/api.ts | 55 +++ .../components/ChatMetadataFeature.test.tsx | 56 +++ .../chat/components/ChatMetadataFeature.tsx | 89 ++++ frontend/app/features/chat/hooks.test.tsx | 11 + frontend/app/features/chat/hooks.ts | 20 +- frontend/app/features/chat/metadata.test.tsx | 141 +++++++ frontend/app/features/chat/metadata.ts | 270 ++++++++++++ frontend/app/features/chat/models.ts | 24 ++ frontend/app/features/chat/pages/Chat.tsx | 20 +- .../shared/api-contract/generated/schema.ts | 394 ++++++++++++++++++ frontend/vite.config.ts | 4 + internal/adapter/chat_repository.go | 57 +++ internal/application/chat/metadata.go | 175 ++++++++ internal/application/chat/metadata_test.go | 107 +++++ internal/db/chat_metadata.go | 156 +++++++ internal/db/chat_metadata_test.go | 87 ++++ internal/db/migrate_test.go | 13 +- ...036_chat_quick_replies_and_buyer_notes.sql | 22 + ...036_chat_quick_replies_and_buyer_notes.sql | 20 + ...036_chat_quick_replies_and_buyer_notes.sql | 20 + internal/server/application_ports.go | 5 + internal/server/chat_account_tasks_test.go | 58 +++ internal/server/chat_handlers.go | 14 +- internal/server/chat_metadata_handlers.go | 188 +++++++++ ...openapi_remaining_success_contract_test.go | 77 ++++ internal/server/versioned_chat_task_routes.go | 5 + ...st-C1r-CuCX.js => AccountList-D1PDvKjr.js} | 4 +- ...dList-BbF66c_P.js => CardList-BG11KU7H.js} | 6 +- internal/webui/static/assets/Chat-8cCRP4iO.js | 1 + internal/webui/static/assets/Chat-DJNDDkT1.js | 1 - .../webui/static/assets/Dashboard-DBUkwLYQ.js | 1 + .../webui/static/assets/Dashboard-DhFdaJwB.js | 1 - ...mList-C1pjlQfG.js => ItemList-D-9IbEjX.js} | 4 +- .../static/assets/Notifications-BepLRaYn.js | 1 + .../static/assets/Notifications-CccTJna_.js | 1 - .../webui/static/assets/OrderList-CKY0um79.js | 1 + .../webui/static/assets/OrderList-KOW-fFIJ.js | 1 - .../webui/static/assets/Rules-CacQ324l.js | 1 - .../webui/static/assets/Rules-DCuiI2LD.js | 1 + .../webui/static/assets/Settings-BMAitcQx.js | 1 + .../webui/static/assets/Settings-aZQUe0t0.js | 1 - .../static/assets/chat-metadata-74T0w35U.js | 1 + ...r-B5fJPoU1.js => icons-vendor-BSp7PTZg.js} | 190 +++++---- .../webui/static/assets/index-Bu1X-GTG.css | 1 + .../webui/static/assets/index-C6RECy_0.js | 2 - .../webui/static/assets/index-ITqHo9y-.css | 1 - .../webui/static/assets/index-dO7JyNQY.js | 2 + internal/webui/static/index.html | 7 +- 49 files changed, 2349 insertions(+), 122 deletions(-) create mode 100644 frontend/app/features/chat/components/ChatMetadataFeature.test.tsx create mode 100644 frontend/app/features/chat/components/ChatMetadataFeature.tsx create mode 100644 frontend/app/features/chat/metadata.test.tsx create mode 100644 frontend/app/features/chat/metadata.ts create mode 100644 internal/application/chat/metadata.go create mode 100644 internal/application/chat/metadata_test.go create mode 100644 internal/db/chat_metadata.go create mode 100644 internal/db/chat_metadata_test.go create mode 100644 internal/db/migrations/mysql/00036_chat_quick_replies_and_buyer_notes.sql create mode 100644 internal/db/migrations/postgres/00036_chat_quick_replies_and_buyer_notes.sql create mode 100644 internal/db/migrations/sqlite/00036_chat_quick_replies_and_buyer_notes.sql create mode 100644 internal/server/chat_metadata_handlers.go rename internal/webui/static/assets/{AccountList-C1r-CuCX.js => AccountList-D1PDvKjr.js} (79%) rename internal/webui/static/assets/{CardList-BbF66c_P.js => CardList-BG11KU7H.js} (95%) create mode 100644 internal/webui/static/assets/Chat-8cCRP4iO.js delete mode 100644 internal/webui/static/assets/Chat-DJNDDkT1.js create mode 100644 internal/webui/static/assets/Dashboard-DBUkwLYQ.js delete mode 100644 internal/webui/static/assets/Dashboard-DhFdaJwB.js rename internal/webui/static/assets/{ItemList-C1pjlQfG.js => ItemList-D-9IbEjX.js} (67%) create mode 100644 internal/webui/static/assets/Notifications-BepLRaYn.js delete mode 100644 internal/webui/static/assets/Notifications-CccTJna_.js create mode 100644 internal/webui/static/assets/OrderList-CKY0um79.js delete mode 100644 internal/webui/static/assets/OrderList-KOW-fFIJ.js delete mode 100644 internal/webui/static/assets/Rules-CacQ324l.js create mode 100644 internal/webui/static/assets/Rules-DCuiI2LD.js create mode 100644 internal/webui/static/assets/Settings-BMAitcQx.js delete mode 100644 internal/webui/static/assets/Settings-aZQUe0t0.js create mode 100644 internal/webui/static/assets/chat-metadata-74T0w35U.js rename internal/webui/static/assets/{icons-vendor-B5fJPoU1.js => icons-vendor-BSp7PTZg.js} (69%) create mode 100644 internal/webui/static/assets/index-Bu1X-GTG.css delete mode 100644 internal/webui/static/assets/index-C6RECy_0.js delete mode 100644 internal/webui/static/assets/index-ITqHo9y-.css create mode 100644 internal/webui/static/assets/index-dO7JyNQY.js diff --git a/api/openapi.yaml b/api/openapi.yaml index 2d5869e..5b1e1bb 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -2371,6 +2371,126 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorResponse' + "/api/v1/chat/quick-replies": + get: + operationId: getApiV1ChatQuickReplies + summary: getApiV1ChatQuickReplies + security: [{cookieAuth: []}] + parameters: + - name: account_id + in: query + required: true + schema: {type: string} + responses: + '200': + description: 成功 + content: + application/json: + schema: + $ref: '#/components/schemas/ChatQuickReplyList' + '400': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '401': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '403': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '500': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + post: + operationId: postApiV1ChatQuickReplies + summary: postApiV1ChatQuickReplies + security: [{cookieAuth: []}] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ChatQuickReplyCreateRequest' + responses: + '201': + description: 成功 + content: + application/json: + schema: + $ref: '#/components/schemas/ChatQuickReply' + '400': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '401': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '403': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '409': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '500': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + "/api/v1/chat/quick-replies/{quick_reply_id}": + delete: + operationId: deleteApiV1ChatQuickRepliesByquick_reply_id + summary: deleteApiV1ChatQuickRepliesByquick_reply_id + security: [{cookieAuth: []}] + parameters: + - name: quick_reply_id + in: path + required: true + schema: {type: integer} + - name: account_id + in: query + required: true + schema: {type: string} + responses: + '200': + description: 成功 + content: + application/json: + schema: + $ref: '#/components/schemas/OperationResponse' + '400': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '401': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '403': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '404': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '500': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + "/api/v1/chat/buyer-notes/{buyer_id}": + get: + operationId: getApiV1ChatBuyerNotesBybuyer_id + summary: getApiV1ChatBuyerNotesBybuyer_id + security: [{cookieAuth: []}] + parameters: + - name: buyer_id + in: path + required: true + schema: {type: string} + - name: account_id + in: query + required: true + schema: {type: string} + responses: + '200': + description: 成功 + content: + application/json: + schema: + $ref: '#/components/schemas/ChatBuyerNote' + '400': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '401': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '403': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '500': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + put: + operationId: putApiV1ChatBuyerNotesBybuyer_id + summary: putApiV1ChatBuyerNotesBybuyer_id + security: [{cookieAuth: []}] + parameters: + - name: buyer_id + in: path + required: true + schema: {type: string} + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ChatBuyerNoteSaveRequest' + responses: + '200': + description: 成功 + content: + application/json: + schema: + $ref: '#/components/schemas/ChatBuyerNote' + '400': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '401': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '403': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} + '500': {description: 统一错误响应, content: {application/json: {schema: {$ref: '#/components/schemas/ErrorResponse'}}}} "/api/v1/chat/messages": get: operationId: getApiV1ChatMessages @@ -7734,6 +7854,39 @@ components: account_id: {type: string} chat_id: {type: string} message_ids: {type: array, items: {type: object, additionalProperties: {oneOf: [{type: string}, {type: number}]}}} + ChatQuickReply: + type: object + required: [id, account_id, content, created_at] + properties: + id: {type: integer} + account_id: {type: string} + content: {type: string, minLength: 1, maxLength: 2000} + created_at: {type: integer} + ChatQuickReplyList: + type: object + required: [quick_replies] + properties: + quick_replies: {type: array, items: {$ref: '#/components/schemas/ChatQuickReply'}} + ChatQuickReplyCreateRequest: + type: object + required: [account_id, content] + properties: + account_id: {type: string} + content: {type: string, minLength: 1, maxLength: 2000} + ChatBuyerNote: + type: object + required: [account_id, buyer_id, content, updated_at] + properties: + account_id: {type: string} + buyer_id: {type: string} + content: {type: string, maxLength: 2000} + updated_at: {type: integer} + ChatBuyerNoteSaveRequest: + type: object + required: [account_id, content] + properties: + account_id: {type: string} + content: {type: string, maxLength: 2000} OrderDTO: type: object required: [order_id, item_id, item_title, item_image, buyer_id, quantity, amount, order_status, status, cookie_id, created_at] diff --git a/frontend/app/features/chat/api.ts b/frontend/app/features/chat/api.ts index f0cfa80..8281a84 100644 --- a/frontend/app/features/chat/api.ts +++ b/frontend/app/features/chat/api.ts @@ -1,6 +1,8 @@ import { AccountDetail, +ChatBuyerNote, ChatMessage, +ChatQuickReply, ChatSession, OperationResponse } from './models'; @@ -72,6 +74,59 @@ export const getChatMessagePage = async (accountId: string, chatId: string, curs export const getChatMessages = async (accountId: string, chatId: string, beforeId?: number, options?: RequestControlOptions): Promise => (await getChatMessagePage(accountId, chatId, undefined, beforeId, options)).messages; +/** 查询当前账号可复用的人工快捷回复。 */ +export const getChatQuickReplies = async (accountId: string, options?: RequestControlOptions): Promise => { + // response 保存契约客户端返回的快捷回复列表 DTO,随后转换为 feature UI 模型。 + const response = await runContractRequest(/* signal 是本次账号快捷回复查询的超时与取消控制信号。 */ signal => contractClient.GET('/api/v1/chat/quick-replies', { + params: { query: { account_id: accountId } }, + signal, + }), options); + return response.quick_replies.map(/* reply 是当前待转换的快捷回复 DTO。 */ reply => ({ + id: reply.id, + account_id: reply.account_id, + content: reply.content, + created_at: reply.created_at, + })); +}; + +/** 为当前账号新增人工快捷回复。 */ +export const createChatQuickReply = async (accountId: string, content: string, options?: RequestControlOptions): Promise => { + // response 保存创建接口返回的快捷回复 DTO,转换后不向组件暴露生成类型。 + const response = await runContractRequest(/* signal 是本次新增快捷回复请求的超时与取消控制信号。 */ signal => contractClient.POST('/api/v1/chat/quick-replies', { + body: { account_id: accountId, content }, + signal, + }), options); + return { id: response.id, account_id: response.account_id, content: response.content, created_at: response.created_at }; +}; + +/** 删除当前账号下指定的人工快捷回复。 */ +export const deleteChatQuickReply = async (accountId: string, quickReplyId: number, options?: RequestControlOptions): Promise => + runContractRequest(/* signal 是本次删除快捷回复请求的超时与取消控制信号。 */ signal => contractClient.DELETE('/api/v1/chat/quick-replies/{quick_reply_id}', { + params: { path: { quick_reply_id: quickReplyId }, query: { account_id: accountId } }, + signal, + }), options); + +/** 查询当前账号下指定买家的完整备注;未填写时仍返回空内容。 */ +export const getChatBuyerNote = async (accountId: string, buyerId: string, options?: RequestControlOptions): Promise => { + // response 保存契约客户端返回的买家备注 DTO,转换后由聊天 feature 管理。 + const response = await runContractRequest(/* signal 是本次买家备注查询的超时与取消控制信号。 */ signal => contractClient.GET('/api/v1/chat/buyer-notes/{buyer_id}', { + params: { path: { buyer_id: buyerId }, query: { account_id: accountId } }, + signal, + }), options); + return { account_id: response.account_id, buyer_id: response.buyer_id, content: response.content, updated_at: response.updated_at }; +}; + +/** 保存当前账号下指定买家的完整备注;空内容会清除已有备注。 */ +export const saveChatBuyerNote = async (accountId: string, buyerId: string, content: string, options?: RequestControlOptions): Promise => { + // response 保存保存接口返回的最终买家备注 DTO。 + const response = await runContractRequest(/* signal 是本次买家备注保存请求的超时与取消控制信号。 */ signal => contractClient.PUT('/api/v1/chat/buyer-notes/{buyer_id}', { + params: { path: { buyer_id: buyerId } }, + body: { account_id: accountId, content }, + signal, + }), options); + return { account_id: response.account_id, buyer_id: response.buyer_id, content: response.content, updated_at: response.updated_at }; +}; + // sendChatMessage 发送聊天文本消息。 export const sendChatMessage = async (input: { /** account_id 表示账号标识。 */ account_id: string; /** chat_id 表示聊天标识。 */ chat_id: string; /** buyer_id 表示买家标识。 */ buyer_id: string; /** buyer_name 表示买家名称。 */ buyer_name?: string; diff --git a/frontend/app/features/chat/components/ChatMetadataFeature.test.tsx b/frontend/app/features/chat/components/ChatMetadataFeature.test.tsx new file mode 100644 index 0000000..76e7a67 --- /dev/null +++ b/frontend/app/features/chat/components/ChatMetadataFeature.test.tsx @@ -0,0 +1,56 @@ +// @vitest-environment jsdom +import { fireEvent,render,screen,within } from '@testing-library/react'; +import { beforeEach,describe,expect,test,vi } from 'vitest'; +import ChatMetadataFeature from './ChatMetadataFeature'; +import { useChatMetadata } from '../metadata'; +import type { ChatMetadataState } from '../metadata'; +import type { ChatQuickReply,ChatSession } from '../models'; + +vi.mock('../metadata', /* chatMetadataMockFactory 为抽屉组件交互测试提供受控的元数据 Hook 替身。 */ () => ({ useChatMetadata: vi.fn() })); + +// useChatMetadataMock 是可为每个测试设置返回状态的元数据 Hook 替身。 +const useChatMetadataMock = vi.mocked(useChatMetadata); +// quickReplyFixture 是用于验证操作顺序和关闭行为的账号级快捷回复。 +const quickReplyFixture: ChatQuickReply = { id: 1, account_id: 'account-1', content: '测试话术', created_at: 1 }; +// sessionFixture 是使快捷回复发送按钮可用的当前聊天会话。 +const sessionFixture: ChatSession = { account_id: 'account-1', chat_id: 'chat-1', buyer_id: 'buyer-1', buyer_name: '买家', last_message: '', last_message_at: 1, unread_count: 0 }; + +/** metadataFixture 构造抽屉组件交互所需的完整元数据状态,并允许测试观测复制动作。 */ +const metadataFixture = (copyQuickReply: ChatMetadataState['copyQuickReply']): ChatMetadataState => ({ + quickReplies: [quickReplyFixture], quickReplyDraft: '', setQuickReplyDraft: vi.fn(), quickReplyBusy: false, + pendingDeleteQuickReply: null, requestQuickReplyDelete: vi.fn(), cancelQuickReplyDelete: vi.fn(), confirmQuickReplyDelete: vi.fn().mockResolvedValue(undefined), + addQuickReply: vi.fn().mockResolvedValue(undefined), copyQuickReply, copiedQuickReplyID: null, buyerNote: null, noteLoading: false, + noteDialogOpen: false, noteEditing: false, noteDraft: '', setNoteDraft: vi.fn(), noteSaving: false, openNoteDialog: vi.fn(), + closeNoteDialog: vi.fn(), beginNoteEditing: vi.fn(), saveBuyerNote: vi.fn().mockResolvedValue(undefined), metadataError: '', clearMetadataError: vi.fn(), +}); + +describe('ChatMetadataFeature', /* 当前回调验证快捷回复抽屉的操作排序和关闭交互。 */ () => { + beforeEach(/* 当前回调在每个抽屉交互场景前重置 Hook 替身调用记录。 */ () => { + vi.clearAllMocks(); + }); + + test('删除、复制、发送排序正确,复制发送和外部点击均收起抽屉', /* 当前回调验证快捷回复操作的高频关闭流程。 */ async () => { + // copyQuickReply 保存可观测的复制动作替身。 + const copyQuickReply = vi.fn().mockResolvedValue(undefined); + // closeQuickReplyPanel 保存抽屉关闭动作替身。 + const closeQuickReplyPanel = vi.fn(); + // sendQuickReply 保存当前会话模板发送动作替身。 + const sendQuickReply = vi.fn().mockResolvedValue(undefined); + useChatMetadataMock.mockReturnValue(metadataFixture(copyQuickReply)); + render(<>); + // replyCard 是包含当前快捷回复操作按钮的卡片元素。 + const replyCard = screen.getByText('测试话术').closest('article'); + if (replyCard == null) throw new Error('未找到快捷回复卡片'); + // actionNames 保存卡片内按钮按视觉顺序的可访问名称。 + const actionNames = within(replyCard).getAllByRole('button').map(/* actionButton 保存当前待检查的快捷回复操作按钮。 */ actionButton => actionButton.getAttribute('aria-label') || actionButton.textContent); + expect(actionNames).toEqual(['删除快捷回复', '复制', '发送']); + fireEvent.click(within(replyCard).getByRole('button', { name: '复制' })); + expect(copyQuickReply).toHaveBeenCalledWith(quickReplyFixture); + expect(closeQuickReplyPanel).toHaveBeenCalledTimes(1); + fireEvent.click(within(replyCard).getByRole('button', { name: '发送' })); + expect(sendQuickReply).toHaveBeenCalledWith('测试话术'); + expect(closeQuickReplyPanel).toHaveBeenCalledTimes(2); + fireEvent.pointerDown(screen.getByRole('button', { name: '抽屉外区域' })); + expect(closeQuickReplyPanel).toHaveBeenCalledTimes(3); + }); +}); diff --git a/frontend/app/features/chat/components/ChatMetadataFeature.tsx b/frontend/app/features/chat/components/ChatMetadataFeature.tsx new file mode 100644 index 0000000..e28f3ea --- /dev/null +++ b/frontend/app/features/chat/components/ChatMetadataFeature.tsx @@ -0,0 +1,89 @@ +import { Clipboard,FilePenLine,Plus,Send,Trash2,X } from 'lucide-react'; +import React from 'react'; +import { useChatMetadata } from '../metadata'; +import type { ChatSession } from '../models'; + +/** ChatMetadataFeatureProps 描述独立构建的聊天元数据控件所需上下文与外部发送能力。 */ +type ChatMetadataFeatureProps = { + /** activeAccountID 是当前选中的闲鱼账号标识。 */ + activeAccountID: string; + /** selectedSession 是当前正在查看的聊天会话。 */ + selectedSession: ChatSession | undefined; + /** quickReplyPanelOpen 控制右侧快捷回复抽屉是否可见。 */ + quickReplyPanelOpen: boolean; + /** closeQuickReplyPanel 收起右侧快捷回复抽屉。 */ + closeQuickReplyPanel: () => void; + /** sendQuickReply 将模板文本交给既有可靠聊天发送流程。 */ + sendQuickReply: (content: string) => Promise; + /** sending 表示当前聊天发送请求是否进行中。 */ + sending: boolean; + /** accountOnline 表示当前账号是否可以向平台发送消息。 */ + accountOnline: boolean; +}; + +/** ChatMetadataFeature 提供账号快捷回复和买家备注交互,并由独立构建分片控制聊天页面体积。 */ +const ChatMetadataFeature: React.FC = ({ activeAccountID, selectedSession, quickReplyPanelOpen, closeQuickReplyPanel, sendQuickReply, sending, accountOnline }) => { + // chatMetadata 保存账号快捷回复和当前买家备注的独立数据、取消控制及 UI 交互状态。 + const chatMetadata = useChatMetadata(activeAccountID, selectedSession); + // buyerNoteContent 保存未经字符截断的完整备注;展示区域仅依标题栏的两行空间裁切可见文本。 + const buyerNoteContent = chatMetadata.buyerNote?.content.trim() || ''; + // quickReplyPanelRef 指向快捷回复抽屉根节点,用于区分抽屉内交互与页面外点击。 + const quickReplyPanelRef = React.useRef(null); + + React.useEffect(/* 当前副作用在抽屉展开期间监听页面级指针事件,点击抽屉外部时自动收起并在 cleanup 中移除监听。 */ () => { + if (!quickReplyPanelOpen) return undefined; + /** closeWhenClickOutside 仅在指针目标不属于快捷回复抽屉时收起面板。 */ + const closeWhenClickOutside = (event: PointerEvent): void => { + // eventTarget 保存当前指针事件的目标节点;非 DOM 节点不参与抽屉内外判断。 + const eventTarget = event.target; + if (!(eventTarget instanceof Node) || quickReplyPanelRef.current?.contains(eventTarget)) return; + closeQuickReplyPanel(); + }; + document.addEventListener('pointerdown', closeWhenClickOutside); + return /* 当前 cleanup 在抽屉收起或组件卸载时移除页面级监听。 */ () => document.removeEventListener('pointerdown', closeWhenClickOutside); + }, [closeQuickReplyPanel, quickReplyPanelOpen]); + + return <> + {selectedSession &&
+ +
} + {quickReplyPanelOpen && activeAccountID &&