From 1075860848d14e3d6d1506b91d9c9039433bf4cc Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期一, 03 三月 2025 17:40:13 +0800 Subject: [PATCH] 合并附件和业务表格 --- src/components/chat/components/playBar/hook/useUploadFile.ts | 84 ++++++++++++++++++++++++++--------------- 1 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/components/chat/components/playBar/hook/useUploadFile.ts b/src/components/chat/components/playBar/hook/useUploadFile.ts index 14f2943..5f01e26 100644 --- a/src/components/chat/components/playBar/hook/useUploadFile.ts +++ b/src/components/chat/components/playBar/hook/useUploadFile.ts @@ -1,13 +1,15 @@ import { useEventListener, useFileDialog } from '@vueuse/core'; -import { ref, type Ref } from 'vue'; +import { type Ref } from 'vue'; +import type { Attach } from './useAttach'; import { convertFileSize } from '/@/utils/file'; export type UseUploadFileOptions = { pastTarget: Ref<HTMLElement | null>; + attachFileList: Ref<Attach<UploadFile>[]>; }; -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 +26,10 @@ case 'doc': case 'docx': return 'word'; + case 'csv': + return 'csv'; + case 'txt': + return 'txt'; case 'md': return 'md'; @@ -52,6 +58,10 @@ return 'pdf'; case 'excel': return 'excel'; + case 'csv': + return 'csv'; + case 'txt': + return 'txt'; case 'json': return 'json'; @@ -70,6 +80,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 +93,11 @@ return ''; } }; - +// const supportFileType = ['doc', 'docx', 'md', 'xls', 'xlsx', 'png', 'jpg', 'jpeg', 'gif', 'json', 'pdf']; +const supportFileType = ['csv', 'txt']; 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 { attachFileList } = options; + const parseFiles = (files: FileList) => { const filterFiles: UploadFile[] = []; for (const file of files) { const suffix = file.name.split('.').pop() as FileType; @@ -113,8 +126,25 @@ filterFiles.push(uploadFile); } } - attachFileList.value.push(...filterFiles); - } + attachFileList.value.push( + ...filterFiles.map( + (item) => + ({ + get title() { + return item.name; + }, + type: 'file', + model: item, + get icon() { + return item.icon; + }, + get iconClass() { + return item.iconClass; + }, + } as Attach<UploadFile>) + ) + ); + }; /** * 瑙f瀽绮樿创鏉挎枃浠� @@ -124,46 +154,38 @@ event.stopPropagation(); const data = event.clipboardData || window.clipboardData; const files = data.files as FileList; - parseFiles(files) + parseFiles(files); }; - const clearFileList = () => { - attachFileList.value = []; - }; + 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 + accept: '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]; - // Revoke object URL for image files + const deleteUploadFile = (file: UploadFile) => { if (file.previewUrl) { URL.revokeObjectURL(file.previewUrl); } - attachFileList.value.splice(index, 1); }; useEventListener(options.pastTarget, 'paste', pasteUpload); return { attachFileList, - clearFileList, - deleteIndexFile, - openFileClick + deleteUploadFile, + openFileClick, }; }; -- Gitblit v1.9.3