Browse Source

[feat]亲密度分析,截图回复-识图回复,增加生成中状态,优化显示效果

hezihao 7 months ago
parent
commit
c4e6bcfcfe

+ 6 - 2
lib/data/bean/option_select_item.dart

@@ -5,15 +5,19 @@ part 'option_select_item.g.dart';
 /// 选项选择实体类
 @JsonSerializable()
 class OptionSelectItem {
-  // 名称
+  // 名称,只用来渲染
   @JsonKey(name: 'name')
   String name;
 
+  // 数据,用来提交给服务端的数据
+  @JsonKey(name: 'value')
+  String value;
+
   // 是否选中
   @JsonKey(name: 'selected')
   bool selected;
 
-  OptionSelectItem(this.name, {this.selected = false});
+  OptionSelectItem(this.name, this.value, {this.selected = false});
 
   factory OptionSelectItem.fromJson(Map<String, dynamic> json) =>
       _$OptionSelectItemFromJson(json);

+ 6 - 1
lib/data/bean/option_select_item.g.dart

@@ -9,8 +9,13 @@ part of 'option_select_item.dart';
 OptionSelectItem _$OptionSelectItemFromJson(Map<String, dynamic> json) =>
     OptionSelectItem(
       json['name'] as String,
+      json['value'] as String,
       selected: json['selected'] as bool? ?? false,
     );
 
 Map<String, dynamic> _$OptionSelectItemToJson(OptionSelectItem instance) =>
-    <String, dynamic>{'name': instance.name, 'selected': instance.selected};
+    <String, dynamic>{
+      'name': instance.name,
+      'value': instance.value,
+      'selected': instance.selected,
+    };

+ 3 - 3
lib/module/intimacy_analyse/intimacy_analyse_upload/intimacy_analyse_upload_controller.dart

@@ -139,7 +139,7 @@ class IntimacyAnalyseUploadController extends BaseController {
           var iconUrl = item.iconUrl ?? "";
           var optionList =
               item.options?.map((value) {
-                return OptionSelectItem(value);
+                return OptionSelectItem(value, value);
               }).toList() ??
               [];
           return OptionSelectConfig(title, iconUrl, optionList);
@@ -265,12 +265,12 @@ class IntimacyAnalyseUploadController extends BaseController {
       if (directionOptionSelectConfigList.isEmpty || !firstRowConfigIsCustom) {
         // 没有自定义配置,添加一个
         directionOptionSelectConfigList[0] = OptionSelectConfig("", "", [
-          OptionSelectItem(customDirection),
+          OptionSelectItem(customDirection, customDirection),
         ], isCustom: true);
       } else {
         // 已经有一个,在原来的基础上,添加1个
         OptionSelectConfig oldConfig = directionOptionSelectConfigList[0];
-        oldConfig.options.add(OptionSelectItem(customDirection));
+        oldConfig.options.add(OptionSelectItem(customDirection, customDirection));
       }
       directionOptionSelectConfigList.refresh();
     });

+ 5 - 3
lib/module/intimacy_analyse/screenshot_reply/conversation_analysis/conversation_analysis_controller.dart

@@ -101,7 +101,8 @@ class ConversationAnalysisController extends BaseController {
     if (forTaConfig != null && forTaConfig.isNotEmpty) {
       var itemList =
           forTaConfig.map((item) {
-            return OptionSelectItem(item.title);
+            var title = item.title;
+            return OptionSelectItem(title, title);
           }).toList();
       optionSelectConfigList.add(
         OptionSelectConfig(StringName.forTa, "", itemList),
@@ -113,7 +114,8 @@ class ConversationAnalysisController extends BaseController {
     if (forMeConfig != null) {
       var itemList =
           forMeConfig.map((item) {
-            return OptionSelectItem(item.title);
+            var title = item.title;
+            return OptionSelectItem(title, title);
           }).toList();
       optionSelectConfigList.add(
         OptionSelectConfig(StringName.forMe, "", itemList),
@@ -161,7 +163,7 @@ class ConversationAnalysisController extends BaseController {
           return item.fileBackendPath ?? "";
         }).toList();
     // 选择的标题
-    String title = currentSelectOption.value?.name ?? "";
+    String title = currentSelectOption.value?.value ?? "";
 
     if (imageList.isEmpty) {
       ToastUtil.show(StringName.noUploadConversationImageTip);

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

@@ -57,6 +57,9 @@ class ScanImageReplyController extends BaseController {
   /// 是否上传页
   RxBool isUploadPage = true.obs;
 
+  /// 是否生成结果中
+  RxBool isResultGenerating = false.obs;
+
   /// 上传图片列表
   Rxn<UploadInfo> uploadInfo = Rxn();
 
@@ -102,7 +105,11 @@ class ScanImageReplyController extends BaseController {
     if (toneList.isNotEmpty) {
       var newList =
           toneList.map((item) {
-            return OptionSelectItem("${item.emoji} ${item.title}");
+            return OptionSelectItem(
+              "${item.emoji} ${item.title}",
+              // 提交给服务端的数据,不能包含表情字符
+              item.title ?? "",
+            );
           }).toList();
 
       replyToneOptionSelectConfigList.clear();
@@ -184,8 +191,7 @@ class ScanImageReplyController extends BaseController {
     // 上传的图片后端地址
     List<String> imageList = [uploadInfo.value?.fileBackendPath ?? ""];
     // 选择的回复语气
-    // String title = currentSelectReplyToneOption.value?.name ?? "";
-    String title = "高冷";
+    String title = currentSelectReplyToneOption.value?.value ?? "";
     // 当前选择的回复模式
     String mode = currentReplyMode.value?.value ?? "";
 
@@ -204,7 +210,11 @@ class ScanImageReplyController extends BaseController {
 
     StringBuffer buffer = StringBuffer();
 
+    // 切换为生成中
+    isResultGenerating.value = true;
     replyToneList.clear();
+    // 添加一条,正在回复的条目
+    replyToneList.add("");
     replyToneList.refresh();
 
     // 请求分析截图
@@ -220,9 +230,11 @@ class ScanImageReplyController extends BaseController {
         IntimacyReplyAnalyzeResponse response =
             IntimacyReplyAnalyzeResponse.fromJson(jsonDecode(json));
 
-        List<String> contentList = response.choices?.map((item) {
-          return item.delta?.content ?? "";
-        }).toList() ?? [];
+        List<String> contentList =
+            response.choices?.map((item) {
+              return item.delta?.content ?? "";
+            }).toList() ??
+            [];
         // 数组转字符串
         String content = contentList.join("");
 

+ 4 - 3
lib/module/intimacy_analyse/screenshot_reply/scan_image_reply/scan_image_reply_view.dart

@@ -270,7 +270,8 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
   /// 回复语气列表卡片
   Widget _buildReplyToneListCard() {
     return Obx(() {
-      if (controller.replyToneList.isEmpty) {
+      // 为生成
+      if (!controller.isResultGenerating.value) {
         return SizedBox();
       }
       return Container(
@@ -423,9 +424,9 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
               margin: EdgeInsets.only(left: 21.w, top: 12.h, bottom: 12.h),
               child: Text(
                 replyTone,
-                maxLines: 1,
+                // maxLines: 1,
                 style: TextStyle(
-                  overflow: TextOverflow.ellipsis,
+                  // overflow: TextOverflow.ellipsis,
                   color: ColorName.black80,
                   fontSize: 14.sp,
                   fontWeight: FontWeight.w500,