mod: 请求参数结构、评论页面初始化

This commit is contained in:
guozhigq
2023-04-21 21:44:51 +08:00
parent 3aee691d00
commit ebbb0b86a2
13 changed files with 98 additions and 26 deletions

View File

@ -13,4 +13,7 @@ class Api {
// 用户(被)关注数、投稿数
// https://api.bilibili.com/x/relation/stat?vmid=697166795
static const String userStat = '/x/relation/stat';
// 评论列表
static const String replyList = '/x/v2/reply';
}

33
lib/http/reply.dart Normal file
View File

@ -0,0 +1,33 @@
import 'package:pilipala/http/api.dart';
import 'package:pilipala/http/init.dart';
class ReplyHttp {
static Future replyList({
required String oid,
required int pageNum,
required int type,
int sort = 1,
}) async {
var res = await Request().get(Api.replyList, data: {
'oid': oid,
'pn': pageNum,
'type': type,
'sort': 1,
});
print(res);
if (res.data['code'] == 0) {
} else {
Map errMap = {
-400: '请求错误',
-404: '无此项',
12002: '评论区已关闭',
12009: '评论主体的type不合法',
};
return {
'status': false,
'date': [],
'msg': errMap[res.data['code']] ?? '请求异常',
};
}
}
}

View File

@ -2,7 +2,7 @@ import 'package:pilipala/http/api.dart';
import 'package:pilipala/http/init.dart';
class UserHttp {
static Future<dynamic> userStat(mid) async {
static Future<dynamic> userStat({required int mid}) async {
var res = await Request().get(Api.userStat, data: {'vmid': mid});
if (res.data['code'] == 0) {
return {'status': true, 'data': res.data['data']};

View File

@ -10,13 +10,13 @@ import 'package:pilipala/models/video_detail_res.dart';
/// view层根据 status 判断渲染逻辑
class VideoHttp {
// 首页推荐视频
static Future rcmdVideoList(data) async {
static Future rcmdVideoList({required int ps, required int freshIdx}) async {
var res = await Request().get(
Api.recommendList,
data: {
'feed_version': 'V3',
'ps': data['ps'],
'fresh_idx': data['fresh_idx']
'ps': ps,
'fresh_idx': freshIdx,
},
);
if (res.data['code'] == 0) {
@ -31,13 +31,10 @@ class VideoHttp {
}
// 最热视频
static Future hotVideoList(data) async {
static Future hotVideoList({required int pn, required int ps}) async {
var res = await Request().get(
Api.hotList,
data: {
'pn': data['pn'],
'ps': data['ps'],
},
data: {'pn': pn, 'ps': ps},
);
if (res.data['code'] == 0) {
List<HotVideoItemModel> list = [];
@ -51,7 +48,7 @@ class VideoHttp {
}
// 视频信息 标题、简介
static Future videoIntro(aid) async {
static Future videoIntro({required String aid}) async {
var res = await Request().get(Api.videoIntro, data: {'aid': aid});
VideoDetailResponse result = VideoDetailResponse.fromJson(res.data);
if (result.code == 0) {
@ -67,13 +64,13 @@ class VideoHttp {
return {
'status': false,
'data': null,
'msg': errMap[result.code] ?? '请求异常'
'msg': errMap[result.code] ?? '请求异常',
};
}
}
// 相关视频
static Future relatedVideoList(aid) async {
static Future relatedVideoList({required String aid}) async {
var res = await Request().get(Api.relatedList, data: {'aid': aid});
if (res.data['code'] == 0) {
List<HotVideoItemModel> list = [];