|
137 | 137 | type="textarea"
|
138 | 138 | :maxlength="100000"
|
139 | 139 | @keydown.enter="sendChatHandle($event)"
|
| 140 | + @paste="handlePaste" |
| 141 | + @drop="handleDrop" |
140 | 142 | />
|
141 | 143 |
|
142 | 144 | <div class="operate flex align-center">
|
|
188 | 190 | :show-file-list="false"
|
189 | 191 | :accept="getAcceptList()"
|
190 | 192 | :on-change="(file: any, fileList: any) => uploadFile(file, fileList)"
|
| 193 | + ref="upload" |
191 | 194 | >
|
192 | 195 | <el-tooltip
|
193 | 196 | :disabled="mode === 'mobile'"
|
@@ -301,6 +304,8 @@ const localLoading = computed({
|
301 | 304 | }
|
302 | 305 | })
|
303 | 306 |
|
| 307 | +const upload = ref() |
| 308 | +
|
304 | 309 | const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
|
305 | 310 | const documentExtensions = ['pdf', 'docx', 'txt', 'xls', 'xlsx', 'md', 'html', 'csv']
|
306 | 311 | const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'flv']
|
@@ -434,6 +439,54 @@ const uploadFile = async (file: any, fileList: any) => {
|
434 | 439 | }
|
435 | 440 | })
|
436 | 441 | }
|
| 442 | +// 粘贴处理 |
| 443 | +const handlePaste = (event: ClipboardEvent) => { |
| 444 | + if (!props.applicationDetails.file_upload_enable) return |
| 445 | + const clipboardData = event.clipboardData |
| 446 | + if (!clipboardData) return |
| 447 | +
|
| 448 | + // 获取剪贴板中的文件 |
| 449 | + const files = clipboardData.files |
| 450 | + if (files.length === 0) return |
| 451 | +
|
| 452 | + // 转换 FileList 为数组并遍历处理 |
| 453 | + Array.from(files).forEach((rawFile: File) => { |
| 454 | + // 创建符合 el-upload 要求的文件对象 |
| 455 | + const elFile = { |
| 456 | + uid: Date.now(), // 生成唯一ID |
| 457 | + name: rawFile.name, |
| 458 | + size: rawFile.size, |
| 459 | + raw: rawFile, // 原始文件对象 |
| 460 | + status: 'ready', // 文件状态 |
| 461 | + percentage: 0 // 上传进度 |
| 462 | + } |
| 463 | +
|
| 464 | + // 手动触发上传逻辑(模拟 on-change 事件) |
| 465 | + uploadFile(elFile, [elFile]) |
| 466 | + }) |
| 467 | +
|
| 468 | + // 阻止默认粘贴行为 |
| 469 | + event.preventDefault() |
| 470 | +} |
| 471 | +// 新增拖拽处理 |
| 472 | +const handleDrop = (event: DragEvent) => { |
| 473 | + if (!props.applicationDetails.file_upload_enable) return |
| 474 | + event.preventDefault() |
| 475 | + const files = event.dataTransfer?.files |
| 476 | + if (!files) return |
| 477 | +
|
| 478 | + Array.from(files).forEach((rawFile) => { |
| 479 | + const elFile = { |
| 480 | + uid: Date.now(), |
| 481 | + name: rawFile.name, |
| 482 | + size: rawFile.size, |
| 483 | + raw: rawFile, |
| 484 | + status: 'ready', |
| 485 | + percentage: 0 |
| 486 | + } |
| 487 | + uploadFile(elFile, [elFile]) |
| 488 | + }) |
| 489 | +} |
437 | 490 | // 语音录制任务id
|
438 | 491 | const intervalId = ref<any | null>(null)
|
439 | 492 | // 语音录制开始秒数
|
|
0 commit comments