提交 29447b04 authored 作者: yueweilu's avatar yueweilu

我的收藏

上级 8ea915d8
......@@ -28,7 +28,7 @@ abstract class CommonAPI {
final result = await HttpService.to.post(
'/v1/message/Message/getList',
params: {
'currentPage': page,
'page': page,
'pageSize': limit,
},
);
......@@ -58,7 +58,7 @@ abstract class CommonAPI {
final result = await HttpService.to.post(
'/v1/members/Information/myReadRecord',
params: {
'currentPage': page,
'page': page,
'pageSize': limit,
},
);
......@@ -121,7 +121,7 @@ abstract class CommonAPI {
final result = await HttpService.to.post(
'/v1/book/Information/searchBook',
params: {
'currentPage': page,
'page': page,
'pageSize': limit,
'keyword':keyWord
},
......@@ -132,5 +132,23 @@ abstract class CommonAPI {
});
}
/// 9、收藏 取消收藏
static Future <bool> love({
required String bookId,
required String love
}) async {
final result = await HttpService.to.post(
'/v1/book/Information/collection',
params: {
'book_id':bookId,
'is_select':love
},
);
if (result.data is Map && result.data['is_success'] == 1){
return true;
}
return false;
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ abstract class CourseAPI {
final result = await HttpService.to.post(
'/v1/members/Information/myCourse',
params: {
'currentPage': page,
'page': page,
'pageSize': limit,
},
);
......
......@@ -38,7 +38,7 @@ abstract class LibraryAPI {
final result = await HttpService.to.post(
'/v1/book/category/getBookList',
params: {
'currentPage': page,
'page': page,
'pageSize': limit,
},
);
......
......@@ -13,6 +13,23 @@ abstract class MineAPI {
return result.data;
}
/// 2、我的收藏
static Future <List<CourseModel>> love({
int page = 1,
int limit = 10,
}) async {
final result = await HttpService.to.post(
'/v1/members/Information/myCollection',
params: {
'page': page,
'pageSize': limit,
},
);
if (result.data is! Map && result.data['list'] is! List) return [];
return List.generate(result.data['list'].length, (index){
return CourseModel.fromJson(result.data['list'][index]);
});
}
}
\ No newline at end of file
......@@ -5,6 +5,10 @@ part of models;
/// authors : "华佗"
/// img : "https://resource.vning.net/book/img/vning_hEBkC8RG26_1646976647301.jpg"
/// progress : "0%"
/// lastChapter : "最近章节"
/// createTime : "创建时间"
/// introduction : "介绍"
///
class CourseModel {
CourseModel({
......@@ -16,8 +20,10 @@ class CourseModel {
this.lastChapter,
this.createTime,
this.days,
this.introduction,
this.readNum,
this.isCollection
this.isCollection,
this.collectionId
});
CourseModel.fromJson(dynamic json) {
......@@ -29,9 +35,10 @@ class CourseModel {
lastChapter = json['last_chapter'];
createTime = json['create_time'];
days = json['days'];
introduction = json['introduction'];
readNum = json['read_num'];
isCollection = json['is_collection'];
collectionId = json['collection_id'];
}
num? bookId;
String? bookName;
......@@ -44,6 +51,7 @@ class CourseModel {
String? introduction;
num? readNum;
num? isCollection;
num? collectionId;
int get type {
......@@ -74,8 +82,10 @@ class CourseModel {
String? lastChapter,
String? createTime,
String? days,
String? introduction,
num? readNum,
num? isCollection,
num? collectionId,
}) => CourseModel( bookId: bookId ?? this.bookId,
bookName: bookName ?? this.bookName,
......@@ -85,8 +95,10 @@ class CourseModel {
lastChapter: lastChapter ?? this.lastChapter,
createTime: createTime ?? this.createTime,
days: days ?? this.days,
introduction: introduction ?? this.introduction,
readNum: readNum ?? this.readNum,
isCollection: isCollection ?? this.isCollection
isCollection: isCollection ?? this.isCollection,
collectionId: collectionId ?? this.collectionId
);
Map<String, dynamic> toJson() {
......@@ -101,6 +113,8 @@ class CourseModel {
map['days'] = days;
map['read_num'] = readNum;
map['is_collection'] = isCollection;
map['collection_id'] = collectionId;
map['introduction'] = introduction;
return map;
}
......
......@@ -6,9 +6,11 @@ class ReadModel {
required this.value,
required this.name,
this.link,
this.icon
});
String value;
String name;
String? link;
String? icon;
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ class MineController extends GetxController {
void onReady() {
_getAds();
_getNums();
_getInfo();
getInfo();
super.onReady();
}
......@@ -39,19 +39,19 @@ class MineController extends GetxController {
}
/// 获取个人信息数据
void _getInfo() async {
void getInfo() async {
userInfo = await MineAPI.userInfo();
reads = [
ReadModel(name: '笔记',value: userInfo['note_nums'].toString(),),
ReadModel(name: '讨论',value: userInfo['comment_nums'].toString()),
ReadModel(name: '错题',value: userInfo['wrong_nums'].toString()),
ReadModel(name: '收藏',value: userInfo['collect_nums'].toString())
ReadModel(name: '收藏',value: userInfo['collect_nums'].toString(),link: Routes.love)
];
accounts = [
ReadModel(name: '优惠券',value: userInfo['coupon_nums'].toString()),
ReadModel(name: '积分',value: userInfo['integral_nums'].toString(),link: Routes.coin),
ReadModel(name: '紫金币',value: userInfo['bean_nums'].toString(),link: Routes.coin),
ReadModel(name: '订单',value: userInfo['orders_nums'].toString())
ReadModel(name: '优惠券',value: userInfo['coupon_nums'].toString(),icon: 'assets/images/coupon.png'),
ReadModel(name: '积分',value: userInfo['integral_nums'].toString(),link: Routes.coin,icon: 'assets/images/point.png'),
ReadModel(name: '紫金币',value: userInfo['bean_nums'].toString(),link: Routes.coin,icon: 'assets/images/coin.png'),
ReadModel(name: '订单',value: userInfo['orders_nums'].toString(),icon: 'assets/images/order.png')
];
update();
}
......
......@@ -70,7 +70,12 @@ class _MinePageState extends State<MinePage> {
context.pushNamed(Routes.userInfo);
},),
Gaps.vGaps10,
BuildRead(items: controller.reads),
BuildRead(items: controller.reads,onTap: (ReadModel model) async{
final result = await context.pushNamed(model.link??'');
if (result == true){
controller.getInfo();
}
}),
controller.ads.isNotEmpty?Gaps.vGaps10:const SizedBox(),
controller.ads.isNotEmpty?
Container(
......
......@@ -45,19 +45,20 @@ class BuildAccount extends StatelessWidget {
},
child: Column(
children: [
Container(
SizedBox(
width: 25.w,
height: 25.w,
color: Colors.green,
// color: Colors.green,
child: Image.asset(model.icon!),
),
Gaps.vGaps5,
Text(model.name,style: TextStyle(fontSize:12.w,height: 1.6,color: Colours.c9),),
items.indexOf(model) == 0?Row(
children: [
Text(model.value.toString(),style: TextStyle(fontSize: 16,height: 1.6,fontWeight: Fonts.medium,color: AppTheme.primary,),),
Text(model.value.toString(),style: const TextStyle(fontSize: 16,height: 1.6,fontWeight: Fonts.medium,color: AppTheme.primary,),),
const Text('张',style: TextStyle(fontSize: 12,height:1.6,color: Colours.c3),)
],
):Text(model.value.toString(),style: TextStyle(fontSize: 16,height:1.6,color: Colours.c3),)
):Text(model.value.toString(),style: const TextStyle(fontSize: 16,height:1.6,color: Colours.c3),)
],
),
);
......
......@@ -3,7 +3,7 @@ part of mine;
class BuildRead extends StatelessWidget {
final void Function()? onTap;
final void Function(ReadModel model)? onTap;
final List <ReadModel>items;
const BuildRead ({
super.key,
......@@ -35,8 +35,12 @@ class BuildRead extends StatelessWidget {
behavior: HitTestBehavior.opaque,
onTap: (){
if (model.link != null){
context.pushNamed(model.link!);
if (onTap !=null) onTap;
if (model.link != Routes.love){
context.pushNamed(model.link!);
}
else{
if (onTap !=null) onTap!(model);
}
}
},
child: Column(
......
part of user_love;
class UserLoveController extends GetxController {
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
final int _limit = 20;
int _page = 1;
bool _noMore = false;
// 收藏数据
List<CourseModel> loves = [];
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
/// 取消收藏
void unLoved({
required String bookId
}) async {
bool result = await CommonAPI.love(bookId: bookId, love: '0');
if (result) {
onRefresh();
}
}
/// 获取课程内图书列表
Future<void> _getLoves([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await MineAPI.love(
page: _page,
limit: _limit
);
// 如果是刷新 清理数据
if (isRefresh) loves.clear();
loves.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getLoves(true);
refreshController.finishRefresh(IndicatorResult.success);
refreshController.resetFooter();
} catch (error) {
refreshController.finishRefresh(IndicatorResult.fail);
}
}
void onLoading() async {
if (_noMore) {
refreshController.finishLoad(IndicatorResult.noMore);
return;
}
try {
await _getLoves();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
library user_love;
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_book/apis/index.dart';
import 'package:flutter_book/models/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:go_router/go_router.dart';
import '../../theme.dart';
import '../../utils/index.dart';
import '../../widgets/index.dart';
part 'controller.dart';
part 'view.dart';
part 'widgets/item.dart';
part of user_love;
class UserLovePage extends StatefulWidget {
const UserLovePage({Key? key}) : super(key: key);
@override
State<UserLovePage> createState() => _UserLovePageState();
}
class _UserLovePageState extends State<UserLovePage> {
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
context.pop(true);
return false;
},
child: GetBuilder<UserLoveController>(
init: UserLoveController(),
builder:(controller) => Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('我的收藏'),
),
body: Container(
color: Colours.cF9,
child: CustomPullScrollView(
controller: controller.refreshController,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: ListView.builder(
itemBuilder: (BuildContext context, int index){
CourseModel model = controller.loves[index];
return BuildItem(model: model,onTap: (){
controller.unLoved(bookId: model.bookId.toString());
},);
},
itemCount: controller.loves.length,
),
),
),
),
),
);
}
}
part of user_love;
class BuildItem extends StatelessWidget {
final CourseModel model;
final void Function()? onTap;
const BuildItem({
Key? key,
required this.model,
this.onTap
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.only(left: 10,top: 15,bottom: 15),
margin: const EdgeInsets.only(top:15,left: 10,right: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colours.cC7.withOpacity(0.5), // 阴影颜色
spreadRadius: 2, // 阴影扩散半径
blurRadius: 5, // 阴影模糊半径
offset: const Offset(0, 2), // 阴影偏移
),
],
),
// height: 200,
// color: Colors.cyanAccent,
child: Row(
children: [
/// 左侧
Container(
width: 73,
height: 87,
color: Colors.red,
child: CustomImage.network(url: model.img??''),
),
/// 右侧
Expanded(
child: Container(
margin: const EdgeInsets.only(left: 10,right: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(model.bookName??'',overflow: TextOverflow.ellipsis,maxLines: 1,style: const TextStyle(fontSize: 14,fontWeight: Fonts.medium,height: 1.5,color: Colours.c3),),
const SizedBox(height: 4,),
Text(model.authors??'',style: const TextStyle(fontSize: 12,color: Colours.c9,height: 1.5),),
Gaps.vGaps15,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(),
GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.only(top: 10),
width: 30,
height: 30,
// color: Colors.yellow,
child: Image.asset(
'assets/images/del.png',
),
),
)
],
)
],
),
),
)
],
),
);
}
}
......@@ -18,6 +18,7 @@ import 'package:flutter_book/pages/study_history/index.dart';
import 'package:flutter_book/pages/study_report/index.dart';
import 'package:flutter_book/pages/user_coin/index.dart';
import 'package:flutter_book/pages/user_info/index.dart';
import 'package:flutter_book/pages/user_love/index.dart';
import 'package:flutter_book/pages/user_msg/index.dart';
import 'package:flutter_book/pages/user_nick/index.dart';
import 'package:flutter_book/pages/web/index.dart';
......
......@@ -67,6 +67,8 @@ abstract class Routes {
static const about = 'about';
// 最近学习
static const studyHistory = 'study_history';
// 我的收藏
static const love = 'love';
static final GoRouter config = GoRouter(
......@@ -259,6 +261,15 @@ abstract class Routes {
child: const StudyHistoryPage()
)
),
GoRoute(
path: '/$love',
name: love,
pageBuilder: (context, state) =>CupertinoPage(
name: state.uri.toString(),
key: state.pageKey,
child: const UserLovePage()
)
),
]
);
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论