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,7 +369,10 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
curve: Curves.easeInOut, curve: Curves.easeInOut,
), ),
), ),
child: FloatingActionButton( child: Obx(
() => _dynamicDetailController.replyReqCode.value == 12061
? const SizedBox()
: FloatingActionButton(
heroTag: null, heroTag: null,
onPressed: () { onPressed: () {
feedBack(); feedBack();
@ -390,7 +393,8 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
// 完成评论,数据添加 // 完成评论,数据添加
if (value != null && value['data'] != null) if (value != null && value['data'] != null)
{ {
_dynamicDetailController.replyList.add(value['data']), _dynamicDetailController.replyList
.add(value['data']),
_dynamicDetailController.acount.value++ _dynamicDetailController.acount.value++
} }
}, },
@ -400,6 +404,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
child: const Icon(Icons.reply), 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,7 +277,10 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
parent: fabAnimationCtr, parent: fabAnimationCtr,
curve: Curves.easeInOut, curve: Curves.easeInOut,
)), )),
child: FloatingActionButton( child: Obx(
() => _videoReplyController.replyReqCode.value == 12061
? const SizedBox()
: FloatingActionButton(
heroTag: null, heroTag: null,
onPressed: () { onPressed: () {
feedBack(); feedBack();
@ -297,7 +300,10 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
(value) => { (value) => {
// 完成评论,数据添加 // 完成评论,数据添加
if (value != null && value['data'] != null) if (value != null && value['data'] != null)
{_videoReplyController.replyList.add(value['data'])} {
_videoReplyController.replyList
.add(value['data'])
}
}, },
); );
}, },
@ -306,6 +312,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
), ),
), ),
), ),
),
], ],
), ),
); );

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,11 +271,13 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
const Spacer(), const Spacer(),
SizedBox( SizedBox(
height: 36, height: 36,
child: FilledButton( child: Obx(
onPressed: () => submitReplyAdd(), () => FilledButton(
onPressed: message.isNotEmpty ? submitReplyAdd : null,
child: const Text('发送'), child: const Text('发送'),
), ),
), ),
),
], ],
), ),
), ),