Merge branch 'main' into lyc-dev

This commit is contained in:
lyc 2024-07-23 16:04:16 +08:00
commit a618032d25
4 changed files with 85 additions and 99 deletions

View File

@ -9,6 +9,13 @@ export const getSmarttalkPage = (params) => {
})
}
export const getPrepareById = (id) => {
return request({
url: '/smarttalk/file/' + id,
method: 'get'
})
}
export function deleteSmarttalk(id) {
return request({
url: '/smarttalk/file/' + id,

View File

@ -1,5 +1,49 @@
const { ipcRenderer } = window.electron || {}
export const asyncLocalFile = (item) => {
return new Promise((resolve) => {
//判断是否需要从线上拿新的文件
isAsyncLocalFile(item.fileNewName, item.lastModifyTime, item.fileMd5).then(
({ isAsync, type }) => {
item.async = !isAsync
if (isAsync === true) {
item.async = 'on'
if (type === 'down') {
ipcRenderer.send('download-file-default', {
url: item.fileFullPath,
fileName: item.fileNewName
})
ipcRenderer.once('download-file-default' + item.fileNewName, (e, isSuccess) => {
item.async = isSuccess
resolve()
})
}
if (type === 'upload') {
let cookie = localStorage.getItem('Admin-Token')
ipcRenderer.send('upload-file-change', {
id: item.id,
fileNewName: item.fileNewName,
cookie,
fileType: item.fileType
})
ipcRenderer.once(
'upload-file-change-success' + item.fileNewName,
(e, { data, md5 }) => {
item.fileSize = data.fileSize
item.md5 = md5
item.async = true
resolve()
}
)
}
} else {
resolve()
}
}
)
})
}
export const isHaveLocalFile = async (fileNewName) => {
return new Promise((resolve, reject) => {
ipcRenderer.send('is-have-local-file', fileNewName)

View File

@ -100,10 +100,10 @@ import { Check, UploadFilled, Switch } from '@element-plus/icons-vue'
</script>
<script>
import FileImage from '@/components/file-image/index.vue'
import { isHaveLocalFile } from '@/utils/talkFile'
import { asyncLocalFile } from '@/utils/talkFile'
import { toTimeText } from '@/utils/date'
import { ElMessage, ElMessageBox } from 'element-plus'
import { deleteSmarttalk, updateSmarttalk } from '@/api/file'
import { deleteSmarttalk, updateSmarttalk, getPrepareById } from '@/api/file'
const { ipcRenderer } = window.electron || {}
export default {
@ -182,9 +182,10 @@ export default {
return temp + 'GB'
}
},
openFileWin(item) {
isHaveLocalFile(item.fileNewName).then((res) => {
if (res === true) {
openFileWin(items) {
getPrepareById(items.id).then((item) => {
Object.assign(items, item)
asyncLocalFile(items).then(() => {
ipcRenderer.send('open-path-app', item.fileNewName)
if (this.listenList.indexOf(item.fileNewName) === -1) {
this.listenList.push(item.fileNewName)
@ -205,16 +206,7 @@ export default {
item.async = true
})
}
} else {
item.async = 'on'
ipcRenderer.once('download-file-default' + item.fileNewName, (e, isSuccess) => {
item.async = isSuccess
})
ipcRenderer.send('download-file-default', {
url: item.fileFullPath,
fileName: item.fileNewName
})
}
})
}
}

View File

@ -71,7 +71,7 @@ import FileListItem from '@/views/prepare/container/file-list-item.vue'
import { getSmarttalkPage, moveSmarttalk } from '@/api/file'
import { toTimeText } from '@/utils/date'
import { ElMessage } from 'element-plus'
import { isHaveLocalFile, parseCataByNode, creatPPT, isAsyncLocalFile } from '@/utils/talkFile'
import { parseCataByNode, creatPPT, asyncLocalFile } from '@/utils/talkFile'
import FileOperBatch from '@/views/prepare/container/file-oper-batch.vue'
import useUserStore from '@/store/modules/user'
import { homeWorkConfig } from '@/utils/config'
@ -121,15 +121,6 @@ export default {
this.userStore = useUserStore()
},
mounted() {
// const destination = '0901(A)-PPT.pptx'
// ipcRenderer.send('open-path-app',this.filePath)
// const source = 'D:\\edufile\\0901(A)-PPT.pptx'
// ipcRenderer.send('copy-file-default',{ source, destination })
// ipcRenderer.send('download-file-default',this.fileUrl)
// getSmarttalkPage({nowPage:1,pageSize:2}).then(res=>{
// console.log(res)
// })
// let filePath = window.rootTalkFilePath + item.fileNewName
},
methods: {
createFile() {
@ -159,59 +150,6 @@ export default {
clickChoose(value) {
this.checkFileList = value ? this.currentFileList : []
},
async asyncAllFile() {
this.lastAsyncAllTime = new Date()
localStorage.setItem('lastAsyncAllTime', this.lastAsyncAllTime)
this.asyncAllFileVisiable = true
const test = (item) => {
return new Promise((resolve) => {
//线
isAsyncLocalFile(item.fileNewName, item.lastModifyTime, item.fileMd5).then(
({ isAsync, type }) => {
console.log(isAsync, type)
item.async = !isAsync
if (isAsync === true) {
item.async = 'on'
if (type === 'down') {
ipcRenderer.send('download-file-default', {
url: item.fileFullPath,
fileName: item.fileNewName
})
ipcRenderer.once('download-file-default' + item.fileNewName, (e, isSuccess) => {
item.async = isSuccess
resolve()
})
}
if (type === 'upload') {
let cookie = localStorage.getItem('Admin-Token')
ipcRenderer.send('upload-file-change', {
id: item.id,
fileNewName: item.fileNewName,
cookie,
fileType: item.fileType
})
ipcRenderer.once(
'upload-file-change-success' + item.fileNewName,
(e, { data, md5 }) => {
item.fileSize = data.fileSize
item.md5 = md5
item.async = true
resolve()
}
)
}
} else {
resolve()
}
}
)
})
}
for (let i = 0; i < this.currentFileList.length; i++) {
await test(this.currentFileList[i])
}
this.asyncAllFileVisiable = false
},
deleteTalk(item) {
let index = this.currentFileList.indexOf(item)
this.currentFileList.splice(index, 1)
@ -277,6 +215,30 @@ export default {
}
console.log('File copied to:', filePath)
},
asyncAllFile() {
this.isLoading = true
getSmarttalkPage({
...this.uploadData,
orderByColumn: 'uploadTime',
isAsc: 'desc',
pageSize: 500
})
.then(async (res) => {
this.currentFileList = [...res.rows]
this.isLoading = false
this.lastAsyncAllTime = new Date()
localStorage.setItem('lastAsyncAllTime', this.lastAsyncAllTime)
this.asyncAllFileVisiable = true
for (let i = 0; i < this.currentFileList.length; i++) {
let item = this.currentFileList[i]
await asyncLocalFile(item)
}
this.asyncAllFileVisiable = false
})
.catch(() => {
this.isLoading = false
})
},
nodeClick(data) {
if (this.currentNode.id === data.node.id) return
this.curBookImg = data.textBook.curBookImg
@ -287,26 +249,7 @@ export default {
this.uploadData.levelSecondId = cata[1]
this.uploadData.levelThirdId = cata[2]
this.uploadData.textbookId = data.textBook.curBookId
this.isLoading = true
getSmarttalkPage({
...this.uploadData,
orderByColumn: 'uploadTime',
isAsc: 'desc',
pageSize: 500
})
.then((res) => {
this.currentFileList = [...res.rows]
this.isLoading = false
this.currentFileList.filter((item) => {
isHaveLocalFile(item.fileNewName).then((res) => {
item.async = res
})
})
})
.catch((res) => {
console.log(res)
this.isLoading = false
})
this.asyncAllFile()
},
//
handleHomeWork(){