Browse Source

[New]新增文件搜索页临时逻辑

zhipeng 1 year ago
parent
commit
f70e97a511

+ 0 - 1
lib/base/base_request.dart

@@ -1,6 +1,5 @@
 import 'dart:io';
 
-import 'package:electronic_assistant/data/repositories/account_repository.dart';
 import 'package:electronic_assistant/utils/app_info_util.dart';
 import 'package:electronic_assistant/utils/mmkv_util.dart';
 import 'package:flutter/cupertino.dart';

+ 11 - 0
lib/module/chat/controller.dart

@@ -17,6 +17,7 @@ import 'package:pull_to_refresh/pull_to_refresh.dart';
 import 'package:uuid/uuid.dart';
 
 import '../../data/bean/talks.dart';
+import '../../router/app_pages.dart';
 import '../../utils/http_handler.dart';
 
 class ChatController extends BaseController {
@@ -84,6 +85,16 @@ class ChatController extends BaseController {
     _sendMessage(chatContent);
   }
 
+  void onAddFileClick() {
+    Get.toNamed(RoutePath.fileSearch)?.then((talkInfo) {
+      if (talkInfo is TalkBean) {
+        this.talkInfo.value = talkInfo;
+        agenda.value = null;
+        sendInitialMessage();
+      }
+    });
+  }
+
   void loadMoreHistory() {
     bool isEmpty = chatItems.isEmpty;
 

+ 9 - 4
lib/module/chat/view.dart

@@ -187,10 +187,15 @@ class ChatPage extends BasePage<ChatController> {
                         minLines: null,
                       ),
                     )),
