Browse Source

段落组件样式根据Json模板调整

loki.wu 2 years ago
parent
commit
64d32589fd

+ 17 - 0
lib/converts/alignment_convert.dart

@@ -35,6 +35,23 @@ class AlignmentConvert {
     }
   }
 
+  static MainAxisAlignment horizontalToMainConvert(HorizontalLayout? value) {
+    if (value == null) {
+      return MainAxisAlignment.start;
+    } else {
+      switch (value) {
+        case HorizontalLayout.Left:
+          return MainAxisAlignment.start;
+        case HorizontalLayout.Center:
+          return MainAxisAlignment.center;
+        case HorizontalLayout.Right:
+          return MainAxisAlignment.end;
+        case HorizontalLayout.Stretch:
+          return MainAxisAlignment.spaceEvenly;
+      }
+    }
+  }
+
   static Alignment verticalLayoutConvert(VerticalLayout? value) {
     if (value == null) {
       return Alignment.center;

+ 5 - 2
lib/pages/components/input_text.dart

@@ -18,7 +18,7 @@ class RInputText extends StatefulWidget {
 class _RInputTextState extends State<RInputText> {
   _RInputTextState({required this.inputText});
   final InputText inputText;
-  final _controller = TextEditingController(text: '');
+  final _controller = TextEditingController();
   final _focusNode = FocusNode();
   double? _lineWidth = 136.0;
   double? _fontSize = 22.0;
@@ -31,6 +31,9 @@ class _RInputTextState extends State<RInputText> {
 
   @override
   initState() {
+    if (inputText.isReadOnly!) {
+      _controller.text = 'test';
+    }
     final fontColor = inputText.fontColor;
     if (fontColor != null) {
       _fontColor = Color.fromARGB(
@@ -71,7 +74,7 @@ class _RInputTextState extends State<RInputText> {
       decoration: BoxDecoration(
         border: Border.all(
           width: 1,
-          color: Colors.grey,
+          color: inputText.isReadOnly! ? Colors.transparent : Colors.grey,
         ),
         color: _backgroundColor,
       ),

+ 82 - 71
lib/pages/paragraph_page.dart

@@ -1,9 +1,9 @@
+import 'package:fis_lib_report/converts/alignment_convert.dart';
 import 'package:fis_lib_report/pages/components/RDateTime.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';
 import 'package:fis_lib_report/pages/components/static_Text.dart';
-import 'package:fis_lib_report/pages/helpler.dart';
 import 'package:fis_lib_report/report/dateTimeElement.dart';
 import 'package:fis_lib_report/report/element_type.dart';
 import 'package:fis_lib_report/report/inputText.dart';
@@ -14,7 +14,6 @@ import 'package:fis_lib_report/report/multiSelected.dart';
 import 'package:fis_lib_report/report/paragraph.dart';
 import 'package:fis_lib_report/report/singleSelected.dart';
 import 'package:fis_lib_report/report/staticText.dart';
-import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 
 class ParagraphPage extends StatefulWidget {
@@ -44,83 +43,95 @@ class _ParagraphState extends State<ParagraphPage> {
     if (_itemCount == 0) {
       return const SizedBox();
     }
-    return Row(
-      mainAxisAlignment:
-          widget.paragraph.horizontalAlignment == HorizontalLayout.Center
-              ? MainAxisAlignment.center
-              : MainAxisAlignment.start,
-      crossAxisAlignment: CrossAxisAlignment.start,
-      children: [
-        ..._elements!.map((element) {
-          if (element.elementType!.name == ElementType.inputText!.name) {
-            InputText inputText = element as InputText;
-            return RInputText(
-              inputText: inputText,
-            );
-          } else if (element.elementType!.name ==
-              ElementType.staticText!.name) {
-            StaticText staticText = element as StaticText;
-            return RStaticText(staticText);
-          } else if (element.elementType!.name ==
-              ElementType.singleSelected!.name) {
-            SingleSelected singleSelected = element as SingleSelected;
+    final margin = widget.paragraph.margin!;
+    return Container(
+      margin: EdgeInsets.only(
+        top: margin.top!,
+        bottom: margin.bottom!,
+        left: margin.left!,
+        right: margin.right!,
+      ),
+      alignment: AlignmentConvert.verticalLayoutConvert(
+          widget.paragraph.verticalAlignment),
+      child: Row(
+        mainAxisAlignment:
+            widget.paragraph.horizontalAlignment == HorizontalLayout.Center
+                ? MainAxisAlignment.center
+                : MainAxisAlignment.start,
+        crossAxisAlignment: CrossAxisAlignment.start,
+        children: [
+          ..._elements!.map((element) {
+            if (element.elementType!.name == ElementType.inputText!.name) {
+              InputText inputText = element as InputText;
+              return RInputText(
+                inputText: inputText,
+              );
+            } else if (element.elementType!.name ==
+                ElementType.staticText!.name) {
+              StaticText staticText = element as StaticText;
+              return RStaticText(staticText);
+            } else if (element.elementType!.name ==
+                ElementType.singleSelected!.name) {
+              SingleSelected singleSelected = element as SingleSelected;
+
+              List<String>? values = singleSelected.items;
 
-            List<String>? values = singleSelected.items;
+              if (values != null && values.isNotEmpty) {
+                return SizedBox(
+                  width: 104,
+                  height: 28,
+                  child: DropdownButton(
+                    onChanged: (Object? value) {},
+                    items: values.map<DropdownMenuItem<String>>((String value) {
+                      return DropdownMenuItem<String>(
+                        value: value,
+                        child: Text(value),
+                      );
+                    }).toList(),
+                  ),
+                );
+              }
+            } else if (element.elementType!.name == ElementType.line!.name) {
+              Line line = element as Line;
+              return RLine(line);
+            } else if (element.elementType!.name ==
+                ElementType.dateTime!.name) {
+              final dateTime = element as DateTimeElement;
+              return RDateTime(dateTime);
+            } else if (element.elementType!.name ==
+                ElementType.multiSelected!.name) {
+              final multiSelected = element as MultiSelected;
 
-            if (values != null && values.isNotEmpty) {
+              List<String>? values = multiSelected.items;
               return SizedBox(
-                width: 104,
+                width: 120,
                 height: 28,
-                child: DropdownButton(
-                  onChanged: (Object? value) {},
-                  items: values.map<DropdownMenuItem<String>>((String value) {
-                    return DropdownMenuItem<String>(
-                      value: value,
-                      child: Text(value),
-                    );
-                  }).toList(),
+                child: TextField(
+                  cursorWidth: 0,
+                  mouseCursor: SystemMouseCursors.click,
+                  decoration: const InputDecoration(
+                    suffixIcon: Icon(Icons.arrow_drop_down),
+                  ),
+                  onTap: () {
+                    _showMultiSelect(values);
+                  },
                 ),
               );
             }
-          } else if (element.elementType!.name == ElementType.line!.name) {
-            Line line = element as Line;
-            return RLine(line);
-          } else if (element.elementType!.name == ElementType.dateTime!.name) {
-            final dateTime = element as DateTimeElement;
-            return RDateTime(dateTime);
-          } else if (element.elementType!.name ==
-              ElementType.multiSelected!.name) {
-            final multiSelected = element as MultiSelected;
-
-            List<String>? values = multiSelected.items;
-            return SizedBox(
-              width: 120,
-              height: 28,
-              child: TextField(
-                cursorWidth: 0,
-                mouseCursor: SystemMouseCursors.click,
-                decoration: const InputDecoration(
-                  suffixIcon: Icon(Icons.arrow_drop_down),
-                ),
-                onTap: () {
-                  _showMultiSelect(values);
-                },
-              ),
+            return Container(
+              height: 30,
+              width: 80,
+              decoration: BoxDecoration(
+                  border: Border.all(
+                    width: 0.5,
+                    color: const Color.fromARGB(255, 83, 83, 83),
+                  ),
+                  color: Colors.grey[200]),
+              child: const Text('组件占位'),
             );
-          }
-          return Container(
-            height: 30,
-            width: 80,
-            decoration: BoxDecoration(
-                border: Border.all(
-                  width: 0.5,
-                  color: const Color.fromARGB(255, 83, 83, 83),
-                ),
-                color: Colors.grey[200]),
-            child: const Text('组件占位'),
-          );
-        }),
-      ],
+          }),
+        ],
+      ),
     );
   }