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

+ 1 - 0
assets/string/base/string.xml

@@ -128,4 +128,5 @@
     <string name="popup_nearly_two_week">近两周</string>
     <string name="popup_nearly_a_month">近一个月</string>
     <string name="popup_custom_time">自定义时间</string>
+    <string name="popup_agenda_filter_txt">展示%s待办</string>
 </resources>

+ 2 - 1
lib/main.dart

@@ -1,6 +1,7 @@
 import 'dart:io';
 
 import 'package:atmob_channel_reader/atmob_channel_reader.dart';
+import 'package:electronic_assistant/data/consts/build_config.dart';
 import 'package:electronic_assistant/resource/colors.gen.dart';
 import 'package:electronic_assistant/resource/string.gen.dart';
 import 'package:electronic_assistant/resource/string_source.dart';
@@ -43,7 +44,7 @@ void main() async {
 }
 
 void checkEnv() {
-  if (!Constants.isProdEnv()) {
+  if (!Constants.isProdEnv() && !BuildConfig.isDebug) {
     ToastUtil.showToast('不是正式环境!!!', addPostFrame: true);
   }
 }

+ 57 - 8
lib/module/agenda/controller.dart

@@ -1,5 +1,7 @@
 import 'package:electronic_assistant/base/base_controller.dart';
 import 'package:electronic_assistant/data/repositories/agenda_repository.dart';
+import 'package:electronic_assistant/module/agenda/utils.dart';
+import 'package:electronic_assistant/popup/agenda_time_popup.dart';
 import 'package:electronic_assistant/utils/error_handler.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:get/get_rx/src/rx_types/rx_types.dart';
@@ -7,10 +9,14 @@ import 'package:pull_to_refresh/pull_to_refresh.dart';
 
 import '../../data/api/request/agenda_request.dart';
 import '../../data/bean/agenda.dart';
+import '../../utils/time_utils.dart';
 import 'detail/view.dart';
 
 class AgendaController extends BaseController {
-  String get filterTxt => '展示近两周待办';
+  AgendaTimeType? _timeFilterType;
+  final _filterTxt = ''.obs;
+
+  String get filterTxt => _filterTxt.value;
 
   final agendaDetailPopupTag = 'agendaDetailPopupTag';
   final todoIsExpanded = true.obs;
@@ -23,18 +29,43 @@ class AgendaController extends BaseController {
   final doneSize = 0.obs;
   final int limit = 10;
 
-  int _timeFilterIndex = 0;
-
-  int get timeFilterIndex => _timeFilterIndex;
+  AgendaTimeType? get timeFilterType => _timeFilterType;
+  DateRange? searchTime;
 
   @override
   void onReady() {
+    reset();
     refreshTodoTaskList();
     agendaDonePage(0, limit, isClearAll: true);
   }
 
-  void setTimeFilterIndex(int index) {
-    _timeFilterIndex = index;
+  void reset() {
+    _setTimeFilterType(AgendaTimeType.nearlyAWeek);
+  }
+
+  void onClickTimeType(AgendaTimeType type) {
+    _setTimeFilterType(type);
+    refreshTodoTaskList();
+    agendaDonePage(0, limit, isClearAll: true);
+  }
+
+  void _setTimeFilterType(AgendaTimeType type) {
+    _timeFilterType = type;
+    _filterTxt.value = getAgendaFilterTxt(type);
+    switch (type) {
+      case AgendaTimeType.nearlyAWeek:
+        searchTime = TimeUtils.getLastDates(const Duration(days: 7));
+        break;
+      case AgendaTimeType.nearlyTwoWeek:
+        searchTime = TimeUtils.getLastDates(const Duration(days: 14));
+        break;
+      case AgendaTimeType.nearlyAMonth:
+        searchTime = TimeUtils.getLastDates(const Duration(days: 31));
+        break;
+      case AgendaTimeType.customTime:
+        searchTime = TimeUtils.getLastDates(const Duration());
+        break;
+    }
   }
 
   void onLoadMoreDoneData() {
@@ -43,7 +74,12 @@ class AgendaController extends BaseController {
 
   agendaDonePage(int offset, int limit, {bool? isClearAll}) {
     agendaRepository
-        .agendaPage(offset, limit, completeStatus: TaskStatus.DONE)
+        .agendaPage(
+      offset, limit,
+      completeStatus: TaskStatus.DONE,
+      // startTime: searchTime?.startTime.millisecondsSinceEpoch,
+      // endTime: searchTime?.endTime.millisecondsSinceEpoch
+    )
         .then((response) {
       doneSize.value = response.count;
       if (isClearAll == true) {
@@ -68,7 +104,12 @@ class AgendaController extends BaseController {
 
   refreshTodoTaskList() {
     agendaRepository
-        .agendaPage(0, 999, completeStatus: TaskStatus.TODO)
+        .agendaPage(
+      0, 999,
+      completeStatus: TaskStatus.TODO,
+      // startTime: searchTime?.startTime.millisecondsSinceEpoch,
+      // endTime: searchTime?.endTime.millisecondsSinceEpoch
+    )
         .then((response) {
       agendaTodoList.clear();
       if (response.list != null) {
@@ -119,4 +160,12 @@ class AgendaController extends BaseController {
   void onAgendaUpdate(Agenda item) {
     AgendaDetailPage.start(item);
   }
+
+  void clearFilterTime() {
+    _timeFilterType = null;
+    _filterTxt.value = '';
+    searchTime = null;
+    refreshTodoTaskList();
+    agendaDonePage(0, limit, isClearAll: true);
+  }
 }

+ 33 - 0
lib/module/agenda/utils.dart

@@ -0,0 +1,33 @@
+import 'package:electronic_assistant/popup/agenda_time_popup.dart';
+import 'package:electronic_assistant/resource/string.gen.dart';
+import 'package:electronic_assistant/utils/expand.dart';
+import 'package:get/get.dart';
+
+String getAgendaFilterTxt(AgendaTimeType type,
+    {String? startTime, String? endTime}) {
+  String filterTxt;
+  switch (type) {
+    case AgendaTimeType.nearlyAWeek:
+      filterTxt = StringName.popupAgendaFilterTxt.tr
+          .replacePlaceholders([StringName.popupNearlyAWeek.tr]);
+      break;
+    case AgendaTimeType.nearlyTwoWeek:
+      filterTxt = StringName.popupAgendaFilterTxt.tr
+          .replacePlaceholders([StringName.popupNearlyTwoWeek.tr]);
+      break;
+    case AgendaTimeType.nearlyAMonth:
+      filterTxt = StringName.popupAgendaFilterTxt.tr
+          .replacePlaceholders([StringName.popupNearlyAMonth.tr]);
+      break;
+    case AgendaTimeType.customTime:
+      if (startTime == null || endTime == null) {
+        filterTxt = StringName.popupAgendaFilterTxt.tr
+            .replacePlaceholders([StringName.popupCustomTime.tr]);
+      } else {
+        filterTxt = StringName.popupAgendaFilterTxt.tr.replacePlaceholders(
+            ['${StringName.popupCustomTime.tr} $startTime-$endTime']);
+      }
+      break;
+  }
+  return filterTxt;
+}

+ 38 - 28
lib/module/agenda/view.dart

@@ -53,31 +53,41 @@ class AgendaPage extends BasePage<AgendaController> {
                       color: ColorName.primaryTextColor)),
               centerTitle: true,
             ),
-            _buildSearchView(),
-            SizedBox(height: 12.h),
-            Container(
-              margin: EdgeInsets.only(left: 12.w),
-              padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
-              decoration: BoxDecoration(
-                  color: const Color(0xFFE9E9E9),
-                  borderRadius: BorderRadius.circular(8.w)),
-              child: IntrinsicWidth(
-                child: Row(
-                  children: [
-                    Text(controller.filterTxt,
-                        style: TextStyle(
-                            fontSize: 13.sp,
-                            color: ColorName.secondaryTextColor)),
-                    SizedBox(width: 6.w),
-                    Opacity(
-                        opacity: 0.7,
-                        child: ImageIcon(
-                            Assets.images.iconTaskFilterClose.provider(),
-                            size: 16.w))
-                  ],
-                ),
-              ),
-            ),
+            // _buildSearchView(),
+            // SizedBox(height: 12.h),
+            // Obx(() {
+            //   return Visibility(
+            //     visible: controller.filterTxt.isNotEmpty,
+            //     child: Container(
+            //       margin: EdgeInsets.only(left: 12.w),
+            //       padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
+            //       decoration: BoxDecoration(
+            //           color: const Color(0xFFE9E9E9),
+            //           borderRadius: BorderRadius.circular(8.w)),
+            //       child: IntrinsicWidth(
+            //         child: Row(
+            //           children: [
+            //             Text(controller.filterTxt,
+            //                 style: TextStyle(
+            //                     fontSize: 13.sp,
+            //                     color: ColorName.secondaryTextColor)),
+            //             SizedBox(width: 6.w),
+            //             GestureDetector(
+            //               onTap: () {
+            //                 controller.clearFilterTime();
+            //               },
+            //               child: Opacity(
+            //                   opacity: 0.7,
+            //                   child: ImageIcon(
+            //                       Assets.images.iconTaskFilterClose.provider(),
+            //                       size: 16.w)),
+            //             )
+            //           ],
+            //         ),
+            //       ),
+            //     ),
+            //   );
+            // }),
             SizedBox(width: 7.h),
             Expanded(
                 child: SmartRefresher(
@@ -154,9 +164,9 @@ class AgendaPage extends BasePage<AgendaController> {
           return GestureDetector(
             onTap: () {
               showAgendaTimePopup(
-                  context, Alignment.bottomLeft, controller.timeFilterIndex,
-                  callback: (index) {
-                controller.setTimeFilterIndex(index);
+                  context, Alignment.bottomLeft, controller.timeFilterType,
+                  callback: (type) {
+                controller.onClickTimeType(type);
               });
             },
             child: Column(

+ 20 - 12
lib/popup/agenda_time_popup.dart

@@ -1,39 +1,47 @@
+import 'package:electronic_assistant/dialog/add_agenda_dialog.dart';
 import 'package:electronic_assistant/popup/template_utils.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
 import 'package:get/get.dart';
 
 import '../resource/string.gen.dart';
 import 'common_popup.dart';
 
-typedef AgendaPopupCallback = void Function(int index);
+typedef AgendaPopupCallback = void Function(AgendaTimeType type);
 
-void showAgendaTimePopup(BuildContext context, Alignment alignment,
-    int selectIndex,
+enum AgendaTimeType { nearlyAWeek, nearlyTwoWeek, nearlyAMonth, customTime }
+
+void showAgendaTimePopup(
+    BuildContext context, Alignment alignment, AgendaTimeType? type,
     {AgendaPopupCallback? callback}) {
-  showViewTargetPopup(context, alignment, [
-    createSelectItem(StringName.popupNearlyAWeek.tr, selectIndex == 0,
+  showViewTargetPopup(context, alignment, offset: Offset(-24.w, 0), [
+    createSelectItem(
+        StringName.popupNearlyAWeek.tr, type == AgendaTimeType.nearlyAWeek,
         onItemClick: () {
-          callback?.call(0);
+      callback?.call(AgendaTimeType.nearlyAWeek);
       SmartDialog.dismiss();
     }),
     createPopupDivider(),
-    createSelectItem(StringName.popupNearlyTwoWeek.tr, selectIndex == 1,
+    createSelectItem(
+        StringName.popupNearlyTwoWeek.tr, type == AgendaTimeType.nearlyTwoWeek,
         onItemClick: () {
-      callback?.call(1);
+      callback?.call(AgendaTimeType.nearlyTwoWeek);
       SmartDialog.dismiss();
     }),
     createPopupDivider(),
-    createSelectItem(StringName.popupNearlyAMonth.tr, selectIndex == 2,
+    createSelectItem(
+        StringName.popupNearlyAMonth.tr, type == AgendaTimeType.nearlyAMonth,
         onItemClick: () {
-      callback?.call(2);
+      callback?.call(AgendaTimeType.nearlyAMonth);
       SmartDialog.dismiss();
     }),
     createPopupDivider(),
-    createSelectItem(StringName.popupCustomTime.tr, selectIndex == 3,
+    createSelectItem(
+        StringName.popupCustomTime.tr, type == AgendaTimeType.customTime,
         onItemClick: () {
-      callback?.call(3);
+      callback?.call(AgendaTimeType.customTime);
       SmartDialog.dismiss();
     }),
   ]);

+ 5 - 3
lib/popup/common_popup.dart

@@ -46,12 +46,14 @@ void showPressTouchPopup(
   );
 }
 
-void showViewTargetPopup(
-    BuildContext context, Alignment alignment, List<Widget> childWidget) {
+void showViewTargetPopup(BuildContext context, Alignment alignment,
+    List<Widget> childWidget,
+    {Offset? offset}) {
   SmartDialog.showAttach(
     targetContext: context,
     targetBuilder: (targetOffset, targetSize) {
-      return Offset(targetOffset.dx, targetOffset.dy);
+      return Offset(targetOffset.dx + (offset != null ? offset.dx : 0),
+          targetOffset.dy + (offset != null ? offset.dy : 0));
     },
     alignment: alignment,
     animationType: SmartAnimationType.fade,

+ 19 - 0
lib/utils/time_utils.dart

@@ -0,0 +1,19 @@
+class DateRange {
+  DateTime startTime;
+  DateTime endTime;
+
+  DateRange(this.startTime, this.endTime);
+}
+
+class TimeUtils {
+  //获得离当前最近的时间段
+  static DateRange getLastDates(Duration duration) {
+    DateTime now = DateTime.now();
+    DateTime endTime = DateTime(now.year, now.month, now.day, 23, 59, 59);
+    DateTime startTime =
+        endTime.subtract(duration).add(const Duration(days: 1));
+    startTime =
+        DateTime(startTime.year, startTime.month, startTime.day, 0, 0, 0);
+    return DateRange(startTime, endTime);
+  }
+}