Browse Source

基础组件结构调整

loki.wu 2 years ago
parent
commit
1ef21c3c3f

File diff suppressed because it is too large
+ 317 - 282
assets/single_image.json


+ 0 - 1
lib/converts/alignment_convert.dart

@@ -1,6 +1,5 @@
 import 'package:fis_lib_report/report/interfaces/position_layout.dart';
 import 'package:flutter/widgets.dart';
-import 'package:flutter/widgets.dart';
 
 class AlignmentConvert {
   static TextAlignVertical verticalAlignmentConvert(VerticalLayout? value) {

+ 7 - 16
lib/main.dart

@@ -1,12 +1,6 @@
-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/block_element_page.dart';
 import 'package:fis_lib_report/pages/components/vid_image.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_edit.dart';
 import 'package:fis_lib_report/report_info/report_info.dart';
 import 'package:flutter/material.dart';
@@ -51,17 +45,9 @@ class MyHomePage extends StatefulWidget {
 }
 
 class _MyHomePageState extends State<MyHomePage> {
-  ReportTemplateDocument _reportTemplate = ReportTemplateDocument();
-  double _height = 0;
-  double _width = 0;
-  List<IBlockElement> _blocks = [];
-  List<IBlockElement> _header = [];
-  List<IBlockElement> _footer = [];
-  double _baseFontSize = 9.0;
-  double _footerDistance = 34.0;
   String _jsonStr = '';
-  double _footerHeight = 0;
-  EdgeInsetsGeometry _padding = EdgeInsets.all(PtToPxConverter.ptToPx(56.83));
+  final EdgeInsetsGeometry _padding =
+      EdgeInsets.all(PtToPxConverter.ptToPx(56.83));
   late FEventHandler<String> onSelect;
 
   @override
@@ -73,6 +59,11 @@ class _MyHomePageState extends State<MyHomePage> {
       });
     });
     super.initState();
+    Future.delayed(
+        const Duration(milliseconds: 8000),
+        () => rootBundle.loadString('assets/single_image.json').then((jsonStr) {
+              ReportInfo.instance.reload('', DateTime.now(), jsonStr, onSelect);
+            }));
   }
 
   @override

+ 1 - 7
lib/pages/block_element_page.dart

@@ -1,16 +1,12 @@
-import 'dart:math';
-
 import 'package:fis_lib_report/pages/components/input_imageList.dart';
 import 'package:fis_lib_report/pages/helpler.dart';
 import 'package:fis_lib_report/pages/paragraph_page.dart';
 import 'package:fis_lib_report/pages/rt_table.dart';
