瀏覽代碼

实现文本输入框&单选框的数据驱动

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

文件差異過大導致無法顯示
+ 0 - 3002
assets/test.json


+ 16 - 4
lib/main.dart

@@ -1,3 +1,5 @@
+import 'dart:convert';
+
 import 'package:fis_lib_report/converts/event_type.dart';
 import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
 import 'package:fis_lib_report/pages/components/vid_image.dart';
@@ -51,6 +53,7 @@ class _MyHomePageState extends State<MyHomePage> {
   late FEventHandler<String> onSelect;
   String _aiJson = '';
   String _petStr = '';
+  String _testStr = '';
   @override
   initState() {
     onSelect = FEventHandler<String>();
@@ -66,6 +69,9 @@ class _MyHomePageState extends State<MyHomePage> {
     rootBundle.loadString('assets/pet.json').then((jsonStr) {
       _petStr = jsonStr;
     });
+    rootBundle.loadString('assets/test.json').then((jsonStr) {
+      _testStr = jsonStr;
+    });
     super.initState();
   }
 
@@ -90,10 +96,10 @@ class _MyHomePageState extends State<MyHomePage> {
                 reportDate: DateTime.now(),
                 jsonStr: _jsonStr,
                 onSelect: onSelect,
-                patinentAge: '22',
-                patinentId: '20220705',
-                patinentName: 'name',
-                patinentSex: '男',
+                // patinentAge: '22',
+                // patinentId: '20220705',
+                // patinentName: 'name',
+                // patinentSex: '男',
               ),
             ),
           const SizedBox(width: 40),
@@ -152,6 +158,12 @@ class _MyHomePageState extends State<MyHomePage> {
                   onPressed: () {
                     setState(() {});
                   }),
+              MaterialButton(
+                  child: Text('testInfo'),
+                  onPressed: () {
+                    final reportMap = jsonDecode(_testStr);
+                    ReportInfo.instance.fromJson(reportMap);
+                  }),
             ],
           ),
         ],

+ 3 - 3
lib/pages/block_element_page.dart

