代码优化

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>
<div class="canvasitem">
<div class="pdfAdnFabric" id="pdfAdnFabric" >
<!-- @touchmove="handleTouchMove"
@touchend="handleTouchEnd"
@mousedown="handleMouseDown"
@mousemove="handleMouseMove"
@mouseup="handleMouseUp" -->
<div :class="ispointer ? 'ispointer' : ''">
<canvas ref="fabriccanvas" />
</div>
<!-- style="pointer-events: none;" -->
<div v-if="props.pdfObj.numberOfPdf === 2" :class="ispointer ? 'ispointer' : ''">
<canvas ref="fabriccanvas1" />
</div>
@ -80,7 +74,10 @@ const renderPage = async (canvasobj) => {
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) => {
const img = document.createElement('img')
img.src = canvasobj.canvas.toDataURL('image/png')
@ -106,16 +103,6 @@ const renderPage = async (canvasobj) => {
}
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
// }
// })
// }
// })
})
}
//
@ -393,8 +380,18 @@ defineExpose({
savaDataStore
})
watchEffect(() => {
console.log(toolState.model,'监听')
setTimeout(() => {
console.log(toolState,'监听')
}, 300)
if(toolState.isPdfWin){
// if(toolState.isToolWin){
// ispointer.value=false
// }else{
// ispointer.value=true
// }
watchToolState() //
}
})
</script>

View File

@ -73,11 +73,6 @@ const renderPage = async (canvasobj) => {
canvasContext: canvasobj.context,
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) => {
const img = document.createElement('img')
img.src = canvasobj.canvas.toDataURL('image/png')
@ -90,7 +85,6 @@ const renderPage = async (canvasobj) => {
if (canvasobj.index == 0) {
canvasFabricVue.value.canvas.setWidth(screenWidth)
canvasFabricVue.value.canvas.setHeight(screenHeight)
// updateCanvasBackgroundImage(canvasFabricVue,img)
displayData(canvasFabricVue, canvsStore, canvasobj, fabric, img)
} else {
canvas1FabricVue.value.canvas.setWidth(screenWidth)
@ -198,10 +192,7 @@ const initPdf = async (type = 'default') => {
})
}
//
// savecanvsStore(imgarr, canvsStore)
if (props.pdfObj.numberOfPdf == 1) {
// imgarr.value[0]
canvasFabricVue.value.history.clean()
} else {
canvasFabricVue.value.history.clean()
@ -380,7 +371,10 @@ defineExpose({
savaDataStore
})
watchEffect(() => {
setTimeout(() => {
console.log(toolState,'监听')
}, 300)
if(toolState.isPdfWin){
// if(toolState.isToolWin){
// ispointer.value=false

View File

@ -41,6 +41,7 @@ const { ipcRenderer } = require('electron')
import { getBookMarkById } from '@/api/eTextbook/index'
import {useToolState} from '@/store/modules/tool'
pdfjsLib.GlobalWorkerOptions.workerSrc = getStaticUrl('/lib/build/pdf.worker.mjs')
const toolState = useToolState();
const route = useRoute();
const isOnLoadShow = ref(false) //
@ -70,14 +71,9 @@ const navtopage = (type) => {
if (pdfObj.numPages > numPagesTotal.value) return
pdfCanvaslist.value.initPdf('rest')
}
//
//
const minimize = async () => {
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) => {
numPagesTotal.value = data
@ -104,11 +100,12 @@ const switchPageMode = () => {
}
}
onMounted(async () => {
toolState.isPdfWin=true
toolState.isPdfWin=true //pdf
// pdfObj.pdfUrl = getStaticUrl(route.query.path, 'user', 'selfFile', true) //线
pdfObj.pdfUrl = getStaticUrl('aaa.pdf', 'user', 'selfFile', true) //
textbookId.value = route.query.textbookId
pdfObj.bookId=textbookId.value
//
getBookMarkById(textbookId.value).then(res=>{
pdfObj.allPageData=getUniqueArrayByLastOccurrence(res.data)
isOnLoadShow.value=true