Переглянути джерело

[new]增加任务刷新功能

zk 1 рік тому
батько
коміт
04ec82f415

+ 9 - 0
lib/data/repositories/talk_repository.dart

@@ -24,6 +24,15 @@ class TalkRepository {
 
   RxList<Rxn<TalkBean>> get talkList => _talkList;
 
+  void renovateTalkData(TalkBean talkInfo) {
+    for (int i = 0; i < _talkList.length; i++) {
+      if (_talkList[i].value?.id == talkInfo.id) {
+        _talkList[i].value = talkInfo;
+        break;
+      }
+    }
+  }
+
   void addNewTalkData(TalkBean talkInfo) {
     _talkList.insert(0, Rxn<TalkBean>(talkInfo));
   }

+ 15 - 3
lib/data/repositories/task_repository.dart

@@ -2,8 +2,10 @@ import 'package:electronic_assistant/base/app_base_request.dart';
 import 'package:electronic_assistant/data/api/atmob_api.dart';
 import 'package:electronic_assistant/data/api/response/talk_query_response.dart';
 import 'package:electronic_assistant/data/bean/talks.dart';
+import 'package:electronic_assistant/data/repositories/talk_repository.dart';
 import 'package:electronic_assistant/utils/async_util.dart';
 import 'package:electronic_assistant/utils/cancel_future.dart';
+import 'package:electronic_assistant/utils/toast_util.dart';
 import 'package:flutter/cupertino.dart';
 import '../../utils/http_handler.dart';
 import '../api/request/talk_query_request.dart';
@@ -68,15 +70,22 @@ class TaskRepository {
     String taskIds = electronicTasks.join(',');
     return atmobApi
         .talkQuery(TalkQueryRequest(taskIds))
-        .then(HttpHandler.handle(false))
-        .then((response) => _dealTaskStatus(response));
+        .then(HttpHandler.handle(true))
+        .then((response) => _dealTaskStatus(response))
+        .then((data) {
+      if (electronicTasks.isEmpty) {
+        return;
+      } else {
+        throw Exception('task not finished');
+      }
+    });
   }
 
   Future<void> _dealTaskStatus(TalkQueryResponse response) {
     response.talks?.forEach((element) {
       if (element.status == TalkStatus.analysing ||
           element.status == TalkStatus.waitAnalysis) {
-        //TODO 刷新生成中的bean类数据
+        talkRepository.renovateTalkData(element);
       } else if (element.status == TalkStatus.analysisSuccess ||
           element.status == TalkStatus.analysisFail) {
         electronicTasks.remove(element.taskId);
@@ -90,10 +99,13 @@ class TaskRepository {
   }
 
   void _notifyGenerationStatus(TalkBean element) {
+    talkRepository.renovateTalkData(element);
     if (element.status == TalkStatus.analysisSuccess) {
       debugPrint('生成成功-${element.id}');
+      ToastUtil.showToast('生成成功');
     } else if (element.status == TalkStatus.analysisFail) {
       debugPrint('生成失败-${element.id}');
+      ToastUtil.showToast('生成失败');
     }
   }
 

+ 77 - 74
lib/module/files/view.dart

@@ -163,80 +163,83 @@ class FilesPage extends BasePage<FilesController> {
   }
 
   Widget _buildFileItem(BuildContext context, int index) {
-    TalkBean? talkBean = controller.talkList[index].value;
-    if (talkBean == null) {
-      return Container();
-    }
-    return Padding(
-        padding: EdgeInsets.only(bottom: 8.w),
-        child: GestureDetector(
-          onTap: () {
-            TalkPage.start(talkBean);
-          },
-          child: Container(
-            decoration: BoxDecoration(
-              color: Colors.white,
-              borderRadius: BorderRadius.circular(8.w),
-            ),
-            padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 14.w),
-            child: Row(
-              crossAxisAlignment: CrossAxisAlignment.start,
-              children: [
-                Image(
-                    image: (talkBean.status == TalkStatus.analysing ||
-                            talkBean.status == TalkStatus.waitAnalysis)
-                        ? Assets.images.iconTalkAnalysis.provider()
-                        : Assets.images.iconFilesFile.provider(),
-                    width: 28.w,
-                    height: 32.w),
-                Expanded(
-                    child: Padding(
-                  padding: EdgeInsets.symmetric(horizontal: 8.w),
-                  child: Column(
-                    crossAxisAlignment: CrossAxisAlignment.start,
-                    children: [
-                      Text(talkBean.title.orEmpty,
-                          maxLines: 1,
-                          overflow: TextOverflow.ellipsis,
-                          style: TextStyle(
-                              fontSize: 14.sp,
-                              color: ColorName.primaryTextColor,
-                              fontWeight: FontWeight.bold)),
-                      Text(talkBean.summary.orEmpty,
-                          maxLines: 2,
-                          overflow: TextOverflow.ellipsis,
-                          style: TextStyle(
-                              fontSize: 12.sp,
-                              color: talkBean.status == TalkStatus.analysisFail
-                                  ? "#F5574E".toColor()
-                                  : ColorName.secondaryTextColor)),
-                      Container(
-                        margin: EdgeInsets.only(top: 6.w),
-                        child: Row(
-                          crossAxisAlignment: CrossAxisAlignment.center,
-                          children: [
-                            Text(talkBean.duration.toFormattedDuration(),
-                                style: TextStyle(
-                                    fontSize: 12.sp,
-                                    color: ColorName.tertiaryTextColor)),
-                            Text("  |  ",
-                                style: TextStyle(
-                                    fontSize: 12.sp,
-                                    color: ColorName.tertiaryTextColor,
-                                    fontWeight: FontWeight.bold)),
-                            Text(talkBean.createTime.orEmpty,
-                                style: TextStyle(
-                                    fontSize: 12.sp,
-                                    color: ColorName.tertiaryTextColor)),
-                          ],
-                        ),
-                      )
-                    ],
-                  ),
-                )),
-              ],
+    return Obx(() {
+      TalkBean? talkBean = controller.talkList[index].value;
+      if (talkBean == null) {
+        return Container();
+      }
+      return Padding(
+          padding: EdgeInsets.only(bottom: 8.w),
+          child: GestureDetector(
+            onTap: () {
+              TalkPage.start(talkBean);
+            },
+            child: Container(
+              decoration: BoxDecoration(
+                color: Colors.white,
+                borderRadius: BorderRadius.circular(8.w),
+              ),
+              padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 14.w),
+              child: Row(
+                crossAxisAlignment: CrossAxisAlignment.start,
+                children: [
+                  Image(
+                      image: (talkBean.status == TalkStatus.analysing ||
+                              talkBean.status == TalkStatus.waitAnalysis)
+                          ? Assets.images.iconTalkAnalysis.provider()
+                          : Assets.images.iconFilesFile.provider(),
+                      width: 28.w,
+                      height: 32.w),
+                  Expanded(
+                      child: Padding(
+                    padding: EdgeInsets.symmetric(horizontal: 8.w),
+                    child: Column(
+                      crossAxisAlignment: CrossAxisAlignment.start,
+                      children: [
+                        Text(talkBean.title.orEmpty,
+                            maxLines: 1,
+                            overflow: TextOverflow.ellipsis,
+                            style: TextStyle(
+                                fontSize: 14.sp,
+                                color: ColorName.primaryTextColor,
+                                fontWeight: FontWeight.bold)),
+                        Text(talkBean.summary.orEmpty,
+                            maxLines: 2,
+                            overflow: TextOverflow.ellipsis,
+                            style: TextStyle(
+                                fontSize: 12.sp,
+                                color:
+                                    talkBean.status == TalkStatus.analysisFail
+                                        ? "#F5574E".toColor()
+                                        : ColorName.secondaryTextColor)),
+                        Container(
+                          margin: EdgeInsets.only(top: 6.w),
+                          child: Row(
+                            crossAxisAlignment: CrossAxisAlignment.center,
+                            children: [
+                              Text(talkBean.duration.toFormattedDuration(),
+                                  style: TextStyle(
+                                      fontSize: 12.sp,
+                                      color: ColorName.tertiaryTextColor)),
+                              Text("  |  ",
+                                  style: TextStyle(
+                                      fontSize: 12.sp,
+                                      color: ColorName.tertiaryTextColor,
+                                      fontWeight: FontWeight.bold)),
+                              Text(talkBean.createTime.orEmpty,
+                                  style: TextStyle(
+                                      fontSize: 12.sp,
+                                      color: ColorName.tertiaryTextColor)),
+                            ],
+                          ),
+                        )
+                      ],
+                    ),
+                  )),
+                ],
+              ),
             ),
-          ),
-        ));
+          ));
+    });
   }
 }