文件同步功能BUG修复

This commit is contained in:
朱浩 2024-12-27 15:04:13 +08:00
parent 2463feb0b7
commit d07944e4ad
4 changed files with 78 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "aix-win-ws", "name": "aix-win-ws",
"version": "2.5.9", "version": "2.5.10",
"description": "", "description": "",
"main": "./out/main/index.js", "main": "./out/main/index.js",
"author": "上海交大重庆人工智能研究院", "author": "上海交大重庆人工智能研究院",

View File

@ -13,6 +13,34 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
const appTempFilePath = userDataPath + '\\tempFile\\' const appTempFilePath = userDataPath + '\\tempFile\\'
let Spark = new SparkMD5.ArrayBuffer() 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 }) => { ipcMain.on('upload-file-change', (e, { id, fileNewName, cookie, fileType }) => {
let filePath = appRootFilePath + fileNewName let filePath = appRootFilePath + fileNewName
//执行更新,上传文件 //执行更新,上传文件
@ -58,7 +86,6 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
} }
//倒数十秒提交更改,十秒之内有继续修改则重置倒数 //倒数十秒提交更改,十秒之内有继续修改则重置倒数
uploadId = setTimeout(() => { uploadId = setTimeout(() => {
console.log(223)
//执行更新,上传文件 //执行更新,上传文件
let formData = new FormData() let formData = new FormData()
formData.append('id', id) formData.append('id', id)
@ -89,8 +116,12 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
function getFileMsg(path) { function getFileMsg(path) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try {
const stats = fs.statSync(path) const stats = fs.statSync(path)
return resolve(stats.mtime.getTime()) resolve(stats.mtime.getTime())
}catch (e) {
reject(e)
}
}) })
} }
@ -303,17 +334,20 @@ export default async function ({ app, shell, BrowserWindow, ipcMain }) {
}, },
onDownloadCancelled: async () => { onDownloadCancelled: async () => {
console.log("取消") console.log("取消")
reject({type:"取消了下载"}) resolve({type:"取消了下载"})
}, },
onDownloadInterrupted: async () => { onDownloadInterrupted: async () => {
console.log('中断') console.log('中断')
reject({type:"下载被中断"}) resolve({type:"下载被中断"})
}, },
onError: (err, data) => { onError: (err, data) => {
console.log(err.toString()) 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) => { .catch((error) => {
console.log(error)
e.reply('download-file-default' + fileName, false) e.reply('download-file-default' + fileName, false)
}) })
}) })

View File

@ -1,3 +1,5 @@
import {ElMessage} from "element-plus";
const { ipcRenderer } = window.electron || {} const { ipcRenderer } = window.electron || {}
export const asyncLocalFile = (item) => { export const asyncLocalFile = (item) => {
@ -15,6 +17,9 @@ export const asyncLocalFile = (item) => {
fileName: item.fileNewName fileName: item.fileNewName
}) })
ipcRenderer.once('download-file-default' + item.fileNewName, (e, isSuccess) => { ipcRenderer.once('download-file-default' + item.fileNewName, (e, isSuccess) => {
if (isSuccess == false) {
ElMessage.error(`${item.fileShowName}下载失败!`)
}
item.async = isSuccess item.async = isSuccess
resolve() 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}删除失败,并没有该文件!`)
}

View File

@ -83,6 +83,7 @@
</template> </template>
</el-popover> </el-popover>
<el-button size="small" @click="isDialogOpen = true">上传资料</el-button> <el-button size="small" @click="isDialogOpen = true">上传资料</el-button>
<el-button size="small" @click="reloadFiles">资源重载</el-button>
</div> </div>
</div> </div>
<el-checkbox-group <el-checkbox-group
@ -188,7 +189,7 @@ import KjListItem from '@/views/prepare/container/kj-list-item.vue'
import { getSmarttalkPage, moveSmarttalk, creatAPT } from '@/api/file' import { getSmarttalkPage, moveSmarttalk, creatAPT } from '@/api/file'
import { toTimeText } from '@/utils/date' import { toTimeText } from '@/utils/date'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { parseCataByNode, creatPPT, asyncLocalFile } from '@/utils/talkFile' import {parseCataByNode, creatPPT, asyncLocalFile, removeLocalFiles} from '@/utils/talkFile'
import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue' import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue'
import SetHomework from '@/components/set-homework/index.vue' import SetHomework from '@/components/set-homework/index.vue'
import outLink from '@/utils/linkConfig' import outLink from '@/utils/linkConfig'
@ -301,7 +302,7 @@ export default {
}, },
currentSCFileList() { currentSCFileList() {
// return this.currentFileList.filter((item) => item.fileFlag !== 'apt' && item.fileFlag !== '') // return this.currentFileList.filter((item) => 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) console.log('File copied to:', filePath)
}, },
reloadFiles() {
// TODO
removeLocalFiles(this.currentSCFileList)
this.currentSCFileList.filter((item) => {
item.async = false
})
},
asyncAllFile() { asyncAllFile() {
this.isLoading = true this.isLoading = true
return getSmarttalkPage({ return getSmarttalkPage({