二期:教材打开开发

This commit is contained in:
朱浩 2024-08-07 15:49:37 +08:00
parent 3bcb0a2ef3
commit 9f510187c0
2 changed files with 51 additions and 7 deletions

View File

@ -71,6 +71,8 @@ const curBookId = ref(-1)
const curBookName = ref('') const curBookName = ref('')
// //
const curBookImg = ref('') const curBookImg = ref('')
//
const curBookPath = ref('')
// //
const volumeOne = ref([]) const volumeOne = ref([])
// //
@ -126,10 +128,11 @@ const getSubjectContent = async () => {
} }
// //
const changeBook = ({ id, itemtitle, avartar }) => { const changeBook = ({ id, itemtitle, avartar, fileurl }) => {
curBookId.value = id curBookId.value = id
curBookName.value = itemtitle curBookName.value = itemtitle
curBookImg.value = BaseUrl + avartar curBookImg.value = BaseUrl + avartar
curBookPath.value = fileurl
getTreeData() getTreeData()
setTimeout(() => { setTimeout(() => {
dialogVisible.value = false dialogVisible.value = false
@ -176,7 +179,8 @@ const emitChangeBook = () => {
textBook: { textBook: {
curBookId: curBookId.value, curBookId: curBookId.value,
curBookName: curBookName.value, curBookName: curBookName.value,
curBookImg: curBookImg.value curBookImg: curBookImg.value,
curBookPath: curBookPath.value
}, },
node: curNode node: curNode
} }
@ -276,6 +280,7 @@ const getSubject = async () => {
curBookName.value = subjectList.value[0].itemtitle curBookName.value = subjectList.value[0].itemtitle
curBookId.value = subjectList.value[0].id curBookId.value = subjectList.value[0].id
curBookImg.value = BaseUrl + subjectList.value[0].avartar curBookImg.value = BaseUrl + subjectList.value[0].avartar
curBookPath.value = subjectList.value[0].fileurl
} }
@ -291,7 +296,7 @@ const handleNodeClick = (data, node) => {
* data : 当前节点数据 * data : 当前节点数据
* node : 当前节点对象 包含当前节点所有数据 parent属性 指向父节点Node对象 * node : 当前节点对象 包含当前节点所有数据 parent属性 指向父节点Node对象
*/ */
const nodeData = data; const nodeData = data;
const parentNode = node.parent.data; const parentNode = node.parent.data;
@ -306,7 +311,8 @@ const handleNodeClick = (data, node) => {
textBook: { textBook: {
curBookId: curBookId.value, curBookId: curBookId.value,
curBookName: curBookName.value, curBookName: curBookName.value,
curBookImg: curBookImg.value curBookImg: curBookImg.value,
curBookPath: curBookPath.value
}, },
node: toRaw(nodeData) node: toRaw(nodeData)
} }
@ -428,4 +434,4 @@ onMounted(() => {
background-color: #eaf3ff !important; background-color: #eaf3ff !important;
color: #409EFF color: #409EFF
} }
</style> </style>

View File

@ -66,6 +66,7 @@ import { Check } from '@element-plus/icons-vue'
import Reserv from '@/views/prepare/container/reserv.vue' import Reserv from '@/views/prepare/container/reserv.vue'
</script> </script>
<script> <script>
const Remote = require('@electron/remote')
import ChooseTextbook from '@/components/choose-textbook/index.vue' import ChooseTextbook from '@/components/choose-textbook/index.vue'
import uploadDialog from '@/components/upload-dialog/index.vue' import uploadDialog from '@/components/upload-dialog/index.vue'
import { Refresh } from '@element-plus/icons-vue' import { Refresh } from '@element-plus/icons-vue'
@ -84,7 +85,7 @@ import outLink from '@/utils/linkConfig'
import { createWindow } from '@/utils/tool' import { createWindow } from '@/utils/tool'
import { uniqBy, cloneDeep } from 'lodash' import { uniqBy, cloneDeep } from 'lodash'
import { delClasswork, addEntpcourse } from '@/api/teaching/classwork' import { delClasswork, addEntpcourse } from '@/api/teaching/classwork'
const fs = require('fs');
const { ipcRenderer } = window.electron || {} const { ipcRenderer } = window.electron || {}
export default { export default {
@ -110,6 +111,7 @@ export default {
fileList: [], fileList: [],
currentNode: {}, currentNode: {},
currentFileList: [], currentFileList: [],
curBookPath: '',
lastAsyncAllTime: '', lastAsyncAllTime: '',
uploadData: { uploadData: {
textbookId: null, textbookId: null,
@ -160,6 +162,38 @@ export default {
} }
}, },
methods: { methods: {
getBookPathFromServer() {
let fileName = this.curBookPath
if (!fileName) return
fileName = fileName.replace('.txt', '.pdf')
return new Promise((resolve, reject)=>{
const userDataPath = Remote.app.getPath('userData')
const appRootFilePath = userDataPath + '\\selfFile\\'
let filePath = appRootFilePath + fileName
fs.access(filePath, fs.constants.F_OK, (err) => {
let filePath = import.meta.env.VITE_APP_RES_FILE_PATH + fileName
if (err) {
//线
ipcRenderer.send('download-file-default', {
url: filePath,
fileName: fileName
})
ipcRenderer.once('download-file-default' + fileName, (e, isSuccess) => {
if (isSuccess === true) {
resolve(appRootFilePath + fileName)
}else {
ElMessage({
type: 'info',
message: `下载教材失败!`
})
}
})
}else {
resolve(appRootFilePath + fileName)
}
})
})
},
createFile() { createFile() {
creatPPT(this.currentNode.label + '.pptx', this.uploadData).then((res) => { creatPPT(this.currentNode.label + '.pptx', this.uploadData).then((res) => {
this.currentFileList.unshift(res.resData) this.currentFileList.unshift(res.resData)
@ -279,8 +313,10 @@ export default {
}) })
}, },
async nodeClick(data) { async nodeClick(data) {
console.log(data)
if (this.currentNode.id === data.node.id) return if (this.currentNode.id === data.node.id) return
this.curBookImg = data.textBook.curBookImg this.curBookImg = data.textBook.curBookImg
this.curBookPath = data.textBook.curBookPath
this.checkFileList = [] this.checkFileList = []
let cata = parseCataByNode(data.node) let cata = parseCataByNode(data.node)
this.currentNode = data.node this.currentNode = data.node
@ -453,7 +489,9 @@ export default {
}, },
// PDF- // PDF-
navtoPdf() { async navtoPdf() {
let path = await this.getBookPathFromServer()
console.log(path)
createWindow('open-PDF', { url: '/classBegins/index' }) createWindow('open-PDF', { url: '/classBegins/index' })
}, },
// - // -