From 8e0522bc6b6b9e10aae57112eb2d00795400b40a Mon Sep 17 00:00:00 2001 From: machuanyu <840649825@qq.com> Date: Thu, 14 Mar 2024 09:14:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/model/job/job_fav_student.dart | 2 +- .../pages/favorite_student_dialog.dart | 173 +++++++++++--- .../pages/job_favorite.dart | 223 ++++++++++-------- .../lib/utils/request/rest_client.dart | 7 +- 4 files changed, 273 insertions(+), 132 deletions(-) diff --git a/marking_app/lib/common/model/job/job_fav_student.dart b/marking_app/lib/common/model/job/job_fav_student.dart index cad13e2..1b7c893 100644 --- a/marking_app/lib/common/model/job/job_fav_student.dart +++ b/marking_app/lib/common/model/job/job_fav_student.dart @@ -46,7 +46,7 @@ class Items extends Object { int teacherId; @JsonKey(name: 'teacherAccount') - String teacherAccount; + String? teacherAccount; @JsonKey(name: 'folderName') String folderName; diff --git a/marking_app/lib/pages/homework_correction/pages/favorite_student_dialog.dart b/marking_app/lib/pages/homework_correction/pages/favorite_student_dialog.dart index 8894ada..c4d03ee 100644 --- a/marking_app/lib/pages/homework_correction/pages/favorite_student_dialog.dart +++ b/marking_app/lib/pages/homework_correction/pages/favorite_student_dialog.dart @@ -1,17 +1,49 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:marking_app/common/model/job/job_fav_student.dart'; +import 'package:marking_app/utils/easy_refresh/MyEmptyWidget.dart'; +import 'package:photo_view/photo_view.dart'; import 'package:photo_view/photo_view_gallery.dart'; class FavoriteStudentDialog extends StatefulWidget { - const FavoriteStudentDialog({Key? key}) : super(key: key); + final Items item; + final List group; + final Function deleteFav; + + const FavoriteStudentDialog( + {Key? key, required this.item, required this.group,required this.deleteFav}) + : super(key: key); @override State createState() => _FavoriteStudentDialogState(); } class _FavoriteStudentDialogState extends State { - int defaultIndex = 1; + int defaultIndex = 0; + List imageList = []; + late PageController pageController; + late Items currentStudent; + + void initState() { + pageController = PageController(initialPage: defaultIndex); + currentStudent = widget.item; + List list = []; + widget.group.forEach((element) { + for (var item in element['list']) { + list.add(item); + } + }); + setState(() { + imageList = list; + defaultIndex = list.indexWhere((element) => element.id == widget.item.id); + }); + } + + void dispose() { + super.dispose(); + pageController.dispose(); + } @override Widget build(BuildContext context) { @@ -25,24 +57,34 @@ class _FavoriteStudentDialogState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Text( - '14班 张小凡', + '${currentStudent.className} ${currentStudent.studentName}', style: TextStyle(fontSize: 12.sp, color: Color(0xFF4E73FD)), ), Expanded(child: Container()), Text( - '6题', + '第${currentStudent.questionPage}页', style: TextStyle(fontSize: 12.sp, color: Color(0xFF868686)), ), - Padding( - padding: EdgeInsets.symmetric(horizontal: 8.r), - child: Image.asset( - 'assets/images/favorite_delete_icon.png', - width: 22.r, - height: 22.r, - ), - ), InkWell( onTap: (){ + widget.deleteFav(currentStudent); + imageList.removeAt(defaultIndex); + setState(() { + + }); + + }, + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 8.r), + child: Image.asset( + 'assets/images/favorite_delete_icon.png', + width: 22.r, + height: 22.r, + ), + ), + ), + InkWell( + onTap: () { Navigator.pop(context); }, child: Image.asset( @@ -53,47 +95,106 @@ class _FavoriteStudentDialogState extends State { ), ], ), - SizedBox(height: 10.r,), + SizedBox( + height: 10.r, + ), + imageList.length>0? Expanded( child: Container( - color:Color(0xFF868686), + color: Colors.white, width: MediaQuery.of(context).size.width, - /* child: PhotoViewGallery.builder( + child: PhotoViewGallery.builder( scrollPhysics: const BouncingScrollPhysics(), - builder: (BuildContext context, int index) { + builder: (BuildContext context, int index) { + final Items item = imageList[index]; return PhotoViewGalleryPageOptions( - imageProvider: NetworkImage(widget.imageItems[index]), + imageProvider: NetworkImage(item.questionPicture), + heroAttributes: PhotoViewHeroAttributes(tag: item.id), ); }, - itemCount: 2, - pageController:PageController(initialPage: defaultIndex), - // onPageChanged: (){}, + itemCount: imageList.length, + pageController: pageController, + onPageChanged: (index) { + setState(() { + defaultIndex = index; + currentStudent = imageList[index]; + }); + }, scrollDirection: Axis.horizontal, - ),*/ + + ), ), + ):Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).size.height/2 - 200.r), + child: MyEmptyWidget(), ), + if(imageList.length>0) Padding( - padding:EdgeInsets.symmetric(vertical: 15.r), + padding: EdgeInsets.symmetric(vertical: 15.r), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Container( -width: (MediaQuery.of(context).size.width - 78.r)/2 - 10.r, - height: 28.r, - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(6.r)), - border: Border.all(width: 1.r,color: Color(0xFFCACACA),style: BorderStyle.solid), + InkWell( + onTap: () { + if (defaultIndex > 0) { + setState(() { + defaultIndex = defaultIndex - 1; + pageController.jumpToPage(defaultIndex); + }); + } + }, + child: Container( + width: + (MediaQuery.of(context).size.width - 78.r) / 2 - 10.r, + height: 28.r, + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(6.r)), + border: Border.all( + width: 1.r, + color: Color(0xFFCACACA), + style: BorderStyle.solid), + ), + child: Center( + child: Text( + '上一页', + style: TextStyle( + fontSize: 10.r, + color: defaultIndex == 0 + ? Color(0xFFCACACA) + : Color(0xFF505E6E)), + )), ), - child: Center(child: Text('上一页',style: TextStyle(fontSize: 10.r,color: Color(0xFF505E6E)),)), ), - Container( - width: (MediaQuery.of(context).size.width - 78.r)/2 - 10.r, - height: 28.r, - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(6.r)), - border: Border.all(width: 1.r,color: Color(0xFFCACACA),style: BorderStyle.solid), + InkWell( + onTap: () { + if (defaultIndex < imageList.length - 1) { + setState(() { + defaultIndex = defaultIndex + 1; + pageController.jumpToPage(defaultIndex); + }); + } + }, + child: Container( + width: + (MediaQuery.of(context).size.width - 78.r) / 2 - 10.r, + height: 28.r, + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(6.r)), + border: Border.all( + width: 1.r, + color: Color(0xFFCACACA), + style: BorderStyle.solid), + ), + child: Center( + child: Text( + '下一页', + style: TextStyle( + fontSize: 10.r, + color: defaultIndex == imageList.length - 1 + ? Color(0xFFCACACA) + : Color(0xFF505E6E)), + )), ), - child: Center(child: Text('下一页',style: TextStyle(fontSize: 10.r,color: Color(0xFF505E6E)),)), ), ], ), diff --git a/marking_app/lib/pages/homework_correction/pages/job_favorite.dart b/marking_app/lib/pages/homework_correction/pages/job_favorite.dart index 484f19d..988169a 100644 --- a/marking_app/lib/pages/homework_correction/pages/job_favorite.dart +++ b/marking_app/lib/pages/homework_correction/pages/job_favorite.dart @@ -9,6 +9,7 @@ import 'package:marking_app/common/model/job/job_fav_student.dart'; import 'package:marking_app/common/model/job/job_favorite_item_model.dart'; import 'package:marking_app/common/model/job/job_report_join_class.dart'; import 'package:marking_app/pages/homework_correction/pages/favorite_student_dialog.dart'; +import 'package:marking_app/utils/easy_refresh/MyEmptyWidget.dart'; import 'package:marking_app/utils/index.dart'; import 'package:marking_app/utils/my_text.dart'; import 'package:marking_app/utils/request/rest_client.dart'; @@ -61,7 +62,7 @@ class _JobFavoriteState extends State with CommonMixin { Future> getData() async { var _client = await getClient(); var result = - await _client.getListOfJobFavorites(widget.jobId, widget.jobName, widget.className, loginName, pageSize); + await _client.getListOfJobFavorites(widget.jobId, widget.jobName, widget.className, pageSize); return result.data!.items; } @@ -89,20 +90,30 @@ class _JobFavoriteState extends State with CommonMixin { }); }, mounted); } - print('involveClasses=${involveClasses!.length}'); _future = getData(); } catch (e) { print(e); } } - void showStudentDialog(BuildContext context) { + deleteFav(Items student) async{ + RestClient _client = await getClient(); + BaseStructureResult res = await _client.getJobDeFavorites(widget.jobId,student.studentId,student.questionPage); + if(res.success){ + _future = getData(); + setState(() { + + }); + } + } + + void showStudentDialog(BuildContext context,Items item,List groups) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( insetPadding: EdgeInsets.all(25.r), - content: FavoriteStudentDialog(), + content: FavoriteStudentDialog(item: item,group: groups, deleteFav: deleteFav,), contentPadding: EdgeInsets.all(0), shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(15.r)))); }, @@ -127,17 +138,17 @@ class _JobFavoriteState extends State with CommonMixin { context, _future, (List? datas) { - /* if (datas == null) + if (datas == null) return Container( child: Center( child: quickText('请求错误'), ), - );*/ - print('datas${datas}'); - + ); List pageList = []; List groupList = []; + String name = ''; if (datas!.length > 0) { + name = datas[0].jobName; for (var item in datas) { pageList.add(item.questionPage); } @@ -147,8 +158,8 @@ class _JobFavoriteState extends State with CommonMixin { var printList = datas.where((element) => element.questionPage == page).toList(); groupList.add({"questionPage": page, "list": printList}); } + groupList.sort((a, b) => a['questionPage'].compareTo(b['questionPage'])); } - return Container( child: Column( children: [ @@ -158,7 +169,7 @@ class _JobFavoriteState extends State with CommonMixin { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - '函数A的对称性研究', + name, style: TextStyle(fontSize: 14.sp, color: Color(0xFF3C3C3C)), ), // 下拉框 @@ -186,74 +197,84 @@ class _JobFavoriteState extends State with CommonMixin { color: Color(0xFFCCCCCC), ), ), + groupList.length>0? Expanded( child: isPadFlag ? Padding( padding: EdgeInsets.only(top: 10.r, bottom: 8.r, left: 14.r, right: 14.r), child: Column( crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only(bottom: 5.r), - child: Text( - '第六题', - style: TextStyle(fontSize: 14.sp, color: Color(0xFF2E5BFF)), - ), - ), - GridView( - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - mainAxisSpacing: 8.r, - crossAxisSpacing: 10.r, - childAspectRatio: 556 / 112, - ), - shrinkWrap: true, + children: List.generate(groupList.length, (index) { + var item = groupList[index]; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Container( - padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 10.r), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(6.r)), - ), - child: InkWell( - onTap: () { - showStudentDialog(context); - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - quickText('张小凡', color: Color(0xFF333333), size: 12.sp), - Expanded(child: Container()), - Padding( - padding: EdgeInsets.only(right: 8.r), - child: Text( - '12班', - style: TextStyle(fontSize: 12.sp, color: Color(0xFF666666)), - ), - ), - InkWell( - onTap: () async { - print('删除'); - }, - child: Image.asset( - 'assets/images/favorite_delete_icon.png', - width: 26.r, - height: 26.r, - ), - ), - ], - ), + Padding( + padding: EdgeInsets.only(bottom: 5.r), + child: Text( + '第${item['questionPage']}页', + style: TextStyle(fontSize: 14.sp, color: Color(0xFF2E5BFF)), ), ), + GridView( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + mainAxisSpacing: 8.r, + crossAxisSpacing: 10.r, + childAspectRatio: 556 / 112, + ), + shrinkWrap: true, + children: List.generate(item['list'].length, (i){ + Items student = item['list'][i]; + return Container( + padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 10.r), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(6.r)), + ), + child: InkWell( + onTap: () { + showStudentDialog(context,student,groupList); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + quickText(student.studentName, color: Color(0xFF333333), size: 12.sp), + Expanded(child: Container()), + Padding( + padding: EdgeInsets.only(right: 8.r), + child: Text( + student.className, + style: TextStyle(fontSize: 12.sp, color: Color(0xFF666666)), + ), + ), + InkWell( + onTap: () async { + deleteFav(student); + }, + child: Image.asset( + 'assets/images/favorite_delete_icon.png', + width: 26.r, + height: 26.r, + ), + ), + ], + ), + ), + ); + }) + ), ], - ), - ], + ); + }) + + ), ) : ListView.builder( shrinkWrap: true, itemBuilder: (context, index) { - // Items item = datas[index]; + var item = groupList[index]; return Padding( padding: EdgeInsets.only(top: 10.r, bottom: 8.r, left: 14.r, right: 14.r), child: Column( @@ -262,47 +283,61 @@ class _JobFavoriteState extends State with CommonMixin { Padding( padding: EdgeInsets.only(bottom: 5.r), child: Text( - '第六题', + '第${item['questionPage']}页', style: TextStyle(fontSize: 14.sp, color: Color(0xFF2E5BFF)), ), ), - Container( - padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 10.r), - margin: EdgeInsets.only(top: 5.r), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(6.r)), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - quickText('张小凡', color: Color(0xFF333333), size: 14.sp), - Expanded(child: Container()), - Padding( - padding: EdgeInsets.only(right: 8.r), - child: Text( - '12班', - style: TextStyle(fontSize: 14.sp, color: Color(0xFF666666)), - ), + ListView.builder( + itemBuilder: (context,i){ + Items student = item['list'][i]; + return InkWell( + onTap: (){ + showStudentDialog(context,student,groupList); + }, + child: Container( + padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 10.r), + margin: EdgeInsets.only(top: 5.r), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(6.r)), ), - InkWell( - onTap: () async {}, - child: Image.asset( - 'assets/images/favorite_delete_icon.png', - width: 32.r, - height: 32.r, - ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + quickText(student.studentName, color: Color(0xFF333333), size: 14.sp), + Expanded(child: Container()), + Padding( + padding: EdgeInsets.only(right: 8.r), + child: Text( + student.className, + style: TextStyle(fontSize: 14.sp, color: Color(0xFF666666)), + ), + ), + InkWell( + onTap: () async { + deleteFav(student); + }, + child: Image.asset( + 'assets/images/favorite_delete_icon.png', + width: 32.r, + height: 32.r, + ), + ), + ], ), - ], - ), - ), + ), + ); + },itemCount: item['list'].length,shrinkWrap: true,), + ], ), ); }, - // itemCount: datas.length, - itemCount: 10, + itemCount: groupList.length, ), + ):Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).size.height/2 - 200.r), + child: MyEmptyWidget(), ), ], )); diff --git a/marking_app/lib/utils/request/rest_client.dart b/marking_app/lib/utils/request/rest_client.dart index 87f2218..a0dbd59 100644 --- a/marking_app/lib/utils/request/rest_client.dart +++ b/marking_app/lib/utils/request/rest_client.dart @@ -309,7 +309,6 @@ abstract class RestClient { @the_retrofit.Query("JobId") int jobId, @the_retrofit.Query("JobName") String jobName, @the_retrofit.Query("className") String className, - @the_retrofit.Query("Account") String loginName, @the_retrofit.Query("PageSize") int pageSize, ); @@ -340,4 +339,10 @@ abstract class RestClient { // 作业 => 取消/设置优先 @the_retrofit.POST("/api/read/jc-job-read-level") Future getSetJobReadLevel(@the_retrofit.Body() JobLevelSetParams params); + + + // 作业 => 取消收藏 + @the_retrofit.POST("/api/jobs/de-fav-student-job") + Future getJobDeFavorites( + @the_retrofit.Field("jobId") int jobId, @the_retrofit.Field("studentId") int studentId,@the_retrofit.Field("questionPage") int questionPage); }