gavin.chen 1 жил өмнө
parent
commit
af3653e11f

+ 80 - 63
lib/pages/check/health_check_record/controller.dart

@@ -313,69 +313,86 @@ class HealthCheckRecordController extends FControllerBase {
     }
   }
 
-  void getExamLabelsByExamNoAsync(ResidentModel rowData) async {
-    List<String> barCodes = [];
-    var labels = await registrationManager.getExamLabelsByExamNoAsync(
-        physicalExamNumber: rowData.physicalExamNumber!);
-    for (var element in labels.eaxmLabels!) {
-      var barCode = await drawRedRect(element, rowData);
-      if (barCode.isNotEmpty) {
-        barCodes.add(barCode);
-      }
-    }
-    if (barCodes.length > 0) {
-      rpc.platform.printLabels(barCodes);
-      return;
-    }
-  }
-
-  Future<String> drawRedRect(
-      HealthExamLabelDTO labelDto, ResidentModel rowData) async {
-    const size = Size(360, 240);
-    final svg = Barcode.code128().toSvg(labelDto.uniquedCode!, height: 80);
-    final qrcode =
-        Barcode.qrCode().toSvg(labelDto.uniquedCode!, height: 50, width: 50);
-    final PictureInfo pictureInfo =
-        await vg.loadPicture(SvgStringLoader(svg), null);
-    final PictureInfo qrcodeInfo =
-        await vg.loadPicture(SvgStringLoader(qrcode), null);
-    var a = await _capturePainterToImage(InfoPainter(labelDto, rowData),
-        BarcodePainter(pictureInfo), QrcodePainter(qrcodeInfo), size);
-    String base64Image = base64Encode(a!);
-    print(base64Image);
-
-    return base64Image;
-  }
-
-  /// 将CustomPainter绘制的内容转换为图片
-  Future<Uint8List?> _capturePainterToImage(
-      CustomPainter painter,
-      CustomPainter barcodePainter,
-      CustomPainter qrcodePainter,
-      Size size) async {
-    final bounds = Offset.zero & size;
-    // final bounds2 = Offset.zero & Size(size.width - 20, size.height - 20);
-    final picture = PictureRecorder();
-    final pictureCanvas = Canvas(picture);
-    // 给Canvas设置绘制范围
-    pictureCanvas.clipRect(bounds);
-    painter.paint(pictureCanvas, size);
-    // 在Canvas上进行绘制
-    // barcodePainter.paint(pictureCanvas, size);
-    // 在Canvas上进行绘制
-    qrcodePainter.paint(pictureCanvas, size);
-
-    // 结束绘制
-    final recordedPicture = picture.endRecording();
-    final image =
-        await recordedPicture.toImage(size.width.toInt(), size.height.toInt());
-
-    // 转换为字节数组
-    final byteData = await image.toByteData(format: ImageByteFormat.png);
-    final bytes = byteData?.buffer.asUint8List();
-
-    return bytes;
-  }
+  // void getExamLabelsByExamNoAsync(ResidentModel rowData) async {
+  //   List<String> barCodes = [];
+  //   var labels = await registrationManager.getExamLabelsByExamNoAsync(
+  //       physicalExamNumber: rowData.physicalExamNumber!);
+  //   // for (var element in labels.eaxmLabels!) {}
+  //   for (var i = 0; i < labels.eaxmLabels!.length; i++) {
+  //     final element = labels.eaxmLabels![i];
+  //     var barCode = "";
+  //     if (i == 0) {
+  //       barCode = await drawQRcode(element, rowData);
+  //     } else {
+  //       barCode = await drawBarcode(element, rowData);
+  //     }
+  //     if (barCode.isNotEmpty) {
+  //       barCodes.add(barCode);
+  //     }
+  //   }
+  //   if (barCodes.length > 0) {
+  //     rpc.platform.printLabels(barCodes);
+  //     return;
+  //   }
+  // }
+
+  // Future<String> drawBarcode(
+  //     HealthExamLabelDTO labelDto, ResidentModel rowData) async {
+  //   const size = Size(360, 240);
+  //   final svg = Barcode.code128().toSvg(labelDto.uniquedCode!, height: 80);
+  //   final PictureInfo pictureInfo =
+  //       await vg.loadPicture(SvgStringLoader(svg), null);
+  //   var a = await _capturePainterToImage(
+  //       InfoPainter(labelDto, rowData), BarcodePainter(pictureInfo), size);
+  //   String base64Image = base64Encode(a!);
+  //   print(base64Image);
+
+  //   return base64Image;
+  // }
+
+  // Future<String> drawQRcode(
+  //     HealthExamLabelDTO labelDto, ResidentModel rowData) async {
+  //   const size = Size(360, 240);
+  //   final svg = Barcode.code128().toSvg(labelDto.uniquedCode!, height: 80);
+  //   final qrcode =
+  //       Barcode.qrCode().toSvg(labelDto.uniquedCode!, height: 50, width: 50);
+  //   final PictureInfo pictureInfo =
+  //       await vg.loadPicture(SvgStringLoader(svg), null);
+  //   final PictureInfo qrcodeInfo =
+  //       await vg.loadPicture(SvgStringLoader(qrcode), null);
+  //   var a = await _capturePainterToImage(
+  //       InfoPainter(labelDto, rowData), QrcodePainter(qrcodeInfo), size);
+  //   String base64Image = base64Encode(a!);
+  //   print(base64Image);
+
+  //   return base64Image;
+  // }
+
+  // /// 将CustomPainter绘制的内容转换为图片
+  // Future<Uint8List?> _capturePainterToImage(
+  //     CustomPainter painter, CustomPainter codePainter, Size size) async {
+  //   final bounds = Offset.zero & size;
+  //   // final bounds2 = Offset.zero & Size(size.width - 20, size.height - 20);
+  //   final picture = PictureRecorder();
+  //   final pictureCanvas = Canvas(picture);
+  //   // 给Canvas设置绘制范围
+  //   pictureCanvas.clipRect(bounds);
+  //   painter.paint(pictureCanvas, size);
+  //   // 在Canvas上进行绘制
+  //   codePainter.paint(pictureCanvas, size);
+  //   // 在Canvas上进行绘制
+
+  //   // 结束绘制
+  //   final recordedPicture = picture.endRecording();
+  //   final image =
+  //       await recordedPicture.toImage(size.width.toInt(), size.height.toInt());
+
+  //   // 转换为字节数组
+  //   final byteData = await image.toByteData(format: ImageByteFormat.png);
+  //   final bytes = byteData?.buffer.asUint8List();
+
+  //   return bytes;
+  // }
 
   Future<void> getRegisterInfoPage({
     int? pageSize = 10,

+ 2 - 1
lib/pages/check/health_check_record/controllers/list_controller.dart

@@ -145,7 +145,8 @@ class ListController {
     return TextButton(
       onPressed: () {
         if (kIsWeb) {
-          controller.getExamLabelsByExamNoAsync(rowData);
+          // controller.getExamLabelsByExamNoAsync(rowData);
+          print("web not support yet");
         } else {
           Get.dialog(
             Center(

+ 95 - 25
lib/pages/medical_checkup_station/registration/controller.dart

@@ -76,45 +76,59 @@ class RegistrationController extends GetxController {
     var labels = await registrationManager.getExamLabelsByExamNoAsync(
         physicalExamNumber: rowData.physicalExamNumber!);
     barCodeList.clear();
-    for (var element in labels.eaxmLabels!) {
-      var barCodeData = await drawRedRect(element, rowData);
-      if (barCodeData.isNotEmpty) {
-        barCodeList.add(barCodeData);
+    for (var i = 0; i < labels.eaxmLabels!.length; i++) {
+      final element = labels.eaxmLabels![i];
+      var barCode = Uint8List(0);
+      // if (i == 0) {
+      // } else {
+      // }
+      barCode = await drawBarcode(element, rowData);
+      if (barCode.isNotEmpty) {
+        if (i == 0) {
+          var qrCode = await drawQRcode(element, rowData);
+          barCodeList.add(qrCode);
+        }
+        barCodeList.add(barCode);
       }
     }
   }
 
-  Future<Uint8List> drawRedRect(
+  Future<Uint8List> drawBarcode(
       HealthExamLabelDTO labelDto, ResidentModel resident) async {
     const size = Size(360, 240);
     final svg = Barcode.code128().toSvg(
       labelDto.uniquedCode!,
       width: 350,
-      height: 100,
+      height: 120,
     );
-    final qrcode = Barcode.qrCode(
+    final PictureInfo pictureInfo =
+        await vg.loadPicture(SvgStringLoader(svg), null);
+    var a = await _capturePainterToImage(
+        InfoPainter(labelDto, resident), BarcodePainter(pictureInfo), size);
+    return a!;
+  }
+
+  Future<Uint8List> drawQRcode(
+      HealthExamLabelDTO labelDto, ResidentModel resident) async {
+    const size = Size(360, 240);
+    final svg = Barcode.qrCode(
       typeNumber: 1,
       errorCorrectLevel: BarcodeQRCorrectionLevel.low,
     ).toSvg(
       labelDto.uniquedCode!,
-      width: 120,
-      height: 120,
+      width: 200,
+      height: 200,
     );
-    final PictureInfo qrcodeInfo =
-        await vg.loadPicture(SvgStringLoader(qrcode), null);
     final PictureInfo pictureInfo =
         await vg.loadPicture(SvgStringLoader(svg), null);
-    var a = await _capturePainterToImage(InfoPainter(labelDto, resident),
-        BarcodePainter(pictureInfo), QrcodePainter(qrcodeInfo), size);
+    var a = await _capturePainterToImage(
+        QRInfoPainter(labelDto, resident), QrcodePainter(pictureInfo), size);
     return a!;
   }
 
   /// 将CustomPainter绘制的内容转换为图片
   Future<Uint8List?> _capturePainterToImage(
-      CustomPainter painter,
-      CustomPainter barcodePainter,
-      CustomPainter qrcodePainter,
-      Size size) async {
+      CustomPainter painter, CustomPainter codePainter, Size size) async {
     final bounds = Offset.zero & size;
     // final bounds2 = Offset.zero & Size(size.width - 20, size.height - 20);
     final picture = PictureRecorder();
@@ -123,9 +137,7 @@ class RegistrationController extends GetxController {
     pictureCanvas.clipRect(bounds);
     painter.paint(pictureCanvas, size);
     // 在Canvas上进行绘制
-    barcodePainter.paint(pictureCanvas, size);
-
-    qrcodePainter.paint(pictureCanvas, size);
+    codePainter.paint(pictureCanvas, size);
 
     // 结束绘制
     final recordedPicture = picture.endRecording();
@@ -164,7 +176,7 @@ class InfoPainter extends CustomPainter {
     canvas.drawRect(
         Rect.fromLTWH(0, 0, size.width, size.height), backgroundPaint);
     canvas.drawLine(
-        Offset(0, 125), Offset(360, 125), Paint()..color = Colors.black);
+        Offset(0, 95), Offset(360, 95), Paint()..color = Colors.black);
 
     // Simulate drawing the content
     TextSpan titleSpan = TextSpan(
@@ -189,7 +201,7 @@ class InfoPainter extends CustomPainter {
       textDirection: TextDirection.ltr,
     );
     subTitleTp1.layout();
-    subTitleTp1.paint(canvas, Offset(10, 70));
+    subTitleTp1.paint(canvas, Offset(10, 65));
 
     TextSpan subTitleSpanAge = TextSpan(
       text: '${resident.age} 岁',
@@ -201,7 +213,7 @@ class InfoPainter extends CustomPainter {
       textDirection: TextDirection.ltr,
     );
     subTitleTpAge.layout();
-    subTitleTpAge.paint(canvas, Offset(150, 70));
+    subTitleTpAge.paint(canvas, Offset(150, 65));
     canvas.restore();
   }
 
@@ -217,7 +229,7 @@ class BarcodePainter extends CustomPainter {
   @override
   void paint(Canvas canvas, Size size) {
     canvas.save();
-    canvas.translate(5, 130);
+    canvas.translate(5, 100);
     canvas.scale(1, 1);
     canvas.drawPicture(pictureInfo.picture);
     canvas.restore(); // 恢复之前保存的绘制状态
@@ -229,13 +241,71 @@ class BarcodePainter extends CustomPainter {
   }
 }
 
+class QRInfoPainter extends CustomPainter {
+  HealthExamLabelDTO labelDto;
+  ResidentModel resident;
+  QRInfoPainter(this.labelDto, this.resident);
+  @override
+  void paint(Canvas canvas, Size size) {
+    canvas.save();
+    Paint backgroundPaint = Paint()..color = Colors.white;
+    canvas.drawRect(
+        Rect.fromLTWH(0, 0, size.width, size.height), backgroundPaint);
+    // canvas.drawLine(
+    //     Offset(0, 95), Offset(360, 95), Paint()..color = Colors.black);
+
+    // Simulate drawing the content
+    TextSpan titleSpan = TextSpan(
+      text: '${labelDto.title ?? ''}',
+      style: TextStyle(fontSize: 40, height: 1, color: Colors.black),
+    );
+    TextPainter titleTp = TextPainter(
+      text: titleSpan,
+      textAlign: TextAlign.left,
+      textDirection: TextDirection.ltr,
+    );
+    titleTp.layout();
+    titleTp.paint(canvas, Offset(10, 8));
+
+    TextSpan subTitleSpanName = TextSpan(
+      text: '${resident.name} ',
+      style: TextStyle(fontSize: 30, height: 1, color: Colors.black),
+    );
+    TextPainter subTitleTp1 = TextPainter(
+      text: subTitleSpanName,
+      textAlign: TextAlign.left,
+      textDirection: TextDirection.ltr,
+    );
+    subTitleTp1.layout();
+    subTitleTp1.paint(canvas, Offset(10, 70));
+
+    TextSpan subTitleSpanAge = TextSpan(
+      text: '${resident.age} 岁',
+      style: TextStyle(fontSize: 30, height: 1, color: Colors.black),
+    );
+    TextPainter subTitleTpAge = TextPainter(
+      text: subTitleSpanAge,
+      textAlign: TextAlign.left,
+      textDirection: TextDirection.ltr,
+    );
+    subTitleTpAge.layout();
+    subTitleTpAge.paint(canvas, Offset(10, 110));
+    canvas.restore();
+  }
+
+  @override
+  bool shouldRepaint(covariant CustomPainter oldDelegate) {
+    return false;
+  }
+}
+
 class QrcodePainter extends CustomPainter {
   PictureInfo pictureInfo;
   QrcodePainter(this.pictureInfo);
   @override
   void paint(Canvas canvas, Size size) {
     canvas.save();
-    canvas.translate(230, 0);
+    canvas.translate(150, 0);
     canvas.scale(1, 1);
     canvas.drawPicture(pictureInfo.picture);
     canvas.restore(); // 恢复之前保存的绘制状态

+ 3 - 2
lib/pages/widgets/qr_view_example.dart

@@ -90,13 +90,14 @@ class _QRViewExampleState extends State<QRViewExample> {
           borderLength: 30,
           borderWidth: 10,
           // cutOutSize: 400,
-          cutOutWidth: 600,
+          cutOutWidth: 300,
           cutOutHeight: 300,
         ),
         formatsAllowed: widget.isBarcode
             ? [
                 ///一维码则指定使用128的格式,会识别快一点
-                BarcodeFormat.code128,
+                // BarcodeFormat.code128,
+                BarcodeFormat.qrcode,
               ]
             : [],
         onPermissionSet: (ctrl, p) => _onPermissionSet(context, ctrl, p),