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 |   42 ++++++++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/src/components/chat/components/playBar/hook/useUploadFile.ts b/src/components/chat/components/playBar/hook/useUploadFile.ts
index 912c6c0..5f01e26 100644
--- a/src/components/chat/components/playBar/hook/useUploadFile.ts
+++ b/src/components/chat/components/playBar/hook/useUploadFile.ts
@@ -1,9 +1,11 @@
 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' | 'txt' | 'csv';
@@ -93,10 +95,8 @@
 };
 // 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 attachFileList = ref<UploadFile[]>([]);
-
+	const { attachFileList } = options;
 	const parseFiles = (files: FileList) => {
 		const filterFiles: UploadFile[] = [];
 		for (const file of files) {
@@ -126,7 +126,24 @@
 				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>)
+			)
+		);
 	};
 
 	/**
@@ -140,17 +157,14 @@
 		parseFiles(files);
 	};
 
-	const clearFileList = () => {
-		attachFileList.value = [];
-	};
+
 	const {
 		files,
 		open: openFileDialog,
 		reset: resetOpenFileDialog,
 		onChange: onPickFileChange,
 	} = useFileDialog({
-		accept:
-			'text/csv,text/plain', // Only accept csv and txt files
+		accept: 'text/csv,text/plain', // Only accept csv and txt files
 		reset: true,
 	});
 
@@ -161,21 +175,17 @@
 		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,
+		deleteUploadFile,
 		openFileClick,
 	};
 };

--
Gitblit v1.9.3