From d07944e4ad3f28155ea03d6e85f742238536263b Mon Sep 17 00:00:00 2001
From: zhuhao <979263092@qq.com>
Date: Fri, 27 Dec 2024 15:04:13 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8C=E6=AD=A5=E5=8A=9F?=
=?UTF-8?q?=E8=83=BDBUG=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 2 +-
src/main/file.js | 47 +++++++++++++++++++++---
src/renderer/src/utils/talkFile/index.js | 26 +++++++++++++
src/renderer/src/views/prepare/index.vue | 12 +++++-
4 files changed, 78 insertions(+), 9 deletions(-)
diff --git a/package.json b/package.json
index f27fc00..9ac8a1d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "aix-win-ws",
- "version": "2.5.9",
+ "version": "2.5.10",
"description": "",
"main": "./out/main/index.js",
"author": "上海交大重庆人工智能研究院",
diff --git a/src/main/file.js b/src/main/file.js
index 3de3333..5764d91 100644
--- a/src/main/file.js
+++ b/src/main/file.js
@@ -13,6 +13,34 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
const appTempFilePath = userDataPath + '\\tempFile\\'
let Spark = new SparkMD5.ArrayBuffer()
+ ipcMain.on('remove-local-file-list', (e, list) => {
+ let filePath = appRootFilePath
+ for (let i = 0; i < list.length; i++) {
+ let item = list[i];
+ if (!isAccess(filePath + item.fileNewName)) {
+ e.reply('remove-local-file-list-not', item)
+ continue
+ }
+ try {
+ fs.unlinkSync(filePath + item.fileNewName);
+ console.log(`${filePath} 已成功删除`);
+ } catch (err) {
+ console.error(`删除文件时出错:`, err);
+ e.reply('remove-local-file-list-error', item)
+ }
+ }
+ e.reply('remove-local-file-list-reply')
+ })
+
+ const isAccess = (filePath) => {
+ try {
+ fs.accessSync(filePath);
+ return true
+ } catch (err) {
+ return false
+ }
+ }
+
ipcMain.on('upload-file-change', (e, { id, fileNewName, cookie, fileType }) => {
let filePath = appRootFilePath + fileNewName
//执行更新,上传文件
@@ -58,7 +86,6 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
}
//倒数十秒提交更改,十秒之内有继续修改则重置倒数
uploadId = setTimeout(() => {
- console.log(223)
//执行更新,上传文件
let formData = new FormData()
formData.append('id', id)
@@ -89,8 +116,12 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
function getFileMsg(path) {
return new Promise((resolve, reject) => {
- const stats = fs.statSync(path)
- return resolve(stats.mtime.getTime())
+ try {
+ const stats = fs.statSync(path)
+ resolve(stats.mtime.getTime())
+ }catch (e) {
+ reject(e)
+ }
})
}
@@ -303,17 +334,20 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
},
onDownloadCancelled: async () => {
console.log("取消")
- reject({type:"取消了下载"})
+ resolve({type:"取消了下载"})
},
onDownloadInterrupted: async () => {
console.log('中断')
- reject({type:"下载被中断"})
+ resolve({type:"下载被中断"})
},
onError: (err, data) => {
console.log(err.toString())
- reject({type:"下载出错",err})
+ resolve({type:"下载出错",err})
}
}
+ }).catch(err=>{
+ console.log(err)
+ resolve({type:"下载出错",err})
})
})
}
@@ -360,6 +394,7 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
})
})
.catch((error) => {
+ console.log(error)
e.reply('download-file-default' + fileName, false)
})
})
diff --git a/src/renderer/src/utils/talkFile/index.js b/src/renderer/src/utils/talkFile/index.js
index fa56bb2..495e1cd 100644
--- a/src/renderer/src/utils/talkFile/index.js
+++ b/src/renderer/src/utils/talkFile/index.js
@@ -1,3 +1,5 @@
+import {ElMessage} from "element-plus";
+
const { ipcRenderer } = window.electron || {}
export const asyncLocalFile = (item) => {
@@ -15,6 +17,9 @@ export const asyncLocalFile = (item) => {
fileName: item.fileNewName
})
ipcRenderer.once('download-file-default' + item.fileNewName, (e, isSuccess) => {
+ if (isSuccess == false) {
+ ElMessage.error(`${item.fileShowName}下载失败!`)
+ }
item.async = isSuccess
resolve()
})
@@ -112,3 +117,24 @@ export const creatAIPPT = (name, url, uploadData) => {
})
})
}
+
+export const removeLocalFiles = async (list) => {
+ return new Promise((resolve, reject) => {
+ ipcRenderer.send('remove-local-file-list', JSON.parse(JSON.stringify(list)))
+ ipcRenderer.removeListener('remove-local-file-list-error', removeLocalFileListError)
+ ipcRenderer.removeListener('remove-local-file-list-not', removeLocalFileListNot)
+ ipcRenderer.on('remove-local-file-list-error', removeLocalFileListError)
+ ipcRenderer.on('remove-local-file-list-not', removeLocalFileListNot)
+ ipcRenderer.once('remove-local-file-list-reply', (e, res) => {
+ resolve(res)
+ })
+ })
+}
+
+function removeLocalFileListError(e, item) {
+ ElMessage.error(`${item.fileShowName}删除失败`)
+}
+
+function removeLocalFileListNot(e, item) {
+ ElMessage.error(`${item.fileShowName}删除失败,并没有该文件!`)
+}
diff --git a/src/renderer/src/views/prepare/index.vue b/src/renderer/src/views/prepare/index.vue
index bdc2e45..7a39828 100644
--- a/src/renderer/src/views/prepare/index.vue
+++ b/src/renderer/src/views/prepare/index.vue
@@ -83,6 +83,7 @@
上传资料
+ 资源重载
item.fileFlag !== 'apt' && item.fileFlag !== '课件')
- return this.currentFileList.filter((item) => !['apt','aippt','课件'].includes(item.fileFlag))
+ return this.currentFileList.filter((item) => !['apt','aippt'].includes(item.fileFlag))
}
},
@@ -933,6 +934,13 @@ export default {
}
console.log('File copied to:', filePath)
},
+ reloadFiles() {
+ // TODO清除当前页所有文件缓存
+ removeLocalFiles(this.currentSCFileList)
+ this.currentSCFileList.filter((item) => {
+ item.async = false
+ })
+ },
asyncAllFile() {
this.isLoading = true
return getSmarttalkPage({