Preview.vue
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<el-dialog v-bind="$attrs" :close-on-click-modal="false" :modal-append-to-body="false"
v-on="$listeners" @open="onOpen" fullscreen lock-scroll class="NCC-full-dialog"
:show-close="false" :modal="false">
<div class="NCC-full-dialog-header">
<div class="header-title">
<img src="@/assets/images/ncc.png" class="header-logo" />
<p class="header-txt"> · 打印预览</p>
</div>
<div class="options">
<!-- <el-button type="primary" size="small" @click="word">Word下载</el-button> -->
<el-button type="primary" size="small" @click="print">打印</el-button>
<el-button @click="closeDialog()">{{$t('common.cancelButton')}}</el-button>
</div>
</div>
<div class="main" v-loading="loading" :element-loading-text="$t('common.loadingText')">
<div ref="tsPrint" class="print-content" v-html="data" />
</div>
</el-dialog>
</template>
<script>
import { getPrintDevInfo } from '@/api/system/printDev'
export default {
props: ['id'],
data() {
return {
data: '',
loading: false
}
},
methods: {
onOpen() {
this.loading = true
getPrintDevInfo(this.id).then(res => {
this.data = res.data.printTemplate
this.loading = false
})
},
closeDialog() {
this.$emit('update:visible', false)
},
word() {
let print = this.$refs.tsPrint.innerHTML
const blob = new Blob([print], {
type: ''
})
const name = '下载文档.doc'
this.downloadFile(blob, name)
},
downloadFile(data, name, type) {
let blob = new Blob([data], {
type: type || ''
})
let downloadElement = document.createElement('a')
let href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = name
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
},
print() {
let print = this.$refs.tsPrint.innerHTML
let newWindow = window.open('_blank')
newWindow.document.body.innerHTML = print
newWindow.print()
newWindow.close()
},
}
}
</script>
<style lang="scss" scoped>
.print-content {
background: white;
padding: 40px 30px;
margin: 0 auto;
border-radius: 4px;
width: 600px;
height: 100%;
overflow: hidden;
}
</style>