文件同步功能BUG修复
This commit is contained in:
parent
2463feb0b7
commit
d07944e4ad
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "aix-win-ws",
|
||||
"version": "2.5.9",
|
||||
"version": "2.5.10",
|
||||
"description": "",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "上海交大重庆人工智能研究院",
|
||||
|
|
|
@ -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) => {
|
||||
try {
|
||||
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 () => {
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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}删除失败,并没有该文件!`)
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
</template>
|
||||
</el-popover>
|
||||
<el-button size="small" @click="isDialogOpen = true">上传资料</el-button>
|
||||
<el-button size="small" @click="reloadFiles">资源重载</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<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 { toTimeText } from '@/utils/date'
|
||||
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 SetHomework from '@/components/set-homework/index.vue'
|
||||
import outLink from '@/utils/linkConfig'
|
||||
|
@ -301,7 +302,7 @@ export default {
|
|||
},
|
||||
currentSCFileList() {
|
||||
// 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)
|
||||
},
|
||||
reloadFiles() {
|
||||
// TODO清除当前页所有文件缓存
|
||||
removeLocalFiles(this.currentSCFileList)
|
||||
this.currentSCFileList.filter((item) => {
|
||||
item.async = false
|
||||
})
|
||||
},
|
||||
asyncAllFile() {
|
||||
this.isLoading = true
|
||||
return getSmarttalkPage({
|
||||
|
|
Loading…
Reference in New Issue