From 254816a712847b099184d84ca8631a50fb32f39e Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期一, 03 三月 2025 15:24:09 +0800 Subject: [PATCH] 初步对接 --- src/components/chat/components/playBar/hook/useUploadFile.ts | 46 +++++++++++++++++++++++++++++----------------- 1 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/components/chat/components/playBar/hook/useUploadFile.ts b/src/components/chat/components/playBar/hook/useUploadFile.ts index 14f2943..912c6c0 100644 --- a/src/components/chat/components/playBar/hook/useUploadFile.ts +++ b/src/components/chat/components/playBar/hook/useUploadFile.ts @@ -6,8 +6,8 @@ pastTarget: Ref<HTMLElement | null>; }; -export type FileType = 'doc' | 'docx' | 'pdf' | 'md' | 'xls' | 'xlsx' | 'png' | 'jpg' | 'jpeg' | 'gif' | 'json'; -export type FileGroupType = 'word' | 'pdf' | 'excel' | 'image' | 'json' | 'md'; +export type FileType = 'doc' | 'docx' | 'pdf' | 'md' | 'xls' | 'xlsx' | 'png' | 'jpg' | 'jpeg' | 'gif' | 'json' | 'txt' | 'csv'; +export type FileGroupType = 'word' | 'pdf' | 'excel' | 'image' | 'json' | 'md' | 'csv' | 'txt'; export type UploadFile = { name: string; type: FileType; @@ -24,6 +24,10 @@ case 'doc': case 'docx': return 'word'; + case 'csv': + return 'csv'; + case 'txt': + return 'txt'; case 'md': return 'md'; @@ -52,6 +56,10 @@ return 'pdf'; case 'excel': return 'excel'; + case 'csv': + return 'csv'; + case 'txt': + return 'txt'; case 'json': return 'json'; @@ -70,6 +78,10 @@ return 'text-red-400'; case 'excel': return 'text-green-400'; + case 'csv': + return 'text-green-500'; + case 'txt': + return 'text-cyan-400'; case 'json': return 'text-yellow-400'; @@ -79,12 +91,13 @@ return ''; } }; - +// const supportFileType = ['doc', 'docx', 'md', 'xls', 'xlsx', 'png', 'jpg', 'jpeg', 'gif', 'json', 'pdf']; +const supportFileType = ['csv', 'txt']; +const acceptFiles = [].join(',') export const useUploadFile = (options: UseUploadFileOptions) => { - const supportFileType = ['doc', 'docx', 'md', 'xls', 'xlsx', 'png', 'jpg', 'jpeg', 'gif', 'json', 'pdf']; const attachFileList = ref<UploadFile[]>([]); - const parseFiles = (files:FileList) => { + const parseFiles = (files: FileList) => { const filterFiles: UploadFile[] = []; for (const file of files) { const suffix = file.name.split('.').pop() as FileType; @@ -114,7 +127,7 @@ } } attachFileList.value.push(...filterFiles); - } + }; /** * 瑙f瀽绮樿创鏉挎枃浠� @@ -124,7 +137,7 @@ event.stopPropagation(); const data = event.clipboardData || window.clipboardData; const files = data.files as FileList; - parseFiles(files) + parseFiles(files); }; const clearFileList = () => { @@ -132,22 +145,21 @@ }; const { files, - open:openFileDialog, - reset:resetOpenFileDialog, + open: openFileDialog, + reset: resetOpenFileDialog, onChange: onPickFileChange, } = useFileDialog({ accept: - 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/markdown,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,image/png,image/jpeg,image/gif,application/json,application/pdf', // Set to accept only image files - reset:true + 'text/csv,text/plain', // Only accept csv and txt files + reset: true, }); - - const openFileClick = () =>{ + const openFileClick = () => { openFileDialog(); - } + }; onPickFileChange((files) => { - if(!files) return; - parseFiles(files) + if (!files) return; + parseFiles(files); }); const deleteIndexFile = (index) => { const file = attachFileList.value[index]; @@ -164,6 +176,6 @@ attachFileList, clearFileList, deleteIndexFile, - openFileClick + openFileClick, }; }; -- Gitblit v1.9.3