From a1dfd24ab83cfb35976af08297568b5dba8c1fd3 Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Thu, 8 Aug 2024 14:15:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SharedFilesModel/index.tsx | 43 +++++++++++++++++++---- src/page/Meeting/index.tsx | 2 +- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/components/SharedFilesModel/index.tsx b/src/components/SharedFilesModel/index.tsx index 0cdc223..7f8ed0c 100644 --- a/src/components/SharedFilesModel/index.tsx +++ b/src/components/SharedFilesModel/index.tsx @@ -1,6 +1,7 @@ import styles from '@/components/SharedFilesModel/index.module.scss' import { DeleteOutlined, + FolderOutlined, ProfileOutlined, ReloadOutlined, SearchOutlined, @@ -12,6 +13,8 @@ import { DeleteRoomFile, GetRoomFile, GetRoomFileDwUrl, GetRoomUpFileurl, PostRo import axios from 'axios'; import { useLocation } from 'react-router-dom'; import { storage } from '@/utils'; +const fs = require('fs').promises; +const { exec } = require('child_process'); const { Column } = Table @@ -262,7 +265,7 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => { }) } } - }).then(() => { + }).then(async () => { const fileIndex = fileList.data.findIndex((row: any) => row.id === item.id); let fileItem = [...fileList.data] as any; fileItem[fileIndex].percentComplete = 100 @@ -273,17 +276,43 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => { ...fileList, data: fileItem, }) - const downloadLink = document.createElement("a"); - downloadLink.href = res.data; - downloadLink.download = item.fileName; - downloadLink.click(); - getRoomFile() + const setting = await JSON.parse(storage.getItem('setting') as string) + try { + await fs.access(setting.shareFilesPath, fs.constants.F_OK) + const response = await fetch(res.data); + const arrayBuffer = await response.arrayBuffer(); + const buffer = Buffer.from(arrayBuffer); + fs.writeFile(`${setting.shareFilesPath}${fileItem[fileIndex].fileName}`, buffer, {}); + message.success(`下载成功!文件已保存至:${setting.shareFilesPath}`) + try { + await fs.access(setting.shareFilesPath, fs.constants.F_OK); + if (process.platform === 'win32') { + exec(`explorer "${setting.shareFilesPath}"`); + } else if (process.platform === 'darwin') { + exec(`open "${setting.shareFilesPath}"`); + } + } catch (error: any) { + if (error.code === 'ENOENT') { + message.error('文件夹不存在!') + } else { + message.error(error) + } + } + getRoomFile() + } catch (error: any) { + if (error.code === 'ENOENT') { + message.error('文件夹不存在!') + return + } else { + message.error(error) + } + } }) } }) }} /> - {/* */} + {/* */} )} /> diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index 2c9de5d..44a1f49 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -273,7 +273,6 @@ const Meeting: React.FC = () => { useEffect(() => { if (recorder) { - const setting = JSON.parse(storage.getItem('setting') as string) recorder.start(); recorder.ondataavailable = (event: any) => { const blob = new Blob([event.data], { @@ -281,6 +280,7 @@ const Meeting: React.FC = () => { }); const reader = new FileReader() as any; reader.onload = async () => { + const setting = await JSON.parse(storage.getItem('setting') as string) const buffer = Buffer.from(reader.result); await fs.writeFile(`${setting.recordingFilesPath}${+new Date()}.mp4`, buffer, {}); message.success(`录制成功!文件已保存至:${setting.recordingFilesPath}`)