You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/ui/community/community_func.dart

151 lines
5.2 KiB

3 years ago
import 'package:aku_new_community/constants/api.dart';
3 years ago
import 'package:aku_new_community/constants/saas_api.dart';
3 years ago
import 'package:aku_new_community/model/good/market_swiper_model.dart';
3 years ago
import 'package:aku_new_community/models/community/dynamic_my_list_body.dart';
3 years ago
import 'package:aku_new_community/models/community/information_list_model.dart';
3 years ago
import 'package:aku_new_community/models/community/topic_model.dart';
import 'package:aku_new_community/models/home/home_activity_model.dart';
import 'package:aku_new_community/models/home/home_announce_model.dart';
import 'package:aku_new_community/models/home/home_swiper_model.dart';
3 years ago
import 'package:aku_new_community/models/market/goods_popular_model.dart';
import 'package:aku_new_community/models/market/market_all_category_model.dart';
import 'package:aku_new_community/models/market/market_category_model.dart';
import 'package:aku_new_community/models/market/market_statistics_model.dart';
3 years ago
import 'package:aku_new_community/utils/network/base_list_model.dart';
import 'package:aku_new_community/utils/network/base_model.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
import 'package:bot_toast/bot_toast.dart';
class CommunityFunc {
///查询热门话题
3 years ago
static Future<List<TopicModel>> getListGambit() async {
var model = await NetUtil().get(
3 years ago
SAASAPI.community.topNewList,
3 years ago
params: {'hotShowNum': 3, 'showNum': 3},
);
3 years ago
if ((model.data as List).length == 0) return [];
return (model.data as List).map((e) => TopicModel.fromJson(e)).toList();
}
///我的动态
3 years ago
static Future<List<DynamicMyListBody>> getMyEventItem() async {
BaseListModel model = await NetUtil().getList(
3 years ago
SAASAPI.community.dynamicMyListL,
params: {'pageNum': 1, 'size': 8},
);
3 years ago
if (model.rows.length == 0) return [];
3 years ago
return model.rows.map((e) => DynamicMyListBody.fromJson(e)).toList();
}
///查询热门资讯
3 years ago
static Future<List<InformationListModel>> getHotNews() async {
BaseListModel model = await NetUtil().getList(
3 years ago
SAASAPI.information.list,
params: {'pageNum': 1, 'size': 4},
);
3 years ago
if (model.rows.length == 0) return [];
3 years ago
return model.rows.map((e) => InformationListModel.fromJson(e)).toList();
}
///给单个资讯增加浏览量
static Future<String> addViews(int newsId) async {
BaseModel model = await NetUtil().get(
API.community.addViews,
3 years ago
params: {
'newsId': newsId,
},
);
if (model.success) return '';
return model.msg;
}
///查询顶部统计信息
static Future<MarketStatisticsModel?> getMarketStatistics() async {
BaseModel model = await NetUtil().get(
3 years ago
SAASAPI.market.home.topInfo,
);
if (model.success) {
return MarketStatisticsModel.fromJson(model.data);
} else {
BotToast.showText(text: model.msg);
return null;
}
}
///获取商品分类
static Future<List<MarketCategoryModel>> getGoodsClassificationList(
3 years ago
int parentId) async {
BaseListModel model = await NetUtil().getList(
3 years ago
SAASAPI.market.category.category,
3 years ago
params: {'pageNum': 1, 'size': 9, 'parentId': parentId},
);
3 years ago
if (model.rows.length == 0) return [];
return model.rows.map((e) => MarketCategoryModel.fromJson(e)).toList();
}
///查询爆款推荐
3 years ago
static Future<List<GoodsPopularModel>> getGoodsPopularModel(int num) async {
BaseModel model = await NetUtil().get(
3 years ago
SAASAPI.market.good.popular,
3 years ago
params: {'num': num},
);
3 years ago
if (model.data!.length == 0) return [];
return (model.data as List)
.map((e) => GoodsPopularModel.fromJson(e))
.toList();
}
3 years ago
///获取所有商品的分类
static Future<List<MarketAllCategoryModel>> getCategory() async {
3 years ago
BaseModel model = await NetUtil().get(
3 years ago
SAASAPI.market.category.categoryInfo,
3 years ago
);
3 years ago
if (model.data!.length == 0)
return [];
else {
3 years ago
return (model.data as List)
.map((e) => MarketAllCategoryModel.fromJson(e))
3 years ago
.toList();
}
}
3 years ago
///获取商城的轮播图
static Future<List<MarketSwiperModel>> marketSwiper() async {
BaseModel model = await NetUtil().get(
3 years ago
SAASAPI.market.rotation.rotation,
);
3 years ago
if (model.data!.length == 0) return [];
return (model.data as List)
.map((e) => MarketSwiperModel.fromJson(e))
.toList();
}
3 years ago
static Future<List<HomeActivityModel>> activityList() async {
BaseListModel model = await NetUtil().getList(
3 years ago
SAASAPI.activity.list,
params: {'pageNum': 1, 'size': 5},
);
3 years ago
if (model.rows.length == 0) return [];
return model.rows.map((e) => HomeActivityModel.fromJson(e)).toList();
}
static Future<List<HomeAnnounceModel>> board() async {
BaseListModel model = await NetUtil().getList(
3 years ago
SAASAPI.announce.list,
params: {'pageNum': 1, 'size': 5},
);
3 years ago
if (model.rows.length == 0) return [];
return model.rows.map((e) => HomeAnnounceModel.fromJson(e)).toList();
}
static Future<List<HomeSwiperModel>> swiper() async {
BaseModel model = await NetUtil().get(
3 years ago
SAASAPI.homeCarouse.list,
);
3 years ago
if (model.data!.length == 0) return [];
return (model.data as List)
.map((e) => HomeSwiperModel.fromJson(e))
.toList();
}
}