Commit 5afa10ec by taowenzhong

实现pdf存根功能

parent 140b2ea4
...@@ -55,11 +55,11 @@ ...@@ -55,11 +55,11 @@
"js-beautify": "1.13.0", "js-beautify": "1.13.0",
"js-cookie": "3.0.1", "js-cookie": "3.0.1",
"jsencrypt": "3.0.0-rc.1", "jsencrypt": "3.0.0-rc.1",
"jspdf": "^2.5.1",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"luckyexcel": "^1.0.1", "luckyexcel": "^1.0.1",
"moment": "^2.29.4", "moment": "^2.29.4",
"nprogress": "0.2.0", "nprogress": "0.2.0",
"print-js": "^1.6.0",
"qrcodejs2": "0.0.2", "qrcodejs2": "0.0.2",
"quill": "1.3.7", "quill": "1.3.7",
"screenfull": "5.0.2", "screenfull": "5.0.2",
......
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="cancel">取 消</el-button> <el-button @click="cancel">取 消</el-button>
<el-button v-if="form.auditStatus === '1'" type="warning" @click="print">打印</el-button> <el-button v-if="form.auditStatus === '1'" type="warning" @click="print(form)">生成PDF</el-button>
<el-button v-if="!isHandle" type="primary" @click="submitForm">提 交</el-button> <el-button v-if="!isHandle" type="primary" @click="submitForm">提 交</el-button>
</span> </span>
</el-dialog> </el-dialog>
...@@ -314,7 +314,7 @@ ...@@ -314,7 +314,7 @@
</template> </template>
<script> <script>
import printJS from 'print-js' import JSPDF from 'jspdf'
import * as htmlToImage from 'html-to-image' import * as htmlToImage from 'html-to-image'
import { import {
addRelation, addRelation,
...@@ -456,17 +456,28 @@ export default { ...@@ -456,17 +456,28 @@ export default {
}; };
}, },
methods: { methods: {
print() { print(form) {
htmlToImage.toPng(this.$refs.printDom, { htmlToImage.toPng(this.$refs.printDom, {
pixelRatio: 5 pixelRatio: 2
}).then((dataUrl) => { }).then((dataUrl) => {
printJS({ this.getBase64ImageSize(dataUrl, (size) => {
type: 'image', const pdf = new JSPDF('p', 'mm', 'a4')
printable: [dataUrl], const ratio = 210 / size.width * size.height
documentTitle: '报名审核存根' pdf.addImage(dataUrl, 'png', 1, 1, 210, ratio)
pdf.save(`${form.project}-${form.studentName}.pdf`)
}) })
}) })
}, },
getBase64ImageSize(base64, callback) {
let img = new Image();
img.onload = function() {
callback({ width: img.width, height: img.height });
};
img.onerror = function() {
callback(null);
};
img.src = base64;
},
/** 查询【请填写功能名称】列表 */ /** 查询【请填写功能名称】列表 */
getList() { getList() {
this.loading = true; this.loading = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment