Commit 3b4aa2e485da37218961ab10dd05be6a4d64e5a4

Authored by 李泰瑜
1 parent a1a71eb0

图片生成二维码

ant-design-vue-jeecg/src/views/system/receipt/ReceiptDetailList.vue
... ... @@ -4,6 +4,7 @@
4 4 <div class="table-operator" v-if="mainId">
5 5 <a-button v-has="'receiptDetail:add'" @click="handleAdd" type="primary" icon="plus">新增</a-button>
6 6 <a-button v-has="'receiptDetail:export'" type="primary" icon="download" @click="handleExportXls('入库单详情')">导出</a-button>
  7 + <a-button @click="batchPrint()" type="primary">打印</a-button>
7 8 <a-upload
8 9 v-has="'receiptDetail:import'"
9 10 name="file"
... ... @@ -232,6 +233,17 @@ export default {
232 233 this.$refs.modalEditForm.title = "编辑";
233 234 this.$refs.modalEditForm.disableSubmit = false;
234 235 },
  236 +
  237 + batchPrint() {
  238 + if (this.selectedRowKeys.length <= 0) {
  239 + this.$message.warning('请选择一条记录!');
  240 + return;
  241 + } else {
  242 + var ids = "";
  243 + ids = this.selectedRowKeys[0];
  244 + window.open(window._CONFIG['domianURL'] + "/jmreport/view/797678301889273856/?id=" + ids, "newWindow", "toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=100");
  245 + }
  246 + },
235 247 }
236 248 }
237 249 </script>
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/tool/ToolController.java 0 → 100644
  1 +package org.jeecg.modules.wms.api.tool;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import org.jeecg.utils.QRCodeGenerator;
  6 +import org.jeecg.utils.support.PassApiAuthentication;
  7 +import org.springframework.http.HttpHeaders;
  8 +import org.springframework.http.HttpStatus;
  9 +import org.springframework.http.MediaType;
  10 +import org.springframework.http.ResponseEntity;
  11 +import org.springframework.web.bind.annotation.GetMapping;
  12 +import org.springframework.web.bind.annotation.PathVariable;
  13 +import org.springframework.web.bind.annotation.RequestMapping;
  14 +import org.springframework.web.bind.annotation.RestController;
  15 +
  16 +import com.google.zxing.WriterException;
  17 +
  18 +import lombok.extern.slf4j.Slf4j;
  19 +
  20 +/**
  21 + * <p>
  22 + * 用户表 前端控制器
  23 + * </p>
  24 + * @Author scott
  25 + * @since 2018-12-20
  26 + */
  27 +@Slf4j
  28 +@RestController
  29 +@RequestMapping("/api/tool")
  30 +public class ToolController {
  31 +
  32 + @PassApiAuthentication
  33 + @GetMapping(value = "/image/{text}")
  34 + public ResponseEntity<byte[]> getImage(@PathVariable("text") String text) {
  35 + byte[] qrcode = null;
  36 + try {
  37 + qrcode = QRCodeGenerator.getQRCodeImage(text, 100, 100,false);
  38 + } catch (WriterException e) {
  39 + e.printStackTrace();
  40 + } catch (IOException e) {
  41 + e.printStackTrace();
  42 + }
  43 + // Set headers
  44 + final HttpHeaders headers = new HttpHeaders();
  45 + headers.setContentType(MediaType.IMAGE_PNG);
  46 + return new ResponseEntity<byte[]>(qrcode, headers, HttpStatus.CREATED);
  47 + }
  48 +
  49 +}
... ...
huaheng-wms-core/src/main/java/org/jeecg/utils/QRCodeGenerator.java 0 → 100644
  1 +package org.jeecg.utils;
  2 +
  3 +
  4 +import com.google.zxing.BarcodeFormat;
  5 +import com.google.zxing.EncodeHintType;
  6 +import com.google.zxing.WriterException;
  7 +import com.google.zxing.client.j2se.MatrixToImageWriter;
  8 +import com.google.zxing.common.BitMatrix;
  9 +import com.google.zxing.datamatrix.DataMatrixWriter;
  10 +import com.google.zxing.qrcode.QRCodeWriter;
  11 +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
  12 +
  13 +import java.io.ByteArrayOutputStream;
  14 +import java.io.IOException;
  15 +import java.util.HashMap;
  16 +import java.util.Map;
  17 +
  18 +/**
  19 + * 生成二维码
  20 + * @author Enzo Cotter
  21 + * @date 2020/2/21
  22 + */
  23 +public class QRCodeGenerator {
  24 +
  25 + public static byte[] getQRCodeImage(String text, int width, int height,boolean whiten) throws WriterException, IOException {
  26 + QRCodeWriter qrCodeWriter = new QRCodeWriter();
  27 + BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
  28 + if (whiten)
  29 + {
  30 + bitMatrix = deleteWhite(bitMatrix);
  31 + }
  32 + ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream();
  33 + MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOutputStream);
  34 + byte[] pngData = pngOutputStream.toByteArray();
  35 + return pngData;
  36 + }
  37 +
  38 + /**
  39 +  * 删除白边
  40 + * */
  41 +
  42 + private static BitMatrix deleteWhite(BitMatrix matrix) {
  43 + int[] rec = matrix.getEnclosingRectangle();
  44 + int resWidth = rec[2] + 1;
  45 + int resHeight = rec[3] + 1;
  46 +
  47 + BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
  48 + resMatrix.clear();
  49 + for (int i = 0; i < resWidth; i++) {
  50 + for (int j = 0; j < resHeight; j++) {
  51 + if (matrix.get(i + rec[0], j + rec[1])) {
  52 + resMatrix.set(i, j);
  53 + }
  54 + }
  55 + }
  56 + return resMatrix;
  57 + }
  58 +
  59 + public static byte[] getDataMatrixImage(String text, int width, int height) throws WriterException, IOException {
  60 + Map<EncodeHintType,Object> hints = new HashMap<EncodeHintType, Object>();
  61 + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
  62 +
  63 + DataMatrixWriter dataMatrixWriter = new DataMatrixWriter();
  64 + BitMatrix bitMatrix = dataMatrixWriter.encode(text, BarcodeFormat.DATA_MATRIX, width, height,hints);
  65 +
  66 + ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream();
  67 + MatrixToImageWriter.writeToStream(bitMatrix, "jpg", pngOutputStream);
  68 +
  69 + byte[] pngData = pngOutputStream.toByteArray();
  70 + return pngData;
  71 + }
  72 +
  73 +}
... ...