index.jsx 1.85 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8
import React, {
  useState,
  useImperativeHandle,
  forwardRef,
  useRef,
} from "react";
import styles from "./index.less";
import { QRCodeSVG } from "qrcode.react";
wuhao's avatar
wuhao committed
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
const pageStyle = `
@media all {
    .page-break {
    display: none;
    }
}

@media print {
    html, body {
    height: initial !important;
    overflow: initial !important;
    position:relative;
    -webkit-print-color-adjust: exact;
    word-break: break-all;
    }

}

@media print {
    .page-break {
    margin-top:0;
    display: block;
    page-break-before: auto;
    }
}

@media print {
    .page-noprint {
        display: none !important;
    }
}

@page {
    size: auto;
    margin: 0px;
}
`;
wuhao's avatar
wuhao committed
46 47 48 49 50 51 52 53

let PrintQrCode = forwardRef(({ selectedItems }, ref) => {
  let printRef = useRef();
  useImperativeHandle(ref, () => ({
    dom: printRef,
  }));

  return (
wuhao's avatar
wuhao committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    <>
      <style type="text/css" media="print">
        {pageStyle}
      </style>
      <div className={styles.qrcode} ref={printRef}>
        {selectedItems.map((item, i) => {
          return (
            <div key={item.id}>
              <ul>
                <li>
                  <p>
                    <b>物料编码: </b> <span>{item.materieCode}</span>
                  </p>
                  <p>
                    <b>物料名称: </b> <span>{item.materieName}</span>
                  </p>
                  <p>
                    <b>批次号/SN号: </b> <span>{item.materieControlNo}</span>
                  </p>
                  <p>
                    <b>供应商: </b> <span>{item.supplierName}</span>
                  </p>
                </li>
                <li>
                  <QRCodeSVG value={item.id} size={350}></QRCodeSVG>
                </li>
              </ul>
              <span className="page-break"></span>
            </div>
          );
        })}
      </div>
    </>
wuhao's avatar
wuhao committed
87 88 89 90
  );
});

export { PrintQrCode };