|
|
@@ -1,3 +1,5 @@
|
|
|
+import 'dart:io';
|
|
|
+
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import 'package:injectable/injectable.dart';
|
|
|
@@ -6,11 +8,24 @@ import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
import '../../../../data/bean/option_select_config.dart';
|
|
|
import '../../../../data/bean/option_select_item.dart';
|
|
|
+import '../../../../data/bean/upload_info.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
|
|
|
@injectable
|
|
|
class ConversationAnalysisController extends BaseController {
|
|
|
+ /// 上传场景
|
|
|
+ final UploadSceneType uploadSceneType = UploadSceneType.conversationAnalysis;
|
|
|
+
|
|
|
+ /// 亲密度分析帮助类
|
|
|
+ IntimacyAnalyzeConfigHelper intimacyAnalyzeConfigHelper;
|
|
|
+
|
|
|
+ /// 文件上传管理器
|
|
|
+ UploadFileManager uploadFileManager;
|
|
|
+
|
|
|
/// 是否是上传页
|
|
|
Rx<bool> isUploadPage = false.obs;
|
|
|
|
|
|
@@ -45,6 +60,20 @@ class ConversationAnalysisController extends BaseController {
|
|
|
● 你的主要爱语:肯定的言辞(如情话、鼓励)
|
|
|
'''.obs;
|
|
|
|
|
|
+ /// 上传图片列表
|
|
|
+ RxList<UploadInfo> uploadInfoList = <UploadInfo>[].obs;
|
|
|
+
|
|
|
+ ConversationAnalysisController(
|
|
|
+ this.intimacyAnalyzeConfigHelper,
|
|
|
+ this.uploadFileManager,
|
|
|
+ );
|
|
|
+
|
|
|
+ @override
|
|
|
+ void onClose() {
|
|
|
+ uploadFileManager.deleteUploadInfoBySceneType(uploadSceneType);
|
|
|
+ super.onClose();
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
void onReady() {
|
|
|
super.onReady();
|
|
|
@@ -70,10 +99,7 @@ class ConversationAnalysisController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/// 选中选项
|
|
|
- void selectOption(
|
|
|
- OptionSelectConfig rowConfig,
|
|
|
- OptionSelectItem optionItem,
|
|
|
- ) {
|
|
|
+ void selectOption(OptionSelectConfig rowConfig, OptionSelectItem optionItem) {
|
|
|
// 先全部反选
|
|
|
rowConfig.options =
|
|
|
rowConfig.options.map((ele) {
|
|
|
@@ -90,21 +116,74 @@ class ConversationAnalysisController extends BaseController {
|
|
|
void clickUnlockBtn(BuildContext context) async {}
|
|
|
|
|
|
/// 点击查看分析按钮
|
|
|
- void clickLookAnalyseBtn(BuildContext context) async {}
|
|
|
+ void clickLookAnalyseBtn(BuildContext context) async {
|
|
|
+ // TODO hezihao,要请求接口,进行分析,出报告,现在先让通过
|
|
|
+ hasReport.value = true;
|
|
|
+ }
|
|
|
|
|
|
/// 点击上传按钮
|
|
|
void clickUploadBtn(BuildContext context) async {
|
|
|
+ // 计算还可以上传多少张图片
|
|
|
+ int count =
|
|
|
+ intimacyAnalyzeConfigHelper.getMaxAssetsCount() - uploadInfoList.length;
|
|
|
+
|
|
|
// 跳转到图片选择,并返回选择的图片列表
|
|
|
List<AssetEntity> selectedAssetList = await ImagePickerUtil.pickImage(
|
|
|
context,
|
|
|
- maxAssetsCount: 9,
|
|
|
+ maxAssetsCount: count,
|
|
|
);
|
|
|
// 选择了图片,切换到上传视图
|
|
|
if (selectedAssetList.isNotEmpty) {
|
|
|
+ _handleSelectedAssetUpload(selectedAssetList);
|
|
|
isUploadPage.value = true;
|
|
|
} else {
|
|
|
// 没选择图片,切换到例子视图
|
|
|
isUploadPage.value = false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// 删除上传信息
|
|
|
+ void deleteUploadInfo(UploadInfo uploadInfo) {
|
|
|
+ uploadFileManager.deleteUploadInfo(uploadInfo);
|
|
|
+ uploadInfoList.removeWhere((item) {
|
|
|
+ return item.id == uploadInfo.id;
|
|
|
+ });
|
|
|
+ uploadInfoList.refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 处理文件上传
|
|
|
+ void _handleSelectedAssetUpload(List<AssetEntity> selectedAssetList) async {
|
|
|
+ for (var entity in selectedAssetList) {
|
|
|
+ // 获取文件路径
|
|
|
+ File? file = await entity.file;
|
|
|
+ if (file == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 添加到上传列表
|
|
|
+ uploadInfoList.add(
|
|
|
+ uploadFileManager.uploadFile(
|
|
|
+ sceneType: uploadSceneType,
|
|
|
+ file: file,
|
|
|
+ onUploadInfoUpdateCallback: (uploadInfo) {
|
|
|
+ // 上传信息更新时回调,更新UI
|
|
|
+ _updateUploadInfo(uploadInfo);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ uploadInfoList.refresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 更新上传信息
|
|
|
+ void _updateUploadInfo(UploadInfo uploadInfo) {
|
|
|
+ // 更新上传信息
|
|
|
+ var newList = [...uploadInfoList];
|
|
|
+ newList.map((item) {
|
|
|
+ if (item.id == uploadInfo.id) {
|
|
|
+ return uploadInfo;
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ }).toList();
|
|
|
+ uploadInfoList.value = newList;
|
|
|
+ }
|
|
|
}
|