Browse Source

修正壳子下无法打开自理评估和中医体质

loki.wu 10 months ago
parent
commit
7f94ff557c

+ 14 - 12
lib/pages/self_care_ability_assessment/view.dart

@@ -20,24 +20,26 @@ class SelfCareAbilityAssessmentView
     super.key,
     this.physicalExamNumber,
   });
+
   final _examManager = Get.find<IExamManager>();
   ExamDTO? currentSelfCareAbilityAssessmentExam;
   final String? physicalExamNumber;
   @override
   Widget build(BuildContext context) {
     return Scaffold(
-        body: FutureBuilder(
-      future: getExamData(physicalExamNumber ?? ''),
-      builder: (context, snapshot) {
-        if (snapshot.connectionState == ConnectionState.waiting) {
-          return Center(child: CircularProgressIndicator());
-        } else if (snapshot.hasError) {
-          return Center(child: Text('Error: ${snapshot.error}'));
-        } else {
-          return buildContent("LNRZLNLPG");
-        }
-      },
-    ));
+      body: FutureBuilder(
+        future: getExamData(physicalExamNumber ?? ''),
+        builder: (context, snapshot) {
+          if (snapshot.connectionState == ConnectionState.waiting) {
+            return Center(child: CircularProgressIndicator());
+          } else if (snapshot.hasError) {
+            return Center(child: Text('Error: ${snapshot.error}'));
+          } else {
+            return buildContent("LNRZLNLPG");
+          }
+        },
+      ),
+    );
   }
 
   Widget buildContent(String key) {

+ 30 - 9
lib/pages/self_care_ability_assessment/widget/assessment_module.dart

@@ -1,7 +1,9 @@
 import 'dart:convert';
 
+import 'package:fis_common/index.dart';
 import 'package:fis_jsonrpc/rpc.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 import 'package:get/get.dart';
 import 'package:vitalapp/architecture/storage/text_storage.dart';
 import 'package:vitalapp/architecture/utils/prompt_box.dart';
@@ -35,6 +37,8 @@ class _SelfCareAssessmentModule extends State<SelfCareAssessmentModule> {
   ///当前最新的模版键值对
   Map<String, dynamic> templateRelation = {};
 
+  String templateCode = '';
+
   ///是否首次进入页面
   bool isFirstEnter = true;
 
@@ -119,15 +123,25 @@ class _SelfCareAssessmentModule extends State<SelfCareAssessmentModule> {
     try {
       if (templateRelation[key] == null) {
         currentTemplate = [];
-        return;
+        if (!FPlatform.isWindows) {
+          return;
+        }
       }
 
-      var template =
-          await _templateManager.readTemplate(templateRelation[key]!);
-      String templateContent =
-          TemplateDTO.fromJson(jsonDecode(template!)).templateContent!;
-      List<Map<String, dynamic>> list =
-          jsonDecode(templateContent).cast<Map<String, dynamic>>();
+      String? template;
+      if (templateRelation.containsKey(key)) {
+        templateCode = templateRelation[key]!;
+        template = await _templateManager.readTemplate(templateCode);
+      }
+      List<Map<String, dynamic>> list = [];
+      if (template == null) {
+        var json = await loadJsonFromAssets('assets/templates/${key}.json');
+        list = jsonDecode(json)["Content"].cast<Map<String, dynamic>>();
+      } else {
+        var templateContent =
+            TemplateDTO.fromJson(jsonDecode(template)).templateContent!;
+        list = jsonDecode(templateContent).cast<Map<String, dynamic>>();
+      }
       for (var i in list) {
         if (i["children"] != null) {
           List<FormObject> currentChildren = [];
@@ -149,6 +163,11 @@ class _SelfCareAssessmentModule extends State<SelfCareAssessmentModule> {
     }
   }
 
+  Future<String> loadJsonFromAssets(String filePath) async {
+    String jsonString = await rootBundle.loadString(filePath);
+    return jsonString;
+  }
+
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -177,14 +196,16 @@ class _SelfCareAssessmentModule extends State<SelfCareAssessmentModule> {
               }
               final result = await widget.callBack(
                 widget.cardKey,
-                templateRelation[widget.cardKey]!,
+                templateCode,
                 jsonEncode(formValue),
               );
 
               Get.back(result: formValue["SelfCareScore"]);
               if (result) {
                 if (!widget.isEdit) formValue.clear();
-                deleteDirectory();
+                if (!FPlatform.isWindows) {
+                  deleteDirectory();
+                }
                 PromptBox.toast('提交成功');
                 setState(() {});
               }

+ 13 - 5
lib/pages/traditional_chinese_medicine_constitution/widget/tcm_card.dart

@@ -51,6 +51,8 @@ class _ConfigurableFormState extends State<TCMConstitutionModule> {
 
   bool isFirstEnter = true;
 
+  String templateCode = '';
+
   /// 当前模板数据
   List<FormObject> currentTemplate = [];
 
@@ -171,6 +173,9 @@ class _ConfigurableFormState extends State<TCMConstitutionModule> {
   }
 
   Future<void> getResourceInfo() async {
+    if (FPlatform.isWindows) {
+      return;
+    }
     TextStorage resourceInfoCacheRecord = TextStorage(
       fileName: "healthGuidance",
       directory: "HealthGuidance/temlpate",
@@ -437,14 +442,16 @@ class _ConfigurableFormState extends State<TCMConstitutionModule> {
                         onTap: () async {
                           final result = await widget.callBack(
                             widget.cardKey,
-                            templateRelation[widget.cardKey]!,
+                            templateCode,
                             jsonEncode(formValue),
                           );
                           if (result) {
                             setState(() {
                               if (!widget.isEdit!) formValue.clear();
                               currentTitleIndex = 0;
-                              deleteDirectory();
+                              if (!FPlatform.isWindows) {
+                                deleteDirectory();
+                              }
                             });
                           }
                           Get.back();
@@ -462,8 +469,8 @@ class _ConfigurableFormState extends State<TCMConstitutionModule> {
 
   String getHealthGuidance(String key) {
     String? value =
-        resourceInfo.firstWhere((element) => element.key == key).value;
-    return value;
+        resourceInfo.firstWhereOrNull((element) => element.key == key)?.value;
+    return value ?? '';
   }
 
   /// 主页面
@@ -553,7 +560,8 @@ class _ConfigurableFormState extends State<TCMConstitutionModule> {
       List<Map<String, dynamic>> list = [];
       String? template;
       if (templateRelation.containsKey(key)) {
-        template = await _templateManager.readTemplate(templateRelation[key]!);
+        templateCode = templateRelation[key]!;
+        template = await _templateManager.readTemplate(templateCode);
       }
       if (template == null) {
         var json = await loadJsonFromAssets('assets/templates/${key}.json');