Browse Source

[feat]亲密度分析,截图回复-识图分析,对接文件上传

hezihao 7 months ago
parent
commit
fe6404efa1

+ 6 - 3
lib/di/get_it.config.dart

@@ -107,9 +107,6 @@ extension GetItInjectableX on _i174.GetIt {
     gh.factory<_i279.IntimacyAnalyseScreenshotReplyController>(
     gh.factory<_i279.IntimacyAnalyseScreenshotReplyController>(
       () => _i279.IntimacyAnalyseScreenshotReplyController(),
       () => _i279.IntimacyAnalyseScreenshotReplyController(),
     );
     );
-    gh.factory<_i464.ScanImageReplyController>(
-      () => _i464.ScanImageReplyController(),
-    );
     gh.factory<_i248.KeyboardGuidePageController>(
     gh.factory<_i248.KeyboardGuidePageController>(
       () => _i248.KeyboardGuidePageController(),
       () => _i248.KeyboardGuidePageController(),
     );
     );
@@ -312,6 +309,12 @@ extension GetItInjectableX on _i174.GetIt {
         gh<_i428.UploadFileManager>(),
         gh<_i428.UploadFileManager>(),
       ),
       ),
     );
     );
+    gh.factory<_i464.ScanImageReplyController>(
+      () => _i464.ScanImageReplyController(
+        gh<_i738.IntimacyAnalyzeConfigHelper>(),
+        gh<_i428.UploadFileManager>(),
+      ),
+    );
     gh.factory<_i666.IntimacyAnalyseUploadController>(
     gh.factory<_i666.IntimacyAnalyseUploadController>(
       () => _i666.IntimacyAnalyseUploadController(
       () => _i666.IntimacyAnalyseUploadController(
         gh<_i283.IntimacyAnalyzeRepository>(),
         gh<_i283.IntimacyAnalyzeRepository>(),

+ 59 - 3
lib/module/intimacy_analyse/screenshot_reply/scan_image_reply/scan_image_reply_controller.dart

@@ -1,3 +1,5 @@
+import 'dart:io';
+
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:get/get_rx/src/rx_types/rx_types.dart';
 import 'package:get/get_rx/src/rx_types/rx_types.dart';
 import 'package:injectable/injectable.dart';
 import 'package:injectable/injectable.dart';
@@ -8,10 +10,22 @@ import 'package:wechat_assets_picker/wechat_assets_picker.dart';
 import '../../../../data/bean/option_select_config.dart';
 import '../../../../data/bean/option_select_config.dart';
 import '../../../../data/bean/option_select_item.dart';
 import '../../../../data/bean/option_select_item.dart';
 import '../../../../utils/image_picker_util.dart';
 import '../../../../utils/image_picker_util.dart';
+import '../../../../utils/intimacy_analyze_config_helper.dart';
+import '../../../../utils/upload/upload_file_manager.dart';
+import '../../../../utils/upload/upload_scene_type.dart';
 
 
 /// 识图回复Controller
 /// 识图回复Controller
 @injectable
 @injectable
 class ScanImageReplyController extends BaseController {
 class ScanImageReplyController extends BaseController {
+  /// 上传场景
+  final UploadSceneType uploadSceneType = UploadSceneType.scanImageReply;
+
+  /// 亲密度分析帮助类
+  IntimacyAnalyzeConfigHelper intimacyAnalyzeConfigHelper;
+
+  /// 文件上传管理器
+  UploadFileManager uploadFileManager;
+
   /// 回复语气选项列表
   /// 回复语气选项列表
   RxList<OptionSelectConfig> replyToneOptionSelectConfigList =
   RxList<OptionSelectConfig> replyToneOptionSelectConfigList =
       <OptionSelectConfig>[].obs;
       <OptionSelectConfig>[].obs;
@@ -19,6 +33,9 @@ class ScanImageReplyController extends BaseController {
   /// 是否上传页
   /// 是否上传页
   RxBool isUploadPage = true.obs;
   RxBool isUploadPage = true.obs;
 
 
+  /// 上传图片列表
+  Rxn<UploadInfo> uploadInfo = Rxn();
+
   /// Ai模型列表
   /// Ai模型列表
   RxList<String> replyModelList = <String>['评论模式', '搭讪模式'].obs;
   RxList<String> replyModelList = <String>['评论模式', '搭讪模式'].obs;
 
 
@@ -28,8 +45,10 @@ class ScanImageReplyController extends BaseController {
   /// 回复语气列表
   /// 回复语气列表
   RxList<String> replyToneList = <String>["真好", "真好看", "真的很好看~"].obs;
   RxList<String> replyToneList = <String>["真好", "真好看", "真的很好看~"].obs;
 
 
-  /// 上传信息
-  Rx<UploadInfo> uploadInfo = UploadInfo().obs;
+  ScanImageReplyController(
+    this.intimacyAnalyzeConfigHelper,
+    this.uploadFileManager,
+  );
 
 
   @override
   @override
   void onReady() {
   void onReady() {
@@ -80,10 +99,13 @@ class ScanImageReplyController extends BaseController {
     // 跳转到图片选择,并返回选择的图片列表
     // 跳转到图片选择,并返回选择的图片列表
     List<AssetEntity> selectedAssetList = await ImagePickerUtil.pickImage(
     List<AssetEntity> selectedAssetList = await ImagePickerUtil.pickImage(
       context,
       context,
-      maxAssetsCount: 9,
+      // 只能最多上传1张图片
+      maxAssetsCount: 1,
     );
     );
     // 切换为上传页
     // 切换为上传页
     if (selectedAssetList.isNotEmpty) {
     if (selectedAssetList.isNotEmpty) {
+      // 上传图片
+      _handleSelectedAssetUpload(selectedAssetList);
       isUploadPage.value = false;
       isUploadPage.value = false;
     } else {
     } else {
       isUploadPage.value = true;
       isUploadPage.value = true;
@@ -92,4 +114,38 @@ class ScanImageReplyController extends BaseController {
 
 
   /// 点击获取回复按钮
   /// 点击获取回复按钮
   void clickGetReplyBtn() {}
   void clickGetReplyBtn() {}
+
+  /// 删除上传信息
+  void deleteUploadInfo(UploadInfo info) {
+    uploadFileManager.deleteUploadInfo(info);
+    uploadInfo.value = info;
+    uploadInfo.refresh();
+  }
+
+  /// 处理文件上传
+  void _handleSelectedAssetUpload(List<AssetEntity> selectedAssetList) async {
+    for (var entity in selectedAssetList) {
+      // 获取文件路径
+      File? file = await entity.file;
+      if (file == null) {
+        continue;
+      }
+      // 添加到上传列表
+      uploadInfo.value = uploadFileManager.uploadFile(
+        sceneType: uploadSceneType,
+        file: file,
+        onUploadInfoUpdateCallback: (uploadInfo) {
+          // 上传信息更新时回调,更新UI
+          _updateUploadInfo(uploadInfo);
+        },
+      );
+    }
+  }
+
+  /// 更新上传信息
+  void _updateUploadInfo(UploadInfo info) {
+    // 更新上传信息
+    uploadInfo.value = info;
+    uploadInfo.refresh();
+  }
 }
 }

+ 45 - 16
lib/module/intimacy_analyse/screenshot_reply/scan_image_reply/scan_image_reply_view.dart

@@ -3,14 +3,17 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:get/get.dart';
 import 'package:get/get.dart';
 import 'package:keyboard/base/base_view.dart';
 import 'package:keyboard/base/base_view.dart';
 import 'package:keyboard/data/bean/upload_info.dart';
 import 'package:keyboard/data/bean/upload_info.dart';
+import '../../../../data/bean/image_viewer_item.dart';
 import '../../../../data/bean/option_select_config.dart';
 import '../../../../data/bean/option_select_config.dart';
 import '../../../../data/bean/option_select_item.dart';
 import '../../../../data/bean/option_select_item.dart';
 import '../../../../resource/assets.gen.dart';
 import '../../../../resource/assets.gen.dart';
 import '../../../../resource/colors.gen.dart';
 import '../../../../resource/colors.gen.dart';
 import '../../../../resource/string.gen.dart';
 import '../../../../resource/string.gen.dart';
-import '../../../../utils/upload/upload_state.dart';
+import '../../../../utils/prefix_util.dart';
+import '../../../../utils/upload/file_data_source_util.dart';
 import '../../../../widget/actionbtn/action_btn.dart';
 import '../../../../widget/actionbtn/action_btn.dart';
 import '../../../../widget/gradient_text.dart';
 import '../../../../widget/gradient_text.dart';
+import '../../image_viewer/image_viewer_page.dart';
 import '../../intimacy_analyse_upload/popup/reply_mode_select_popup.dart';
 import '../../intimacy_analyse_upload/popup/reply_mode_select_popup.dart';
 import '../../intimacy_analyse_upload/widget/upload_item_widget.dart';
 import '../../intimacy_analyse_upload/widget/upload_item_widget.dart';
 import '../../widget/option_select_widget.dart';
 import '../../widget/option_select_widget.dart';
@@ -34,20 +37,33 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
     return Stack(
     return Stack(
       children: [
       children: [
         SingleChildScrollView(
         SingleChildScrollView(
-          child: Column(
-            children: [
-              // 上传截图的卡片
-              _buildUploadScreenshotCard(false),
-              SizedBox(height: 14.h),
-              // 选项卡片
-              _buildOptionCard(),
-              SizedBox(height: 14.h),
-              // 回复语气列表卡片
-              _buildReplyToneListCard(),
-              // 距离底部有一定间距
-              SizedBox(height: 90.h),
-            ],
-          ),
+          child: Obx(() {
+            bool isSample = controller.uploadInfo.value == null;
+            if (isSample) {
+              return Column(
+                children: [
+                  // 上传截图的卡片
+                  _buildUploadScreenshotCard(true),
+                  SizedBox(height: 14.h),
+                ],
+              );
+            } else {
+              return Column(
+                children: [
+                  // 上传截图的卡片
+                  _buildUploadScreenshotCard(false),
+                  SizedBox(height: 14.h),
+                  // 选项卡片
+                  _buildOptionCard(),
+                  SizedBox(height: 14.h),
+                  // 回复语气列表卡片
+                  _buildReplyToneListCard(),
+                  // 距离底部有一定间距
+                  SizedBox(height: 90.h),
+                ],
+              );
+            }
+          }),
         ),
         ),
         // 上传截图按钮
         // 上传截图按钮
         Positioned.fill(
         Positioned.fill(
@@ -120,7 +136,7 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
     } else {
     } else {
       // 上传
       // 上传
       imageWidget = UploadItemWidget(
       imageWidget = UploadItemWidget(
-        imageUploadInfo: controller.uploadInfo.value,
+        imageUploadInfo: controller.uploadInfo.value!,
         hasDeleteBtn: false,
         hasDeleteBtn: false,
         // 失败时的遮罩
         // 失败时的遮罩
         uploadFailMaskWidget: UploadFailMaskWidget(
         uploadFailMaskWidget: UploadFailMaskWidget(
@@ -140,6 +156,19 @@ class ScanImageReplyView extends BaseView<ScanImageReplyController> {
         ),
         ),
         onClickItemCallback: (UploadInfo uploadInfo) {
         onClickItemCallback: (UploadInfo uploadInfo) {
           // 预览图片
           // 预览图片
+          ImageViewerItem imageViewerItem;
+          String src = FileDataSourceUtil.getFileDataSourceSrc(uploadInfo);
+          // 远程图片
+          if (PrefixUtil.isRemoteImage(src)) {
+            imageViewerItem = ImageViewerItem.network(src);
+          } else {
+            // 本地图片
+            imageViewerItem = ImageViewerItem.file(src);
+          }
+          ImageViewerPage.start([imageViewerItem]);
+        },
+        onClickDeleteCallback: (UploadInfo uploadInfo) {
+          controller.deleteUploadInfo(uploadInfo);
         },
         },
       );
       );
     }
     }