mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-07 00:47:19 +08:00
perf: pdf demo
This commit is contained in:
parent
2a15298cf8
commit
870f064598
@ -1,21 +1,28 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import VuePdfEmbed from "vue-pdf-embed";
|
import VuePdfEmbed, {
|
||||||
|
type VuePdfEmbedMethods,
|
||||||
|
type VuePdfEmbedData
|
||||||
|
} from "vue-pdf-embed";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "Pdf"
|
name: "Pdf"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface pdfRefType extends VuePdfEmbedData, VuePdfEmbedMethods {}
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const pdfRef = ref<pdfRefType>();
|
||||||
|
let pageCount = ref(1);
|
||||||
|
let loading = ref(true);
|
||||||
|
let currentPage = ref(1);
|
||||||
|
let currentRotation = ref(0);
|
||||||
|
let showAllPages = ref(false);
|
||||||
|
const rotations = [0, 90, 180, 270];
|
||||||
|
|
||||||
const source =
|
const source =
|
||||||
"https://pure-admin-doc.vercel.app/pdf/Cookie%E5%92%8CSession%E5%8C%BA%E5%88%AB%E7%94%A8%E6%B3%95.pdf";
|
"https://pure-admin-doc.vercel.app/pdf/Cookie%E5%92%8CSession%E5%8C%BA%E5%88%AB%E7%94%A8%E6%B3%95.pdf";
|
||||||
const pdfRef = ref();
|
|
||||||
let loading = ref(true);
|
|
||||||
let showAllPages = ref(false);
|
|
||||||
let pageCount = ref(1);
|
|
||||||
let currentPage = ref(1);
|
|
||||||
|
|
||||||
const handleDocumentRender = () => {
|
const handleDocumentRender = () => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@ -25,6 +32,10 @@ const handleDocumentRender = () => {
|
|||||||
const showAllPagesChange = () => {
|
const showAllPagesChange = () => {
|
||||||
currentPage.value = showAllPages.value ? null : 1;
|
currentPage.value = showAllPages.value ? null : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onPrint = () => {
|
||||||
|
pdfRef.value.print();
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -49,7 +60,7 @@ const showAllPagesChange = () => {
|
|||||||
>
|
>
|
||||||
<div class="flex justify-between items-center h-9">
|
<div class="flex justify-between items-center h-9">
|
||||||
<div v-if="showAllPages" class="font-medium ml-1.25 text-xl">
|
<div v-if="showAllPages" class="font-medium ml-1.25 text-xl">
|
||||||
{{ pageCount }} page(s)
|
共{{ pageCount }}页
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<el-pagination
|
<el-pagination
|
||||||
@ -62,14 +73,39 @@ const showAllPagesChange = () => {
|
|||||||
{{ currentPage }} / {{ pageCount }}
|
{{ currentPage }} / {{ pageCount }}
|
||||||
</el-pagination>
|
</el-pagination>
|
||||||
</div>
|
</div>
|
||||||
<el-checkbox v-model="showAllPages" @change="showAllPagesChange">
|
<div class="w-170px flex-bc">
|
||||||
Show all pages
|
<el-checkbox v-model="showAllPages" @change="showAllPagesChange">
|
||||||
</el-checkbox>
|
显示所有页面
|
||||||
|
</el-checkbox>
|
||||||
|
<el-tooltip
|
||||||
|
effect="dark"
|
||||||
|
:content="`翻转(当前角度${rotations[currentRotation]}度)`"
|
||||||
|
placement="top"
|
||||||
|
>
|
||||||
|
<IconifyIconOnline
|
||||||
|
icon="ic:baseline-rotate-90-degrees-ccw"
|
||||||
|
class="cursor-pointer outline-transparent"
|
||||||
|
@click="
|
||||||
|
currentRotation === 3
|
||||||
|
? (currentRotation = 0)
|
||||||
|
: (currentRotation += 1)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip effect="dark" content="打印" placement="top">
|
||||||
|
<IconifyIconOnline
|
||||||
|
icon="ri:printer-line"
|
||||||
|
class="cursor-pointer outline-transparent"
|
||||||
|
@click="onPrint"
|
||||||
|
/>
|
||||||
|
</el-tooltip>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<el-scrollbar>
|
<el-scrollbar>
|
||||||
<vue-pdf-embed
|
<vue-pdf-embed
|
||||||
class="h-full container overflow-auto"
|
class="h-full container overflow-auto"
|
||||||
ref="pdfRef"
|
ref="pdfRef"
|
||||||
|
:rotation="rotations[currentRotation]"
|
||||||
:page="currentPage"
|
:page="currentPage"
|
||||||
:source="source"
|
:source="source"
|
||||||
@rendered="handleDocumentRender"
|
@rendered="handleDocumentRender"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user