From 8a90da5b64268750e87c1eec958dbefb962c4795 Mon Sep 17 00:00:00 2001 From: zhuhao <979263092@qq.com> Date: Wed, 16 Oct 2024 14:29:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5AI=E7=94=9F=E6=88=90PPT?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/file.js | 72 +++++++++++++++++++ src/renderer/src/utils/talkFile/index.js | 16 +++++ .../src/views/prepare/container/ai-ppt.vue | 26 ++++++- .../views/prepare/container/ppt-dialog.vue | 20 +++++- src/renderer/src/views/prepare/index.vue | 8 ++- 5 files changed, 135 insertions(+), 7 deletions(-) diff --git a/src/main/file.js b/src/main/file.js index 58ee5ec..7612bf4 100644 --- a/src/main/file.js +++ b/src/main/file.js @@ -243,6 +243,78 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) { }) }) + /*创建新的ppt文件*/ + ipcMain.on('creat-ai-file-default', (e, { name, url, uploadData, cookie }) => { + createFolder('tempFile').then(async () => { + let path = appTempFilePath + name.replace(/[\\/:*?"<>|]/, '') + let {type,item} = await downloadFile(url,name) + if (type==="成功") { + let fileType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation' + let formData = new FormData() + for (let key in uploadData) { + if (Object.prototype.hasOwnProperty.call(uploadData, key)) { + // 检查是否是对象自身的属性 + formData.append(key, uploadData[key]) + } + } + formData.append('fileFlag', '课件') + uploadFileByFS({ + url: uploadUrl, + path, + name, + cookie, + fileType, + formData, + success: (response) => { + e.reply('creat-ai-file-default-reply', response.data) + console.log('File uploaded successfully:', response.data) + }, + error: (err) => { + console.error('Error uploading file:', err) + } + }) + }else { + e.reply('creat-ai-file-default-reply', type) + } + }) + }) + + function downloadFile(url,fileName) { + return new Promise((resolve, reject)=>{ + const browserWindow = BrowserWindow.getFocusedWindow() + const id = manager.download({ + window: browserWindow, + url: url, + saveAsFilename: fileName, + directory: appTempFilePath, + callbacks: { + onDownloadStarted: async ({ id, item, webContents }) => { + // Do something with the download id + }, + onDownloadProgress: async ({ id, item, percentCompleted }) => { + // console.log(percentCompleted) + }, + onDownloadCompleted: async ({ id, item }) => { + console.log('完成') + resolve({type:"成功",item}) + }, + onDownloadCancelled: async () => { + console.log("取消") + reject({type:"取消了下载"}) + }, + onDownloadInterrupted: async () => { + console.log('中断') + reject({type:"下载被中断"}) + }, + onError: (err, data) => { + console.log(err.toString()) + reject({type:"下载出错",err}) + } + } + }) + }) + } + //获取应用文件目录 ipcMain.on('get-root-file-path', (e) => { e.reply('get-root-file-path-reply', appRootFilePath) diff --git a/src/renderer/src/utils/talkFile/index.js b/src/renderer/src/utils/talkFile/index.js index 08c9990..ae5dfbb 100644 --- a/src/renderer/src/utils/talkFile/index.js +++ b/src/renderer/src/utils/talkFile/index.js @@ -96,3 +96,19 @@ export const creatPPT = (name, uploadData) => { }) }) } + +export const creatAIPPT = (name, url, uploadData) => { + JSON.parse(JSON.stringify(uploadData)) + return new Promise((resolve, reject) => { + let cookie = localStorage.getItem('Admin-Token') + ipcRenderer.send('creat-ai-file-default', { + name, + url, + uploadData: JSON.parse(JSON.stringify(uploadData)), + cookie + }) + ipcRenderer.once('creat-ai-file-default-reply', (e, res) => { + resolve(res) + }) + }) +} diff --git a/src/renderer/src/views/prepare/container/ai-ppt.vue b/src/renderer/src/views/prepare/container/ai-ppt.vue index 961c874..570e175 100644 --- a/src/renderer/src/views/prepare/container/ai-ppt.vue +++ b/src/renderer/src/views/prepare/container/ai-ppt.vue @@ -47,7 +47,7 @@
{{ outputText }} -
+
@@ -130,6 +130,7 @@ \ No newline at end of file + diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue index be14fab..96800b9 100644 --- a/src/renderer/src/views/prepare/index.vue +++ b/src/renderer/src/views/prepare/index.vue @@ -138,12 +138,13 @@ > - +