opt: 评论框优化

This commit is contained in:
guozhigq
2024-04-26 23:46:54 +08:00
parent 23e2e83636
commit d60bc7fa45
6 changed files with 88 additions and 71 deletions

View File

@ -22,19 +22,14 @@ class ReplyHttp {
return { return {
'status': true, 'status': true,
'data': ReplyData.fromJson(res.data['data']), 'data': ReplyData.fromJson(res.data['data']),
'code': 200,
}; };
} else { } else {
Map errMap = {
-400: '请求错误',
-404: '无此项',
12002: '当前页面评论功能已关闭',
12009: '评论主体的type不合法',
12061: 'UP主已关闭评论区',
};
return { return {
'status': false, 'status': false,
'date': [], 'date': [],
'msg': errMap[res.data['code']] ?? res.data['message'], 'code': res.data['code'],
'msg': res.data['message'],
}; };
} }
} }

View File

@ -25,6 +25,7 @@ class DynamicDetailController extends GetxController {
RxString sortTypeTitle = ReplySortType.time.titles.obs; RxString sortTypeTitle = ReplySortType.time.titles.obs;
RxString sortTypeLabel = ReplySortType.time.labels.obs; RxString sortTypeLabel = ReplySortType.time.labels.obs;
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
RxInt replyReqCode = 200.obs;
@override @override
void onInit() { void onInit() {
@ -84,6 +85,7 @@ class DynamicDetailController extends GetxController {
replyList.addAll(replies); replyList.addAll(replies);
} }
} }
replyReqCode.value = res['code'];
isLoadingMore = false; isLoadingMore = false;
return res; return res;
} }

View File

@ -369,35 +369,40 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
curve: Curves.easeInOut, curve: Curves.easeInOut,
), ),
), ),
child: FloatingActionButton( child: Obx(
heroTag: null, () => _dynamicDetailController.replyReqCode.value == 12061
onPressed: () { ? const SizedBox()
feedBack(); : FloatingActionButton(
showModalBottomSheet( heroTag: null,
context: context, onPressed: () {
isScrollControlled: true, feedBack();
builder: (BuildContext context) { showModalBottomSheet(
return VideoReplyNewDialog( context: context,
oid: _dynamicDetailController.oid ?? isScrollControlled: true,
IdUtils.bv2av(Get.parameters['bvid']!), builder: (BuildContext context) {
root: 0, return VideoReplyNewDialog(
parent: 0, oid: _dynamicDetailController.oid ??
replyType: ReplyType.values[replyType], IdUtils.bv2av(Get.parameters['bvid']!),
); root: 0,
}, parent: 0,
).then( replyType: ReplyType.values[replyType],
(value) => { );
// 完成评论,数据添加 },
if (value != null && value['data'] != null) ).then(
{ (value) => {
_dynamicDetailController.replyList.add(value['data']), // 完成评论,数据添加
_dynamicDetailController.acount.value++ if (value != null && value['data'] != null)
} {
}, _dynamicDetailController.replyList
); .add(value['data']),
}, _dynamicDetailController.acount.value++
tooltip: '评论动态', }
child: const Icon(Icons.reply), },
);
},
tooltip: '评论动态',
child: const Icon(Icons.reply),
),
), ),
), ),
); );

View File

@ -37,6 +37,7 @@ class VideoReplyController extends GetxController {
RxString sortTypeLabel = ReplySortType.time.labels.obs; RxString sortTypeLabel = ReplySortType.time.labels.obs;
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
RxInt replyReqCode = 200.obs;
@override @override
void onInit() { void onInit() {
@ -106,6 +107,7 @@ class VideoReplyController extends GetxController {
replyList.addAll(replies); replyList.addAll(replies);
} }
} }
replyReqCode.value = res['code'];
isLoadingMore = false; isLoadingMore = false;
return res; return res;
} }

View File

