mod: 接口整理、增加up粉丝请求
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/api.dart';
|
||||
import 'package:pilipala/http/init.dart';
|
||||
import 'package:pilipala/http/video.dart';
|
||||
import 'package:pilipala/models/model_rec_video_item.dart';
|
||||
|
||||
class HomeController extends GetxController {
|
||||
@ -21,22 +20,20 @@ class HomeController extends GetxController {
|
||||
|
||||
// 获取推荐
|
||||
Future queryRcmdFeed(type) async {
|
||||
var res = await Request().get(
|
||||
Api.recommendList,
|
||||
data: {'feed_version': "V3", 'ps': count, 'fresh_idx': _currentPage},
|
||||
);
|
||||
List<RecVideoItemModel> list = [];
|
||||
for (var i in res.data['data']['item']) {
|
||||
list.add(RecVideoItemModel.fromJson(i));
|
||||
var res = await VideoHttp.rcmdVideoList({
|
||||
'ps': count,
|
||||
'fresh_idx': _currentPage,
|
||||
});
|
||||
if (res['status']) {
|
||||
if (type == 'init') {
|
||||
videoList.value = res['data'];
|
||||
} else if (type == 'onRefresh') {
|
||||
videoList.insertAll(0, res['data']);
|
||||
} else if (type == 'onLoad') {
|
||||
videoList.addAll(res['data']);
|
||||
}
|
||||
_currentPage += 1;
|
||||
}
|
||||
if (type == 'init') {
|
||||
videoList.value = list;
|
||||
} else if (type == 'onRefresh') {
|
||||
videoList.insertAll(0, list);
|
||||
} else if (type == 'onLoad') {
|
||||
videoList.addAll(list);
|
||||
}
|
||||
_currentPage += 1;
|
||||
isLoadingMore = false;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/api.dart';
|
||||
import 'package:pilipala/http/init.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pilipala/http/video.dart';
|
||||
import 'package:pilipala/models/model_hot_video_item.dart';
|
||||
|
||||
class HotController extends GetxController {
|
||||
@ -21,22 +19,20 @@ class HotController extends GetxController {
|
||||
|
||||
// 获取推荐
|
||||
Future queryHotFeed(type) async {
|
||||
var res = await Request().get(
|
||||
Api.hotList,
|
||||
data: {'pn': _currentPage, 'ps': _count},
|
||||
);
|
||||
List<HotVideoItemModel> list = [];
|
||||
for (var i in res.data['data']['list']) {
|
||||
list.add(HotVideoItemModel.fromJson(i));
|
||||
var res = await VideoHttp.hotVideoList({
|
||||
'pn': _currentPage,
|
||||
'ps': _count,
|
||||
});
|
||||
if (res['status']) {
|
||||
if (type == 'init') {
|
||||
videoList.value = res['data'];
|
||||
} else if (type == 'onRefresh') {
|
||||
videoList.insertAll(0, res['data']);
|
||||
} else if (type == 'onLoad') {
|
||||
videoList.addAll(res['data']);
|
||||
}
|
||||
_currentPage += 1;
|
||||
}
|
||||
if (type == 'init') {
|
||||
videoList.value = list;
|
||||
} else if (type == 'onRefresh') {
|
||||
videoList.insertAll(0, list);
|
||||
} else if (type == 'onLoad') {
|
||||
videoList.addAll(list);
|
||||
}
|
||||
_currentPage += 1;
|
||||
isLoadingMore = false;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/api.dart';
|
||||
import 'package:pilipala/http/init.dart';
|
||||
import 'package:pilipala/http/user.dart';
|
||||
import 'package:pilipala/http/video.dart';
|
||||
import 'package:pilipala/models/video_detail_res.dart';
|
||||
import 'package:pilipala/pages/video/detail/controller.dart';
|
||||
|
||||
@ -20,6 +20,12 @@ class VideoIntroController extends GetxController {
|
||||
// 视频详情 请求返回
|
||||
Rx<VideoDetailData> videoDetail = VideoDetailData().obs;
|
||||
|
||||
// 请求返回的信息
|
||||
String responseMsg = '请求异常';
|
||||
|
||||
// up主粉丝数
|
||||
Map userStat = {'follower': '-'};
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@ -36,17 +42,28 @@ class VideoIntroController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future queryVideoDetail() async {
|
||||
var res = await Request().get(Api.videoDetail, data: {
|
||||
'aid': aid,
|
||||
});
|
||||
VideoDetailResponse result = VideoDetailResponse.fromJson(res.data);
|
||||
videoDetail.value = result.data!;
|
||||
Get.find<VideoDetailController>().tabs.value = [
|
||||
'简介',
|
||||
'评论 ${result.data!.stat!.reply}'
|
||||
];
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
return true;
|
||||
// 获取视频简介
|
||||
Future queryVideoIntro() async {
|
||||
var result = await VideoHttp.videoIntro(aid);
|
||||
if (result['status']) {
|
||||
videoDetail.value = result['data']!;
|
||||
Get.find<VideoDetailController>().tabs.value = [
|
||||
'简介',
|
||||
'评论 ${result['data']!.stat!.reply}'
|
||||
];
|
||||
} else {
|
||||
responseMsg = result['msg'];
|
||||
}
|
||||
// 获取到粉丝数再返回
|
||||
await queryUserStat();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取up主粉丝数
|
||||
Future queryUserStat() async {
|
||||
var result = await UserHttp.userStat(videoDetail.value.owner!.mid);
|
||||
if (result['status']) {
|
||||
userStat = result['data'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pilipala/common/constants.dart';
|
||||
import 'package:pilipala/common/widgets/http_error.dart';
|
||||
import 'package:pilipala/pages/video/detail/widgets/expandable_section.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/common/widgets/stat/danmu.dart';
|
||||
@ -43,27 +44,29 @@ class _VideoIntroPanelState extends State<VideoIntroPanel>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: videoIntroController.queryVideoDetail(),
|
||||
future: videoIntroController.queryVideoIntro(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data) {
|
||||
if (snapshot.data['status']) {
|
||||
// 请求成功
|
||||
// return _buildView(context, false, videoDetail);
|
||||
return VideoInfo(loadingStatus: false, videoDetail: videoDetail);
|
||||
return VideoInfo(
|
||||
loadingStatus: false,
|
||||
videoDetail: videoDetail,
|
||||
videoIntroController: videoIntroController);
|
||||
} else {
|
||||
// 请求错误
|
||||
return Center(
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () {
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
return HttpError(
|
||||
errMsg: snapshot.data['msg'],
|
||||
fn: () => setState(() {}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// return _buildView(context, true, videoDetail);
|
||||
return VideoInfo(loadingStatus: true, videoDetail: videoDetail);
|
||||
return VideoInfo(
|
||||
loadingStatus: true,
|
||||
videoDetail: videoDetail,
|
||||
videoIntroController: videoIntroController);
|
||||
}
|
||||
},
|
||||
);
|
||||
@ -90,8 +93,13 @@ class _VideoIntroPanelState extends State<VideoIntroPanel>
|
||||
class VideoInfo extends StatefulWidget {
|
||||
bool loadingStatus = false;
|
||||
VideoDetailData? videoDetail;
|
||||
VideoIntroController? videoIntroController;
|
||||
|
||||
VideoInfo({Key? key, required this.loadingStatus, this.videoDetail})
|
||||
VideoInfo(
|
||||
{Key? key,
|
||||
required this.loadingStatus,
|
||||
this.videoDetail,
|
||||
this.videoIntroController})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@ -150,19 +158,17 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
? widget.videoDetail!.owner!.name
|
||||
: videoItem['owner'].name),
|
||||
const SizedBox(height: 2),
|
||||
// Text.rich(
|
||||
// TextSpan(
|
||||
// style: TextStyle(
|
||||
// color: Theme.of(context)
|
||||
// .colorScheme
|
||||
// .outline,
|
||||
// fontSize: 11),
|
||||
// children: const [
|
||||
// TextSpan(text: '2.6万粉丝'),
|
||||
// TextSpan(text: ' '),
|
||||
// TextSpan(text: '2.6万粉丝'),
|
||||
// ]),
|
||||
// ),
|
||||
Text(
|
||||
widget.loadingStatus
|
||||
? '- 粉丝'
|
||||
: '${Utils.numFormat(widget.videoIntroController!.userStat['follower'])}粉丝',
|
||||
style: TextStyle(
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.labelSmall!
|
||||
.fontSize,
|
||||
color: Theme.of(context).colorScheme.outline),
|
||||
)
|
||||
]),
|
||||
const Spacer(),
|
||||
AnimatedOpacity(
|
||||
|
@ -1,8 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/video.dart';
|
||||
import 'package:pilipala/models/model_hot_video_item.dart';
|
||||
|
||||
class ReleatedController extends GetxController {
|
||||
// 视频aid
|
||||
@ -10,22 +7,5 @@ class ReleatedController extends GetxController {
|
||||
// 推荐视频列表
|
||||
List relatedVideoList = [];
|
||||
|
||||
Future<dynamic> queryVideoRecommend() async {
|
||||
try {
|
||||
var res = await VideoHttp.videoRecommend({'aid': aid});
|
||||
List<HotVideoItemModel> list = [];
|
||||
try {
|
||||
for (var i in res.data['data']) {
|
||||
list.add(HotVideoItemModel.fromJson(i));
|
||||
}
|
||||
relatedVideoList = list;
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
|
||||
return res.data['data'];
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
}
|
||||
Future<dynamic> queryRelatedVideo() => VideoHttp.relatedVideoList(aid);
|
||||
}
|
||||
|
@ -16,22 +16,22 @@ class _RelatedVideoPanelState extends State<RelatedVideoPanel> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: _releatedController.queryVideoRecommend(),
|
||||
future: _releatedController.queryRelatedVideo(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data!.isNotEmpty) {
|
||||
if (snapshot.data!['status']) {
|
||||
// 请求成功
|
||||
List videoList = _releatedController.relatedVideoList;
|
||||
// List videoList = _releatedController.relatedVideoList;
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
if (index == videoList.length) {
|
||||
if (index == snapshot.data['data'].length) {
|
||||
return SizedBox(height: MediaQuery.of(context).padding.bottom);
|
||||
} else {
|
||||
return VideoCardH(
|
||||
videoItem: videoList[index],
|
||||
videoItem: snapshot.data['data'][index],
|
||||
);
|
||||
}
|
||||
}, childCount: videoList.length + 1));
|
||||
}, childCount: snapshot.data['data'].length + 1));
|
||||
} else {
|
||||
// 请求错误
|
||||
return const Center(
|
||||
|
Reference in New Issue
Block a user