-import 'package:fis_lib_report/report/cellPostion.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/rt_table.dart';
-import 'package:fis_lib_report/report_info/report_info.dart';
 import 'package:flutter/material.dart';
 
 class BlockElementPage extends StatefulWidget {
@@ -28,13 +24,12 @@ class _BlockElementState extends State<BlockElementPage> {
   ElementType? _type;
   @override
   initState() {
-    IBlockElement e = widget.element;
-    _type = e.elementType!;
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
+    _type = widget.element.elementType!;
     if (_type != null && _type!.name == ElementType.rtTable!.name) {
       RTTable t = widget.element as RTTable;
       return RTTablePage(element: t);
@@ -43,7 +38,6 @@ class _BlockElementState extends State<BlockElementPage> {
       return ParagraphPage(paragraph: paragraph);
     } else if (_type != null && _type!.name == ElementType.imageList!.name) {
       final inputImageList = widget.element as InputImageList;
-
       return RInputImageList(inputImageList);
     }
     return Container(

+ 43 - 41
lib/pages/components/datetime.dart

@@ -18,7 +18,6 @@ class RDateTime extends StatefulWidget {
 }
 
 class _RDateTimeState extends State<RDateTime> {
-  late final DateTimeElement dateTimeElement;
   DateTime selectedDate = DateTime.now();
 
   _RDateTimeState();
@@ -34,50 +33,13 @@ class _RDateTimeState extends State<RDateTime> {
 
   @override
   initState() {
-    dateTimeElement = widget.dateTimeElement;
-    //_dateTimeInfo =
-    //     ReportInfo.instance.getElementInfo(dateTimeElement) as DateTimeInfo;
-
-    final format = dateTimeElement.dateTimeFormat;
-    if (format != null) {
-      _dateTimeConvert(
-          format, ReportInfo.instance.reportDate!.millisecondsSinceEpoch);
-    }
-
-    _fontSize = dateTimeElement.fontSize ?? 15.0;
-    //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
-    final fontStyles = dateTimeElement.fontStyles;
-    final fontColor = dateTimeElement.fontColor;
-    if (fontColor != null) {
-      _fontColor = Color.fromARGB(
-          fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
-    }
-    final backgroundColor = dateTimeElement.background;
-    if (backgroundColor != null) {
-      _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
-          backgroundColor.g!, backgroundColor.b!);
-    }
-    final margin = dateTimeElement.margin;
-    if (margin != null) {
-      _margin = EdgeInsets.only(
-          top: margin.top ?? 0,
-          bottom: margin.bottom ?? 0,
-          left: margin.left ?? 0,
-          right: margin.right ?? 0);
-    }
-    _style = TextStyle(
-      fontSize: PtToPxConverter.ptToPx(_fontSize),
-      color: _fontColor,
-      backgroundColor: _backgroundColor,
-    );
-
-    _width = PtToPxConverter.ptToPx(
-        TextSizeConvert.getTextSize(_dateTime, _style).width);
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
+    final dateTimeElement = widget.dateTimeElement;
+    _initDatas();
     return Container(
         margin: _margin,
         decoration: BoxDecoration(
@@ -127,7 +89,7 @@ class _RDateTimeState extends State<RDateTime> {
       lastDate: DateTime(2025),
     );
     if (picked != null && picked != selectedDate) {
-      final format = dateTimeElement.dateTimeFormat;
+      final format = widget.dateTimeElement.dateTimeFormat;
       setState(() {
         selectedDate = picked;
         _dateTimeConvert(format!, selectedDate.millisecondsSinceEpoch);
@@ -135,6 +97,46 @@ class _RDateTimeState extends State<RDateTime> {
     }
   }
 
+  void _initDatas() {
+    final dateTimeElement = widget.dateTimeElement;
+
+    final format = dateTimeElement.dateTimeFormat;
+    if (format != null) {
+      _dateTimeConvert(
+          format, ReportInfo.instance.reportDate!.millisecondsSinceEpoch);
+    }
+
+    _fontSize = dateTimeElement.fontSize ?? 15.0;
+    //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
+    final fontStyles = dateTimeElement.fontStyles;
+    final fontColor = dateTimeElement.fontColor;
+    if (fontColor != null) {
+      _fontColor = Color.fromARGB(
+          fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
+    }
+    final backgroundColor = dateTimeElement.background;
+    if (backgroundColor != null) {
+      _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
+          backgroundColor.g!, backgroundColor.b!);
+    }
+    final margin = dateTimeElement.margin;
+    if (margin != null) {
+      _margin = EdgeInsets.only(
+          top: margin.top ?? 0,
+          bottom: margin.bottom ?? 0,
+          left: margin.left ?? 0,
+          right: margin.right ?? 0);
+    }
+    _style = TextStyle(
+      fontSize: PtToPxConverter.ptToPx(_fontSize),
+      color: _fontColor,
+      backgroundColor: _backgroundColor,
+    );
+
+    _width = PtToPxConverter.ptToPx(
+        TextSizeConvert.getTextSize(_dateTime, _style).width);
+  }
+
   void _dateTimeConvert(String format, int timestamp) {
     if (format == 'yyyy-MM-dd') {
       _dateTime = DateToStringConverter.dateAndTimeToString(

+ 29 - 25
lib/pages/components/input_image.dart

@@ -22,7 +22,6 @@ class RInputImage extends StatefulWidget {
 }
 
 class _RInputImageState extends State<RInputImage> {
-  late final InputImage inputImage;
   InputImageInfo? inputImageInfo;
   _RInputImageState();
   Color _borderColor = Colors.grey;
@@ -34,29 +33,13 @@ class _RInputImageState extends State<RInputImage> {
 
   @override
   initState() {
-    inputImage = widget.inputImage;
-    _hasImageBorder = inputImage.hasImageBorder!;
-
-    final element = ReportInfo.instance.getElementInfo(inputImage);
-    if (element != null) {
-      inputImageInfo = element as InputImageInfo;
-      inputImageInfo!.onSelect!.addListener((sender, e) {
-        setState(() {
-          if (_imageUrl != e) {
-            _imageUrl = e;
-            _child = _getChild();
-          } else {
-            _imageUrl = '';
-            _child = const Text('请点击此处后选择右侧图片');
-          }
-        });
-      });
-    }
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
+    _initDatas();
+
     return MouseRegion(
       cursor: SystemMouseCursors.click,
       child: GestureDetector(
@@ -83,14 +66,15 @@ class _RInputImageState extends State<RInputImage> {
         },
         child: Row(
           mainAxisAlignment: AlignmentConvert.horizontalToMainConvert(
-              inputImage.horizontalAlignment),
+              widget.inputImage.horizontalAlignment),
           children: [
             Container(
               padding: const EdgeInsets.all(3),
-              height: PtToPxConverter.ptToPx(inputImage.imageHeight!) + 6,
-              width: PtToPxConverter.ptToPx(inputImage.imageWidth!) + 6,
+              height:
+                  PtToPxConverter.ptToPx(widget.inputImage.imageHeight!) + 6,
+              width: PtToPxConverter.ptToPx(widget.inputImage.imageWidth!) + 6,
               alignment: Alignment.center,
-              margin: MarginConvert.marginConvert(inputImage.margin),
+              margin: MarginConvert.marginConvert(widget.inputImage.margin),
               decoration: BoxDecoration(
                   border: _hasImageBorder
                       ? Border.all(
@@ -107,13 +91,33 @@ class _RInputImageState extends State<RInputImage> {
     );
   }
 
+  void _initDatas() {
+    _hasImageBorder = widget.inputImage.hasImageBorder!;
+
+    final element = ReportInfo.instance.getElementInfo(widget.inputImage);
+    if (element != null) {
+      inputImageInfo = element as InputImageInfo;
+      inputImageInfo!.onSelect!.addListener((sender, e) {
+        setState(() {
+          if (_imageUrl != e) {
+            _imageUrl = e;
+            _child = _getChild();
+          } else {
+            _imageUrl = '';
+            _child = const Text('请点击此处后选择右侧图片');
+          }
+        });
+      });
+    }
+  }
+
   Widget _getChild() {
     if (_imageUrl.isNotEmpty) {
       return VidImageView.network(
         _imageUrl,
         fit: BoxFit.fill,
-        height: PtToPxConverter.ptToPx(inputImage.imageHeight!),
-        width: PtToPxConverter.ptToPx(inputImage.imageWidth!),
+        height: PtToPxConverter.ptToPx(widget.inputImage.imageHeight!),
+        width: PtToPxConverter.ptToPx(widget.inputImage.imageWidth!),
       );
     }
     return const Text('请点击此处后选择右侧图片');

+ 31 - 29
lib/pages/components/input_imageList.dart

@@ -19,7 +19,7 @@ class RInputImageList extends StatefulWidget {
 }
 
 class _RInputImageListState extends State<RInputImageList> {
-  late final InputImageList inputImageList;
+  InputImageList? inputImageList;
   InputImageListInfo? inputImageListInfo;
   Color _borderColor = Colors.grey;
   bool _isSelected = false;
@@ -31,23 +31,7 @@ class _RInputImageListState extends State<RInputImageList> {
 
   @override
   initState() {
-    inputImageList = widget.inputImageList;
-    _hasImageBorder = inputImageList.hasImageBorder!;
-    _height = PtToPxConverter.ptToPx(inputImageList.imageHeight) + 6;
-    final element = ReportInfo.instance.getBlockElement(inputImageList);
-    if (element != null) {
-      inputImageListInfo = element as InputImageListInfo;
-      inputImageListInfo!.onSelect!.addListener((sender, e) {
-        setState(() {
-          if (_images.contains(e)) {
-            _images.remove(e);
-          } else {
-            _images.add(e);
-          }
-          _child = _getChild();
-        });
-      });
-    }
+    _initDatas();
     super.initState();
   }
 
@@ -61,14 +45,12 @@ class _RInputImageListState extends State<RInputImageList> {
             setState(() {
               _borderColor = Colors.grey;
               _isSelected = false;
-              _hasImageBorder = false;
               inputImageListInfo!.isSelected = false;
             });
           } else {
             setState(() {
               _borderColor = const Color.fromARGB(255, 64, 159, 248);
               _isSelected = true;
-              _hasImageBorder = true;
               inputImageListInfo!.isSelected = true;
             });
           }
@@ -77,11 +59,11 @@ class _RInputImageListState extends State<RInputImageList> {
           padding: const EdgeInsets.all(3),
           height: _height,
           width: PtToPxConverter.ptToPx(
-              inputImageList.imageWidth! * inputImageList.column!),
+              inputImageList!.imageWidth! * inputImageList!.column!),
           alignment: Alignment.center,
-          margin: MarginConvert.marginConvert(inputImageList.margin),
+          margin: MarginConvert.marginConvert(inputImageList!.margin),
           decoration: BoxDecoration(
-              border: _hasImageBorder
+              border: _isSelected
                   ? Border.all(
                       width: 0.5,
                       color: _borderColor,
@@ -97,23 +79,23 @@ class _RInputImageListState extends State<RInputImageList> {
   Widget _getChild() {
     if (_images.isNotEmpty) {
       final rowCount = (_images.length / 2).ceil();
-      _height =
-          rowCount * (PtToPxConverter.ptToPx(inputImageList.imageHeight!) + 3) +
-              6;
+      _height = rowCount *
+              (PtToPxConverter.ptToPx(inputImageList!.imageHeight!) + 3) +
+          6;
       return GridView.builder(
         gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
-          crossAxisCount: inputImageList.column!,
+          crossAxisCount: inputImageList!.column!,
           crossAxisSpacing: 5,
           mainAxisSpacing: 5,
           childAspectRatio:
-              inputImageList.imageWidth! / inputImageList.imageHeight!,
+              inputImageList!.imageWidth! / inputImageList!.imageHeight!,
         ),
         itemCount: _images.length,
         itemBuilder: (BuildContext context, int index) {
           return VidImageView.network(
             _images[index],
             fit: BoxFit.fill,
-            width: PtToPxConverter.ptToPx(inputImageList.imageWidth!) - 20,
+            width: PtToPxConverter.ptToPx(inputImageList!.imageWidth!) - 20,
           );
         },
       );
@@ -127,4 +109,24 @@ class _RInputImageListState extends State<RInputImageList> {
     inputImageListInfo!.onSelect!.dispose();
     super.dispose();
   }
+
+  void _initDatas() {
+    inputImageList = widget.inputImageList;
+    _hasImageBorder = inputImageList!.hasImageBorder!;
+    _height = PtToPxConverter.ptToPx(inputImageList!.imageHeight) + 6;
+    final element = ReportInfo.instance.getBlockElement(inputImageList!);
+    if (element != null) {
+      inputImageListInfo = element as InputImageListInfo;
+      inputImageListInfo!.onSelect!.addListener((sender, e) {
+        setState(() {
+          if (_images.contains(e)) {
+            _images.remove(e);
+          } else {
+            _images.add(e);
+          }
+          _child = _getChild();
+        });
+      });
+    }
+  }
 }

+ 0 - 1
lib/pages/components/input_text.dart

@@ -94,7 +94,6 @@ class _RInputTextState extends State<RInputText> {
       ),
       child: TextField(
           focusNode: _focusNode,
-          autofocus: true,
           readOnly: _isReadOnly,
           decoration: null,
           textAlignVertical: AlignmentConvert.verticalAlignmentConvert(

+ 7 - 11
lib/pages/components/line.dart

@@ -17,27 +17,23 @@ class RLine extends StatefulWidget {
 }
 
 class _LineState extends State<RLine> {
-  late final Line line;
   _LineState();
 
   @override
   initState() {
-    line = widget.line;
-
-    ///TODO(Loki):设置虚线or实线
-    final borderStyle = line.borderStyle;
-
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
-    final stroke = line.stroke!;
+    ///TODO(Loki):设置虚线or实线
+    final borderStyle = widget.line.borderStyle;
+    final stroke = widget.line.stroke!;
     final a = stroke.a!;
     final r = stroke.r!;
     final g = stroke.g!;
     final b = stroke.b!;
-    final margin = line.margin ?? RTThickness.uniform(0);
+    final margin = widget.line.margin ?? RTThickness.uniform(0);
     return Container(
       height: 10, //TODO(Loki):这里的Height在Json中没有
       alignment: Alignment.center,
@@ -46,10 +42,10 @@ class _LineState extends State<RLine> {
           bottom: margin.bottom!,
           right: margin.left!,
           left: margin.left!),
-      width: PtToPxConverter.ptToPx(line.width),
+      width: PtToPxConverter.ptToPx(widget.line.width),
       child: Divider(
-        height: line.thickness,
-        thickness: line.thickness,
+        height: widget.line.thickness,
+        thickness: widget.line.thickness,
         color: Color.fromARGB(a, r, g, b),
       ),
     );

+ 21 - 17
lib/pages/components/multi_selected.dart

@@ -22,7 +22,6 @@ class RMultiSelected extends StatefulWidget {
 }
 
 class _RRMultiSelectedState extends State<RMultiSelected> {
-  late MultiSelected multiSelected;
   _RRMultiSelectedState();
   final String _value = '';
   String? _selectedItemView = '';
@@ -34,26 +33,13 @@ class _RRMultiSelectedState extends State<RMultiSelected> {
   TextStyle _textStyle = TextStyle();
   @override
   initState() {
-    multiSelected = widget.multiSelected;
-    final selectInfo = ReportInfo.instance.getElementInfo(multiSelected);
-    if (selectInfo != null) {
-      _mulitiSelectedInfo = selectInfo as MulitiSelectedInfo;
-    }
-    if (multiSelected.items!.isNotEmpty) {
-      _items = multiSelected.items;
-    }
-    _width = PtToPxConverter.ptToPx(multiSelected.lineWidth);
-    final fontColor = multiSelected.fontColor ?? RTColor.Black;
-    _textStyle = TextStyle(
-      color: Color.fromARGB(
-          fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!),
-      fontSize: PtToPxConverter.ptToPx(multiSelected.fontSize),
-    );
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
+    _initDatas();
+    final multiSelected = widget.multiSelected;
     final background = multiSelected.background ?? RTColor(255, 255, 255, 255);
 
     return Stack(
@@ -84,7 +70,7 @@ class _RRMultiSelectedState extends State<RMultiSelected> {
       final active = e == _value;
       return DropdownMenuItem<String>(
         child: _OptionRow(
-          multiSelected,
+          widget.multiSelected,
           e,
           isActive: active,
           height: 22,
@@ -170,6 +156,24 @@ class _RRMultiSelectedState extends State<RMultiSelected> {
       ),
     );
   }
+
+  void _initDatas() {
+    final multiSelected = widget.multiSelected;
+    final selectInfo = ReportInfo.instance.getElementInfo(multiSelected);
+    if (selectInfo != null) {
+      _mulitiSelectedInfo = selectInfo as MulitiSelectedInfo;
+    }
+    if (multiSelected.items!.isNotEmpty) {
+      _items = multiSelected.items;
+    }
+    _width = PtToPxConverter.ptToPx(multiSelected.lineWidth);
+    final fontColor = multiSelected.fontColor ?? RTColor.Black;
+    _textStyle = TextStyle(
+      color: Color.fromARGB(
+          fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!),
+      fontSize: PtToPxConverter.ptToPx(multiSelected.fontSize),
+    );
+  }
 }
 
 class _OptionRow extends StatefulWidget {

+ 0 - 9
lib/pages/components/page_number.dart

@@ -26,15 +26,6 @@ class _RRPageNumberState extends State<RPageNumber> {
   @override
   initState() {
     pageNumber = widget.space;
-    ReportInfo.instance.onHeightChange!.addListener((sender, e) {
-      final height = ReportInfo.instance.currentHeight;
-      final pageHeight = ReportInfo.instance.pageSize!.height;
-
-      final pageNum = (height / pageHeight!).ceil();
-      setState(() {
-        _text = pageNum.toString();
-      });
-    });
     super.initState();
   }
 

+ 6 - 5
lib/pages/components/single_select.dart

@@ -21,8 +21,14 @@ class _RSingleSelectState extends State<RSingleSelected> {
   String _value = '';
   List<String>? _items = [];
   SingleSelectedInfo? _singleSelectedInfo;
+
   @override
   initState() {
+    super.initState();
+  }
+
+  @override
+  Widget build(BuildContext context) {
     singleSelected = widget.singleSelected;
     final selectInfo = ReportInfo.instance.getElementInfo(singleSelected);
     if (selectInfo != null) {
@@ -31,11 +37,6 @@ class _RSingleSelectState extends State<RSingleSelected> {
     if (singleSelected.items!.isNotEmpty) {
       _items = singleSelected.items;
     }
-    super.initState();
-  }
-
-  @override
-  Widget build(BuildContext context) {
     if (_items!.isEmpty) {
       return const SizedBox();
     }

+ 2 - 6
lib/pages/components/space.dart

@@ -19,20 +19,16 @@ class RSpace extends StatefulWidget {
 }
 
 class _RSpaceState extends State<RSpace> {
-  late Space space;
-
   @override
   initState() {
-    space = widget.space;
-
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
     return Container(
-      width: space.spaceWidth,
-      margin: MarginConvert.marginConvert(space.margin),
+      width: widget.space.spaceWidth,
+      margin: MarginConvert.marginConvert(widget.space.margin),
     );
   }
 }

+ 1 - 4
lib/pages/components/static_image.dart

@@ -26,19 +26,16 @@ class RStaticImage extends StatefulWidget {
 }
 
 class _RInputImageState extends State<RStaticImage> {
-  InputImageInfo? inputImageInfo;
   _RInputImageState();
 
-  late Uint8List _bytes;
-
   @override
   initState() {
-    _bytes = convert.base64Decode(widget.staticImage.source!);
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
+    final _bytes = convert.base64Decode(widget.staticImage.source!);
     return Row(
       mainAxisAlignment: AlignmentConvert.horizontalToMainConvert(
           widget.staticImage.horizontalAlignment),

+ 23 - 43
lib/pages/components/static_text.dart

@@ -20,8 +20,6 @@ class RStaticText extends StatefulWidget {
 }
 
 class _RStaticTextState extends State<RStaticText> {
-  late final StaticText staticText;
-
   _RStaticTextState();
 
   double _fontSize = 15.0;
@@ -33,25 +31,42 @@ class _RStaticTextState extends State<RStaticText> {
 
   @override
   initState() {
-    staticText = widget.staticText;
-    final staticTextInfo = ReportInfo.instance.getElementInfo(staticText);
+    super.initState();
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    initDatas();
+    final text = _staticTextInfo!.text!;
+    return Container(
+      margin: _margin,
+      child: Text(
+        (text),
+        style: _style,
+      ),
+    );
+  }
+
+  void initDatas() {
+    final staticTextInfo =
+        ReportInfo.instance.getElementInfo(widget.staticText);
     if (staticTextInfo != null) {
       _staticTextInfo = staticTextInfo as StaticTextInfo;
     }
-    _fontSize = staticText.fontSize ?? 15.0;
+    _fontSize = widget.staticText.fontSize ?? 15.0;
     //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
     //final fontStyles = staticText.fontStyles;
-    final fontColor = staticText.fontColor;
+    final fontColor = widget.staticText.fontColor;
     if (fontColor != null) {
       _fontColor = Color.fromARGB(
           fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
     }
-    final backgroundColor = staticText.background;
+    final backgroundColor = widget.staticText.background;
     if (backgroundColor != null) {
       _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
           backgroundColor.g!, backgroundColor.b!);
     }
-    final margin = staticText.margin;
+    final margin = widget.staticText.margin;
     if (margin != null) {
       _margin = EdgeInsets.only(
           top: margin.top ?? 0,
@@ -64,40 +79,5 @@ class _RStaticTextState extends State<RStaticText> {
       color: _fontColor,
       backgroundColor: _backgroundColor,
     );
-
-    super.initState();
-  }
-
-  @override
-  Widget build(BuildContext context) {
-    final text = _staticTextInfo!.text!;
-    return Container(
-      margin: _margin,
-      child: Text(
-        (text),
-        style: _style,
-      ),
-    );
-  }
-
-  String _syncText(String value) {
-    try {
-      if (value.contains(' ')) {
-        String result = '';
-        for (var i = 0; i < value.length; i++) {
-          if (value[i] == ' ') {
-            result += value[i] + ' ';
-          } else {
-            result += value[i];
-          }
-        }
-        return result;
-      } else {
-        return value;
-      }
-    } catch (e) {
-      print(e);
-      return value;
-    }
   }
 }

+ 2 - 2
lib/pages/paragraph_page.dart

@@ -46,13 +46,13 @@ class _ParagraphState extends State<ParagraphPage> {
 
   @override
   initState() {
-    _elements = widget.paragraph.elements;
-    _itemCount = _elements!.length;
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
+    _elements = widget.paragraph.elements;
+    _itemCount = _elements!.length;
     if (_itemCount == 0) {
       return const SizedBox();
     }

+ 1 - 1
lib/pages/rt_cell.dart

@@ -23,12 +23,12 @@ class _RTCellState extends State<RTCellPage> {
 
   @override
   initState() {
-    _blocks = widget.cell.blocks;
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
+    _blocks = widget.cell.blocks;
     return _blocks!.isEmpty
         ? Container(
             height: 30,

+ 15 - 11
lib/pages/rt_table.dart

@@ -32,21 +32,11 @@ class _RTTableState extends State<RTTablePage> {
   @override
   initState() {
     super.initState();
-    _cells = widget.element.cells ?? {};
-    List<CellPostion> cellPostions = _cells!.keys.toList();
-    cellPostions.sort(((a, b) => (b.column!).compareTo(a.column!)));
-    // +1 为列数
-    _column = cellPostions.first.column! + 1;
-    _values = _cells!.values.toList();
-    for (int i = 0; i < _column! - 1; i++) {
-      _width += widget.element.columnDefinitions![i].width!;
-    }
-
-    _row = widget.element.rowDefinitions!.length + 1;
   }
 
   @override
   Widget build(BuildContext context) {
+    initCells();
     List<Widget> widgets = [];
     for (int i = 0; i < _row! - 1; i++) {
       final children = _cells!.keys.where((element) => element.row! == i);
@@ -102,4 +92,18 @@ class _RTTableState extends State<RTTablePage> {
       ),
     );
   }
+
+  void initCells() {
+    _cells = widget.element.cells ?? {};
+    List<CellPostion> cellPostions = _cells!.keys.toList();
+    cellPostions.sort(((a, b) => (b.column!).compareTo(a.column!)));
+    // +1 为列数
+    _column = cellPostions.first.column! + 1;
+    _values = _cells!.values.toList();
+    for (int i = 0; i < _column! - 1; i++) {
+      _width += widget.element.columnDefinitions![i].width!;
+    }
+
+    _row = widget.element.rowDefinitions!.length + 1;
+  }
 }

+ 40 - 16
lib/report_edit.dart

@@ -44,6 +44,13 @@ class _ReportEditPageState extends State<ReportEditPage> {
   @override
   initState() {
     _intitTemplate();
+    ReportInfo.instance.onReload.addListener((sender, e) {
+      _header.clear();
+      _blocks.clear();
+      _footer.clear();
+      widget.onSelect.dispose();
+      _intitTemplate(args: e);
+    });
     super.initState();
   }
 
@@ -52,9 +59,9 @@ class _ReportEditPageState extends State<ReportEditPage> {
     if (widget.jsonStr.isEmpty) {
       return const SizedBox();
     }
-    if (!isInit) {
-      _intitTemplate();
-    }
+    // if (!isInit) {
+    //  // _intitTemplate();
+    // }
     return Container(
       decoration: _buildDecoration(),
       padding: _padding,
@@ -62,9 +69,6 @@ class _ReportEditPageState extends State<ReportEditPage> {
       height: _height,
       width: _width,
       child: ListView(
-        // mainAxisAlignment: MainAxisAlignment.center,
-        // crossAxisAlignment: CrossAxisAlignment.center,
-        // mainAxisSize: MainAxisSize.min,
         children: [
           ..._header.map((head) {
             return BlockElementPage(element: head);
@@ -90,21 +94,35 @@ class _ReportEditPageState extends State<ReportEditPage> {
         color: Colors.white);
   }
 
-  void _intitTemplate() {
-    if (widget.jsonStr.isEmpty) {
+  void _intitTemplate({ReportEventArgs? args}) {
+    String jsonStr = widget.jsonStr;
+    DateTime reportDate = widget.reportDate;
+    String reporter = widget.reporter;
+    if (args != null) {
+      jsonStr = args.jsonStr;
+      reporter = args.reporter;
+      reportDate = args.reportDate;
+    }
+    if (jsonStr.isEmpty) {
       return;
     }
-    final reportMap = jsonDecode(widget.jsonStr);
-    final template = ReportTemplateDocument.fromJson(reportMap);
-    _reportTemplate = template;
-    ReportInfo.instance
-        .init(_reportTemplate, widget.reportDate, widget.reporter);
+    final reportMap = jsonDecode(jsonStr);
+
     setState(() {
+      final template = ReportTemplateDocument.fromJson(reportMap);
+      _reportTemplate = template;
+      ReportInfo.instance.init(_reportTemplate, reportDate, reporter);
       _initPage();
     });
-    widget.onSelect.addListener((sender, e) {
-      ReportInfo.instance.selectedInputImage(e);
-    });
+    if (args != null) {
+      args.onSelect.addListener((sender, e) {
+        ReportInfo.instance.selectedInputImage(e);
+      });
+    } else {
+      widget.onSelect.addListener((sender, e) {
+        ReportInfo.instance.selectedInputImage(e);
+      });
+    }
     isInit = true;
   }
 
@@ -131,4 +149,10 @@ class _ReportEditPageState extends State<ReportEditPage> {
       _width = 595.275590551181;
     }
   }
+
+  @override
+  void dispose() {
+    ReportInfo.instance.onReload.dispose();
+    super.dispose();
+  }
 }

+ 0 - 5
lib/report_info/input_image_info.dart

@@ -1,10 +1,5 @@
 import 'package:fis_lib_report/converts/event_type.dart';
-import 'package:fis_lib_report/report/element.dart';
 import 'package:fis_lib_report/report/inputImage.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/interfaces/inputImageList.dart';
 import 'package:fis_lib_report/report_info/block_element_info_interface.dart';
 import 'package:fis_lib_report/report_info/element_info.dart';
 

+ 2 - 0
lib/report_info/input_image_list_info.dart

@@ -23,6 +23,8 @@ class InputImageListInfo extends ElementInfo implements IBlockElementInfo {
     column = inputImageList.column;
     hasGap = inputImageList.hasGap;
     isReadOnly = inputImageList.isReadOnly;
+    onSelect!.dispose();
+    onSelect = FEventHandler();
   }
 
   @override

+ 17 - 4
lib/report_info/report_info.dart

@@ -54,7 +54,7 @@ class ReportInfo {
 
   ReportTemplateDocument? reportTemplate;
 
-  FEventHandler<double>? onHeightChange = FEventHandler();
+  FEventHandler<ReportEventArgs> onReload = FEventHandler();
 
   static ReportInfo get instance {
     _reportInfo ??= ReportInfo._internal();
@@ -87,8 +87,12 @@ class ReportInfo {
     }
   }
 
-  void heightChange(double height) {
-    onHeightChange!.emit(this, height);
+  ///重新渲染UI&重构reportInfo
+  void reload(String reporter, DateTime reportDate, String jsonStr,
+      FEventHandler<String> onSelect) {
+    _reportInfo = null;
+    onReload.emit(
+        this, ReportEventArgs(reportDate, reporter, jsonStr, onSelect));
   }
 
   IBlockElementInfo? getBlockElement(IBlockElement block) {
@@ -171,7 +175,7 @@ class ReportInfo {
   bool _checkImageisSelected(IBlockElementInfo block, String url) {
     if (block is InputImageListInfo) {
       final inputImage = block;
-      if (inputImage.isSelected!) {
+      if (inputImage.isSelected ?? false) {
         inputImage.addImage(url);
         return true;
       }
@@ -220,3 +224,12 @@ class ReportInfo {
     return result;
   }
 }
+
+class ReportEventArgs {
+  final FEventHandler<String> onSelect;
+
+  final String jsonStr;
+  final String reporter;
+  final DateTime reportDate;
+  ReportEventArgs(this.reportDate, this.reporter, this.jsonStr, this.onSelect);
+}

Some files were not shown because too many files changed in this diff