瀏覽代碼

针对Key -Value类型展示时,计算Key的宽度

loki.wu 2 年之前
父節點
當前提交
a88ddab130

+ 3 - 3
lib/pages/components/input_image.dart

@@ -29,7 +29,7 @@ class _RInputImageState extends State<RInputImage> {
   bool _hasImageBorder = false;
   String _imageUrl = '';
 
-  Widget _child = const Text('请点击此处后选择右侧图片');
+  Widget _child = const Text('请点击此处后选择图片');
 
   @override
   initState() {
@@ -104,7 +104,7 @@ class _RInputImageState extends State<RInputImage> {
             _child = _getChild();
           } else {
             _imageUrl = '';
-            _child = const Text('请点击此处后选择右侧图片');
+            _child = const Text('请点击此处后选择图片');
           }
         });
       });
@@ -120,6 +120,6 @@ class _RInputImageState extends State<RInputImage> {
         width: PtToPxConverter.ptToPx(widget.inputImage.imageWidth!),
       );
     }
-    return const Text('请点击此处后选择右侧图片');
+    return const Text('请点击此处后选择图片');
   }
 }

+ 2 - 2
lib/pages/components/input_imageList.dart

@@ -27,7 +27,7 @@ class _RInputImageListState extends State<RInputImageList> {
   final List<String> _images = [];
   double _height = 0.0;
 
-  Widget _child = const Text('请点击此处后选择右侧图片');
+  Widget _child = const Text('请点击此处后选择图片');
 
   @override
   initState() {
@@ -101,7 +101,7 @@ class _RInputImageListState extends State<RInputImageList> {
       );
     }
 
-    return const Text('请点击此处后选择右侧图片');
+    return const Text('请点击此处后选择图片');
   }
 
   @override

+ 3 - 0
lib/pages/components/static_text.dart

