mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect-embeded.git
synced 2025-06-24 13:34:13 +08:00
fixed
This commit is contained in:
parent
b516c0d9d0
commit
2d61e9a1a9
@ -1,40 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="box" v-show="open">
|
<div class="box" v-show="open">
|
||||||
<div
|
<div id="scroller"
|
||||||
id="scroller"
|
|
||||||
class="pdf-viewer"
|
class="pdf-viewer"
|
||||||
@mousedown="startSelection"
|
@mousedown="startSelection"
|
||||||
@mousemove="updateSelection"
|
@mousemove="updateSelection"
|
||||||
@mouseup="endSelection"
|
@mouseup="endSelection"
|
||||||
@scroll="handleScroll"
|
@scroll="handleScroll">
|
||||||
>
|
|
||||||
<canvas ref="pdfCanvas" />
|
<canvas ref="pdfCanvas" />
|
||||||
<canvas ref="tempCanvas" v-show="false" />
|
<canvas ref="tempCanvas" v-show="false" />
|
||||||
<div v-if="selection" class="selection-box" :style="selectionStyle"></div>
|
<div v-if="selection" class="selection-box" :style="selectionStyle"></div>
|
||||||
</div>
|
</div>
|
||||||
<a-button
|
<div class="tool-box">
|
||||||
type="primary"
|
<a-button type="primary" class="tool-button" :icon="h(MinusOutlined)" @click="zoomOut"/>
|
||||||
class="btn"
|
<span>{{ Math.round(zoomLevel * 100) }}%</span>
|
||||||
v-show="captureButtonVisible"
|
<a-button type="primary" class="tool-button" :icon="h(PlusOutlined)" @click="zoomIn" />
|
||||||
:style="captureButtonStyle"
|
</div>
|
||||||
:icon="h(ScissorOutlined)"
|
<a-button type="primary" class="btn" v-show="captureButtonVisible" :style="captureButtonStyle" :icon="h(ScissorOutlined)" @click="captureSelection">截 图</a-button>
|
||||||
@click="captureSelection"
|
<a-button type="primary" class="btn-close" :style="closeButtonStyle" :icon="h(CloseOutlined)" @click="close">取 消</a-button>
|
||||||
>截 图</a-button
|
|
||||||
>
|
|
||||||
<a-button
|
|
||||||
type="primary"
|
|
||||||
class="btn-close"
|
|
||||||
:style="closeButtonStyle"
|
|
||||||
:icon="h(CloseOutlined)"
|
|
||||||
@click="close"
|
|
||||||
>取 消</a-button
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import * as pdfjsLib from 'pdfjs-dist';
|
import * as pdfjsLib from 'pdfjs-dist';
|
||||||
import {h} from "vue";
|
import {h} from "vue";
|
||||||
import {CloseOutlined, ScissorOutlined} from "@ant-design/icons-vue";
|
import {
|
||||||
|
CloseOutlined,
|
||||||
|
MinusOutlined,
|
||||||
|
PlusOutlined,
|
||||||
|
ScissorOutlined
|
||||||
|
} from "@ant-design/icons-vue";
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = import.meta.env.VITE_GLOB_WORK_SRC;
|
pdfjsLib.GlobalWorkerOptions.workerSrc = import.meta.env.VITE_GLOB_WORK_SRC;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -42,6 +35,7 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
open: false,
|
open: false,
|
||||||
|
zoomLevel: 1,
|
||||||
start: false,
|
start: false,
|
||||||
selection: null,
|
selection: null,
|
||||||
startPoint: null,
|
startPoint: null,
|
||||||
@ -50,27 +44,29 @@
|
|||||||
captureButtonStyle: null,
|
captureButtonStyle: null,
|
||||||
closeButtonStyle: null,
|
closeButtonStyle: null,
|
||||||
captureButtonVisible: false,
|
captureButtonVisible: false,
|
||||||
|
pdfData: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
MinusOutlined,
|
||||||
|
PlusOutlined,
|
||||||
CloseOutlined,
|
CloseOutlined,
|
||||||
ScissorOutlined,
|
ScissorOutlined,
|
||||||
h,
|
h,
|
||||||
async loadPdf(param) {
|
async loadPdf() {
|
||||||
let loadingTask;
|
let loadingTask = pdfjsLib.getDocument({data: this.pdfData.slice()});
|
||||||
loadingTask = pdfjsLib.getDocument({data: param});
|
|
||||||
const pdf = await loadingTask.promise;
|
const pdf = await loadingTask.promise;
|
||||||
const page = await pdf.getPage(1); // 获取第一页
|
const page = await pdf.getPage(1); // 获取第一页
|
||||||
const viewport = page.getViewport({scale: 1.75});
|
const viewport = page.getViewport({scale: this.zoomLevel});
|
||||||
const canvas = this.$refs.pdfCanvas;
|
const canvas = this.$refs.pdfCanvas;
|
||||||
const context = canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
canvas.height = viewport.height;
|
console.log(viewport.width + '' + viewport.height);
|
||||||
canvas.width = viewport.width;
|
canvas.width = viewport.width;
|
||||||
const renderContext = {
|
canvas.height = viewport.height;
|
||||||
|
await page.render({
|
||||||
canvasContext: context,
|
canvasContext: context,
|
||||||
viewport: viewport,
|
viewport: viewport,
|
||||||
};
|
}).promise;
|
||||||
await page.render(renderContext).promise;
|
|
||||||
},
|
},
|
||||||
show() {
|
show() {
|
||||||
this.open = true;
|
this.open = true;
|
||||||
@ -121,7 +117,7 @@
|
|||||||
width: `${this.selection.width}px`,
|
width: `${this.selection.width}px`,
|
||||||
height: `${this.selection.height}px`,
|
height: `${this.selection.height}px`,
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
border: '1px dashed red',
|
border: '2px dashed red',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -173,7 +169,15 @@
|
|||||||
},
|
},
|
||||||
hideCaptureButton() {
|
hideCaptureButton() {
|
||||||
this.captureButtonVisible = false;
|
this.captureButtonVisible = false;
|
||||||
}
|
},
|
||||||
|
async zoomIn() {
|
||||||
|
this.zoomLevel = Math.min(3, this.zoomLevel + 0.1);
|
||||||
|
await this.loadPdf();
|
||||||
|
},
|
||||||
|
async zoomOut() {
|
||||||
|
this.zoomLevel = Math.max(0.5, this.zoomLevel - 0.1);
|
||||||
|
await this.loadPdf();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -200,7 +204,7 @@
|
|||||||
|
|
||||||
.selection-box {
|
.selection-box {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
border: 1px dashed red;
|
border: 2px dashed red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,4 +223,29 @@
|
|||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tool-box {
|
||||||
|
position: absolute;
|
||||||
|
top: 5px;
|
||||||
|
right: 20px;
|
||||||
|
margin-right: 20px;
|
||||||
|
padding: 5px;
|
||||||
|
background: #ffffff;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 5px;
|
||||||
|
|
||||||
|
.tool-button {
|
||||||
|
border-radius: 100px;
|
||||||
|
padding: 5px;
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
& > span {
|
||||||
|
padding-left: 10px;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -219,7 +219,8 @@ import { usePermission } from '@/hooks/web/usePermission';
|
|||||||
|
|
||||||
const pdfView = ref<any>();
|
const pdfView = ref<any>();
|
||||||
const openPdf = async (pdfData: any) => {
|
const openPdf = async (pdfData: any) => {
|
||||||
await pdfView.value.loadPdf(pdfData);
|
pdfView.value.pdfData = pdfData;
|
||||||
|
await pdfView.value.loadPdf();
|
||||||
pdfView.value.show();
|
pdfView.value.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user