浏览代码

[feat]亲密度分析,截图回复-识图回复,调整状态判断流程

hezihao 7 月之前
父节点
当前提交
ffb43ef325

+ 18 - 6
lib/module/intimacy_analyse/screenshot_reply/scan_image_reply/scan_image_reply_controller.dart

@@ -54,9 +54,6 @@ class ScanImageReplyController extends BaseController {
   /// 当前选择的语气
   Rxn<OptionSelectItem> currentSelectReplyToneOption = Rxn();
 
-  /// 是否上传页
-  RxBool isUploadPage = true.obs;
-
   /// 是否生成结果中
   RxBool isResultGenerating = false.obs;
 
@@ -72,6 +69,9 @@ class ScanImageReplyController extends BaseController {
   /// 回复语气列表
   RxList<String> replyToneList = <String>[].obs;
 
+  /// 是否有识别结果
+  Rx<bool> hasScanResult = false.obs;
+
   /// 对话分析的订阅(SSE)
   StreamSubscription<Message>? _intimacyReplyAnalyzeSubscription;
 
@@ -168,13 +168,14 @@ class ScanImageReplyController extends BaseController {
       // 只能最多上传1张图片
       maxAssetsCount: 1,
     );
+
     // 切换为上传页
     if (selectedAssetList.isNotEmpty) {
       // 上传图片
       _handleSelectedAssetUpload(selectedAssetList);
-      isUploadPage.value = false;
-    } else {
-      isUploadPage.value = true;
+      // 清空已生成的数据
+      isResultGenerating.value = false;
+      hasScanResult.value = false;
     }
   }
 
@@ -208,10 +209,13 @@ class ScanImageReplyController extends BaseController {
       return;
     }
 
+    // 用于累计生成的内容
     StringBuffer buffer = StringBuffer();
 
     // 切换为生成中
     isResultGenerating.value = true;
+    hasScanResult.value = false;
+
     replyToneList.clear();
     // 添加一条,正在回复的条目
     replyToneList.add("");
@@ -245,8 +249,15 @@ class ScanImageReplyController extends BaseController {
         replyToneList.clear();
         replyToneList.add(buffer.toString());
         replyToneList.refresh();
+
+        // 改为已有识别结果
+        hasScanResult.value = true;
       },
       onError: (error) {
+        // 发生异常
+        isResultGenerating.value = false;
+        hasScanResult.value = false;
+
         AtmobLog.e(_tag, error.toString());
         if (error is ServerErrorException) {
           // 需要Vip权限
@@ -262,6 +273,7 @@ class ScanImageReplyController extends BaseController {
       },
       onDone: () {
         // 流关闭
+        isResultGenerating.value = false;
       },
     );
   }

+ 34 - 9
lib/module/intimacy_analyse/screenshot_reply/scan_image_reply/scan_image_reply_view.dart

@@ -61,7 +61,7 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
                   // 回复语气列表卡片
                   _buildReplyToneListCard(),
                   // 距离底部有一定间距
-                  SizedBox(height: 90.h),
+                  _buildBottomSpace(),
                 ],
               );
             }
@@ -78,6 +78,19 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
     );
   }
 
+  /// 底部间距
+  Widget _buildBottomSpace() {
+    return Obx(() {
+      // 生成中,或已生成,底部高度降低
+      if (controller.isResultGenerating.value ||
+          controller.hasScanResult.value) {
+        return SizedBox(height: 20.h);
+      }
+      // 否则留出距离给底部显示
+      return SizedBox(height: 90.h);
+    });
+  }
+
   /// 上传截图的卡片
   /// [isSample] 是否是样例图片
   Widget _buildUploadScreenshotCard(bool isSample) {
@@ -271,11 +284,7 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
   /// 回复语气列表卡片
   Widget _buildReplyToneListCard() {
     return Obx(() {
-      // 为生成
-      if (!controller.isResultGenerating.value) {
-        return SizedBox();
-      }
-      return Container(
+      Widget resultWidget = Container(
         margin: EdgeInsets.only(left: 12.w, right: 12.w),
         decoration: BoxDecoration(
           // 渐变背景
@@ -365,6 +374,18 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
           ],
         ),
       );
+      // 生成中,展示组件
+      if (controller.isResultGenerating.value) {
+        return resultWidget;
+      } else {
+        // 未生成,不显示
+        if (!controller.hasScanResult.value) {
+          return SizedBox.shrink();
+        } else {
+          // 已生成,显示
+          return resultWidget;
+        }
+      }
     });
   }
 
@@ -565,15 +586,19 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
 
   /// 底部操作按钮
   Widget _buildBottomActionBtn(BuildContext context) {
-    if (controller.isUploadPage.value) {
-      // 上传页,显示上传截图按钮
+    // 例子,则显示上传截图按钮
+    if (controller.uploadInfo.value == null) {
       return Container(
         width: double.maxFinite,
         margin: EdgeInsets.only(top: 8.h, bottom: 20.h),
         child: _buildUploadScreenshotBtn(context),
       );
+    }
+    // 生成中,或已有结果,隐藏按钮
+    if (controller.isResultGenerating.value || controller.hasScanResult.value) {
+      return SizedBox.shrink();
     } else {
-      // 结果页,显示2个按钮,模式切换按钮和获取回复按钮
+      // 上传页或结果页,显示2个按钮,模式切换按钮和获取回复按钮
       return Container(
         width: double.maxFinite,
         margin: EdgeInsets.only(