|
@@ -1,3 +1,4 @@
|
|
|
|
+import 'package:domain/entity/property_news_entity.dart';
|
|
import 'package:plugin_platform/http/http_result.dart';
|
|
import 'package:plugin_platform/http/http_result.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
import 'package:shared/utils/log_utils.dart';
|
|
@@ -55,16 +56,16 @@ class PropertyNewsVm extends _$PropertyNewsVm {
|
|
Future loadMore() async {
|
|
Future loadMore() async {
|
|
Log.d("----property_news_vm-----loadMore");
|
|
Log.d("----property_news_vm-----loadMore");
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
- // if(state.list.length >= state.filterCount){
|
|
|
|
|
|
+ // if(state.list.length >= state.count){
|
|
// return;
|
|
// return;
|
|
// }else {
|
|
// }else {
|
|
- // int curPage = state.curPage + 1;
|
|
|
|
- // state = state.copyWith(curPage: curPage,);
|
|
|
|
|
|
+ // int page = state.page + 1;
|
|
|
|
+ // state = state.copyWith(page: page,);
|
|
// getListData();
|
|
// getListData();
|
|
// }
|
|
// }
|
|
- // 检查 curPage 是否为 null,并初始化为 1
|
|
|
|
- int newCurPage = state.curPage ?? 1;
|
|
|
|
- state = state.copyWith(curPage: ++newCurPage);
|
|
|
|
|
|
+ // 检查 page 是否为 null,并初始化为 1
|
|
|
|
+ int newCurPage = state.page ?? 1;
|
|
|
|
+ state = state.copyWith(page: ++newCurPage);
|
|
getListData();
|
|
getListData();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,13 +75,13 @@ class PropertyNewsVm extends _$PropertyNewsVm {
|
|
Log.d("----property_news_vm-----onRefresh ");
|
|
Log.d("----property_news_vm-----onRefresh ");
|
|
|
|
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
// await Future.delayed(const Duration(seconds: 2));
|
|
- state = state.copyWith(curPage: 1);
|
|
|
|
|
|
+ state = state.copyWith(page: 1);
|
|
getListData();
|
|
getListData();
|
|
}
|
|
}
|
|
|
|
|
|
// 重试请求
|
|
// 重试请求
|
|
Future retryRequest() async {
|
|
Future retryRequest() async {
|
|
- state = state.copyWith(curPage: 1);
|
|
|
|
|
|
+ state = state.copyWith(page: 1);
|
|
_needShowPlaceholder = true;
|
|
_needShowPlaceholder = true;
|
|
getListData();
|
|
getListData();
|
|
}
|
|
}
|
|
@@ -92,72 +93,103 @@ class PropertyNewsVm extends _$PropertyNewsVm {
|
|
changeLoadingState(LoadState.State_Loading, null);
|
|
changeLoadingState(LoadState.State_Loading, null);
|
|
}
|
|
}
|
|
|
|
|
|
- Log.d("加载listData数据---------------start--${state.curPage}---");
|
|
|
|
- // try {
|
|
|
|
- // //请求网络
|
|
|
|
- // Map<String, dynamic> params = {
|
|
|
|
- // "curPage": state.curPage,
|
|
|
|
- // "pageSize": state.pageSize,
|
|
|
|
- // };
|
|
|
|
- // Log.d("请求参数------$params");
|
|
|
|
- // final result = await propertyNewsRepository.fetchPropertyNewsList(params);
|
|
|
|
- // Log.d("请求完成结果------${result.data}");
|
|
|
|
- // //校验成功失败
|
|
|
|
- // if (result.isSuccess) {
|
|
|
|
- // // state = state.copyWith(serverTime: result.data);
|
|
|
|
- // state = state;
|
|
|
|
- // handleList(listResult.data?.rows);
|
|
|
|
- // ToastEngine.show("获取数据成功");
|
|
|
|
- // } else {
|
|
|
|
- // errorMessage = listResult.errorMsg;
|
|
|
|
- // changeLoadingState(LoadState.State_Error);
|
|
|
|
- // ToastEngine.show(result.errorMsg ?? "Network Load Error");
|
|
|
|
- // }
|
|
|
|
- // } catch (e) {
|
|
|
|
- // ToastEngine.show("Error: $e");
|
|
|
|
|
|
+ Log.d("加载listData数据---------------start--${state.page}---");
|
|
|
|
+ try {
|
|
|
|
+ //请求网络
|
|
|
|
+ Map<String, dynamic> params = {
|
|
|
|
+ "page": state.page,
|
|
|
|
+ "limit": state.limit,
|
|
|
|
+ };
|
|
|
|
+ Log.d("请求参数------$params");
|
|
|
|
+ final result = await propertyNewsRepository.fetchList(params);
|
|
|
|
+ //校验成功失败
|
|
|
|
+ if (result.isSuccess) {
|
|
|
|
+ handlerResultList((result.data as PropertyNewsEntity).list);
|
|
|
|
+ } else {
|
|
|
|
+ String errorMessage = result.errorMsg!;
|
|
|
|
+ changeLoadingState(LoadState.State_Error, errorMessage);
|
|
|
|
+ ToastEngine.show(result.errorMsg ?? "Network Load Error");
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ ToastEngine.show("Error: $e");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // await Future.delayed(const Duration(milliseconds: 1500));
|
|
|
|
+ // final List<Map<String, dynamic>> listData = [
|
|
|
|
+ // {
|
|
|
|
+ // "id": 1,
|
|
|
|
+ // "title": "法国进口高档国家的看过艰苦奋斗是感觉扣税的房价过快岁的法国艰苦奋斗是架构开发更加开放的国际法的是",
|
|
|
|
+ // "description": "fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡",
|
|
|
|
+ // "time": "2024-02-15 12:00:00",
|
|
|
|
+ // "isCollection": true,
|
|
|
|
+ // "pic": "https://img1.baidu.com/it/u=2500825327,873404587&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500"
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // "id": 2,
|
|
|
|
+ // "title": "JHKFDSAJKjfkdsfjkasjkjklfajfkajifwoqirujweiqofjndsaikfniasdhfiasdhfiadshfifjadslfjkdlsafjlkadsj",
|
|
|
|
+ // "description": "oifosjf fjdskafj hjiwehfriohjfiash",
|
|
|
|
+ // "time": "2024-10-16 12:00:00",
|
|
|
|
+ // "isCollection": false,
|
|
|
|
+ // "pic": ""
|
|
|
|
+ // },
|
|
|
|
+ // ];
|
|
|
|
+ //
|
|
|
|
+ // if (state.page == 1) {
|
|
|
|
+ // //刷新的方式
|
|
|
|
+ // state = state.copyWith(list: listData);
|
|
|
|
+ // refreshController.finishRefresh();
|
|
|
|
+ // //更新展示的状态
|
|
|
|
+ // changeLoadingState(LoadState.State_Success, null);
|
|
|
|
+ // } else {
|
|
|
|
+ // //加载更多
|
|
|
|
+ // final allList = state.list;
|
|
|
|
+ // if(allList.length >= state.count! * state.limit!){
|
|
|
|
+ // //更新展示的状态
|
|
|
|
+ // changeLoadingState(LoadState.State_Success, null);
|
|
|
|
+ // refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
|
+ // }else {
|
|
|
|
+ // allList.addAll(listData);
|
|
|
|
+ // state = state.copyWith(list: allList);
|
|
|
|
+ // refreshController.finishLoad();
|
|
// }
|
|
// }
|
|
|
|
+ // }
|
|
|
|
+ // // 最后赋值
|
|
|
|
+ // _needShowPlaceholder = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void handlerResultList(List? list) {
|
|
|
|
+ if (list != null && list.isNotEmpty) {
|
|
|
|
+ //有数据,判断是刷新还是加载更多的数据
|
|
|
|
+ if (state.page == 1) {
|
|
|
|
+ //刷新的方式
|
|
|
|
+ state.list!.clear();
|
|
|
|
+ state.list!.addAll(list as List<Map<String, dynamic>>);
|
|
|
|
+ refreshController.finishRefresh();
|
|
|
|
|
|
- await Future.delayed(const Duration(milliseconds: 1500));
|
|
|
|
- final List<Map<String, dynamic>> listData = [
|
|
|
|
- {
|
|
|
|
- "id": 1,
|
|
|
|
- "title": "法国进口高档国家的看过艰苦奋斗是感觉扣税的房价过快岁的法国艰苦奋斗是架构开发更加开放的国际法的是",
|
|
|
|
- "description": "fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡fsklfdsk罚款乱收费上课了发送卡",
|
|
|
|
- "time": "2024-02-15 12:00:00",
|
|
|
|
- "isCollection": true,
|
|
|
|
- "pic": "https://img1.baidu.com/it/u=2500825327,873404587&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- "id": 2,
|
|
|
|
- "title": "JHKFDSAJKjfkdsfjkasjkjklfajfkajifwoqirujweiqofjndsaikfniasdhfiasdhfiadshfifjadslfjkdlsafjlkadsj",
|
|
|
|
- "description": "oifosjf fjdskafj hjiwehfriohjfiash",
|
|
|
|
- "time": "2024-10-16 12:00:00",
|
|
|
|
- "isCollection": false,
|
|
|
|
- "pic": ""
|
|
|
|
- },
|
|
|
|
- ];
|
|
|
|
-
|
|
|
|
- if (state.curPage == 1) {
|
|
|
|
- //刷新的方式
|
|
|
|
- state = state.copyWith(list: listData);
|
|
|
|
- refreshController.finishRefresh();
|
|
|
|
- //更新展示的状态
|
|
|
|
- changeLoadingState(LoadState.State_Success, null);
|
|
|
|
- } else {
|
|
|
|
- //加载更多
|
|
|
|
- final allList = state.list;
|
|
|
|
- if(allList.length >= state.filterCount! * state.pageSize!){
|
|
|
|
//更新展示的状态
|
|
//更新展示的状态
|
|
changeLoadingState(LoadState.State_Success, null);
|
|
changeLoadingState(LoadState.State_Success, null);
|
|
- refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
|
- }else {
|
|
|
|
- allList.addAll(listData);
|
|
|
|
|
|
+ } else {
|
|
|
|
+ //加载更多
|
|
|
|
+ final allList = state.list;
|
|
state = state.copyWith(list: allList);
|
|
state = state.copyWith(list: allList);
|
|
refreshController.finishLoad();
|
|
refreshController.finishLoad();
|
|
|
|
+ // update();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (state.page == 1) {
|
|
|
|
+ //展示无数据的布局
|
|
|
|
+ state.list!.clear();
|
|
|
|
+ changeLoadingState(LoadState.State_Empty, null);
|
|
|
|
+ refreshController.finishRefresh();
|
|
|
|
+ } else {
|
|
|
|
+ //展示加载完成,没有更多数据了
|
|
|
|
+ if(state.list!.length == 0){
|
|
|
|
+ changeLoadingState(LoadState.State_Empty, null);
|
|
|
|
+ }
|
|
|
|
+ refreshController.finishLoad(IndicatorResult.noMore);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // 最后赋值
|
|
|
|
- _needShowPlaceholder = false;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -168,56 +200,38 @@ class PropertyNewsVm extends _$PropertyNewsVm {
|
|
}
|
|
}
|
|
|
|
|
|
// 收藏/取消收藏
|
|
// 收藏/取消收藏
|
|
- void handlerCollection(curItem, bool isCollection){
|
|
|
|
-
|
|
|
|
- List<Map<String, dynamic>> newList = state.list.map((item) {
|
|
|
|
- if(item['id'] == curItem['id']){
|
|
|
|
- return {
|
|
|
|
- ...item,
|
|
|
|
- 'isCollection': !isCollection
|
|
|
|
- };
|
|
|
|
|
|
+ void handlerCollection(curItem, bool liked) async {
|
|
|
|
+ try {
|
|
|
|
+ Map<String, dynamic> params = {
|
|
|
|
+ "id": curItem['id'],
|
|
|
|
+ };
|
|
|
|
+ final result = await propertyNewsRepository.fetchPropertyNewsLikeClick(params);
|
|
|
|
+ //校验成功失败
|
|
|
|
+ if (result.isSuccess) {
|
|
|
|
+ List<Map<String, dynamic>>? newList = state.list?.map((item) {
|
|
|
|
+ if(item['id'] == curItem['id']){
|
|
|
|
+ return {
|
|
|
|
+ ...item,
|
|
|
|
+ 'liked': !liked
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ return item;
|
|
|
|
+ }).toList();
|
|
|
|
+ // Log.d("handlerCollection $newList");
|
|
|
|
+ state = state.copyWith(list: newList);
|
|
|
|
+ if(liked){
|
|
|
|
+ ToastEngine.show("取消收藏");
|
|
|
|
+ }else {
|
|
|
|
+ ToastEngine.show("收藏成功");
|
|
}
|
|
}
|
|
- return item;
|
|
|
|
- }).toList();
|
|
|
|
- // Log.d("handlerCollection $newList");
|
|
|
|
- state = state.copyWith(list: newList);
|
|
|
|
- if(isCollection){
|
|
|
|
- ToastEngine.show("取消收藏");
|
|
|
|
- }else {
|
|
|
|
- ToastEngine.show("收藏成功");
|
|
|
|
|
|
+ } else {
|
|
|
|
+ String errorMessage = result.errorMsg!;
|
|
|
|
+ ToastEngine.show(errorMessage ?? "Network Load Error");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (e) {
|
|
|
|
+ ToastEngine.show("Error: $e");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// 处理数据与展示的逻辑
|
|
|
|
-// void handleList(List<JobAppliedListSGRows>? list) {
|
|
|
|
-// if (list != null && list.isNotEmpty) {
|
|
|
|
-// //有数据,判断是刷新还是加载更多的数据
|
|
|
|
-// if (_curPage == 1) {
|
|
|
|
-// //刷新的方式
|
|
|
|
-// state.list.clear();
|
|
|
|
-// state.list.addAll(list);
|
|
|
|
-// refreshController.finishRefresh();
|
|
|
|
-//
|
|
|
|
-// //更新展示的状态
|
|
|
|
-// changeLoadingState(LoadState.State_Success);
|
|
|
|
-// } else {
|
|
|
|
-// //加载更多
|
|
|
|
-// state.list.addAll(list);
|
|
|
|
-// refreshController.finishLoad();
|
|
|
|
-// update();
|
|
|
|
-// }
|
|
|
|
-// } else {
|
|
|
|
-// if (_curPage == 1) {
|
|
|
|
-// //展示无数据的布局
|
|
|
|
-// state.list.clear();
|
|
|
|
-// changeLoadingState(LoadState.State_Empty);
|
|
|
|
-// refreshController.finishRefresh();
|
|
|
|
-// } else {
|
|
|
|
-// //展示加载完成,没有更多数据了
|
|
|
|
-// refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
}
|
|
}
|