mod: 视频评论页代码整理
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:pilipala/http/api.dart';
|
||||
import 'package:pilipala/http/init.dart';
|
||||
import 'package:pilipala/models/video/reply/data.dart';
|
||||
|
||||
class ReplyHttp {
|
||||
static Future replyList({
|
||||
@ -17,7 +18,7 @@ class ReplyHttp {
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': res.data['data'],
|
||||
'data': ReplyData.fromJson(res.data['data']),
|
||||
};
|
||||
} else {
|
||||
Map errMap = {
|
||||
|
@ -1,26 +1,21 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/reply.dart';
|
||||
import 'package:pilipala/http/video.dart';
|
||||
import 'package:pilipala/models/common/reply_sort_type.dart';
|
||||
import 'package:pilipala/models/common/reply_type.dart';
|
||||
import 'package:pilipala/models/video/reply/data.dart';
|
||||
import 'package:pilipala/models/video/reply/item.dart';
|
||||
|
||||
class VideoReplyController extends GetxController {
|
||||
VideoReplyController(
|
||||
this.aid,
|
||||
this.rpid,
|
||||
this.level,
|
||||
this.replyLevel,
|
||||
);
|
||||
final ScrollController scrollController = ScrollController();
|
||||
// 视频aid 请求时使用的oid
|
||||
int? aid;
|
||||
// 层级 2为楼中楼
|
||||
String? level;
|
||||
String? replyLevel;
|
||||
// rpid 请求楼中楼回复
|
||||
String? rpid;
|
||||
RxList<ReplyItemModel> replyList = [ReplyItemModel()].obs;
|
||||
@ -30,12 +25,6 @@ class VideoReplyController extends GetxController {
|
||||
RxString noMore = ''.obs;
|
||||
// 当前回复的回复
|
||||
ReplyItemModel? currentReplyItem;
|
||||
// 回复来源
|
||||
String replySource = 'main';
|
||||
// 根评论 id 回复楼中楼回复使用
|
||||
int? rPid;
|
||||
// 默认回复主楼
|
||||
String replyLevel = '0';
|
||||
|
||||
ReplySortType sortType = ReplySortType.time;
|
||||
RxString sortTypeTitle = ReplySortType.time.titles.obs;
|
||||
@ -43,51 +32,44 @@ class VideoReplyController extends GetxController {
|
||||
|
||||
Future queryReplyList({type = 'init'}) async {
|
||||
isLoadingMore = true;
|
||||
var res = level == '1'
|
||||
var res = replyLevel == '1'
|
||||
? await ReplyHttp.replyList(
|
||||
oid: aid!,
|
||||
pageNum: currentPage + 1,
|
||||
pageNum: ++currentPage,
|
||||
type: ReplyType.video.index,
|
||||
sort: sortType.index,
|
||||
)
|
||||
: await ReplyHttp.replyReplyList(
|
||||
oid: aid!, root: rpid!, pageNum: currentPage + 1, type: 1);
|
||||
oid: aid!,
|
||||
root: rpid!,
|
||||
pageNum: ++currentPage,
|
||||
type: ReplyType.video.index,
|
||||
);
|
||||
if (res['status']) {
|
||||
res['data'] = ReplyData.fromJson(res['data']);
|
||||
if (res['data'].replies.isNotEmpty) {
|
||||
currentPage = currentPage + 1;
|
||||
List<ReplyItemModel> replies = res['data'].replies;
|
||||
if (replies.isNotEmpty) {
|
||||
noMore.value = '加载中';
|
||||
if (replyList.length == res['data'].page.acount) {
|
||||
noMore.value = '没有更多了';
|
||||
}
|
||||
} else {
|
||||
if (currentPage == 0) {
|
||||
noMore.value = '还没有评论';
|
||||
} else {
|
||||
noMore.value = '没有更多了';
|
||||
return;
|
||||
}
|
||||
// 未登录状态replies可能返回null
|
||||
noMore.value = currentPage == 0 ? '还没有评论' : '没有更多了';
|
||||
}
|
||||
if (type == 'init') {
|
||||
List<ReplyItemModel> replies = res['data'].replies;
|
||||
// 添加置顶回复
|
||||
if (res['data'].upper.top != null) {
|
||||
bool flag = false;
|
||||
for (var i = 0; i < res['data'].topReplies.length; i++) {
|
||||
if (res['data'].topReplies[i].rpid == res['data'].upper.top.rpid) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
bool flag = res['data']
|
||||
.topReplies
|
||||
.any((reply) => reply.rpid == res['data'].upper.top.rpid);
|
||||
if (!flag) {
|
||||
replies.insert(0, res['data'].upper.top);
|
||||
}
|
||||
}
|
||||
replies.insertAll(0, res['data'].topReplies);
|
||||
res['data'].replies = replies;
|
||||
replyList.value = res['data'].replies!;
|
||||
replyList.value = replies;
|
||||
} else {
|
||||
replyList.addAll(res['data'].replies!);
|
||||
res['data'].replies.addAll(replyList);
|
||||
replyList.addAll(replies);
|
||||
}
|
||||
}
|
||||
isLoadingMore = false;
|
||||
|
@ -6,7 +6,6 @@ import 'package:get/get.dart';
|
||||
import 'package:pilipala/common/skeleton/video_reply.dart';
|
||||
import 'package:pilipala/common/widgets/http_error.dart';
|
||||
import 'package:pilipala/models/common/reply_type.dart';
|
||||
import 'package:pilipala/models/video/reply/item.dart';
|
||||
import 'package:pilipala/pages/video/detail/index.dart';
|
||||
import 'package:pilipala/pages/video/detail/replyNew/index.dart';
|
||||
import 'package:pilipala/utils/id_utils.dart';
|
||||
@ -14,14 +13,14 @@ import 'controller.dart';
|
||||
import 'widgets/reply_item.dart';
|
||||
|
||||
class VideoReplyPanel extends StatefulWidget {
|
||||
String? bvid;
|
||||
int rpid;
|
||||
String? level;
|
||||
Key? key;
|
||||
VideoReplyPanel({
|
||||
final String? bvid;
|
||||
final int rpid;
|
||||
final String? replyLevel;
|
||||
|
||||
const VideoReplyPanel({
|
||||
this.bvid,
|
||||
this.rpid = 0,
|
||||
this.level,
|
||||
this.replyLevel,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@ -46,18 +45,13 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
void initState() {
|
||||
int oid = widget.bvid != null ? IdUtils.bv2av(widget.bvid!) : 0;
|
||||
super.initState();
|
||||
replyLevel = widget.level ?? '1';
|
||||
if (widget.level != null && widget.level == '2') {
|
||||
replyLevel = widget.replyLevel ?? '1';
|
||||
if (replyLevel == '2') {
|
||||
_videoReplyController = Get.put(
|
||||
VideoReplyController(oid, widget.rpid.toString(), '2'),
|
||||
VideoReplyController(oid, widget.rpid.toString(), replyLevel),
|
||||
tag: widget.rpid.toString());
|
||||
_videoReplyController.rPid = widget.rpid;
|
||||
} else {
|
||||
// fix 评论加载不对称
|
||||
// int oid = Get.parameters['bvid'] != null
|
||||
// ? IdUtils.bv2av(Get.parameters['bvid']!)
|
||||
// : 0;
|
||||
_videoReplyController = Get.put(VideoReplyController(oid, '', '1'),
|
||||
_videoReplyController = Get.put(VideoReplyController(oid, '', replyLevel),
|
||||
tag: Get.arguments['heroTag']);
|
||||
}
|
||||
|
||||
@ -101,20 +95,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
}
|
||||
}
|
||||
|
||||
void _showReply(source, {ReplyItemModel? replyItem, replyLevel}) async {
|
||||
// source main 直接回复 floor 楼中楼回复
|
||||
if (source == 'floor') {
|
||||
_videoReplyController.currentReplyItem = replyItem;
|
||||
_videoReplyController.replySource = source;
|
||||
_videoReplyController.replyLevel = replyLevel ?? '1';
|
||||
} else {
|
||||
_videoReplyController.replyLevel = '0';
|
||||
}
|
||||
|
||||
// await Future.delayed(const Duration(microseconds: 100));
|
||||
// _videoReplyController.wakeUpReply();
|
||||
}
|
||||
|
||||
// 展示二级回复
|
||||
void replyReply(replyItem) {
|
||||
VideoDetailController videoDetailCtr =
|
||||
@ -136,7 +116,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
setState(() {});
|
||||
_videoReplyController.currentPage = 0;
|
||||
return await _videoReplyController.queryReplyList();
|
||||
},
|
||||
@ -204,18 +183,15 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
double bottom =
|
||||
MediaQuery.of(context).padding.bottom;
|
||||
if (index ==
|
||||
_videoReplyController
|
||||
.replyList.length) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context)
|
||||
.padding
|
||||
.bottom),
|
||||
height: MediaQuery.of(context)
|
||||
.padding
|
||||
.bottom +
|
||||
100,
|
||||
padding:
|
||||
EdgeInsets.only(bottom: bottom),
|
||||
height: bottom + 100,
|
||||
child: Center(
|
||||
child: Obx(() => Text(
|
||||
_videoReplyController
|
||||
@ -265,8 +241,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
|
||||
child: SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0, 2),
|
||||
// 评论内容为空/不足一屏
|
||||
// begin: const Offset(0, 0),
|
||||
end: const Offset(0, 0),
|
||||
).animate(CurvedAnimation(
|
||||
parent: fabAnimationCtr,
|
||||
|
@ -21,11 +21,6 @@ class VideoReplyReplyController extends GetxController {
|
||||
// 当前回复的回复
|
||||
ReplyItemModel? currentReplyItem;
|
||||
|
||||
// 根评论 id 回复楼中楼回复使用
|
||||
int? rPid;
|
||||
// 默认回复主楼
|
||||
String replyLevel = '0';
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
@ -11,14 +11,14 @@ import 'package:pilipala/utils/storage.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class VideoReplyReplyPanel extends StatefulWidget {
|
||||
int? oid;
|
||||
int? rpid;
|
||||
Function? closePanel;
|
||||
ReplyItemModel? firstFloor;
|
||||
String? source;
|
||||
ReplyType? replyType;
|
||||
final int? oid;
|
||||
final int? rpid;
|
||||
final Function? closePanel;
|
||||
final ReplyItemModel? firstFloor;
|
||||
final String? source;
|
||||
final ReplyType? replyType;
|
||||
|
||||
VideoReplyReplyPanel({
|
||||
const VideoReplyReplyPanel({
|
||||
this.oid,
|
||||
this.rpid,
|
||||
this.closePanel,
|
||||
@ -91,7 +91,6 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
_videoReplyReplyController.currentPage = 0;
|
||||
_videoReplyReplyController.rPid = 0;
|
||||
widget.closePanel!();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
|
Reference in New Issue
Block a user