二期:自动同步功能开发
This commit is contained in:
parent
4dc180a26f
commit
2926b4bd63
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
@ -199,22 +200,13 @@ export default {
|
|||
ipcRenderer.on('listen-file-change-on' + item.fileNewName, () => {
|
||||
item.async = 'on'
|
||||
})
|
||||
ipcRenderer.on('listen-file-change-success' + item.fileNewName, (e,{data,md5}) => {
|
||||
ipcRenderer.on('listen-file-change-success' + item.fileNewName, (e, { data, md5 }) => {
|
||||
item.fileSize = data.fileSize
|
||||
item.md5 = md5
|
||||
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
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
const { ipcRenderer } = window.electron || {}
|
||||
export default {
|
||||
|
@ -116,15 +116,6 @@ export default {
|
|||
this.lastAsyncAllTime = localStorage.getItem('lastAsyncAllTime')
|
||||
},
|
||||
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() {
|
||||
|
@ -154,59 +145,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)
|
||||
|
@ -272,17 +210,7 @@ export default {
|
|||
}
|
||||
console.log('File copied to:', filePath)
|
||||
},
|
||||
nodeClick(data) {
|
||||
if (this.currentNode.id === data.node.id) return
|
||||
this.curBookImg = data.textBook.curBookImg
|
||||
console.log(data.textBook)
|
||||
this.checkFileList = []
|
||||
let cata = parseCataByNode(data.node)
|
||||
this.currentNode = data.node
|
||||
this.uploadData.levelFirstId = cata[0]
|
||||
this.uploadData.levelSecondId = cata[1]
|
||||
this.uploadData.levelThirdId = cata[2]
|
||||
this.uploadData.textbookId = data.textBook.curBookId
|
||||
asyncAllFile() {
|
||||
this.isLoading = true
|
||||
getSmarttalkPage({
|
||||
...this.uploadData,
|
||||
|
@ -290,19 +218,33 @@ export default {
|
|||
isAsc: 'desc',
|
||||
pageSize: 500
|
||||
})
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
this.currentFileList = [...res.rows]
|
||||
this.isLoading = false
|
||||
this.currentFileList.filter((item) => {
|
||||
isHaveLocalFile(item.fileNewName).then((res) => {
|
||||
item.async = res
|
||||
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((res) => {
|
||||
console.log(res)
|
||||
.catch(() => {
|
||||
this.isLoading = false
|
||||
})
|
||||
},
|
||||
nodeClick(data) {
|
||||
if (this.currentNode.id === data.node.id) return
|
||||
this.curBookImg = data.textBook.curBookImg
|
||||
this.checkFileList = []
|
||||
let cata = parseCataByNode(data.node)
|
||||
this.currentNode = data.node
|
||||
this.uploadData.levelFirstId = cata[0]
|
||||
this.uploadData.levelSecondId = cata[1]
|
||||
this.uploadData.levelThirdId = cata[2]
|
||||
this.uploadData.textbookId = data.textBook.curBookId
|
||||
this.asyncAllFile()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue