提交 cd195300 authored 作者: CRS's avatar CRS

nwe

...@@ -9,7 +9,9 @@ module.exports = { ...@@ -9,7 +9,9 @@ module.exports = {
], ],
"globals": { "globals": {
'Atomics': 'readonly', 'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly' 'SharedArrayBuffer': 'readonly',
'require': true
}, },
'parserOptions': { 'parserOptions': {
'ecmaVersion': 2018, 'ecmaVersion': 2018,
......
差异被折叠。
...@@ -12,7 +12,10 @@ ...@@ -12,7 +12,10 @@
"core-js": "^3.6.4", "core-js": "^3.6.4",
"echarts": "^4.6.0", "echarts": "^4.6.0",
"element-ui": "^2.13.0", "element-ui": "^2.13.0",
"html2canvas": "^1.0.0-rc.5",
"jquery": "^3.4.1", "jquery": "^3.4.1",
"jspdf": "^1.5.3",
"moment": "^2.24.0",
"node-sass": "^4.13.1", "node-sass": "^4.13.1",
"vue": "^2.6.11", "vue": "^2.6.11",
"vue-router": "^3.0.7", "vue-router": "^3.0.7",
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title> <title>XXX工作台</title>
</head> </head>
<body> <body>
<noscript> <noscript>
......
This image diff could not be displayed because it is too large. You can view the blob instead.
差异被折叠。
// 导出页面为PDF格式
import html2Canvas from 'html2canvas'
import JsPDF from 'jspdf'
import {
Message, Loading
} from 'element-ui'
let loading;
export default{
install (Vue, options) {
Vue.prototype.getPdf = function () {
loading = Loading.service({
lock: true,
text: '正在下载pdf...',
background: 'rgba(0,0,0,.5)'
});
let title = this.htmlTitle
html2Canvas(document.querySelector('#pdfDom'), {
allowTaint: true
}).then(function (canvas) {
console.log(canvas)
let contentWidth = canvas.width;
let contentHeight = canvas.height;
if (contentWidth === '' || contentWidth === undefined || contentHeight === '' || contentHeight === undefined) {
loading.close();
Message.error('转换pdf失败,请稍后再试!')
}
let pageHeight = contentWidth / 595 * 842
let leftHeight = contentHeight
let position = 0
let imgWidth = 595
let imgHeight = 595 / contentWidth * contentHeight
let pageData = canvas.toDataURL('image/jpeg', 1.0)
let PDF = new JsPDF('', 'pt', 'a4')
if (leftHeight < pageHeight) {
PDF.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight)
} else {
while (leftHeight > 0) {
PDF.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight)
leftHeight -= pageHeight
position -= 842
if (leftHeight > 0) {
PDF.addPage()
}
}
}
loading.close();
PDF.save(title + '.pdf')
})
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论