@ -277,32 +277,39 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
parent: fabAnimationCtr, parent: fabAnimationCtr,
curve: Curves.easeInOut, curve: Curves.easeInOut,
)), )),
child: FloatingActionButton( child: Obx(
heroTag: null, () => _videoReplyController.replyReqCode.value == 12061
onPressed: () { ? const SizedBox()
feedBack(); : FloatingActionButton(
showModalBottomSheet( heroTag: null,
context: context, onPressed: () {
isScrollControlled: true, feedBack();
builder: (BuildContext context) { showModalBottomSheet(
return VideoReplyNewDialog( context: context,
oid: _videoReplyController.aid ?? isScrollControlled: true,
IdUtils.bv2av(Get.parameters['bvid']!), builder: (BuildContext context) {
root: 0, return VideoReplyNewDialog(
parent: 0, oid: _videoReplyController.aid ??
replyType: ReplyType.video, IdUtils.bv2av(Get.parameters['bvid']!),
); root: 0,
}, parent: 0,
).then( replyType: ReplyType.video,
(value) => { );
// 完成评论,数据添加 },
if (value != null && value['data'] != null) ).then(
{_videoReplyController.replyList.add(value['data'])} (value) => {
}, // 完成评论,数据添加
); if (value != null && value['data'] != null)
}, {
tooltip: '发表评论', _videoReplyController.replyList
child: const Icon(Icons.reply), .add(value['data'])
}
},
);
},
tooltip: '发表评论',
child: const Icon(Icons.reply),
),
), ),
), ),
), ),

View File

@ -43,6 +43,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
String toolbarType = 'input'; String toolbarType = 'input';
RxBool isForward = false.obs; RxBool isForward = false.obs;
RxBool showForward = false.obs; RxBool showForward = false.obs;
RxString message = ''.obs;
@override @override
void initState() { void initState() {
@ -80,15 +81,15 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
Future submitReplyAdd() async { Future submitReplyAdd() async {
feedBack(); feedBack();
String message = _replyContentController.text; // String message = _replyContentController.text;
var result = await VideoHttp.replyAdd( var result = await VideoHttp.replyAdd(
type: widget.replyType ?? ReplyType.video, type: widget.replyType ?? ReplyType.video,
oid: widget.oid!, oid: widget.oid!,
root: widget.root!, root: widget.root!,
parent: widget.parent!, parent: widget.parent!,
message: widget.replyItem != null && widget.replyItem!.root != 0 message: widget.replyItem != null && widget.replyItem!.root != 0
? ' 回复 @${widget.replyItem!.member!.uname!} : $message' ? ' 回复 @${widget.replyItem!.member!.uname!} : ${message.value}'
: message, : message.value,
); );
if (result['status']) { if (result['status']) {
SmartDialog.showToast(result['data']['success_toast']); SmartDialog.showToast(result['data']['success_toast']);
@ -100,7 +101,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
if (isForward.value) { if (isForward.value) {
await DynamicsHttp.dynamicCreate( await DynamicsHttp.dynamicCreate(
mid: 0, mid: 0,
rawText: message, rawText: message.value,
oid: widget.oid!, oid: widget.oid!,
scene: 5, scene: 5,
); );
@ -188,7 +189,7 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextField( child: TextField(
controller: _replyContentController, controller: _replyContentController,
minLines: 1, minLines: 3,
maxLines: null, maxLines: null,
autofocus: false, autofocus: false,
focusNode: replyContentFocusNode, focusNode: replyContentFocusNode,
@ -199,6 +200,9 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
fontSize: 14, fontSize: 14,
)), )),
style: Theme.of(context).textTheme.bodyLarge, style: Theme.of(context).textTheme.bodyLarge,
onChanged: (text) {
message.value = text;
},
), ),
), ),
), ),
@ -267,9 +271,11 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
const Spacer(), const Spacer(),
SizedBox( SizedBox(
height: 36, height: 36,
child: FilledButton( child: Obx(
onPressed: () => submitReplyAdd(), () => FilledButton(
child: const Text('发送'), onPressed: message.isNotEmpty ? submitReplyAdd : null,
child: const Text('发送'),
),
), ),
), ),
], ],