代码优化
This commit is contained in:
parent
2bf82dc294
commit
f80e7dee2a
|
@ -1,15 +1,9 @@
|
||||||
pdfAdnFabric<template>
|
pdfAdnFabric<template>
|
||||||
<div class="canvasitem">
|
<div class="canvasitem">
|
||||||
<div class="pdfAdnFabric" id="pdfAdnFabric" >
|
<div class="pdfAdnFabric" id="pdfAdnFabric" >
|
||||||
<!-- @touchmove="handleTouchMove"
|
|
||||||
@touchend="handleTouchEnd"
|
|
||||||
@mousedown="handleMouseDown"
|
|
||||||
@mousemove="handleMouseMove"
|
|
||||||
@mouseup="handleMouseUp" -->
|
|
||||||
<div :class="ispointer ? 'ispointer' : ''">
|
<div :class="ispointer ? 'ispointer' : ''">
|
||||||
<canvas ref="fabriccanvas" />
|
<canvas ref="fabriccanvas" />
|
||||||
</div>
|
</div>
|
||||||
<!-- style="pointer-events: none;" -->
|
|
||||||
<div v-if="props.pdfObj.numberOfPdf === 2" :class="ispointer ? 'ispointer' : ''">
|
<div v-if="props.pdfObj.numberOfPdf === 2" :class="ispointer ? 'ispointer' : ''">
|
||||||
<canvas ref="fabriccanvas1" />
|
<canvas ref="fabriccanvas1" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -80,7 +74,10 @@ const renderPage = async (canvasobj) => {
|
||||||
viewport: viewport
|
viewport: viewport
|
||||||
}
|
}
|
||||||
// console.log(renderContext,22222222222222222222)
|
// console.log(renderContext,22222222222222222222)
|
||||||
|
// const textContent = await page.getTextContent();
|
||||||
|
// console.log(textContent);
|
||||||
|
// const annotations = await page.getAnnotations();
|
||||||
|
// console.log(annotations);
|
||||||
page.render(renderContext).promise.then((res) => {
|
page.render(renderContext).promise.then((res) => {
|
||||||
const img = document.createElement('img')
|
const img = document.createElement('img')
|
||||||
img.src = canvasobj.canvas.toDataURL('image/png')
|
img.src = canvasobj.canvas.toDataURL('image/png')
|
||||||
|
@ -106,22 +103,12 @@ const renderPage = async (canvasobj) => {
|
||||||
}
|
}
|
||||||
img.remove()
|
img.remove()
|
||||||
}
|
}
|
||||||
// 判断imgarr的JSONdata在canvsStore.pageArr有没有
|
|
||||||
// canvsStore.pageArr.forEach((item) => {
|
|
||||||
// if (item.page == canvasobj.page) {
|
|
||||||
// imgarr.value.forEach((img) => {
|
|
||||||
// if (img.page == canvasobj.page) {
|
|
||||||
// img.JSONdata = item.JSONdata
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 保存数据
|
// 保存数据
|
||||||
const savaDataStore = () => {
|
const savaDataStore = () => {
|
||||||
if(!toolState.isToolWin){
|
if(!toolState.isToolWin){
|
||||||
toolState.isPdfWin=false
|
toolState.isPdfWin=false
|
||||||
toolState.showBoardAll=true //恢复默认值
|
toolState.showBoardAll=true //恢复默认值
|
||||||
ipcRenderer.invoke('tool-sphere:reset') //重置tool状态
|
ipcRenderer.invoke('tool-sphere:reset') //重置tool状态
|
||||||
ipcRenderer.send('open-PDF:minimize')
|
ipcRenderer.send('open-PDF:minimize')
|
||||||
|
@ -393,8 +380,18 @@ defineExpose({
|
||||||
savaDataStore
|
savaDataStore
|
||||||
})
|
})
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
console.log(toolState.model,'监听')
|
setTimeout(() => {
|
||||||
watchToolState() //监听工具栏
|
console.log(toolState,'监听')
|
||||||
|
|
||||||
|
}, 300)
|
||||||
|
if(toolState.isPdfWin){
|
||||||
|
// if(toolState.isToolWin){
|
||||||
|
// ispointer.value=false
|
||||||
|
// }else{
|
||||||
|
// ispointer.value=true
|
||||||
|
// }
|
||||||
|
watchToolState() //监听工具栏
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -73,11 +73,6 @@ const renderPage = async (canvasobj) => {
|
||||||
canvasContext: canvasobj.context,
|
canvasContext: canvasobj.context,
|
||||||
viewport: viewport
|
viewport: viewport
|
||||||
}
|
}
|
||||||
// console.log(renderContext,22222222222222222222)
|
|
||||||
// const textContent = await page.getTextContent();
|
|
||||||
// console.log(textContent);
|
|
||||||
// const annotations = await page.getAnnotations();
|
|
||||||
// console.log(annotations);
|
|
||||||
page.render(renderContext).promise.then((res) => {
|
page.render(renderContext).promise.then((res) => {
|
||||||
const img = document.createElement('img')
|
const img = document.createElement('img')
|
||||||
img.src = canvasobj.canvas.toDataURL('image/png')
|
img.src = canvasobj.canvas.toDataURL('image/png')
|
||||||
|
@ -90,7 +85,6 @@ const renderPage = async (canvasobj) => {
|
||||||
if (canvasobj.index == 0) {
|
if (canvasobj.index == 0) {
|
||||||
canvasFabricVue.value.canvas.setWidth(screenWidth)
|
canvasFabricVue.value.canvas.setWidth(screenWidth)
|
||||||
canvasFabricVue.value.canvas.setHeight(screenHeight)
|
canvasFabricVue.value.canvas.setHeight(screenHeight)
|
||||||
// updateCanvasBackgroundImage(canvasFabricVue,img)
|
|
||||||
displayData(canvasFabricVue, canvsStore, canvasobj, fabric, img)
|
displayData(canvasFabricVue, canvsStore, canvasobj, fabric, img)
|
||||||
} else {
|
} else {
|
||||||
canvas1FabricVue.value.canvas.setWidth(screenWidth)
|
canvas1FabricVue.value.canvas.setWidth(screenWidth)
|
||||||
|
@ -198,10 +192,7 @@ const initPdf = async (type = 'default') => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 保存数据
|
// 保存数据
|
||||||
// savecanvsStore(imgarr, canvsStore)
|
|
||||||
|
|
||||||
if (props.pdfObj.numberOfPdf == 1) {
|
if (props.pdfObj.numberOfPdf == 1) {
|
||||||
// imgarr.value[0]
|
|
||||||
canvasFabricVue.value.history.clean()
|
canvasFabricVue.value.history.clean()
|
||||||
} else {
|
} else {
|
||||||
canvasFabricVue.value.history.clean()
|
canvasFabricVue.value.history.clean()
|
||||||
|
@ -380,7 +371,10 @@ defineExpose({
|
||||||
savaDataStore
|
savaDataStore
|
||||||
})
|
})
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
console.log(toolState,'监听')
|
setTimeout(() => {
|
||||||
|
console.log(toolState,'监听')
|
||||||
|
|
||||||
|
}, 300)
|
||||||
if(toolState.isPdfWin){
|
if(toolState.isPdfWin){
|
||||||
// if(toolState.isToolWin){
|
// if(toolState.isToolWin){
|
||||||
// ispointer.value=false
|
// ispointer.value=false
|
||||||
|
|
|
@ -41,6 +41,7 @@ const { ipcRenderer } = require('electron')
|
||||||
import { getBookMarkById } from '@/api/eTextbook/index'
|
import { getBookMarkById } from '@/api/eTextbook/index'
|
||||||
import {useToolState} from '@/store/modules/tool'
|
import {useToolState} from '@/store/modules/tool'
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = getStaticUrl('/lib/build/pdf.worker.mjs')
|
pdfjsLib.GlobalWorkerOptions.workerSrc = getStaticUrl('/lib/build/pdf.worker.mjs')
|
||||||
|
|
||||||
const toolState = useToolState();
|
const toolState = useToolState();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const isOnLoadShow = ref(false) //加载完毕显示
|
const isOnLoadShow = ref(false) //加载完毕显示
|
||||||
|
@ -70,14 +71,9 @@ const navtopage = (type) => {
|
||||||
if (pdfObj.numPages > numPagesTotal.value) return
|
if (pdfObj.numPages > numPagesTotal.value) return
|
||||||
pdfCanvaslist.value.initPdf('rest')
|
pdfCanvaslist.value.initPdf('rest')
|
||||||
}
|
}
|
||||||
// 最小化窗口
|
// 关闭窗口
|
||||||
const minimize = async () => {
|
const minimize = async () => {
|
||||||
await pdfCanvaslist.value.savaDataStore()
|
await pdfCanvaslist.value.savaDataStore()
|
||||||
// toolState.isPdfWin=false
|
|
||||||
// toolState.showBoardAll=true //恢复默认值
|
|
||||||
// console.log(toolState.showBoardAll,"关闭")
|
|
||||||
// // ipcRenderer.send('tool-sphere:reset') //重置tool状态
|
|
||||||
// ipcRenderer.send('open-PDF:minimize')
|
|
||||||
}
|
}
|
||||||
const handleUpdate = (data) => {
|
const handleUpdate = (data) => {
|
||||||
numPagesTotal.value = data
|
numPagesTotal.value = data
|
||||||
|
@ -104,11 +100,12 @@ const switchPageMode = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
toolState.isPdfWin=true
|
toolState.isPdfWin=true //设置打开pdf窗口
|
||||||
// pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线上
|
// pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线上
|
||||||
pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //本地
|
pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //本地
|
||||||
textbookId.value = route.query.textbookId
|
textbookId.value = route.query.textbookId
|
||||||
pdfObj.bookId=textbookId.value
|
pdfObj.bookId=textbookId.value
|
||||||
|
//初始化获取接口数据
|
||||||
getBookMarkById(textbookId.value).then(res=>{
|
getBookMarkById(textbookId.value).then(res=>{
|
||||||
pdfObj.allPageData=getUniqueArrayByLastOccurrence(res.data)
|
pdfObj.allPageData=getUniqueArrayByLastOccurrence(res.data)
|
||||||
isOnLoadShow.value=true
|
isOnLoadShow.value=true
|
||||||
|
|
Loading…
Reference in New Issue