-                    Image(
-                        image: Assets.images.iconChatAddFile.provider(),
-                        width: 26.w,
-                        height: 26.w),
+                    GestureDetector(
+                      onTap: () {
+                        controller.onAddFileClick();
+                      },
+                      child: Image(
+                          image: Assets.images.iconChatAddFile.provider(),
+                          width: 26.w,
+                          height: 26.w),
+                    ),
                     Container(
                       margin: EdgeInsets.only(left: 16.w),
                       child: GestureDetector(

+ 51 - 0
lib/module/files/search/controller.dart

@@ -0,0 +1,51 @@
+import 'package:electronic_assistant/base/base_controller.dart';
+import 'package:flutter/cupertino.dart';
+import 'package:get/get_rx/src/rx_types/rx_types.dart';
+import 'package:pull_to_refresh/pull_to_refresh.dart';
+
+import '../../../data/bean/talks.dart';
+import '../../../data/repositories/talk_repository.dart';
+import '../../../utils/error_handler.dart';
+
+class FileSearchController extends BaseController {
+  final refreshController = RefreshController(initialRefresh: false);
+
+  int page = 1;
+
+  int pageSize = 10;
+
+  @override
+  void onReady() {
+    super.onReady();
+    onRefreshData();
+  }
+
+  RxList<Rx<TalkBean>> get talkList => talkRepository.talkList;
+
+  void requestTalkData({int page = 1}) {
+    talkRepository.requestTalkPagePaginate(page, pageSize).then((response) {
+      debugPrint("requestTalkData-response-$response");
+      if (talkRepository.talkList.length >= response.count) {
+        debugPrint("requestTalkData-没有更多数据了");
+        refreshController.loadNoData();
+      } else {
+        refreshController.loadComplete();
+      }
+      refreshController.refreshCompleted();
+    }).catchError((error) {
+      debugPrint("requestTalkData-catchError-$error");
+      refreshController.loadFailed();
+      refreshController.refreshFailed();
+      ErrorHandler.toastError(error);
+    });
+  }
+
+  void onRefreshData() {
+    page = 1;
+    requestTalkData(page: page);
+  }
+
+  void onLoadMoreTalkData() {
+    requestTalkData(page: ++page);
+  }
+}

+ 292 - 166
lib/module/files/search/view.dart

@@ -1,179 +1,305 @@
 import 'package:electronic_assistant/base/base_page.dart';
 import 'package:electronic_assistant/resource/assets.gen.dart';
 import 'package:electronic_assistant/resource/colors.gen.dart';
-import 'package:flutter/cupertino.dart';
+import 'package:electronic_assistant/utils/expand.dart';
+import 'package:electronic_assistant/utils/toast_util.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:get/get.dart';
-import 'package:get/get_core/src/get_main.dart';
+import 'package:pull_to_refresh/pull_to_refresh.dart';
 
-class FileSearchPage extends BasePage {
+import '../../../data/bean/talks.dart';
+import '../../../resource/string.gen.dart';
+import 'controller.dart';
+
+class FileSearchPage extends BasePage<FileSearchController> {
   const FileSearchPage({super.key});
 
   @override
-  Widget buildBody(BuildContext context) {
-    return Column(children: [
-      Row(
-        children: [
-          Expanded(
-              child: Padding(
-                padding: EdgeInsets.only(left: 12.w),
-                child: CupertinoSearchTextField(
-                  placeholder: '搜索所有文件标题 / 内容',
-                  prefixIcon:
-                  ImageIcon(Assets.images.iconSearch.provider(), size: 20.w),
-                  backgroundColor: const Color(0xFFF6F6F6),
-                  style:
-                  TextStyle(fontSize: 14.w, color: ColorName.primaryTextColor),
-                  placeholderStyle:
-                  TextStyle(fontSize: 14.w, color: const Color(0xFFAFAFAF)),
-                ),
-              )),
-          TextButton(
-              onPressed: () {
-                Get.back();
-              },
-              child: Text('取消',
-                  style: TextStyle(
-                      fontSize: 14.w, color: ColorName.secondaryTextColor))),
-        ],
-      ),
-      Padding(
-        padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 12.w),
-        child: Row(children: [
-          Text(
-            "搜索结果",
-            style: TextStyle(
-                fontSize: 15.w,
-                color: ColorName.primaryTextColor,
-                fontWeight: FontWeight.bold),
-          ),
-          Expanded(
+  bool immersive() {
+    return true;
+  }
+
+  Widget _buildFileItem(BuildContext context, int index) {
+    return Obx(() {
+      TalkBean talkBean = controller.talkList[index].value;
+      return Padding(
+          padding: EdgeInsets.only(bottom: 8.w),
+          child: GestureDetector(
+            onTap: () {
+              if (talkBean.status == TalkStatus.analysisSuccess) {
+                Get.back(result: talkBean);
+              } else {
+                ToastUtil.showToast("谈话未分析,请选择其他文件");
+              }
+            },
+            child: Container(
+              decoration: BoxDecoration(
+                color: Colors.white,
+                borderRadius: BorderRadius.circular(8.w),
+              ),
+              padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 14.w),
               child: Row(
-                mainAxisAlignment: MainAxisAlignment.end,
+                crossAxisAlignment: CrossAxisAlignment.start,
                 children: [
-                  Text("更新时间排序",
-                      style: TextStyle(
-                          fontSize: 14.w,
-                          fontWeight: FontWeight.bold,
-                          color: ColorName.primaryTextColor)),
                   Image(
-                      image: Assets.images.iconArrowDown.provider(),
-                      width: 16.w,
-                      height: 16.w)
-                ],
-              ))
-        ]),
-      ),
-      Visibility(
-        visible: true,
-        child: Expanded(
-            child: Stack(
-              fit: StackFit.expand,
-              children: [
-                Padding(
-                  padding: EdgeInsets.symmetric(horizontal: 12.w),
-                  child: CustomScrollView(
-                    slivers: [
-                      SliverToBoxAdapter(
-                          child: Text("文件夹",
-                              style: TextStyle(
-                                  fontSize: 14.w,
-                                  color: ColorName.secondaryTextColor))),
-                      SliverAnimatedList(
-                        itemBuilder: _dirItemBuilder,
-                        initialItemCount: 5,
-                      ),
-                      SliverToBoxAdapter(
-                          child: Container(
-                            margin: EdgeInsets.only(top: 8.w),
-                            child: Text("谈话",
-                                style: TextStyle(
-                                    fontSize: 14.w,
-                                    color: ColorName.secondaryTextColor)),
-                          )),
-                      SliverAnimatedList(
-                        itemBuilder: _fileItemBuilder,
-                        initialItemCount: 5,
-                      ),
-                    ],
-                  ),
-                ),
-                Visibility(
-                  visible: false,
-                  child: Stack(
-                    children: [
-                      Container(
-                        color: ColorName.black55,
-                      ),
-                      Container(
-                        // color: ColorName.white,
-                        width: double.infinity,
-                        decoration: BoxDecoration(
-                            color: ColorName.white,
-                            borderRadius: BorderRadius.only(
-                                bottomLeft: Radius.circular(16.w),
-                                bottomRight: Radius.circular(16.w))),
-                        child: Padding(
-                          padding:
-                          EdgeInsets.symmetric(horizontal: 12.w, vertical: 12
-                              .w),
-                          child: IntrinsicHeight(
-                            child: Column(
-                              children: [
-                                Container(
-                                  margin: EdgeInsets.only(bottom: 22.w),
-                                  child: Row(
-                                    children: [
-                                      const Expanded(
-                                          child: Text('更新时间排序',
-                                              style: TextStyle(
-                                                  fontSize: 14,
-                                                  fontWeight: FontWeight.bold,
-                                                  color: ColorName
-                                                      .colorPrimary))),
-                                      ImageIcon(
-                                          Assets.images.iconFilesOrderSelected
-                                              .provider(),
-                                          size: 20.w,
-                                          color: ColorName.colorPrimary)
-                                    ],
-                                  ),
-                                ),
-                                Container(
-                                  margin: EdgeInsets.only(bottom: 6.w),
-                                  child: Row(
-                                    children: [
-                                      const Expanded(
-                                          child: Text('创建时间排序')),
-                                      ImageIcon(
-                                          Assets.images.iconFilesOrderSelected
-                                              .provider(),
-                                          size: 20.w)
-                                    ],
-                                  ),
-                                )
-                              ],
-                            ),
+                      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)),
+                            ],
                           ),
-                        ),
-                      )
-                    ],
-                  ),
-                )
-              ],
-            )),
-      )
-    ]);
+                        )
+                      ],
+                    ),
+                  )),
+                ],
+              ),
+            ),
+          ));
+    });
   }
 
   @override
