From fabffc2363247d8ea7af8b6f7780be6960cc5ebe Mon Sep 17 00:00:00 2001 From: zhuhao <979263092@qq.com> Date: Tue, 21 Jan 2025 12:49:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ebase64=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/file.js | 21 +++++++++++++++++++++ src/renderer/src/utils/talkFile/index.js | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/file.js b/src/main/file.js index a957b42..b370b38 100644 --- a/src/main/file.js +++ b/src/main/file.js @@ -452,6 +452,27 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { }) }) + ipcMain.on('export-img64-file', function (event, {base64, name}) { + name = name || '思维导图' + const parts = base64.split(';base64,'); + const contentType = parts[0].split(':')[1]; + const extension = contentType.split('/')[1]; + const data = Buffer.from(parts[1], 'base64'); + + dialog.showSaveDialog({ + title: '保存图片', + defaultPath: path.join(app.getPath('downloads'), `${name}.${extension}`), + filters: [ + { name: 'Image Files', extensions: [extension] } + ] + }).then(result => { + if (!result.canceled) { + fs.writeFileSync(result.filePath, data); + event.reply('export-img64-file-reply') + } + }); + }) + /*导出文件*/ function exportFile(list, callback) { let win = BrowserWindow.getFocusedWindow() diff --git a/src/renderer/src/utils/talkFile/index.js b/src/renderer/src/utils/talkFile/index.js index 495e1cd..3807a1e 100644 --- a/src/renderer/src/utils/talkFile/index.js +++ b/src/renderer/src/utils/talkFile/index.js @@ -87,6 +87,15 @@ export const exportFile = async (list) => { }) } +export const exportImg64File = async (base64, name) => { + return new Promise((resolve, reject) => { + ipcRenderer.send('export-img64-file', {base64,name}) + ipcRenderer.once('export-img64-file-reply', (e) => { + resolve() + }) + }) +} + export const creatPPT = (name, uploadData) => { JSON.parse(JSON.stringify(uploadData)) return new Promise((resolve, reject) => {