feat: 优化聊天附件拖拽上传提示
- 不支持格式改用轻量提示并展示支持范围 - 扩展拖拽区域并增加全区上传覆盖层 - 补充文档和图片格式校验测试
This commit is contained in:
@@ -34,6 +34,8 @@ export type {
|
||||
ChatTimelineToolStatus,
|
||||
} from './types';
|
||||
export {
|
||||
CHAT_DOCUMENT_SUPPORTED_FORMATS,
|
||||
type ChatDocumentAddFilesResult,
|
||||
type ChatDocumentUploadApi,
|
||||
type ChatDocumentUploadContext,
|
||||
type ChatDocumentUploadView,
|
||||
|
||||
@@ -11,6 +11,8 @@ const MAX_EXCEL_BYTES = 10 * 1024 * 1024;
|
||||
const MAX_TEXT_BYTES = 5 * 1024 * 1024;
|
||||
const POLL_INTERVAL_MS = 750;
|
||||
const MAX_POLL_ATTEMPTS = 80;
|
||||
export const CHAT_DOCUMENT_SUPPORTED_FORMATS =
|
||||
'PDF、Word、PPT、Excel、TXT、Markdown';
|
||||
const SUPPORTED_EXTENSIONS = new Set([
|
||||
'doc',
|
||||
'docx',
|
||||
@@ -54,6 +56,11 @@ export interface ChatDocumentUploadApi {
|
||||
) => Promise<RequestResult<ChatDocumentUploadView>>;
|
||||
}
|
||||
|
||||
export interface ChatDocumentAddFilesResult {
|
||||
rejectedCount: number;
|
||||
unsupportedCount: number;
|
||||
}
|
||||
|
||||
interface LocalDocument extends ChatDocumentAttachment {
|
||||
file?: File;
|
||||
}
|
||||
@@ -198,9 +205,18 @@ export function createChatDocumentUploads(api: ChatDocumentUploadApi) {
|
||||
}
|
||||
|
||||
async function addFiles(files: File[], context: ChatDocumentUploadContext) {
|
||||
const supportedFiles: File[] = [];
|
||||
let unsupportedCount = 0;
|
||||
for (const file of files) {
|
||||
if (SUPPORTED_EXTENSIONS.has(extensionOf(file))) {
|
||||
supportedFiles.push(file);
|
||||
} else {
|
||||
unsupportedCount++;
|
||||
}
|
||||
}
|
||||
const available = Math.max(0, MAX_DOCUMENTS - items.value.length);
|
||||
const accepted = files.slice(0, available);
|
||||
const rejectedCount = Math.max(0, files.length - accepted.length);
|
||||
const accepted = supportedFiles.slice(0, available);
|
||||
const rejectedCount = Math.max(0, supportedFiles.length - accepted.length);
|
||||
const currentTotal = items.value.reduce(
|
||||
(total, item) => total + Number(item.size || 0),
|
||||
0,
|
||||
@@ -220,11 +236,6 @@ export function createChatDocumentUploads(api: ChatDocumentUploadApi) {
|
||||
items.value.push(item);
|
||||
const trackedItem = items.value[items.value.length - 1];
|
||||
if (!trackedItem) continue;
|
||||
if (!SUPPORTED_EXTENSIONS.has(extension)) {
|
||||
trackedItem.status = 'error';
|
||||
trackedItem.error = '仅支持 PDF、Word、PPT、Excel、TXT、Markdown';
|
||||
continue;
|
||||
}
|
||||
if (file.size > maxBytes(extension)) {
|
||||
trackedItem.status = 'error';
|
||||
trackedItem.error = sizeLimitMessage(extension);
|
||||
@@ -239,7 +250,10 @@ export function createChatDocumentUploads(api: ChatDocumentUploadApi) {
|
||||
uploads.push(upload(trackedItem, context));
|
||||
}
|
||||
await Promise.all(uploads);
|
||||
return rejectedCount;
|
||||
return {
|
||||
rejectedCount,
|
||||
unsupportedCount,
|
||||
} satisfies ChatDocumentAddFilesResult;
|
||||
}
|
||||
|
||||
async function remove(item: ChatDocumentAttachment) {
|
||||
|
||||
Reference in New Issue
Block a user