mod: 请求参数结构、评论页面初始化
This commit is contained in:
@ -13,4 +13,7 @@ class Api {
|
|||||||
// 用户(被)关注数、投稿数
|
// 用户(被)关注数、投稿数
|
||||||
// https://api.bilibili.com/x/relation/stat?vmid=697166795
|
// https://api.bilibili.com/x/relation/stat?vmid=697166795
|
||||||
static const String userStat = '/x/relation/stat';
|
static const String userStat = '/x/relation/stat';
|
||||||
|
|
||||||
|
// 评论列表
|
||||||
|
static const String replyList = '/x/v2/reply';
|
||||||
}
|
}
|
||||||
|
33
lib/http/reply.dart
Normal file
33
lib/http/reply.dart
Normal 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']] ?? '请求异常',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ import 'package:pilipala/http/api.dart';
|
|||||||
import 'package:pilipala/http/init.dart';
|
import 'package:pilipala/http/init.dart';
|
||||||
|
|
||||||
class UserHttp {
|
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});
|
var res = await Request().get(Api.userStat, data: {'vmid': mid});
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return {'status': true, 'data': res.data['data']};
|
return {'status': true, 'data': res.data['data']};
|
||||||
|
@ -10,13 +10,13 @@ import 'package:pilipala/models/video_detail_res.dart';
|
|||||||
/// view层根据 status 判断渲染逻辑
|
/// view层根据 status 判断渲染逻辑
|
||||||
class VideoHttp {
|
class VideoHttp {
|
||||||
// 首页推荐视频
|
// 首页推荐视频
|
||||||
static Future rcmdVideoList(data) async {
|
static Future rcmdVideoList({required int ps, required int freshIdx}) async {
|
||||||
var res = await Request().get(
|
var res = await Request().get(
|
||||||
Api.recommendList,
|
Api.recommendList,
|
||||||
data: {
|
data: {
|
||||||
'feed_version': 'V3',
|
'feed_version': 'V3',
|
||||||
'ps': data['ps'],
|
'ps': ps,
|
||||||
'fresh_idx': data['fresh_idx']
|
'fresh_idx': freshIdx,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0) {
|
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(
|
var res = await Request().get(
|
||||||
Api.hotList,
|
Api.hotList,
|
||||||
data: {
|
data: {'pn': pn, 'ps': ps},
|
||||||
'pn': data['pn'],
|
|
||||||
'ps': data['ps'],
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
List<HotVideoItemModel> list = [];
|
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});
|
var res = await Request().get(Api.videoIntro, data: {'aid': aid});
|
||||||
VideoDetailResponse result = VideoDetailResponse.fromJson(res.data);
|
VideoDetailResponse result = VideoDetailResponse.fromJson(res.data);
|
||||||
if (result.code == 0) {
|
if (result.code == 0) {
|
||||||
@ -67,13 +64,13 @@ class VideoHttp {
|
|||||||
return {
|
return {
|
||||||
'status': false,
|
'status': false,
|
||||||
'data': null,
|
'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});
|
var res = await Request().get(Api.relatedList, data: {'aid': aid});
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
List<HotVideoItemModel> list = [];
|
List<HotVideoItemModel> list = [];
|
||||||
|
@ -20,10 +20,10 @@ class HomeController extends GetxController {
|
|||||||
|
|
||||||
// 获取推荐
|
// 获取推荐
|
||||||
Future queryRcmdFeed(type) async {
|
Future queryRcmdFeed(type) async {
|
||||||
var res = await VideoHttp.rcmdVideoList({
|
var res = await VideoHttp.rcmdVideoList(
|
||||||
'ps': count,
|
ps: count,
|
||||||
'fresh_idx': _currentPage,
|
freshIdx: _currentPage,
|
||||||
});
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
if (type == 'init') {
|
if (type == 'init') {
|
||||||
videoList.value = res['data'];
|
videoList.value = res['data'];
|
||||||
|
@ -19,10 +19,10 @@ class HotController extends GetxController {
|
|||||||
|
|
||||||
// 获取推荐
|
// 获取推荐
|
||||||
Future queryHotFeed(type) async {
|
Future queryHotFeed(type) async {
|
||||||
var res = await VideoHttp.hotVideoList({
|
var res = await VideoHttp.hotVideoList(
|
||||||
'pn': _currentPage,
|
pn: _currentPage,
|
||||||
'ps': _count,
|
ps: _count,
|
||||||
});
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
if (type == 'init') {
|
if (type == 'init') {
|
||||||
videoList.value = res['data'];
|
videoList.value = res['data'];
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class VideoDetailController extends GetxController {
|
class VideoDetailController extends GetxController {
|
||||||
|
int tabInitialIndex = 0;
|
||||||
// tabs
|
// tabs
|
||||||
RxList<String> tabs = <String>['简介', '评论'].obs;
|
RxList<String> tabs = <String>['简介', '评论'].obs;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class VideoIntroController extends GetxController {
|
|||||||
|
|
||||||
// 获取视频简介
|
// 获取视频简介
|
||||||
Future queryVideoIntro() async {
|
Future queryVideoIntro() async {
|
||||||
var result = await VideoHttp.videoIntro(aid);
|
var result = await VideoHttp.videoIntro(aid: aid);
|
||||||
if (result['status']) {
|
if (result['status']) {
|
||||||
videoDetail.value = result['data']!;
|
videoDetail.value = result['data']!;
|
||||||
Get.find<VideoDetailController>().tabs.value = [
|
Get.find<VideoDetailController>().tabs.value = [
|
||||||
@ -61,7 +61,7 @@ class VideoIntroController extends GetxController {
|
|||||||
|
|
||||||
// 获取up主粉丝数
|
// 获取up主粉丝数
|
||||||
Future queryUserStat() async {
|
Future queryUserStat() async {
|
||||||
var result = await UserHttp.userStat(videoDetail.value.owner!.mid);
|
var result = await UserHttp.userStat(mid: videoDetail.value.owner!.mid!);
|
||||||
if (result['status']) {
|
if (result['status']) {
|
||||||
userStat = result['data'];
|
userStat = result['data'];
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,5 @@ class ReleatedController extends GetxController {
|
|||||||
// 推荐视频列表
|
// 推荐视频列表
|
||||||
List relatedVideoList = [];
|
List relatedVideoList = [];
|
||||||
|
|
||||||
Future<dynamic> queryRelatedVideo() => VideoHttp.relatedVideoList(aid);
|
Future<dynamic> queryRelatedVideo() => VideoHttp.relatedVideoList(aid: aid);
|
||||||
}
|
}
|
||||||
|
17
lib/pages/video/detail/reply/controller.dart
Normal file
17
lib/pages/video/detail/reply/controller.dart
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/http/reply.dart';
|
||||||
|
|
||||||
|
class VideoReplyController extends GetxController {
|
||||||
|
// 视频aid
|
||||||
|
String aid = Get.parameters['aid']!;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
queryReplyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future queryReplyList() async {
|
||||||
|
var res = await ReplyHttp.replyList(oid: aid, pageNum: 1, type: 1);
|
||||||
|
}
|
||||||
|
}
|
4
lib/pages/video/detail/reply/index.dart
Normal file
4
lib/pages/video/detail/reply/index.dart
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
library video_reply_panel;
|
||||||
|
|
||||||
|
export './controller.dart';
|
||||||
|
export './view.dart';
|
17
lib/pages/video/detail/reply/view.dart
Normal file
17
lib/pages/video/detail/reply/view.dart
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class VideoReplyPanel extends StatefulWidget {
|
||||||
|
const VideoReplyPanel({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<VideoReplyPanel> createState() => _VideoReplyPanelState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _VideoReplyPanelState extends State<VideoReplyPanel> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const SliverToBoxAdapter(
|
||||||
|
child: Text('评论'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||||
|
import 'package:pilipala/pages/video/detail/reply/index.dart';
|
||||||
import 'package:pilipala/pages/video/detail/controller.dart';
|
import 'package:pilipala/pages/video/detail/controller.dart';
|
||||||
import 'package:pilipala/pages/video/detail/introduction/index.dart';
|
import 'package:pilipala/pages/video/detail/introduction/index.dart';
|
||||||
import 'package:pilipala/pages/video/detail/related/index.dart';
|
import 'package:pilipala/pages/video/detail/related/index.dart';
|
||||||
@ -19,6 +20,7 @@ class _VideoDetailPageState extends State<VideoDetailPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DefaultTabController(
|
return DefaultTabController(
|
||||||
|
initialIndex: videoDetailController.tabInitialIndex,
|
||||||
length: videoDetailController.tabs.length, // tab的数量.
|
length: videoDetailController.tabs.length, // tab的数量.
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
@ -137,9 +139,7 @@ class _VideoDetailPageState extends State<VideoDetailPage> {
|
|||||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
|
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
|
||||||
context),
|
context),
|
||||||
),
|
),
|
||||||
const SliverToBoxAdapter(
|
const VideoReplyPanel()
|
||||||
child: Text('评论'),
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user