eztech-core-components 1.0.63 → 1.0.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/comps/CorePdfDialog.vue +9 -8
- package/comps/CorePdfViewer.vue +92 -0
- package/package.json +1 -1
package/comps/CorePdfDialog.vue
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
<div v-if="loading" class="bg-[#525659] px-20 h-[900px] flex items-center justify-center text-slate-200 text-lg font-medium gap-2">
|
|
4
4
|
<i class="el-icon-loading" /> Түр хүлээнэ үү..
|
|
5
5
|
</div>
|
|
6
|
-
<div v-else-if="
|
|
7
|
-
<
|
|
6
|
+
<div v-else-if="hrefBlob" class="relative w-full h-[900px]">
|
|
7
|
+
<core-pdf-viewer :blob="hrefBlob" />
|
|
8
|
+
<!-- <iframe
|
|
8
9
|
id="pdfFrame"
|
|
9
|
-
:src="
|
|
10
|
+
:src="hrefBlob + pdfUrlParams"
|
|
10
11
|
class="w-full h-full"
|
|
11
12
|
frameborder="0"
|
|
12
13
|
@load="handlePrintPdf"
|
|
13
|
-
/>
|
|
14
|
+
/> -->
|
|
14
15
|
</div>
|
|
15
16
|
</el-dialog>
|
|
16
17
|
</template>
|
|
@@ -21,7 +22,7 @@ export default {
|
|
|
21
22
|
return {
|
|
22
23
|
pdfDownload: false,
|
|
23
24
|
loading: false,
|
|
24
|
-
|
|
25
|
+
hrefBlob: null,
|
|
25
26
|
numPages: 0
|
|
26
27
|
}
|
|
27
28
|
},
|
|
@@ -39,7 +40,7 @@ export default {
|
|
|
39
40
|
},
|
|
40
41
|
set () {
|
|
41
42
|
if (!this.isPdfPrint) {
|
|
42
|
-
this.
|
|
43
|
+
this.hrefBlob = null
|
|
43
44
|
}
|
|
44
45
|
this.set_pdf_url({ url: null, title: '' })
|
|
45
46
|
}
|
|
@@ -57,7 +58,7 @@ export default {
|
|
|
57
58
|
async handlePrint () {
|
|
58
59
|
try {
|
|
59
60
|
this.loading = true
|
|
60
|
-
this.
|
|
61
|
+
this.hrefBlob = null
|
|
61
62
|
const response = await this.$axios.get(this.pdfUrl, {
|
|
62
63
|
responseType: 'blob',
|
|
63
64
|
params: {
|
|
@@ -65,7 +66,7 @@ export default {
|
|
|
65
66
|
}
|
|
66
67
|
})
|
|
67
68
|
const pdfUrl = URL.createObjectURL(response.data)
|
|
68
|
-
this.
|
|
69
|
+
this.hrefBlob = pdfUrl
|
|
69
70
|
} catch (err) {
|
|
70
71
|
this.$showErrorBlob(err)
|
|
71
72
|
} finally {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="blob-pdf-viewer" @contextmenu.prevent @selectstart.prevent @dragstart.prevent>
|
|
3
|
+
<vue-pdf
|
|
4
|
+
:src="pdfLoadingTask"
|
|
5
|
+
:page="currentPage"
|
|
6
|
+
@num-pages="pageCount = $event"
|
|
7
|
+
@password="onPassword"
|
|
8
|
+
@error="onError"
|
|
9
|
+
style="display: block; width: 100%;"
|
|
10
|
+
/>
|
|
11
|
+
<div class="controls" v-if="pageCount > 1">
|
|
12
|
+
<button @click="currentPage--" :disabled="currentPage <= 1">‹ Prev</button>
|
|
13
|
+
<span>{{ currentPage }} / {{ pageCount }}</span>
|
|
14
|
+
<button @click="currentPage++" :disabled="currentPage >= pageCount">Next ›</button>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script>
|
|
20
|
+
import vuePdf from 'vue-pdf'
|
|
21
|
+
export default {
|
|
22
|
+
components: { vuePdf },
|
|
23
|
+
props: {
|
|
24
|
+
blob: {
|
|
25
|
+
type: Blob,
|
|
26
|
+
required: true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
data() {
|
|
30
|
+
return {
|
|
31
|
+
pdfLoadingTask: null,
|
|
32
|
+
currentPage: 1,
|
|
33
|
+
pageCount: 0
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
watch: {
|
|
37
|
+
blob: {
|
|
38
|
+
immediate: true,
|
|
39
|
+
handler(newBlob) {
|
|
40
|
+
if (!newBlob) return
|
|
41
|
+
const blobUrl = URL.createObjectURL(newBlob)
|
|
42
|
+
this.pdfLoadingTask = vuePdf.createLoadingTask(blobUrl)
|
|
43
|
+
this.$once('hook:beforeDestroy', () => {
|
|
44
|
+
URL.revokeObjectURL(blobUrl)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
methods: {
|
|
50
|
+
onPassword(callback) {
|
|
51
|
+
const password = prompt('This PDF is password protected. Enter password:')
|
|
52
|
+
callback(password)
|
|
53
|
+
},
|
|
54
|
+
onError(err) {
|
|
55
|
+
this.$emit('error', err)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
60
|
+
<style scoped>
|
|
61
|
+
.blob-pdf-viewer {
|
|
62
|
+
position: relative;
|
|
63
|
+
width: 100%;
|
|
64
|
+
height: 900px;
|
|
65
|
+
background: #2d2d2d;
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
-webkit-user-select: none;
|
|
68
|
+
user-select: none;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.controls {
|
|
72
|
+
position: absolute;
|
|
73
|
+
bottom: 20px;
|
|
74
|
+
left: 50%;
|
|
75
|
+
transform: translateX(-50%);
|
|
76
|
+
background: rgba(0,0,0,0.8);
|
|
77
|
+
color: white;
|
|
78
|
+
padding: 10px 20px;
|
|
79
|
+
border-radius: 30px;
|
|
80
|
+
font-family: Arial, sans-serif;
|
|
81
|
+
z-index: 10;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.controls button {
|
|
85
|
+
background: none;
|
|
86
|
+
border: none;
|
|
87
|
+
color: white;
|
|
88
|
+
font-size: 18px;
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
padding: 0 15px;
|
|
91
|
+
}
|
|
92
|
+
</style>
|