fix
pyt
54 分钟以前 c627bf9394e93f9f9d8c04ca33441eac47d2ad7d
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
export function printFile(html) {
  if (!html) return;
  let userAgent = navigator.userAgent;
  html = "<style media='print'>.ant-image-mask{display: none;}@page {margin: 0mm; size: landscape;font-size: 10px;} body {padding: 10mm;} table, tbody, thead {width: 100% !important;} td, th {text-align: center;} colgroup {position: absolute; width: 100% !important;}</style><body>" + html + "</body>";
  if (
    (userAgent.indexOf("compatible") > -1 &&
      userAgent.indexOf("MSIE") > -1) ||
    userAgent.indexOf("Edge") > -1 ||
    (userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1)
  ) {
    // IE浏览器
    let page = window.open("", "_blank"); // 打开一个新窗口,用于打印
    page.document.write(html); // 写入打印页面的内容
    page.document.execCommand("print");
    page.close(); // 关闭打印窗口
  } else {
    let doc = document.getElementById('printf');
    if (doc) {
      document.getElementById("printElement").removeChild(doc)
    }
    let iframe = document.createElement("iframe");
    iframe.id = "printf";
    iframe.style.width = "0";
    iframe.style.height = "0";
    document.getElementById("printElement").appendChild(iframe);
    iframe.contentWindow.document.write(html);
    iframe.contentWindow.focus();
    iframe.contentWindow.print();
  }
}