@@ -40,6 +40,9 @@ class _RStaticTextState extends State<RStaticText> {
     final text = _staticTextInfo!.text!;
     return Container(
       margin: _margin,
+      width: widget.staticText.lineWidth! > 0
+          ? PtToPxConverter.ptToPx(widget.staticText.lineWidth!) - 2
+          : null,
       child: Text(
         (text),
         style: _style,

+ 49 - 3
lib/pages/paragraph_page.dart

@@ -22,6 +22,8 @@ import 'package:fis_lib_report/report/line.dart';
 import 'package:fis_lib_report/report/multiSelected.dart';
 import 'package:fis_lib_report/report/page_number.dart';
 import 'package:fis_lib_report/report/paragraph.dart';
+import 'package:fis_lib_report/report/rt_Cell.dart';
+import 'package:fis_lib_report/report/rt_table.dart';
 import 'package:fis_lib_report/report/singleSelected.dart';
 import 'package:fis_lib_report/report/space.dart';
 import 'package:fis_lib_report/report/static_text.dart';
@@ -55,6 +57,53 @@ class _ParagraphState extends State<ParagraphPage> {
     _itemCount = _elements!.length;
     if (_itemCount == 0) {
       return const SizedBox();
+    } else if (_itemCount == 2 &&
+        _elements![0].elementType!.name == ElementType.staticText!.name &&
+        (_elements![1].elementType!.name == ElementType.singleSelected!.name ||
+            _elements![1].elementType!.name ==
+                ElementType.multiSelected!.name ||
+            _elements![1].elementType!.name == ElementType.inputText!.name)) {
+      try {
+        final staticText = _elements![0];
+        if (staticText.parent != null) {
+          final paragraph = staticText.parent as Paragraph;
+          if (paragraph.parent != null) {
+            final cell = paragraph.parent as RTCell;
+            if (cell.parent != null) {
+              final table = cell.parent as RTTable;
+              final values = table.cells!.values.toList();
+              for (var i = 0; i < values.length; i++) {
+                if (values[i] == cell) {
+                  final key = table.cells!.keys.toList()[i];
+                  final column = key.column;
+                  final width = table.columnDefinitions![column!].width;
+                  var valueWidth = 0.0;
+                  if (_elements![1].elementType!.name ==
+                      ElementType.inputText!.name) {
+                    final input = _elements![1] as InputText;
+                    valueWidth = input.lineWidth!;
+                  }
+                  if (_elements![1].elementType!.name ==
+                      ElementType.singleSelected!.name) {
+                    final input = _elements![1] as SingleSelected;
+                    valueWidth = input.lineWidth!;
+                  }
+                  if (_elements![1].elementType!.name ==
+                      ElementType.multiSelected!.name) {
+                    final input = _elements![1] as MultiSelected;
+                    valueWidth = input.lineWidth!;
+                  }
+                  final textWidth = width! - valueWidth;
+                  final textElement = staticText as StaticText;
+                  textElement.lineWidth = textWidth;
+                }
+              }
+            }
+          }
+        }
+      } catch (e) {
+        print(e);
+      }
     }
     final margin = widget.paragraph.margin!;
     return Container(
@@ -76,9 +125,6 @@ class _ParagraphState extends State<ParagraphPage> {
             } else if (element.elementType!.name ==
                 ElementType.staticText!.name) {
               StaticText staticText = element as StaticText;
-              if (staticText.lineWidth == 0) {
-                staticText.lineWidth = staticText.lineLength! * 10.5;
-              }
               return RStaticText(staticText);
             } else if (element.elementType!.name ==
                 ElementType.singleSelected!.name) {

+ 1 - 3
lib/report/interfaces/element.dart

@@ -5,9 +5,7 @@ import 'package:fis_lib_report/report/interfaces/report_element.dart';
 import 'package:fis_lib_report/report/measure_tag.dart';
 import 'package:fis_lib_report/report/rt_thickness.dart';
 
-abstract class IElement {
-  String? id;
-
+abstract class IElement extends IReportElement {
   /// Gets or sets the element index.
   int? index;
 

+ 1 - 1
lib/report/interfaces/report_element.dart

@@ -1,3 +1,3 @@
 abstract class IReportElement {
-  late String id;
+  String? id;
 }

+ 4 - 2
lib/report/paragraph.dart

@@ -22,7 +22,9 @@ class Paragraph extends Element implements IParagraph {
 
   bool? isEmptyFirst;
 
-  Paragraph.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
+  Paragraph.fromJson(Map<String, dynamic> json, {IElement? parent})
+      : super.fromJson(json) {
+    this.parent = parent;
     lineSpace = json['LineSpace'];
     List<dynamic> jsonElements = json['Elements'];
     jsonElements.forEach((map) {
@@ -34,7 +36,7 @@ class Paragraph extends Element implements IParagraph {
         final line = Line.fromJson(map);
         elements!.add(line);
       } else if (jsonType.name == ElementType.staticText!.name) {
-        final staticText = StaticText.fromJson(map);
+        final staticText = StaticText.fromJson(map, parent: this);
         elements!.add(staticText);
       } else if (jsonType.name == ElementType.singleSelected!.name) {
         final singleSelected = SingleSelected.fromJson(map);

+ 3 - 5
lib/report/report_template_document.dart

@@ -90,6 +90,9 @@ class ReportTemplateDocument implements IReportTemplateDocument {
   @override
   RTPageSize? pageSize;
 
+  @override
+  String? id;
+
   /// Gets the custom input element tags of the report template.
   @override
   Map<String, ElementTag>? tags;
@@ -102,10 +105,6 @@ class ReportTemplateDocument implements IReportTemplateDocument {
   @override
   String? version;
 
-  /// Gets the id.
-  @override
-  late String id;
-
   /// Gets the report template footer.
   @override
   List<IBlockElement>? footer = [];
@@ -126,7 +125,6 @@ class ReportTemplateDocument implements IReportTemplateDocument {
     footerDistance = 34;
   }
 
-  //TODO(Loki):目前仅能支持常规模板解析,其他模板需添加缺少的类
   ReportTemplateDocument.fromJson(Map<String, dynamic> json) {
     try {
       isCustom = json['IsCustom'];

+ 6 - 2
lib/report/rt_Cell.dart

@@ -3,6 +3,8 @@ import 'package:fis_lib_report/report/element.dart';
 import 'package:fis_lib_report/report/element_type.dart';
 import 'package:fis_lib_report/report/interfaces/block_element.dart';
 import 'package:fis_lib_report/report/interfaces/cell.dart';
+import 'package:fis_lib_report/report/interfaces/element.dart';
+import 'package:fis_lib_report/report/interfaces/report_element.dart';
 import 'package:fis_lib_report/report/paragraph.dart';
 import 'package:fis_lib_report/report/rt_color.dart';
 
@@ -21,7 +23,9 @@ class RTCell extends Element implements ICell {
 
   Borders? borders;
 
-  RTCell.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
+  RTCell.fromJson(Map<String, dynamic> json, {IElement? parent})
+      : super.fromJson(json) {
+    this.parent = parent;
     final jsonBackground = json['Background'];
     background = RTColor.fromJson(jsonBackground);
     if (json['HeightType'] != null) {
@@ -37,7 +41,7 @@ class RTCell extends Element implements ICell {
       final jsonType = map['ElementType'];
       final type = ElementType.fromJson(jsonType);
       if (type.name == ElementType.paragraph!.name) {
-        final block = Paragraph.fromJson(map);
+        final block = Paragraph.fromJson(map, parent: this);
         blocks!.add(block);
       }
     });

+ 1 - 1
lib/report/rt_grid.dart

@@ -82,7 +82,7 @@ class RTGrid extends Element implements IGrid {
         final jsonType = map['ElementType'];
         final type = ElementType.fromJson(jsonType);
         if (type.name == ElementType.rtCell!.name) {
-          final cell = RTCell.fromJson(map);
+          final cell = RTCell.fromJson(map, parent: this);
           cells![key] = cell;
         }
       }

+ 4 - 1
lib/report/static_text.dart

@@ -1,3 +1,4 @@
+import 'package:fis_lib_report/report/interfaces/element.dart';
 import 'package:fis_lib_report/report/interfaces/staticText.dart';
 import 'package:fis_lib_report/report/text_element.dart';
 
@@ -8,7 +9,9 @@ class StaticText extends TextElement implements IStaticText {
   @override
   String? text;
 
-  StaticText.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
+  StaticText.fromJson(Map<String, dynamic> json, {IElement? parent})
+      : super.fromJson(json) {
+    this.parent = parent;
     ignoreUndo = json['IgnoreUndo'];
     text = json['Text'];
   }