-  bool immersive() {
-    return false;
+  Widget buildBody(BuildContext context) {
+    return Scaffold(
+      backgroundColor: const Color.fromRGBO(246, 245, 248, 1),
+      appBar: AppBar(
+        title: Text(StringName.talkAll.tr),
+        backgroundColor: const Color.fromRGBO(246, 245, 248, 1),
+        scrolledUnderElevation: 0,
+        leading: IconButton(
+          icon: const Icon(Icons.arrow_back_ios_new_rounded),
+          onPressed: () {
+            Navigator.pop(context);
+          },
+        ),
+      ),
+      body: Column(
+        children: [
+          Expanded(
+              child: Padding(
+            padding: EdgeInsets.only(left: 12.w, right: 12.w),
+            child: SmartRefresher(
+              enablePullUp: true,
+              enablePullDown: true,
+              controller: controller.refreshController,
+              onRefresh: controller.onRefreshData,
+              onLoading: controller.onLoadMoreTalkData,
+              child: CustomScrollView(
+                slivers: [
+                  Obx(() {
+                    return SliverList.builder(
+                        itemBuilder: _buildFileItem,
+                        itemCount: controller.talkList.length);
+                  }),
+                ],
+              ),
+            ),
+          ))
+        ],
+      ),
+    );
+
+    // return Column(children: [
+    //   Row(
+    //     children: [
+    //       Expanded(
+    //           child: Padding(
+    //             padding: EdgeInsets.only(left: 12.w),
+    //             child: CupertinoSearchTextField(
+    //               placeholder: '搜索所有文件标题 / 内容',
+    //               prefixIcon:
+    //               ImageIcon(Assets.images.iconSearch.provider(), size: 20.w),
+    //               backgroundColor: const Color(0xFFF6F6F6),
+    //               style:
+    //               TextStyle(fontSize: 14.w, color: ColorName.primaryTextColor),
+    //               placeholderStyle:
+    //               TextStyle(fontSize: 14.w, color: const Color(0xFFAFAFAF)),
+    //             ),
+    //           )),
+    //       TextButton(
+    //           onPressed: () {
+    //             Get.back();
+    //           },
+    //           child: Text('取消',
+    //               style: TextStyle(
+    //                   fontSize: 14.w, color: ColorName.secondaryTextColor))),
+    //     ],
+    //   ),
+    //   Padding(
+    //     padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 12.w),
+    //     child: Row(children: [
+    //       Text(
+    //         "搜索结果",
+    //         style: TextStyle(
+    //             fontSize: 15.w,
+    //             color: ColorName.primaryTextColor,
+    //             fontWeight: FontWeight.bold),
+    //       ),
+    //       Expanded(
+    //           child: Row(
+    //             mainAxisAlignment: MainAxisAlignment.end,
+    //             children: [
+    //               Text("更新时间排序",
+    //                   style: TextStyle(
+    //                       fontSize: 14.w,
+    //                       fontWeight: FontWeight.bold,
+    //                       color: ColorName.primaryTextColor)),
+    //               Image(
+    //                   image: Assets.images.iconArrowDown.provider(),
+    //                   width: 16.w,
+    //                   height: 16.w)
+    //             ],
+    //           ))
+    //     ]),
+    //   ),
+    //   Visibility(
+    //     visible: true,
+    //     child: Expanded(
+    //         child: Stack(
+    //           fit: StackFit.expand,
+    //           children: [
+    //             Padding(
+    //               padding: EdgeInsets.symmetric(horizontal: 12.w),
+    //               child: CustomScrollView(
+    //                 slivers: [
+    //                   SliverToBoxAdapter(
+    //                       child: Text("文件夹",
+    //                           style: TextStyle(
+    //                               fontSize: 14.w,
+    //                               color: ColorName.secondaryTextColor))),
+    //                   SliverAnimatedList(
+    //                     itemBuilder: _dirItemBuilder,
+    //                     initialItemCount: 5,
+    //                   ),
+    //                   SliverToBoxAdapter(
+    //                       child: Container(
+    //                         margin: EdgeInsets.only(top: 8.w),
+    //                         child: Text("谈话",
+    //                             style: TextStyle(
+    //                                 fontSize: 14.w,
+    //                                 color: ColorName.secondaryTextColor)),
+    //                       )),
+    //                   SliverAnimatedList(
+    //                     itemBuilder: _fileItemBuilder,
+    //                     initialItemCount: 5,
+    //                   ),
+    //                 ],
+    //               ),
+    //             ),
+    //             Visibility(
+    //               visible: false,
+    //               child: Stack(
+    //                 children: [
+    //                   Container(
+    //                     color: ColorName.black55,
+    //                   ),
+    //                   Container(
+    //                     // color: ColorName.white,
+    //                     width: double.infinity,
+    //                     decoration: BoxDecoration(
+    //                         color: ColorName.white,
+    //                         borderRadius: BorderRadius.only(
+    //                             bottomLeft: Radius.circular(16.w),
+    //                             bottomRight: Radius.circular(16.w))),
+    //                     child: Padding(
+    //                       padding:
+    //                       EdgeInsets.symmetric(horizontal: 12.w, vertical: 12
+    //                           .w),
+    //                       child: IntrinsicHeight(
+    //                         child: Column(
+    //                           children: [
+    //                             Container(
+    //                               margin: EdgeInsets.only(bottom: 22.w),
+    //                               child: Row(
+    //                                 children: [
+    //                                   const Expanded(
+    //                                       child: Text('更新时间排序',
+    //                                           style: TextStyle(
+    //                                               fontSize: 14,
+    //                                               fontWeight: FontWeight.bold,
+    //                                               color: ColorName
+    //                                                   .colorPrimary))),
+    //                                   ImageIcon(
+    //                                       Assets.images.iconFilesOrderSelected
+    //                                           .provider(),
+    //                                       size: 20.w,
+    //                                       color: ColorName.colorPrimary)
+    //                                 ],
+    //                               ),
+    //                             ),
+    //                             Container(
+    //                               margin: EdgeInsets.only(bottom: 6.w),
+    //                               child: Row(
+    //                                 children: [
+    //                                   const Expanded(
+    //                                       child: Text('创建时间排序')),
+    //                                   ImageIcon(
+    //                                       Assets.images.iconFilesOrderSelected
+    //                                           .provider(),
+    //                                       size: 20.w)
+    //                                 ],
+    //                               ),
+    //                             )
+    //                           ],
+    //                         ),
+    //                       ),
+    //                     ),
+    //                   )
+    //                 ],
+    //               ),
+    //             )
+    //           ],
+    //         )),
+    //   )
+    // ]);
   }
 
-  Widget _dirItemBuilder(BuildContext context, int index,
-      Animation<double> animation) {
+  Widget _dirItemBuilder(
+      BuildContext context, int index, Animation<double> animation) {
     return Padding(
       padding: EdgeInsets.symmetric(vertical: 12.w),
       child: Row(
@@ -213,8 +339,8 @@ class FileSearchPage extends BasePage {
     );
   }
 
-  Widget _fileItemBuilder(BuildContext context, int index,
-      Animation<double> animation) {
+  Widget _fileItemBuilder(
+      BuildContext context, int index, Animation<double> animation) {
     return Padding(
       padding: EdgeInsets.symmetric(vertical: 12.w),
       child: Row(
@@ -252,18 +378,18 @@ class FileSearchPage extends BasePage {
                         Text('1m12s',
                             maxLines: 1,
                             style: TextStyle(
-                                fontSize: 12.w, color: ColorName
-                                .tertiaryTextColor)),
+                                fontSize: 12.w,
+                                color: ColorName.tertiaryTextColor)),
                         Text(' | ',
                             maxLines: 1,
                             style: TextStyle(
-                                fontSize: 12.w, color: ColorName
-                                .tertiaryTextColor)),
+                                fontSize: 12.w,
+                                color: ColorName.tertiaryTextColor)),
                         Text('2024-04-15 10:04',
                             maxLines: 1,
                             style: TextStyle(
-                                fontSize: 12.w, color: ColorName
-                                .tertiaryTextColor)),
+                                fontSize: 12.w,
+                                color: ColorName.tertiaryTextColor)),
                       ],
                     ),
                   )
