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
<template>
<div class="need-know" :id="'need-know_' + keyname" v-if="detail">
<!-- <h2>{{detail.titleZh}}</h2> -->
<div class="body" ref="body" v-html="$l(detail, 'content')"></div>
</div>
</template>
<script>
import {getNeedKnowByKey, download} from '@/api/system/needKnow'
import html2canvas from 'html2canvas'
import FileSaver from 'file-saver'
import saveFie from '@/plugins/download'
export default {
props:{
keyname: String
},
data(){
return {
detail: null
}
},
created(){
getNeedKnowByKey(this.keyname).then(res => {
this.detail = res.data
})
},
methods:{
downloadPdf(){
download({id: this.detail.id}).then(res => {
this.$download.pdf(res, '入仓须知.pdf')
})
},
download(){
// 直接保存图片
let l = this.$loading()
/* document.querySelectorAll(`#need-know_${this.keyname} img`).forEach(img => {
img.setAttribute('crossOrigin', '*')
}) */
html2canvas(document.querySelector("#need-know_" + this.keyname)).then(canvas => {
canvas.toBlob((blob) => {
FileSaver.saveAs(blob, this.keyname + '.png')
})
}).finally(res => {
l.close()
});
},
}
}
</script>
<style scoped>
.body img{
max-width: 100%;
}
.need-know{
padding: 20px;
}
</style>