cloud-web-corejs 1.0.118 → 1.0.120

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.
@@ -75,7 +75,8 @@ export default {
75
75
  selectMulti: true,
76
76
  formData: {},
77
77
  vxeOption: {},
78
- tableData: []
78
+ tableData: [],
79
+ fieldKey:"userId"
79
80
  };
80
81
  },
81
82
  methods: {
@@ -0,0 +1,71 @@
1
+ import html2canvas from "html2canvas";
2
+ import jspdf from "jspdf";
3
+ export async function exportPDF(option) {
4
+ const dom = option.dom;
5
+ let fileName = option.fileName;
6
+ if (!dom) return
7
+ let height = "";
8
+ // 获取dom元素
9
+ let dom1 = dom.querySelector(".d-cont");
10
+ try {
11
+ if (dom1) {
12
+ height = dom1.style.height;
13
+ dom1.style.height = "auto";
14
+ }
15
+
16
+ if (dom) {
17
+ html2canvas(dom).then(async (canvas) => {
18
+ // A4纸,纵向
19
+ let pdf = new jspdf("p", "mm", "a4");
20
+ let ctx = canvas.getContext("2d");
21
+ let a4w = 190;
22
+ // A4大小,210mm x 297mm,四边各保留10mm的边距,显示区域190x277
23
+ let a4h = 277;
24
+ // 按A4显示比例换算一页图像的像素高度
25
+ let imgHeight = Math.floor((a4h * canvas.width) / a4w);
26
+ let renderedHeight = 0;
27
+ while (renderedHeight < canvas.height) {
28
+ let page = document.createElement("canvas");
29
+ page.width = canvas.width;
30
+ // 可能内容不足一页
31
+ page.height = Math.min(imgHeight, canvas.height - renderedHeight);
32
+ // 用getImageData剪裁指定区域,并画到前面创建的canvas对象中
33
+ page
34
+ .getContext("2d")
35
+ .putImageData(
36
+ ctx.getImageData(
37
+ 0,
38
+ renderedHeight,
39
+ canvas.width,
40
+ Math.min(imgHeight, canvas.height - renderedHeight)
41
+ ),
42
+ 0,
43
+ 0
44
+ );
45
+ // 添加图像到页面,保留10mm边距
46
+ pdf.addImage(
47
+ page.toDataURL("image/jpeg", 1.0),
48
+ "JPEG",
49
+ 10,
50
+ 10,
51
+ a4w,
52
+ Math.min(a4h, (a4w * page.height) / page.width)
53
+ );
54
+
55
+ renderedHeight += imgHeight;
56
+ if (renderedHeight < canvas.height) {
57
+ // 如果后面还有内容,添加一个空页
58
+ pdf.addPage();
59
+ }
60
+ // delete page;
61
+ }
62
+ // 保存文件
63
+ pdf.save(`${fileName}.pdf`);
64
+ });
65
+ }
66
+ } catch (err) {
67
+ console.log(err);
68
+ } finally {
69
+ if (dom1) dom1.style.height = height;
70
+ }
71
+ }