From ee41ad7d1bb33e02e05551e0f63f1cfbf0adc2cc Mon Sep 17 00:00:00 2001 From: "1147192855@qq.com" <1147192855@qq.com> Date: Thu, 11 Apr 2024 15:53:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=9C=E4=B8=9A=E9=A6=96?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/event_bus/job_home_refresh_bus.dart | 12 +++ .../lib/pages/homework_correction/index.dart | 66 +++++++------ .../pages/homework_correction/job_home.dart | 96 ++++++++++++++----- marking_app/lib/routes/RouterManager.dart | 72 ++++++-------- 4 files changed, 151 insertions(+), 95 deletions(-) create mode 100644 marking_app/lib/common/model/event_bus/job_home_refresh_bus.dart diff --git a/marking_app/lib/common/model/event_bus/job_home_refresh_bus.dart b/marking_app/lib/common/model/event_bus/job_home_refresh_bus.dart new file mode 100644 index 0000000..32f2485 --- /dev/null +++ b/marking_app/lib/common/model/event_bus/job_home_refresh_bus.dart @@ -0,0 +1,12 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'job_home_refresh_bus.g.dart'; + +@JsonSerializable() +class JobHomeRefreshBus extends Object { + JobHomeRefreshBus(); + + factory JobHomeRefreshBus.fromJson(Map srcJson) => _$JobHomeRefreshBusFromJson(srcJson); + + Map toJson() => _$JobHomeRefreshBusToJson(this); +} diff --git a/marking_app/lib/pages/homework_correction/index.dart b/marking_app/lib/pages/homework_correction/index.dart index 196ffe3..51b9c4e 100644 --- a/marking_app/lib/pages/homework_correction/index.dart +++ b/marking_app/lib/pages/homework_correction/index.dart @@ -7,6 +7,8 @@ * @Description: 阅卷主页 */ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -16,7 +18,9 @@ import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:marking_app/common/config/request_config.dart'; +import 'package:marking_app/common/model/event_bus/job_home_refresh_bus.dart'; import 'package:marking_app/common/model/job/job_task_item.dart'; +import 'package:marking_app/pages/common/event_bus_mixin.dart'; import 'package:marking_app/pages/homework_correction/components/new_version_of_homework/homework_tasks_view_item.dart'; import 'package:marking_app/provider/review_provider.dart'; import 'package:marking_app/routes/RouterManager.dart'; @@ -40,14 +44,7 @@ class HomeworkCorrection extends StatefulHookConsumerWidget { } class _HomeworkCorrectionState extends ConsumerState - with - CommonMixin, - TickerProviderStateMixin, - RefreshDataHandle, - AutomaticKeepAliveClientMixin { - @override - bool get wantKeepAlive => true; - + with CommonMixin, EventBusMixin, TickerProviderStateMixin, RefreshDataHandle { /* Tab控制器 */ late TabController _tabController; late TabController _tabController2; @@ -127,6 +124,7 @@ class _HomeworkCorrectionState extends ConsumerState _tabController.dispose(); _refreshController1.dispose(); _refreshController2.dispose(); + eventCancel(); super.dispose(); } @@ -152,8 +150,6 @@ class _HomeworkCorrectionState extends ConsumerState @override Widget build(BuildContext context) { - super.build(context); //调用super.build(返回值始终返回null,应将其忽略) - return AnnotatedRegion( value: const SystemUiOverlayStyle( systemNavigationBarColor: Color(0xFF000000), @@ -176,7 +172,19 @@ class _HomeworkCorrectionState extends ConsumerState child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ - Expanded(flex: 1, child: SizedBox()), + Expanded( + flex: 1, + child: Container( + alignment: Alignment.centerLeft, + padding: EdgeInsets.only(left: 10.w), + child: InkWell( + onTap: () => easyThrottle('BACK_JOB_HOME', () => Navigator.of(context).pop()), + child: Icon( + Icons.arrow_back_ios_sharp, + size: 16.sp, + ), + ), + )), Expanded( flex: 4, child: Container( @@ -226,9 +234,7 @@ class _HomeworkCorrectionState extends ConsumerState child: quickText( '待批阅', size: 14.sp, - color: _tabIndex == 0 - ? Theme.of(context).primaryColor - : const Color.fromRGBO(80, 94, 110, 1), + color: _tabIndex == 0 ? Theme.of(context).primaryColor : const Color.fromRGBO(80, 94, 110, 1), fontWeight: _tabIndex == 0 ? FontWeight.bold : null, ), ), @@ -246,9 +252,7 @@ class _HomeworkCorrectionState extends ConsumerState child: quickText( '已批阅', size: 14.sp, - color: _tabIndex == 1 - ? Theme.of(context).primaryColor - : const Color.fromRGBO(80, 94, 110, 1), + color: _tabIndex == 1 ? Theme.of(context).primaryColor : const Color.fromRGBO(80, 94, 110, 1), fontWeight: _tabIndex == 1 ? FontWeight.bold : null, ), ), @@ -261,11 +265,9 @@ class _HomeworkCorrectionState extends ConsumerState flex: 1, child: InkWell( onTap: () { - RouterManager.router - .navigateTo(context, RouterManager.jobStudentGroupPath, transition: getTransition()); + RouterManager.router.navigateTo(context, RouterManager.jobStudentGroupPath, transition: getTransition()); }, - child: Icon(IconData(0xe63e, fontFamily: "AlibabaIcon"), - color: Color.fromRGBO(44, 48, 63, 1), size: 24.sp), + child: Icon(IconData(0xe63e, fontFamily: "AlibabaIcon"), color: Color.fromRGBO(44, 48, 63, 1), size: 24.sp), ), ), ], @@ -305,6 +307,9 @@ class _HomeworkCorrectionState extends ConsumerState data: markingDatas1, onLoad: onMyLoad, onRefresh: onMyRefresh, + eventFire: () { + eventFire(model: JobHomeRefreshBus()); + }, ), $EasyRefresh( controller: _refreshController2, @@ -313,6 +318,9 @@ class _HomeworkCorrectionState extends ConsumerState data: markingDatas2, onLoad: onMyLoad, onRefresh: onMyRefresh, + eventFire: () { + eventFire(model: JobHomeRefreshBus()); + }, ), ], ), @@ -334,6 +342,7 @@ Widget $easyRefresh({ required EasyRefreshController controller, required Future Function(EasyRefreshController controller, MarkingListParams params, int tab) onRefresh, required Future Function(EasyRefreshController controller, MarkingListParams params, int tab) onLoad, + required Function eventFire, required MarkingListParams params, required List data, required int tab, @@ -366,7 +375,10 @@ Widget $easyRefresh({ return HomeworkTasksViewItem( completed: completed, jobTaskItem: data[index], - call: () => controller.callRefresh(), + call: () { + controller.callRefresh(); + eventFire(); + }, ); }, itemCount: data.length, @@ -414,9 +426,7 @@ Widget $reviewedItem(BuildContext context, {required JobTaskItem jobTaskItem}) { alignment: Alignment.center, padding: EdgeInsets.only(left: 2.w), decoration: BoxDecoration( - color: jobTaskItem.markingTypeEnum.name == '作业' - ? const Color.fromRGBO(104, 136, 253, 1) - : const Color.fromRGBO(255, 175, 56, 1), + color: jobTaskItem.markingTypeEnum.name == '作业' ? const Color.fromRGBO(104, 136, 253, 1) : const Color.fromRGBO(255, 175, 56, 1), borderRadius: BorderRadius.only( topLeft: Radius.circular(14.r), topRight: Radius.circular(3.r), @@ -477,8 +487,7 @@ Widget $reviewedItem(BuildContext context, {required JobTaskItem jobTaskItem}) { onTap: () => easyThrottle('go_to_homework_report', () { RouterManager.router.navigateTo( context, - RouterManager.jobReportPagePath + - '?title=${Uri.encodeComponent(jobTaskItem.title)}&id=${jobTaskItem.id}', + RouterManager.jobReportPagePath + '?title=${Uri.encodeComponent(jobTaskItem.title)}&id=${jobTaskItem.id}', transition: getTransition(), ); }), @@ -521,8 +530,7 @@ Widget $theTabBar({required TabController controller, ValueChanged? onTap, if (customTime.endDate != null) { // print(customTime.startDate!.year == customTime.endDate!.year); if (!isPad() && customTime.startDate!.year == customTime.endDate!.year) { - customTimeStr = - customTime.startDate.toString().substring(5, 10) + '~${customTime.endDate.toString().substring(5, 10)}'; + customTimeStr = customTime.startDate.toString().substring(5, 10) + '~${customTime.endDate.toString().substring(5, 10)}'; } else { customTimeStr += '~${customTime.endDate?.toString().substring(0, 10)}'; } diff --git a/marking_app/lib/pages/homework_correction/job_home.dart b/marking_app/lib/pages/homework_correction/job_home.dart index 3fcb9db..9916e0a 100644 --- a/marking_app/lib/pages/homework_correction/job_home.dart +++ b/marking_app/lib/pages/homework_correction/job_home.dart @@ -2,10 +2,15 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:marking_app/common/mixin/common.dart'; +import 'package:marking_app/common/model/event_bus/job_home_refresh_bus.dart'; import 'package:marking_app/common/model/marking/marking_list_params.dart'; +import 'package:marking_app/pages/common/event_bus_mixin.dart'; +import 'package:marking_app/routes/RouterManager.dart'; import 'package:marking_app/utils/index.dart'; import 'package:marking_app/utils/my_text.dart'; +import 'package:badges/badges.dart' as badges; + import '../../utils/my_future_builder.dart'; class JobHome extends StatefulWidget { @@ -15,16 +20,16 @@ class JobHome extends StatefulWidget { State createState() => _JobHomeState(); } -class _JobHomeState extends State with CommonMixin, AutomaticKeepAliveClientMixin { +class _JobHomeState extends State with CommonMixin, EventBusMixin, AutomaticKeepAliveClientMixin { @override bool get wantKeepAlive => true; - late Future _future; + late Future _future; List entrances = [ EntranceModel( title: '作业批阅', image: '', - navigationUrl: '', + navigationUrl: RouterManager.jobMainListPagePath, ), EntranceModel( title: '学生历史作业', @@ -56,19 +61,32 @@ class _JobHomeState extends State with CommonMixin, AutomaticKeepAliveC @override void initState() { _future = getData(); + eventOn(callback: (JobHomeRefreshBus item) { + _future = getData(); + toUpState(setState, () {}, mounted); + }); super.initState(); } - Future getData() async { - var _client = await getClient(); - var _result = await _client.getJobsByPage(MarkingListParams( - isFinish: false, - page: 1, - limit: 1, - pageType: 0, - )); - if (_result == null) return 0; - return _result.data?.total ?? 0; + @override + void dispose() { + eventCancel(); + super.dispose(); + } + + Future getData() async { + try { + var _client = await getClient(); + var _result = await _client.getJobsByPage(MarkingListParams( + isFinish: false, + page: 1, + limit: 1, + pageType: 0, + )); + return _result.data?.total ?? 0; + } catch (e) { + return 0; + } } @override @@ -97,7 +115,7 @@ class _JobHomeState extends State with CommonMixin, AutomaticKeepAliveC _future = getData(); toUpState(setState, () {}, mounted); }, - child: MyFutureBuilder.buildFutureBuilderOfSingleInstance(context, _future, (data) { + child: MyFutureBuilder.buildFutureBuilderOfSingleInstance(context, _future, (data) { if (data == null) return Center( child: Container( @@ -112,22 +130,50 @@ class _JobHomeState extends State with CommonMixin, AutomaticKeepAliveC ); return Container( + padding: EdgeInsets.symmetric(vertical: 40.h, horizontal: 20.w), child: GridView( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, - mainAxisSpacing: 10.r, - crossAxisSpacing: 10.r, - childAspectRatio: 556 / 112, + mainAxisSpacing: 24.r, + crossAxisSpacing: 24.r, + childAspectRatio: 556 / 200, ), children: entrances.map((e) { - return Container( - alignment: Alignment.center, - child: Row( - children: [ - quickText(e.title), - ], - ), - ); + bool isJob = e.title == '作业批阅'; + + return InkWell( + onTap: () => easyThrottle('GO_TO_JOB_HOME_NAVIGATION', () { + RouterManager.router.navigateTo(context, e.navigationUrl, transition: getTransition()); + }), + child: badges.Badge( + showBadge: isJob && data > 0, + ignorePointer: false, + badgeContent: quickText(data, color: Colors.white), + badgeAnimation: badges.BadgeAnimation.rotation( + animationDuration: Duration(seconds: 1), + colorChangeAnimationDuration: Duration(seconds: 1), + loopAnimation: false, + curve: Curves.fastOutSlowIn, + colorChangeAnimationCurve: Curves.easeInCubic, + ), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(6.r)), + border: Border.all( + width: 0.5.w, + color: Color.fromARGB(255, 219, 226, 250), + ), + ), + alignment: Alignment.center, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // Image(image: e.image), + quickText(e.title, size: 12.sp), + ], + ), + ), + )); }).toList(), ), ); diff --git a/marking_app/lib/routes/RouterManager.dart b/marking_app/lib/routes/RouterManager.dart index 21516c5..0470c24 100644 --- a/marking_app/lib/routes/RouterManager.dart +++ b/marking_app/lib/routes/RouterManager.dart @@ -7,13 +7,12 @@ * @Description: 路由 */ -import 'dart:convert'; - import 'package:fluro/fluro.dart'; import 'package:flutter/material.dart'; import 'package:marking_app/common/model/enum/marking_list_type.dart'; import 'package:marking_app/pages/common/startUpPage.dart'; import 'package:marking_app/pages/homework_correction/do_papers_job_exam.dart'; +import 'package:marking_app/pages/homework_correction/index.dart'; import 'package:marking_app/pages/homework_correction/job_personal_detail.dart'; import 'package:marking_app/pages/homework_correction/job_priority_review_set.dart'; import 'package:marking_app/pages/homework_correction/job_report.dart'; @@ -64,6 +63,8 @@ class RouterManager { static const String jobListParticipateInClassPath = '/job/list/participateInClass'; // 作业 ==> 收藏页面 static const String jobFavoritePagePath = '/job/favorite/index'; +// 作业 ==> 列表页面 + static const String jobMainListPagePath = '/job/mainList/index'; static const String reportClassTeacherPath = 'report/details/reportClassTeacher'; static const String reportSubjectTeacherPath = 'report/details/reportSubjectTeacher'; @@ -100,18 +101,14 @@ class RouterManager { } // 启动页 - static final _startUpPageHandler = - Handler(handlerFunc: (BuildContext? context, Map> params) => const StartUpPage()); + static final _startUpPageHandler = Handler(handlerFunc: (BuildContext? context, Map> params) => const StartUpPage()); // 主页 - static final _mainPageHandler = - Handler(handlerFunc: (BuildContext? context, Map> params) => const TheMainPage()); + static final _mainPageHandler = Handler(handlerFunc: (BuildContext? context, Map> params) => const TheMainPage()); // 登录页 - static final _loginPageHandler = - Handler(handlerFunc: (BuildContext? context, Map> params) => const TheLogin()); + static final _loginPageHandler = Handler(handlerFunc: (BuildContext? context, Map> params) => const TheLogin()); // 阅卷进度页面 static final _progressPageHandler = Handler( - handlerFunc: (BuildContext? context, Map> params) => - Progress(int.parse(params['examSubjectId']![0]), params['name']![0])); + handlerFunc: (BuildContext? context, Map> params) => Progress(int.parse(params['examSubjectId']![0]), params['name']![0])); // 回评页面 static final _reviewPageHandler = Handler(handlerFunc: (BuildContext? context, Map> params) { int markingUserId = int.parse(params['markingUserId']![0]); @@ -130,11 +127,8 @@ class RouterManager { // 回评异常页面 static final _reviewAbnormalPageHandler = Handler( - handlerFunc: (BuildContext? context, Map> params) => ProgressAbnormal( - int.parse(params['examSubjectId']![0]), - params['markingId']![0], - params['name']![0], - params['questionNum']![0])); + handlerFunc: (BuildContext? context, Map> params) => + ProgressAbnormal(int.parse(params['examSubjectId']![0]), params['markingId']![0], params['name']![0], params['questionNum']![0])); // 阅卷页面 static final _markingDoPageHandler = Handler(handlerFunc: (BuildContext? context, Map> params) { try { @@ -176,8 +170,7 @@ class RouterManager { } }); // 批阅作业页面 - static final _markingHomeworkDoPageHandler = - Handler(handlerFunc: (BuildContext? context, Map> params) { + static final _markingHomeworkDoPageHandler = Handler(handlerFunc: (BuildContext? context, Map> params) { try { int taskId = int.parse(params['taskId']![0]); int jobId = int.parse(params['jobId']![0]); @@ -221,8 +214,7 @@ class RouterManager { handlerFunc: (BuildContext? context, Map> params) => const OhterPage(), ); - static final _reportClassTeacherPageHandler = - Handler(handlerFunc: (BuildContext? context, Map> params) { + static final _reportClassTeacherPageHandler = Handler(handlerFunc: (BuildContext? context, Map> params) { int examId = int.parse(params['examId']![0]); return ReportClassTeacher(examId: examId); @@ -292,7 +284,7 @@ class RouterManager { if (params['gradeId'] != null && params['gradeId']?[0] != null && params['gradeId']![0] != 'null') { gradeId = int.parse(params['gradeId']![0]); } - return QuickDataCheckPage(jobId: jobId, className: className,gradeName:gradeName,schoolId:schoolId,gradeId:gradeId); + return QuickDataCheckPage(jobId: jobId, className: className, gradeName: gradeName, schoolId: schoolId, gradeId: gradeId); }, ); @@ -310,7 +302,7 @@ class RouterManager { handlerFunc: (BuildContext? context, Map> params) { String groupId = params['groupId']![0]; String title = params['title']![0]; - return JobPriorityReviewSet(groupId: groupId,title:title); + return JobPriorityReviewSet(groupId: groupId, title: title); }, ); @@ -334,7 +326,7 @@ class RouterManager { if (params['gradeId'] != null && params['gradeId']?[0] != null && params['gradeId']![0] != 'null') { gradeId = int.parse(params['gradeId']![0]); } - return JobFavorite(jobId: jobId, gradeId: gradeId, schoolId: schoolId, className: className,jobName:jobName); + return JobFavorite(jobId: jobId, gradeId: gradeId, schoolId: schoolId, className: className, jobName: jobName); }, ); @@ -343,14 +335,19 @@ class RouterManager { handlerFunc: (BuildContext? context, Map> params) { String studentName = params['studentName']![0]; int studentId = int.parse(params['studentId']![0]); - return JobPersonalDetail(studentId: studentId,studentName:studentName); + return JobPersonalDetail(studentId: studentId, studentName: studentName); }, ); + // 优先配置个人详情 + static final _jobMainListPathHandler = Handler( + handlerFunc: (BuildContext? context, Map> params) => HomeworkCorrection(), + ); + // 学生报告详情 static final _reportCardDialogPathHandler = Handler( handlerFunc: (BuildContext? context, Map> params) { - /* String studentName = params['studentName']![0]; + /* String studentName = params['studentName']![0]; int studentId = int.parse(params['studentId']![0]); return ReportCardDialog(studentId: studentId,studentName:studentName);*/ }, @@ -358,7 +355,7 @@ class RouterManager { // 学生历史报告 static final _reportHistoryPathHandler = Handler( handlerFunc: (BuildContext? context, Map> params) { - /* String studentName = params['studentName']![0]; + /* String studentName = params['studentName']![0]; int studentId = int.parse(params['studentId']![0]);*/ return ReportHistory(); }, @@ -380,35 +377,28 @@ class RouterManager { router.define(markingReviewPath, handler: _reviewPageHandler, transitionType: TransitionType.material); router.define(markingJobReviewPath, handler: _reviewJobPageHandler, transitionType: TransitionType.material); router.define(markingDoPath, handler: _markingDoPageHandler, transitionType: TransitionType.material); - router.define(markingHomeworkDoPath, - handler: _markingHomeworkDoPageHandler, transitionType: TransitionType.material); - router.define(markingReviewAbnormalPath, - handler: _reviewAbnormalPageHandler, transitionType: TransitionType.material); + router.define(markingHomeworkDoPath, handler: _markingHomeworkDoPageHandler, transitionType: TransitionType.material); + router.define(markingReviewAbnormalPath, handler: _reviewAbnormalPageHandler, transitionType: TransitionType.material); router.define(agreementPath, handler: _agreementPageHandler, transitionType: TransitionType.material); router.define(ohterMainPagePath, handler: _ohterMainPageHandler, transitionType: TransitionType.material); - router.define(reportClassTeacherPath, - handler: _reportClassTeacherPageHandler, transitionType: TransitionType.material); - router.define(reportSubjectTeacherPath, - handler: _reportSubjectTeacherPageHandler, transitionType: TransitionType.material); - router.define(reportPersonalSubjectPath, - handler: _reportPersonalSubjectPageHandler, transitionType: TransitionType.material); + router.define(reportClassTeacherPath, handler: _reportClassTeacherPageHandler, transitionType: TransitionType.material); + router.define(reportSubjectTeacherPath, handler: _reportSubjectTeacherPageHandler, transitionType: TransitionType.material); + router.define(reportPersonalSubjectPath, handler: _reportPersonalSubjectPageHandler, transitionType: TransitionType.material); router.define(userMinePath, handler: _userMinePageHandler, transitionType: TransitionType.material); router.define(reportDetailPath, handler: _reportDetailPath, transitionType: TransitionType.material); router.define(jobReportPagePath, handler: _jobReportPageHandler, transitionType: TransitionType.material); router.define(jobExamPagePath, handler: _jobExamPageHandler, transitionType: TransitionType.material); - router.define(jobListParticipateInClassPath, - handler: _jobListParticipateInClassHandler, transitionType: TransitionType.material); + router.define(jobListParticipateInClassPath, handler: _jobListParticipateInClassHandler, transitionType: TransitionType.material); router.define(quickDataCheckPath, handler: _quickDataCheckPageHandler, transitionType: TransitionType.material); - router.define(quickCheckPersonalPath, - handler: _quickCheckPersonalPageHandler, transitionType: TransitionType.material); - router.define(jobPriorityReviewSetPath, - handler: _jobPriorityReviewSetPageHandler, transitionType: TransitionType.material); + router.define(quickCheckPersonalPath, handler: _quickCheckPersonalPageHandler, transitionType: TransitionType.material); + router.define(jobPriorityReviewSetPath, handler: _jobPriorityReviewSetPageHandler, transitionType: TransitionType.material); router.define(jobStudentGroupPath, handler: _jobStudentGroupPageHandler, transitionType: TransitionType.material); router.define(jobFavoritePagePath, handler: _jobFavoritePagePathHandler, transitionType: TransitionType.material); router.define(jobPersonalDetailPath, handler: _jobPersonalDetailPathHandler, transitionType: TransitionType.material); router.define(reportCardDialogPath, handler: _reportCardDialogPathHandler, transitionType: TransitionType.material); router.define(reportHistoryPath, handler: _reportHistoryPathHandler, transitionType: TransitionType.material); + router.define(jobMainListPagePath, handler: _jobMainListPathHandler, transitionType: TransitionType.material); // getTransition()