@@ -275,4 +401,4 @@ class FileSearchPage extends BasePage {
       ),
     );
   }
-}
+}

+ 3 - 1
lib/router/app_pages.dart

@@ -1,12 +1,13 @@
 import 'package:electronic_assistant/module/files/controller.dart';
+import 'package:electronic_assistant/module/files/search/controller.dart';
 import 'package:electronic_assistant/module/main/controller.dart';
+import 'package:electronic_assistant/module/record/controller.dart';
 import 'package:electronic_assistant/module/store/controller.dart';
 import 'package:electronic_assistant/module/store/view.dart';
 import 'package:electronic_assistant/module/talk/controller.dart';
 import 'package:electronic_assistant/module/talk/summary/controller.dart';
 import 'package:electronic_assistant/module/talk/todo/controller.dart';
 import 'package:electronic_assistant/module/talk/view.dart';
-import 'package:electronic_assistant/module/record/controller.dart';
 import 'package:electronic_assistant/module/task/search/task_search.dart';
 import 'package:electronic_assistant/module/task/view.dart';
 import 'package:get/get.dart';
@@ -69,6 +70,7 @@ class AppBinding extends Bindings {
     lazyPut(() => TodoController());
     lazyPut(() => StoreController());
     lazyPut(() => FilesController());
+    lazyPut(() => FileSearchController());
   }
 
   void lazyPut<S>(InstanceBuilderCallback<S> builder) {