@@ -30,13 +30,13 @@ class _BlockElementState extends State<BlockElementPage> {
   @override
   Widget build(BuildContext context) {
     _type = widget.element.elementType!;
-    if (_type != null && _type!.name == ElementType.rtTable!.name) {
+    if (_type != null && _type!.name == ElementType.rtTable.name) {
       RTTable t = widget.element as RTTable;
       return RTTablePage(element: t);
-    } else if (_type != null && _type!.name == ElementType.paragraph!.name) {
+    } else if (_type != null && _type!.name == ElementType.paragraph.name) {
       final paragraph = widget.element as Paragraph;
       return ParagraphPage(paragraph: paragraph);
-    } else if (_type != null && _type!.name == ElementType.imageList!.name) {
+    } else if (_type != null && _type!.name == ElementType.imageList.name) {
       final inputImageList = widget.element as InputImageList;
       return Center(
         child: RInputImageList(inputImageList),

+ 46 - 36
lib/pages/components/input_text.dart

@@ -2,7 +2,6 @@ import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
 import 'package:fis_lib_report/converts/text_size_converter.dart';
 import 'package:fis_lib_report/converts/alignment_convert.dart';
 import 'package:fis_lib_report/report/inputText.dart';
-import 'package:fis_lib_report/report_info/element_info.dart';
 import 'package:fis_lib_report/report_info/input_text_info.dart';
 import 'package:fis_lib_report/report_info/report_info.dart';
 import 'package:flutter/material.dart';
@@ -32,10 +31,10 @@ class _RInputTextState extends State<RInputText> {
   TextStyle? _textStyle;
   InputTextInfo? _inputTextInfo;
   bool _isReadOnly = false;
+  String _text = '';
 
   @override
   initState() {
-    _initDatas();
     ReportInfo.instance.onReloadFinsh.addListener((sender, e) {
       _initDatas();
     });
@@ -46,12 +45,8 @@ class _RInputTextState extends State<RInputText> {
   Widget build(BuildContext context) {
     final inputTextInfo = ReportInfo.instance.getElementInfo(widget.inputText);
     if (_inputTextInfo != inputTextInfo) {
+      if (_inputTextInfo != null) _inputTextInfo!.onTextChange.dispose();
       _inputTextInfo = inputTextInfo as InputTextInfo;
-      _inputTextInfo!.onTextChange.addListener((sender, e) {
-        setState(() {
-          _controller.text = e;
-        });
-      });
     }
     if (!_inputTextInfo!.isListening!) {
       _initDatas();
@@ -106,52 +101,43 @@ class _RInputTextState extends State<RInputText> {
     if (_inputTextInfo != null) {
       _inputTextInfo!.text = value;
     }
-    final width = TextSizeConvert.getTextSize(value, _textStyle).width + 15;
-    //TODO(LOki):此处需要区分不同的输入框
-    if (inputText.tag!.name == 'HospitalName') {
-      if (_lineWidth! < width) {
-        setState(() {
-          if (width < 480) {
-            _lineWidth = width;
-          }
-        });
-      } else if (_controller.text.isEmpty) {
-        setState(() {
-          //重置长度
-          _lineWidth = inputText.lineWidth;
-        });
-      } else if (TextSizeConvert.getTextSize(_controller.text, _textStyle)
-              .width >
-          inputText.lineWidth!) {
-        setState(() {
-          if (width < 480) {
-            _lineWidth = width;
-          }
-        });
-      }
-    }
+
+    _syncWidth(
+      inputText,
+      value,
+    );
   }
 
   @override
   void dispose() {
+    _inputTextInfo!.onTextChange.dispose();
     _controller.dispose();
     super.dispose();
   }
 
   void _initDatas() {
+    final inputText = widget.inputText;
+    _textStyle = TextStyle(
+      fontSize: PtToPxConverter.ptToPx(inputText.fontSize),
+      color: _fontColor,
+    );
     _controller.text = '';
     _focusNode.addListener(() {
       if (!_focusNode.hasFocus) {
         _onInputChanged(_textStyle!, _controller.text);
       }
     });
-    final inputText = widget.inputText;
+
     _isReadOnly = inputText.isReadOnly!;
     final inputTextInfo = ReportInfo.instance.getElementInfo(inputText);
     _inputTextInfo = inputTextInfo as InputTextInfo;
     _inputTextInfo!.onTextChange.addListener((sender, e) {
       setState(() {
         _controller.text = e;
+        _syncWidth(
+          inputText,
+          e,
+        );
       });
     });
     if (_inputTextInfo!.isReadOnly!) {
@@ -169,10 +155,7 @@ class _RInputTextState extends State<RInputText> {
       _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
           backgroundColor.g!, backgroundColor.b!);
     }
-    _textStyle = TextStyle(
-      fontSize: PtToPxConverter.ptToPx(inputText.fontSize),
-      color: _fontColor,
-    );
+
     //TODO(Loki):set FontName in TextField
     final fontName = inputText.fontName;
     //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
@@ -188,4 +171,31 @@ class _RInputTextState extends State<RInputText> {
     });
     setState(() {});
   }
+
+  void _syncWidth(InputText inputText, String value) {
+    final width = TextSizeConvert.getTextSize(value, _textStyle!).width + 15;
+
+    if (inputText.tag!.name == 'HospitalName') {
+      if (_lineWidth! < width) {
+        setState(() {
+          if (width < 480) {
+            _lineWidth = width;
+          }
+        });
+      } else if (_controller.text.isEmpty) {
+        setState(() {
+          //重置长度
+          _lineWidth = inputText.lineWidth;
+        });
+      } else if (TextSizeConvert.getTextSize(_controller.text, _textStyle!)
+              .width >
+          inputText.lineWidth!) {
+        setState(() {
+          if (width < 480) {
+            _lineWidth = width;
+          }
+        });
+      }
+    }
+  }
 }

+ 3 - 1
lib/pages/components/single_select.dart

@@ -35,7 +35,9 @@ class _RSingleSelectState extends State<RSingleSelected> {
       _singleSelectedInfo = selectInfo as SingleSelectedInfo;
       _singleSelectedInfo!.onSelectedChange.addListener((sender, e) {
         if (_singleSelectedInfo!.items!.contains(e)) {
-          _value = _singleSelectedInfo!.selectedItem;
+          setState(() {
+            _value = _singleSelectedInfo!.selectedItem;
+          });
         }
       });
     }

+ 17 - 22
lib/pages/paragraph_page.dart

@@ -1,7 +1,6 @@
 import 'package:fis_lib_report/converts/alignment_convert.dart';
 import 'package:fis_lib_report/pages/components/datetime.dart';
 import 'package:fis_lib_report/pages/components/input_image.dart';
-import 'package:fis_lib_report/pages/components/input_imageList.dart';
 import 'package:fis_lib_report/pages/components/input_text.dart';
 import 'package:fis_lib_report/pages/components/line.dart';
 import 'package:fis_lib_report/pages/components/multi_select.dart';
@@ -17,7 +16,6 @@ import 'package:fis_lib_report/report/element_type.dart';
 import 'package:fis_lib_report/report/inputImage.dart';
 import 'package:fis_lib_report/report/inputText.dart';
 import 'package:fis_lib_report/report/interfaces/element.dart';
-import 'package:fis_lib_report/report/interfaces/position_layout.dart';
 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';
@@ -28,7 +26,6 @@ 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';
 import 'package:fis_lib_report/report/static_image.dart';
-import 'package:fis_lib_report/report_info/report_info.dart';
 import 'package:flutter/material.dart';
 
 class ParagraphPage extends StatefulWidget {
@@ -58,11 +55,10 @@ class _ParagraphState extends State<ParagraphPage> {
     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)) {
+        _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) {
@@ -79,17 +75,17 @@ class _ParagraphState extends State<ParagraphPage> {
                   final width = table.columnDefinitions![column!].width;
                   var valueWidth = 0.0;
                   if (_elements![1].elementType!.name ==
-                      ElementType.inputText!.name) {
+                      ElementType.inputText.name) {
                     final input = _elements![1] as InputText;
                     valueWidth = input.lineWidth!;
                   }
                   if (_elements![1].elementType!.name ==
-                      ElementType.singleSelected!.name) {
+                      ElementType.singleSelected.name) {
                     final input = _elements![1] as SingleSelected;
                     valueWidth = input.lineWidth!;
                   }
                   if (_elements![1].elementType!.name ==
-                      ElementType.multiSelected!.name) {
+                      ElementType.multiSelected.name) {
                     final input = _elements![1] as MultiSelected;
                     valueWidth = input.lineWidth!;
                   }
@@ -119,41 +115,40 @@ class _ParagraphState extends State<ParagraphPage> {
         alignment: WrapAlignment.spaceEvenly,
         children: [
           ..._elements!.map((element) {
-            if (element.elementType!.name == ElementType.inputText!.name) {
+            if (element.elementType!.name == ElementType.inputText.name) {
               InputText inputText = element as InputText;
               return RInputText(inputText: inputText);
             } else if (element.elementType!.name ==
-                ElementType.staticText!.name) {
+                ElementType.staticText.name) {
               StaticText staticText = element as StaticText;
               return RStaticText(staticText);
             } else if (element.elementType!.name ==
-                ElementType.singleSelected!.name) {
+                ElementType.singleSelected.name) {
               SingleSelected singleSelected = element as SingleSelected;
               return RSingleSelected(singleSelected);
-            } else if (element.elementType!.name == ElementType.line!.name) {
+            } else if (element.elementType!.name == ElementType.line.name) {
               Line line = element as Line;
               return RLine(line);
-            } else if (element.elementType!.name ==
-                ElementType.dateTime!.name) {
+            } else if (element.elementType!.name == ElementType.dateTime.name) {
               final dateTime = element as DateTimeElement;
               return RDateTime(dateTime);
             } else if (element.elementType!.name ==
-                ElementType.multiSelected!.name) {
+                ElementType.multiSelected.name) {
               final multiSelected = element as MultiSelected;
               return RMultiSelected(multiSelected);
             } else if (element.elementType!.name ==
-                ElementType.inputImage!.name) {
+                ElementType.inputImage.name) {
               final inputImage = element as InputImage;
               return RInputImage(inputImage);
             } else if (element.elementType!.name ==
-                ElementType.staticImage!.name) {
+                ElementType.staticImage.name) {
               final staticImage = element as StaticImage;
               return RStaticImage(staticImage);
-            } else if (element.elementType!.name == ElementType.space!.name) {
+            } else if (element.elementType!.name == ElementType.space.name) {
               final space = element as Space;
               return RSpace(space);
             } else if (element.elementType!.name ==
-                ElementType.pageNumber!.name) {
+                ElementType.pageNumber.name) {
               final pageNumber = element as PageNumber;
               return RPageNumber(pageNumber);
             }

+ 1 - 1
lib/pages/rt_cell.dart

@@ -38,7 +38,7 @@ class _RTCellState extends State<RTCellPage> {
             alignment: WrapAlignment.start,
             children: [
               ..._blocks!.map((e) {
-                if (e.elementType!.name == ElementType.paragraph!.name) {
+                if (e.elementType!.name == ElementType.paragraph.name) {
                   final paragraph = e as Paragraph;
                   return ParagraphPage(paragraph: paragraph);
                 }

+ 15 - 15
lib/report/element_type.dart

@@ -1,21 +1,21 @@
 class ElementType {
   String? name;
 
-  static ElementType? rtGrid = ElementType('RTGrid');
-  static ElementType? rtTable = ElementType('RTTable');
-  static ElementType? rtCell = ElementType('RTCell');
-  static ElementType? paragraph = ElementType('Paragraph');
-  static ElementType? inputText = ElementType('InputText');
-  static ElementType? line = ElementType('Line');
-  static ElementType? staticText = ElementType('StaticText');
-  static ElementType? singleSelected = ElementType('SingleSelected');
-  static ElementType? multiSelected = ElementType('MultiSelected');
-  static ElementType? imageList = ElementType('ImageList');
-  static ElementType? dateTime = ElementType('DateTime');
-  static ElementType? inputImage = ElementType('InputImage');
-  static ElementType? staticImage = ElementType('StaticImage');
-  static ElementType? space = ElementType('Space');
-  static ElementType? pageNumber = ElementType('PageNumber');
+  static ElementType rtGrid = ElementType('RTGrid');
+  static ElementType rtTable = ElementType('RTTable');
+  static ElementType rtCell = ElementType('RTCell');
+  static ElementType paragraph = ElementType('Paragraph');
+  static ElementType inputText = ElementType('InputText');
+  static ElementType line = ElementType('Line');
+  static ElementType staticText = ElementType('StaticText');
+  static ElementType singleSelected = ElementType('SingleSelected');
+  static ElementType multiSelected = ElementType('MultiSelected');
+  static ElementType imageList = ElementType('ImageList');
+  static ElementType dateTime = ElementType('DateTime');
+  static ElementType inputImage = ElementType('InputImage');
+  static ElementType staticImage = ElementType('StaticImage');
+  static ElementType space = ElementType('Space');
+  static ElementType pageNumber = ElementType('PageNumber');
 
   ElementType(this.name);
 

+ 12 - 12
lib/report/paragraph.dart

@@ -27,39 +27,39 @@ class Paragraph extends Element implements IParagraph {
     this.parent = parent;
     lineSpace = json['LineSpace'];
     List<dynamic> jsonElements = json['Elements'];
-    jsonElements.forEach((map) {
+    for (var map in jsonElements) {
       final jsonType = ElementType.fromJson(map['ElementType']);
-      if (jsonType.name == ElementType.inputText!.name) {
+      if (jsonType.name == ElementType.inputText.name) {
         final inputText = InputText.fromJson(map);
         elements!.add(inputText);
-      } else if (jsonType.name == ElementType.line!.name) {
+      } else if (jsonType.name == ElementType.line.name) {
         final line = Line.fromJson(map);
         elements!.add(line);
-      } else if (jsonType.name == ElementType.staticText!.name) {
+      } else if (jsonType.name == ElementType.staticText.name) {
         final staticText = StaticText.fromJson(map, parent: this);
         elements!.add(staticText);
-      } else if (jsonType.name == ElementType.singleSelected!.name) {
+      } else if (jsonType.name == ElementType.singleSelected.name) {
         final singleSelected = SingleSelected.fromJson(map);
         elements!.add(singleSelected);
-      } else if (jsonType.name == ElementType.multiSelected!.name) {
+      } else if (jsonType.name == ElementType.multiSelected.name) {
         final multiSelected = MultiSelected.fromJson(map);
         elements!.add(multiSelected);
-      } else if (jsonType.name == ElementType.dateTime!.name) {
+      } else if (jsonType.name == ElementType.dateTime.name) {
         final dateTime = DateTimeElement.fromJson(map);
         elements!.add(dateTime);
-      } else if (jsonType.name == ElementType.inputImage!.name) {
+      } else if (jsonType.name == ElementType.inputImage.name) {
         final inputImage = InputImage.fromJson(map);
         elements!.add(inputImage);
-      } else if (jsonType.name == ElementType.staticImage!.name) {
+      } else if (jsonType.name == ElementType.staticImage.name) {
         final staticImage = StaticImage.fromJson(map);
         elements!.add(staticImage);
-      } else if (jsonType.name == ElementType.space!.name) {
+      } else if (jsonType.name == ElementType.space.name) {
         final space = Space.fromJson(map);
         elements!.add(space);
-      } else if (jsonType.name == ElementType.pageNumber!.name) {
+      } else if (jsonType.name == ElementType.pageNumber.name) {
         final pageNumber = PageNumber.fromJson(map);
         elements!.add(pageNumber);
       }
-    });
+    }
   }
 }

+ 13 - 13
lib/report/report_template_document.dart

@@ -14,11 +14,8 @@ class ReportTemplateDocument implements IReportTemplateDocument {
   Set<String> _customizeComments = {};
   Set<String> _customizeReportComments = {};
   Set<String> _customizeCalculations = {};
-  List<IBlockElement> _blocks = [];
-  List<IBlockElement> _headers = [];
-  List<IBlockElement> _footers = [];
-  String? _fontName;
 
+  @override
   Map<String, Map<String, String>> get customizeTranslation =>
       _customizeTranslation;
   @override
@@ -26,18 +23,21 @@ class ReportTemplateDocument implements IReportTemplateDocument {
     _customizeTranslation = v ?? {};
   }
 
+  @override
   Set<String> get customizeComments => _customizeComments;
   @override
   set customizeReportComments(Set<String>? v) {
     _customizeReportComments = v ?? {};
   }
 
+  @override
   Set<String> get customizeReportComments => _customizeReportComments;
   @override
   set customizeComments(Set<String>? v) {
     _customizeComments = v ?? {};
   }
 
+  @override
   Set<String> get customizeCalculations => _customizeCalculations;
   @override
   set customizeCalculations(Set<String>? v) {
@@ -143,7 +143,7 @@ class ReportTemplateDocument implements IReportTemplateDocument {
       pagePadding = RTThickness.fromJson(json['PagePadding'] ?? {});
       pageSize = RTPageSize.fromJson(json['PageSize'] ?? {});
       Map jsonTags = json['Tags'];
-      if (jsonTags.length > 0) {
+      if (jsonTags.isNotEmpty) {
         //TODO(Loki):tags convert
       } else {
         tags = {};
@@ -175,13 +175,13 @@ class ReportTemplateDocument implements IReportTemplateDocument {
         final type = block['ElementType'];
         final jsonType = ElementType.fromJson(type);
         final name = jsonType.name;
-        if (name == ElementType.rtTable!.name) {
+        if (name == ElementType.rtTable.name) {
           final jsonBlock = RTTable.fromJson(block);
           blocks!.add(jsonBlock);
-        } else if (name == ElementType.paragraph!.name) {
+        } else if (name == ElementType.paragraph.name) {
           final jsonBlock = Paragraph.fromJson(block);
           blocks!.add(jsonBlock);
-        } else if (name == ElementType.imageList!.name) {
+        } else if (name == ElementType.imageList.name) {
           final inputImageList = InputImageList.fromJson(block);
           blocks!.add(inputImageList);
         }
@@ -193,13 +193,13 @@ class ReportTemplateDocument implements IReportTemplateDocument {
         final type = block['ElementType'];
         final jsonType = ElementType.fromJson(type);
         final name = jsonType.name;
-        if (name == ElementType.rtTable!.name) {
+        if (name == ElementType.rtTable.name) {
           final jsonBlock = RTTable.fromJson(block);
           header!.add(jsonBlock);
-        } else if (name == ElementType.paragraph!.name) {
+        } else if (name == ElementType.paragraph.name) {
           final jsonBlock = Paragraph.fromJson(block);
           header!.add(jsonBlock);
-        } else if (name == ElementType.imageList!.name) {
+        } else if (name == ElementType.imageList.name) {
           final inputImageList = InputImageList.fromJson(block);
           header!.add(inputImageList);
         }
@@ -211,10 +211,10 @@ class ReportTemplateDocument implements IReportTemplateDocument {
         final type = block['ElementType'];
         final jsonType = ElementType.fromJson(type);
         final name = jsonType.name;
-        if (name == ElementType.rtTable!.name) {
+        if (name == ElementType.rtTable.name) {
           final jsonBlock = RTTable.fromJson(block);
           footer!.add(jsonBlock);
-        } else if (name == ElementType.paragraph!.name) {
+        } else if (name == ElementType.paragraph.name) {
           final paragraph = Paragraph.fromJson(block);
           footer!.add(paragraph);
         }

+ 3 - 3
lib/report/rt_Cell.dart

@@ -37,14 +37,14 @@ class RTCell extends Element implements ICell {
           .firstWhere((element) => element.name == json['WidthType']);
     }
     List<dynamic> jsonBlocks = json['Blocks'];
-    jsonBlocks.forEach((map) {
+    for (var map in jsonBlocks) {
       final jsonType = map['ElementType'];
       final type = ElementType.fromJson(jsonType);
-      if (type.name == ElementType.paragraph!.name) {
+      if (type.name == ElementType.paragraph.name) {
         final block = Paragraph.fromJson(map, parent: this);
         blocks!.add(block);
       }
-    });
+    }
     final jsonBorders = json['Borders'];
     borders = Borders.fromJson(jsonBorders);
   }

+ 9 - 9
lib/report/rt_grid.dart

@@ -48,12 +48,12 @@ class RTGrid extends Element implements IGrid {
     horizontalAlignment = HorizontalLayout.Left;
 
     List<dynamic> jsonColumnDefinitions = json["ColumnDefinitions"] ?? [];
-    jsonColumnDefinitions.forEach((map) {
+    for (var map in jsonColumnDefinitions) {
       if (map is Map<String, dynamic>) {
         final rtcolumn = RTColumnDefinition.fromJson(map);
         columnDefinitions!.add(rtcolumn);
       }
-    });
+    }
     isDelete = json['IsDelete'];
     isInsertColumn = json['IsInsertColumn'];
     deleteRowIndex = json['DeleteRowIndex'];
@@ -63,30 +63,30 @@ class RTGrid extends Element implements IGrid {
     mergeDeleteStartColumnIndex = json['MergeDeleteStartColumnIndex'];
     mergeDeleteEndColumnIndex = json['MergeDeleteEndColumnIndex'];
     List<dynamic> jsonRowDefinitions = json['RowDefinitions'] ?? [];
-    jsonRowDefinitions.forEach((map) {
+    for (var map in jsonRowDefinitions) {
       if (map is Map<String, dynamic>) {
         final rtRow = RTRowDefinition.fromJson(map);
         rowDefinitions!.add(rtRow);
       }
-    });
+    }
 
     //TODO(Loki): elements init
     List<dynamic> jsonCells = json['Cells'];
     int index = 0;
-    CellPostion key = new CellPostion();
-    jsonCells.forEach((map) {
+    CellPostion key = CellPostion();
+    for (var map in jsonCells) {
       if (index.isEven) {
         key = CellPostion.fromJson(map);
-        cells![key] = new ICell();
+        cells![key] = ICell();
       } else {
         final jsonType = map['ElementType'];
         final type = ElementType.fromJson(jsonType);
-        if (type.name == ElementType.rtCell!.name) {
+        if (type.name == ElementType.rtCell.name) {
           final cell = RTCell.fromJson(map, parent: this);
           cells![key] = cell;
         }
       }
       index++;
-    });
+    }
   }
 }

+ 1 - 0
lib/report_edit.dart

@@ -6,6 +6,7 @@ import 'package:fis_lib_report/pages/block_element_page.dart';
 import 'package:fis_lib_report/report/interfaces/block_element.dart';
 import 'package:fis_lib_report/report/report_template_document.dart';
 import 'package:fis_lib_report/report/rt_thickness.dart';
+import 'package:fis_lib_report/report_info/report_event_args.dart';
 import 'package:fis_lib_report/report_info/report_info.dart';
 import 'package:flutter/material.dart';
 

+ 3 - 3
lib/report_info/input_text_info.dart

@@ -6,11 +6,11 @@ class InputTextInfo extends TextElementInfo {
   ///是否只读
   bool? isReadOnly;
 
-  ///当前输入框是否处于输入状态
+  ///当前输入框是否已经监听
   bool? isListening;
 
   ///UI绑定的文本
-  String get text => _text ?? '';
+  String get text => _text;
   set text(String v) {
     _text = v;
     onTextChange.emit(this, v);
@@ -19,7 +19,7 @@ class InputTextInfo extends TextElementInfo {
   ///文本改变通知UI变化
   FEventHandler<String> onTextChange = FEventHandler<String>();
 
-  String? _text;
+  String _text = '';
 
   InputTextInfo.fromElement(InputText element) : super.fromElement(element) {
     isReadOnly = element.isReadOnly;

+ 0 - 1
lib/report_info/page_number_info.dart

@@ -1,5 +1,4 @@
 import 'package:fis_lib_report/report/page_number.dart';
-import 'package:fis_lib_report/report/static_text.dart';
 import 'package:fis_lib_report/report_info/text_element_info.dart';
 
 class PageNumberInfo extends TextElementInfo {

+ 18 - 20
lib/report_info/paragraph_info.dart

@@ -33,32 +33,31 @@ class ParagraphInfo extends ElementInfo implements IBlockElementInfo {
       : super.fromElement(paragraph) {
     final elements = paragraph.elements;
     for (var element in elements!) {
-      if (element.elementType!.name == ElementType.inputText!.name) {
+      if (element.elementType!.name == ElementType.inputText.name) {
         InputText inputText = element as InputText;
         elementInfos!.add(InputTextInfo.fromElement(inputText));
-      } else if (element.elementType!.name == ElementType.staticText!.name) {
+      } else if (element.elementType!.name == ElementType.staticText.name) {
         StaticText staticText = element as StaticText;
         elementInfos!.add(StaticTextInfo.fromElement(staticText));
-      } else if (element.elementType!.name ==
-          ElementType.singleSelected!.name) {
+      } else if (element.elementType!.name == ElementType.singleSelected.name) {
         SingleSelected singleSelected = element as SingleSelected;
         elementInfos!.add(SingleSelectedInfo.fromElement(singleSelected));
-      } else if (element.elementType!.name == ElementType.dateTime!.name) {
+      } else if (element.elementType!.name == ElementType.dateTime.name) {
         final dateTime = element as DateTimeElement;
         elementInfos!.add(DateTimeInfo.fromElement(dateTime));
-      } else if (element.elementType!.name == ElementType.multiSelected!.name) {
+      } else if (element.elementType!.name == ElementType.multiSelected.name) {
         final multiSelected = element as MultiSelected;
         elementInfos!.add(MulitiSelectedInfo.fromElement(multiSelected));
-      } else if (element.elementType!.name == ElementType.inputImage!.name) {
+      } else if (element.elementType!.name == ElementType.inputImage.name) {
         final inputImage = element as InputImage;
         elementInfos!.add(InputImageInfo.fromElement(inputImage));
-      } else if (element.elementType!.name == ElementType.staticImage!.name) {
+      } else if (element.elementType!.name == ElementType.staticImage.name) {
         final inputImage = element as StaticImage;
         elementInfos!.add(StaticImageInfo.fromElement(inputImage));
-      } else if (element.elementType!.name == ElementType.pageNumber!.name) {
+      } else if (element.elementType!.name == ElementType.pageNumber.name) {
         final pageNumber = element as PageNumber;
         elementInfos!.add(PageNumberInfo.fromElement(pageNumber));
-      } else if (element.elementType!.name == ElementType.line!.name) {
+      } else if (element.elementType!.name == ElementType.line.name) {
         final pageNumber = element as Line;
         elementInfos!.add(LineInfo.fromElement(pageNumber));
       }
@@ -72,32 +71,31 @@ class ParagraphInfo extends ElementInfo implements IBlockElementInfo {
     final elementInfosmap = <String, dynamic>{};
     elementInfosmap.addAll(super.toJson());
     for (var element in elementInfos!) {
-      if (element.elementType!.name == ElementType.inputText!.name) {
+      if (element.elementType!.name == ElementType.inputText.name) {
         final inputText = element as InputTextInfo;
         elementInfosmap.addAll(inputText.toJson());
-      } else if (element.elementType!.name == ElementType.staticText!.name) {
+      } else if (element.elementType!.name == ElementType.staticText.name) {
         final staticText = element as StaticTextInfo;
         elementInfosmap.addAll(staticText.toJson());
-      } else if (element.elementType!.name ==
-          ElementType.singleSelected!.name) {
+      } else if (element.elementType!.name == ElementType.singleSelected.name) {
         final singleSelected = element as SingleSelectedInfo;
         elementInfosmap.addAll(singleSelected.toJson());
-      } else if (element.elementType!.name == ElementType.dateTime!.name) {
+      } else if (element.elementType!.name == ElementType.dateTime.name) {
         final dateTime = element as DateTimeInfo;
         elementInfosmap.addAll(dateTime.toJson());
-      } else if (element.elementType!.name == ElementType.multiSelected!.name) {
+      } else if (element.elementType!.name == ElementType.multiSelected.name) {
         final elementInfo = element as MulitiSelectedInfo;
         elementInfosmap.addAll(elementInfo.toJson());
-      } else if (element.elementType!.name == ElementType.inputImage!.name) {
+      } else if (element.elementType!.name == ElementType.inputImage.name) {
         final elementInfo = element as InputImageInfo;
         elementInfosmap.addAll(elementInfo.toJson());
-      } else if (element.elementType!.name == ElementType.staticImage!.name) {
+      } else if (element.elementType!.name == ElementType.staticImage.name) {
         final elementInfo = element as StaticImageInfo;
         elementInfosmap.addAll(elementInfo.toJson());
-      } else if (element.elementType!.name == ElementType.pageNumber!.name) {
+      } else if (element.elementType!.name == ElementType.pageNumber.name) {
         final elementInfo = element as PageNumberInfo;
         elementInfosmap.addAll(elementInfo.toJson());
-      } else if (element.elementType!.name == ElementType.line!.name) {
+      } else if (element.elementType!.name == ElementType.line.name) {
         final elementInfo = element as LineInfo;
         elementInfosmap.addAll(elementInfo.toJson());
       }

+ 293 - 0
lib/report_info/report_base_info.dart

@@ -0,0 +1,293 @@
+import 'package:fis_lib_report/converts/event_type.dart';
+import 'package:fis_lib_report/report/element_tag.dart';
+import 'package:fis_lib_report/report/element_type.dart';
+import 'package:fis_lib_report/report/inputImageList.dart';
+import 'package:fis_lib_report/report/interfaces/block_element.dart';
+import 'package:fis_lib_report/report/paragraph.dart';
+import 'package:fis_lib_report/report/report_template_document.dart';
+import 'package:fis_lib_report/report/rt_page_size.dart';
+import 'package:fis_lib_report/report/rt_table.dart';
+import 'package:fis_lib_report/report_info/block_element_info_interface.dart';
+import 'package:fis_lib_report/report_info/element_info.dart';
+import 'package:fis_lib_report/report_info/element_tag_names.dart';
+import 'package:fis_lib_report/report_info/input_image_list_info.dart';
+import 'package:fis_lib_report/report_info/input_text_info.dart';
+import 'package:fis_lib_report/report_info/paragraph_info.dart';
+import 'package:fis_lib_report/report_info/report_event_args.dart';
+import 'package:fis_lib_report/report_info/rt_table_info.dart';
+import 'package:fis_lib_report/report_info/single_selected_info.dart';
+
+class ReportBaseInfo {
+  List<IBlockElementInfo> blocks = [];
+  List<IBlockElementInfo> headers = [];
+  List<IBlockElementInfo> footers = [];
+
+  /// Gets the author of the report template.
+  String? author;
+
+  /// Gets or sets the value to indicate whether the report template is created by user.
+  bool? isCustom;
+
+  /// Gets the report template name.
+  String? name;
+
+  /// Gets the custom input element tags of the report template.
+  Map<String, ElementTag>? tags;
+
+  /// Gets or sets the update time.
+  DateTime? updateTime;
+
+  ///version
+  String? version;
+
+  /// Gets the id.
+  String? id;
+
+  //报告页大小
+  RTPageSize? pageSize;
+
+//报告者
+  String? reporter;
+
+  //报告病人名
+  String? patientName;
+
+  ///病人Id
+  String? patinentId;
+
+  ///病人年龄
+  String? patientAge;
+
+  ///病人性别
+  String? patientSex;
+
+  ///报告日期
+  DateTime? reportDate;
+
+  ///报告模板
+  ReportTemplateDocument? reportTemplate;
+
+  ///重载
+  FEventHandler<ReportEventArgs> onReload = FEventHandler();
+
+  ///重载完成时触发
+  FEventHandler onReloadFinsh = FEventHandler();
+
+  ///关闭页面,释放监听
+  FEventHandler onClose = FEventHandler();
+
+  ///初始化ReportInfo
+  void init(
+    ReportTemplateDocument reportTemplate,
+    DateTime reportDate,
+    String reporter, {
+    String? patientName,
+    String? patinentId,
+    String? patientAge,
+    String? patientSex,
+  }) {
+    try {
+      headers = [];
+      blocks = [];
+      footers = [];
+      this.reportTemplate = reportTemplate;
+      this.reportDate = reportDate;
+      this.reporter = reporter;
+      isCustom = reportTemplate.isCustom;
+      name = reportTemplate.name;
+      updateTime = reportTemplate.updateTime;
+      version = reportTemplate.version;
+      id = reportTemplate.id;
+      for (var element in reportTemplate.header!) {
+        headers.add(_initBlockElement(element));
+      }
+      for (var element in reportTemplate.blocks!) {
+        blocks.add(_initBlockElement(element));
+      }
+      for (var element in reportTemplate.footer!) {
+        footers.add(_initBlockElement(element));
+      }
+      pageSize = reportTemplate.pageSize;
+      final nameInputInfo = getElementInfoByTagName(TagNames.PATIENT_NAME_TAG);
+      if (patientName != null &&
+          patientName.isNotEmpty &&
+          nameInputInfo != null) {
+        final inputInfo = nameInputInfo as InputTextInfo;
+        inputInfo.text = patientName;
+      }
+      final ageInputInfo = getElementInfoByTagName(TagNames.PATIENT_AGE_TAG);
+      if (patientAge != null && patientAge.isNotEmpty && ageInputInfo != null) {
+        final inputInfo = ageInputInfo as InputTextInfo;
+        inputInfo.text = patientAge;
+      }
+      final idInputInfo = getElementInfoByTagName(TagNames.PATIENT_ID_TAG);
+      if (patinentId != null && patinentId.isNotEmpty && idInputInfo != null) {
+        final inputInfo = idInputInfo as InputTextInfo;
+        inputInfo.text = patinentId;
+      }
+      final sexSelectedInfo = getElementInfoByTagName(TagNames.PATIENT_SEX_TAG);
+      if (patientSex != null &&
+          patientSex.isNotEmpty &&
+          sexSelectedInfo != null) {
+        final selectedInfo = sexSelectedInfo as SingleSelectedInfo;
+        selectedInfo.selectedItem = patientSex;
+      }
+    } catch (e) {
+      print(e);
+    }
+  }
+
+  ///跟据TagName获取Elementnt
+  ElementInfo? getElementInfoByTagName(String tagName) {
+    try {
+      for (var e in headers) {
+        if (e.tag != null && e.tag!.name == tagName) {
+          return e;
+        }
+        final elementInfo = _getBaseElementInfoByTagName(e, tagName);
+        if (elementInfo != null) {
+          return elementInfo;
+        }
+      }
+      for (var e in blocks) {
+        if (e.tag != null && e.tag!.name == tagName) {
+          return e;
+        }
+        final elementInfo = _getBaseElementInfoByTagName(e, tagName);
+        if (elementInfo != null) {
+          return elementInfo;
+        }
+      }
+      for (var e in footers) {
+        if (e.tag != null && e.tag!.name == tagName) {
+          return e;
+        }
+        final elementInfo = _getBaseElementInfoByTagName(e, tagName);
+        if (elementInfo != null) {
+          return elementInfo;
+        }
+      }
+    } catch (e) {
+      print(e);
+    }
+    return null;
+  }
+
+  ///获取基础组件信息
+  ElementInfo? _getBaseElementInfoByTagName(
+      IBlockElementInfo block, String tagName) {
+    ElementInfo? result;
+    final type = block.elementType;
+    if (type!.name == ElementType.paragraph.name) {
+      final paragraph = block as ParagraphInfo;
+      for (var el in paragraph.elementInfos!) {
+        if (el.tag != null && el.tag!.name == tagName) {
+          result = el;
+          break;
+        }
+      }
+    }
+    if (result == null) {
+      if (type.name == ElementType.rtTable.name) {
+        final table = block as RTTableInfo;
+        final cells = table.cells!;
+        for (var cell in cells.values) {
+          for (var b in cell.blocks!) {
+            final info = _getBaseElementInfoByTagName(b, tagName);
+            if (info != null) {
+              result = info;
+              break;
+            }
+          }
+        }
+      }
+    }
+
+    return result;
+  }
+
+  IBlockElementInfo _initBlockElement(IBlockElement element) {
+    final _type = element.elementType!;
+    if (_type.name == ElementType.rtTable.name) {
+      final table = element as RTTable;
+      return RTTableInfo.fromElement(table);
+    } else if (_type.name == ElementType.paragraph.name) {
+      final paragraph = element as Paragraph;
+      return ParagraphInfo.fromElement(paragraph);
+    } else {
+      final inputImageList = element as InputImageList;
+      return InputImageListInfo.fromElement(inputImageList);
+    }
+  }
+
+  ///跟据Id获取Elementnt
+  ElementInfo? getElementInfoById(String id) {
+    try {
+      if (id.isEmpty) {
+        return null;
+      }
+      for (var e in headers) {
+        if (e.id == id) {
+          return e;
+        }
+        final elementInfo = _getBaseElementInfoById(e, id);
+        if (elementInfo != null) {
+          return elementInfo;
+        }
+      }
+      for (var e in blocks) {
+        if (e.id == id) {
+          return e;
+        }
+        final elementInfo = _getBaseElementInfoById(e, id);
+        if (elementInfo != null) {
+          return elementInfo;
+        }
+      }
+      for (var e in footers) {
+        if (e.id == id) {
+          return e;
+        }
+        final elementInfo = _getBaseElementInfoById(e, id);
+        if (elementInfo != null) {
+          return elementInfo;
+        }
+      }
+    } catch (e) {
+      print(e);
+    }
+    return null;
+  }
+
+  ///跟据Id获取基础组件信息
+  ElementInfo? _getBaseElementInfoById(IBlockElementInfo block, String id) {
+    ElementInfo? result;
+    final type = block.elementType;
+    if (type!.name == ElementType.paragraph.name) {
+      final paragraph = block as ParagraphInfo;
+      for (var el in paragraph.elementInfos!) {
+        if (el.tag != null && el.id == id) {
+          result = el;
+          break;
+        }
+      }
+    }
+    if (result == null) {
+      if (type.name == ElementType.rtTable.name) {
+        final table = block as RTTableInfo;
+        final cells = table.cells!;
+        for (var cell in cells.values) {
+          for (var b in cell.blocks!) {
+            final info = _getBaseElementInfoById(b, id);
+            if (info != null) {
+              result = info;
+              break;
+            }
+          }
+        }
+      }
+    }
+
+    return result;
+  }
+}

+ 10 - 0
lib/report_info/report_event_args.dart

@@ -0,0 +1,10 @@
+import 'package:fis_lib_report/converts/event_type.dart';
+
+class ReportEventArgs {
+  final FEventHandler<String> onSelect;
+
+  final String jsonStr;
+  final String reporter;
+  final DateTime reportDate;
+  ReportEventArgs(this.reportDate, this.reporter, this.jsonStr, this.onSelect);
+}

+ 57 - 212
lib/report_info/report_info.dart

@@ -1,146 +1,59 @@
 import 'package:fis_lib_report/converts/event_type.dart';
-import 'package:fis_lib_report/report/element_tag.dart';
 import 'package:fis_lib_report/report/element_type.dart';
-import 'package:fis_lib_report/report/inputImageList.dart';
 import 'package:fis_lib_report/report/interfaces/block_element.dart';
 import 'package:fis_lib_report/report/interfaces/element.dart';
-import 'package:fis_lib_report/report/paragraph.dart';
-import 'package:fis_lib_report/report/report_template_document.dart';
-import 'package:fis_lib_report/report/rt_page_size.dart';
-import 'package:fis_lib_report/report/rt_table.dart';
 import 'package:fis_lib_report/report_info/block_element_info_interface.dart';
 import 'package:fis_lib_report/report_info/element_info.dart';
-import 'package:fis_lib_report/report_info/element_tag_names.dart';
 import 'package:fis_lib_report/report_info/input_image_info.dart';
 import 'package:fis_lib_report/report_info/input_image_list_info.dart';
 import 'package:fis_lib_report/report_info/input_text_info.dart';
 import 'package:fis_lib_report/report_info/paragraph_info.dart';
+import 'package:fis_lib_report/report_info/report_base_info.dart';
+import 'package:fis_lib_report/report_info/report_event_args.dart';
 import 'package:fis_lib_report/report_info/rt_table_info.dart';
 import 'package:fis_lib_report/report_info/single_selected_info.dart';
 
-class ReportInfo {
+class ReportInfo extends ReportBaseInfo {
   static ReportInfo? _reportInfo;
-  List<IBlockElementInfo> blocks = [];
-  List<IBlockElementInfo> headers = [];
-  List<IBlockElementInfo> footers = [];
-
-  /// Gets the author of the report template.
-  String? author;
-
-  /// Gets or sets the value to indicate whether the report template is created by user.
-  bool? isCustom;
-
-  /// Gets the report template name.
-  String? name;
-
-  /// Gets the custom input element tags of the report template.
-  Map<String, ElementTag>? tags;
-
-  /// Gets or sets the update time.
-  DateTime? updateTime;
-
-  ///version
-  String? version;
-
-  /// Gets the id.
-  String? id;
 
   ReportInfo._internal();
 
-  //报告页大小
-  RTPageSize? pageSize;
-
-//报告者
-  String? reporter;
-
-  //报告病人名
-  String? patientName;
-
-  ///病人Id
-  String? patinentId;
-
-  ///病人年龄
-  String? patientAge;
-
-  ///病人性别
-  String? patientSex;
-
-  ///报告日期
-  DateTime? reportDate;
-
-  ///报告模板
-  ReportTemplateDocument? reportTemplate;
-
-  ///重载
-  FEventHandler<ReportEventArgs> onReload = FEventHandler();
-
-  ///重载完成时触发
-  FEventHandler onReloadFinsh = FEventHandler();
-
-  ///关闭页面,释放监听
-  FEventHandler onClose = FEventHandler();
-
   ///ReportInfo全局单例
   static ReportInfo get instance {
     _reportInfo ??= ReportInfo._internal();
     return _reportInfo!;
   }
 
-  ///初始化ReportInfo
-  void init(
-    ReportTemplateDocument reportTemplate,
-    DateTime reportDate,
-    String reporter, {
-    String? patientName,
-    String? patinentId,
-    String? patientAge,
-    String? patientSex,
-  }) {
-    try {
-      this.reportTemplate = reportTemplate;
-      this.reportDate = reportDate;
-      this.reporter = reporter;
-      isCustom = reportTemplate.isCustom;
-      name = reportTemplate.name;
-      updateTime = reportTemplate.updateTime;
-      version = reportTemplate.version;
-      id = reportTemplate.id;
-      for (var element in reportTemplate.header!) {
-        headers.add(_initBlockElement(element));
-      }
-      for (var element in reportTemplate.blocks!) {
-        blocks.add(_initBlockElement(element));
-      }
-      for (var element in reportTemplate.footer!) {
-        footers.add(_initBlockElement(element));
-      }
-      pageSize = reportTemplate.pageSize;
-      final nameInputInfo = getElementInfoByTagName(TagNames.PATIENT_NAME_TAG);
-      if (patientName != null &&
-          patientName.isNotEmpty &&
-          nameInputInfo != null) {
-        final inputInfo = nameInputInfo as InputTextInfo;
-        inputInfo.text = patientName;
-      }
-      final ageInputInfo = getElementInfoByTagName(TagNames.PATIENT_AGE_TAG);
-      if (patientAge != null && patientAge.isNotEmpty && ageInputInfo != null) {
-        final inputInfo = ageInputInfo as InputTextInfo;
-        inputInfo.text = patientAge;
-      }
-      final idInputInfo = getElementInfoByTagName(TagNames.PATIENT_ID_TAG);
-      if (patinentId != null && patinentId.isNotEmpty && idInputInfo != null) {
-        final inputInfo = idInputInfo as InputTextInfo;
-        inputInfo.text = patinentId;
-      }
-      final sexSelectedInfo = getElementInfoByTagName(TagNames.PATIENT_SEX_TAG);
-      if (patientSex != null &&
-          patientSex.isNotEmpty &&
-          sexSelectedInfo != null) {
-        final selectedInfo = sexSelectedInfo as SingleSelectedInfo;
-        selectedInfo.selectedItem = patientSex;
+  ///从Json中加载数据
+  void fromJson(Map<String, dynamic> json) {
+    List<dynamic> jsonBlocks = json['BlockInfos'];
+    if (jsonBlocks.isNotEmpty) {
+      for (var block in jsonBlocks) {
+        final type = block['ElementType'];
+        final jsonType = ElementType.fromJson(type);
+        final name = jsonType.name;
+        if (name == ElementType.paragraph.name) {
+          final paragraphInfo = block as Map<String, dynamic>;
+          _paragraphInfoFromJson(paragraphInfo);
+        } else if (name == ElementType.rtTable.name) {
+          final tableInfo = block as Map<String, dynamic>;
+          List<dynamic> jsonElements = tableInfo['Cells'];
+          int index = 0;
+          for (var map in jsonElements) {
+            //TODO(Loki):此处可优化Json的结构,无需区分奇偶
+            if (index.isOdd) {
+              final jsonType = map['ElementType'];
+              final type = ElementType.fromJson(jsonType);
+              if (type.name == ElementType.rtCell.name) {
+                final cellMap = map as Map<String, dynamic>;
+                final jsonBlocks = cellMap['Blocks'] as Map<String, dynamic>;
+                _paragraphInfoFromJson(jsonBlocks);
+              }
+            }
+            index++;
+          }
+        }
       }
-    } catch (e) {
-      print(e);
     }
   }
 
@@ -216,42 +129,6 @@ class ReportInfo {
     }
   }
 
-  ///跟据TagName获取Elementnt
-  ElementInfo? getElementInfoByTagName(String tagName) {
-    try {
-      for (var e in headers) {
-        if (e.tag != null && e.tag!.name == tagName) {
-          return e;
-        }
-        final elementInfo = _getBaseElementInfoByTagName(e, tagName);
-        if (elementInfo != null) {
-          return elementInfo;
-        }
-      }
-      for (var e in blocks) {
-        if (e.tag != null && e.tag!.name == tagName) {
-          return e;
-        }
-        final elementInfo = _getBaseElementInfoByTagName(e, tagName);
-        if (elementInfo != null) {
-          return elementInfo;
-        }
-      }
-      for (var e in footers) {
-        if (e.tag != null && e.tag!.name == tagName) {
-          return e;
-        }
-        final elementInfo = _getBaseElementInfoByTagName(e, tagName);
-        if (elementInfo != null) {
-          return elementInfo;
-        }
-      }
-    } catch (e) {
-      print(e);
-    }
-    return null;
-  }
-
   ///跟据UI组件获取ReportInfo中的组件
   ElementInfo? getElementInfo(IElement element) {
     try {
@@ -279,17 +156,27 @@ class ReportInfo {
     return null;
   }
 
-  IBlockElementInfo _initBlockElement(IBlockElement element) {
-    final _type = element.elementType!;
-    if (_type.name == ElementType.rtTable!.name) {
-      final table = element as RTTable;
-      return RTTableInfo.fromElement(table);
-    } else if (_type.name == ElementType.paragraph!.name) {
-      final paragraph = element as Paragraph;
-      return ParagraphInfo.fromElement(paragraph);
-    } else {
-      final inputImageList = element as InputImageList;
-      return InputImageListInfo.fromElement(inputImageList);
+  void _paragraphInfoFromJson(Map<String, dynamic> paragraphInfo) {
+    List<dynamic> jsonElements = paragraphInfo['ElementInfos'];
+    if (jsonElements.isEmpty) {
+      return;
+    }
+    for (var map in jsonElements) {
+      final jsonType = ElementType.fromJson(map['ElementType']);
+      final id = map['Id'];
+      if (jsonType.name == ElementType.inputText.name) {
+        final info = getElementInfoById(id);
+        if (info != null) {
+          final inputInfo = info as InputTextInfo;
+          inputInfo.text = map['Text'];
+        }
+      } else if (jsonType.name == ElementType.singleSelected.name) {
+        final info = getElementInfoById(id);
+        if (info != null) {
+          final inputInfo = info as SingleSelectedInfo;
+          inputInfo.selectedItem = map['SelectedItem'];
+        }
+      }
     }
   }
 
@@ -318,7 +205,7 @@ class ReportInfo {
   ElementInfo? _getBaseElementInfo(IBlockElementInfo block, IElement element) {
     ElementInfo? result;
     final type = block.elementType;
-    if (type!.name == ElementType.paragraph!.name) {
+    if (type!.name == ElementType.paragraph.name) {
       final paragraph = block as ParagraphInfo;
       for (var el in paragraph.elementInfos!) {
         if (el.id == element.id) {
@@ -328,7 +215,7 @@ class ReportInfo {
       }
     }
     if (result == null) {
-      if (type.name == ElementType.rtTable!.name) {
+      if (type.name == ElementType.rtTable.name) {
         final table = block as RTTableInfo;
         final cells = table.cells!;
         for (var cell in cells.values) {
@@ -346,45 +233,12 @@ class ReportInfo {
     return result;
   }
 
-  ///获取基础组件信息
-  ElementInfo? _getBaseElementInfoByTagName(
-      IBlockElementInfo block, String tagName) {
-    ElementInfo? result;
-    final type = block.elementType;
-    if (type!.name == ElementType.paragraph!.name) {
-      final paragraph = block as ParagraphInfo;
-      for (var el in paragraph.elementInfos!) {
-        if (el.tag != null && el.tag!.name == tagName) {
-          result = el;
-          break;
-        }
-      }
-    }
-    if (result == null) {
-      if (type.name == ElementType.rtTable!.name) {
-        final table = block as RTTableInfo;
-        final cells = table.cells!;
-        for (var cell in cells.values) {
-          for (var b in cell.blocks!) {
-            final info = _getBaseElementInfoByTagName(b, tagName);
-            if (info != null) {
-              result = info;
-              break;
-            }
-          }
-        }
-      }
-    }
-
-    return result;
-  }
-
   Map<String, dynamic> _getElementInfo(IBlockElementInfo element) {
     final _type = element.elementType!;
-    if (_type.name == ElementType.rtTable!.name) {
+    if (_type.name == ElementType.rtTable.name) {
       final table = element as RTTableInfo;
       return table.toJson();
-    } else if (_type.name == ElementType.paragraph!.name) {
+    } else if (_type.name == ElementType.paragraph.name) {
       final paragraph = element as ParagraphInfo;
       return paragraph.toJson();
     } else {
@@ -393,12 +247,3 @@ class ReportInfo {
     }
   }
 }
-
-class ReportEventArgs {
-  final FEventHandler<String> onSelect;
-
-  final String jsonStr;
-  final String reporter;
-  final DateTime reportDate;
-  ReportEventArgs(this.reportDate, this.reporter, this.jsonStr, this.onSelect);
-}

+ 2 - 2
lib/report_info/rt_cell_info.dart

@@ -10,7 +10,7 @@ class RTCellInfo extends ElementInfo {
 
   RTCellInfo.fromElement(ICell value) : super.fromElement(value) {
     for (var element in value.blocks!) {
-      if (element.elementType!.name == ElementType.paragraph!.name) {
+      if (element.elementType!.name == ElementType.paragraph.name) {
         final paragraphInfo = element as Paragraph;
         final block = ParagraphInfo.fromElement(paragraphInfo);
         blocks!.add(block);
@@ -24,7 +24,7 @@ class RTCellInfo extends ElementInfo {
     map.addAll(super.toJson());
     final blockInfos = <String, dynamic>{};
     for (var b in blocks!) {
-      if (b.elementType!.name == ElementType.paragraph!.name) {
+      if (b.elementType!.name == ElementType.paragraph.name) {
         final paragraphInfo = b as ParagraphInfo;
         blockInfos.addAll(paragraphInfo.toJson());
       }

+ 1 - 0
lib/report_info/single_selected_info.dart

@@ -13,6 +13,7 @@ class SingleSelectedInfo extends TextElementInfo {
   String get selectedItem => _selectedItem;
   set selectedItem(String v) {
     if (items!.contains(v)) _selectedItem = v;
+    onSelectedChange.emit(this, v);
   }
 
   ///选中项改变通知UI变化

部分文件因文件數量過多而無法顯示