代码优化

This commit is contained in:
zhangxuelin 2024-08-13 15:14:26 +08:00
parent 2bf82dc294
commit f80e7dee2a
3 changed files with 25 additions and 37 deletions

View File

@ -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()
} }
// imgarrJSONdatacanvsStore.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>

View File

@ -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

View File

@ -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