提交 4bf07ce1 authored 作者: yueweilu's avatar yueweilu

讨论删除 逻辑

上级 004e0834
...@@ -361,6 +361,23 @@ abstract class LibraryAPI { ...@@ -361,6 +361,23 @@ abstract class LibraryAPI {
} }
return false; return false;
} }
/// 18、删除讨论回复
static Future <bool> delComment({
required num bookId,
required num commentId,
}) async {
final result = await HttpService.to.post(
'/v1/book/Information/delComment',
params: {
'book_id':bookId,
'comment_id':commentId
},
);
if (result.data is Map && result.data['is_success'] == 1){
return true;
}
return false;
}
} }
\ No newline at end of file
...@@ -61,6 +61,7 @@ class DiscussController extends GetxController { ...@@ -61,6 +61,7 @@ class DiscussController extends GetxController {
update(); update();
} }
// 点赞 取消点赞
Future<void> commentLove({required DiscussModel discussModel}) async { Future<void> commentLove({required DiscussModel discussModel}) async {
num type = 0; num type = 0;
if (discussModel.isPraise ==0){ if (discussModel.isPraise ==0){
...@@ -81,7 +82,15 @@ class DiscussController extends GetxController { ...@@ -81,7 +82,15 @@ class DiscussController extends GetxController {
update(); update();
} }
// 删除回复
Future<void> delComment({required DiscussModel discussModel}) async {
final result = await LibraryAPI.delComment(bookId:bookDetailModel.bookId!, commentId: discussModel.id!);
if(result){
discuss.remove(discussModel);
Toast.show('删除成功');
}
update();
}
Future<bool> submit() async { Future<bool> submit() async {
......
...@@ -107,6 +107,9 @@ class _ReadDiscussPageState extends State<ReadDiscussPage> { ...@@ -107,6 +107,9 @@ class _ReadDiscussPageState extends State<ReadDiscussPage> {
model: model, model: model,
controller: controller, controller: controller,
bookId: widget.bookDetailModel.bookId.toString(), bookId: widget.bookDetailModel.bookId.toString(),
onTapDel: (DiscussModel dModel){
controller.delComment(discussModel: dModel);
},
); );
}, },
itemCount: controller.discuss.length, itemCount: controller.discuss.length,
......
...@@ -10,24 +10,98 @@ class UserDiscussDesController extends GetxController { ...@@ -10,24 +10,98 @@ class UserDiscussDesController extends GetxController {
controlFinishLoad: true, controlFinishLoad: true,
controlFinishRefresh: true, controlFinishRefresh: true,
); );
late TextEditingController replyInput = TextEditingController();
final int _limit = 10; final int _limit = 10;
int _page = 1; int _page = 1;
bool _noMore = false; bool _noMore = false;
// 展示回复输入框
bool showReply = false;
// 当前要回复的模型
late DiscussModel discussModel;
@override @override
void onReady() { void onReady() {
onRefresh(); // onRefresh();
super.onReady(); super.onReady();
} }
@override @override
void onClose() { void onClose() {
refreshController.dispose(); refreshController.dispose();
replyInput.dispose();
super.onClose(); super.onClose();
} }
void setShow() {
showReply = !showReply;
update();
}
void setDiscussModel(DiscussModel model){
discussModel = model;
}
// 删除回复
Future<void> delComment({required DiscussModel discussModel}) async {
final result = await LibraryAPI.delComment(bookId:model.bookId!, commentId: discussModel.id!);
if(result){
discuss.remove(discussModel);
Toast.show('删除成功');
}
update();
}
Future<bool> submit() async {
Map<String,dynamic> contentMap = {
'text':replyInput.text,
'audio':[],
'image':[]
};
final result = await LibraryAPI.addDiscuss(
bookId: model.bookId.toString(),
chapterId: discussModel.chapterId.toString(),
commentId: discussModel.id.toString(),
quoteContent: '',
title: '',
content: jsonEncode(contentMap)
);
if(result){
Toast.show('话题发表成功');
}
else{
Toast.show('话题发表失败');
}
// 重置所有信息
// reset();
// setShowChat(false);
return result;
}
Future<void> commentLove({required DiscussModel discussModel}) async {
num type = 0;
if (discussModel.isPraise ==0){
type = 1;
}
final result = await LibraryAPI.commentLove(bookId:model.bookId! , type: type, commentId: discussModel.id!);
if(result){
num goodNum = discussModel.goodNum??0;
if(type ==0){
goodNum --;
}
else{
goodNum ++;
}
discussModel.isPraise = type;
discussModel.goodNum = goodNum;
}
update();
}
/// 获取讨论详情 /// 获取讨论详情
Future<void> _getDiscuss([bool isRefresh = false]) async { Future<void> _getDiscuss([bool isRefresh = false]) async {
......
library user_discuss_des; library user_discuss_des;
import 'dart:convert';
import 'package:easy_refresh/easy_refresh.dart'; import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/widgets/index.dart'; import 'package:flutter_book/widgets/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
......
...@@ -4,11 +4,15 @@ class BuildDiscuss extends StatefulWidget { ...@@ -4,11 +4,15 @@ class BuildDiscuss extends StatefulWidget {
final DiscussModel model; final DiscussModel model;
final DiscussController? controller; final DiscussController? controller;
final String bookId; final String bookId;
final void Function(DiscussModel dModel)? onTapDel;
final UserDiscussDesController? userDiscussDesController;
const BuildDiscuss({ const BuildDiscuss({
Key? key, Key? key,
required this.model, required this.model,
this.controller, this.controller,
required this.bookId required this.bookId,
this.userDiscussDesController,
this.onTapDel,
}) : super(key: key); }) : super(key: key);
@override @override
...@@ -35,154 +39,194 @@ class _BuildDiscussState extends State<BuildDiscuss> { ...@@ -35,154 +39,194 @@ class _BuildDiscussState extends State<BuildDiscuss> {
), ),
], ],
), ),
child: Column( child: Slidable(
crossAxisAlignment: CrossAxisAlignment.start, enabled: widget.model.isMy == 1 ? true : false,
children: [ endActionPane: ActionPane(
RichText(text: TextSpan( motion: const ScrollMotion(),
children: [ children: [
TextSpan(text: '话题:',style: TextStyle( SlidableAction(
fontSize: 14.w, // An action can be bigger than the others.
height: 1.5.w, onPressed: (BuildContext context){
color: Colours.c3, if (widget.onTapDel !=null) widget.onTapDel!(widget.model);
)), },
TextSpan(text: widget.model.title,style: TextStyle( backgroundColor: const Color(0xFFAE1414),
fontSize: 14.w, foregroundColor: Colors.white,
height: 1.5.w, // icon: Icons.archive,
color: Colours.c3, label: '删除',
fontWeight: Fonts.medium ),
)), ],
] ),
)), child: Column(
Gaps.vGaps10, crossAxisAlignment: CrossAxisAlignment.start,
Container( children: [
height: 0.5.w, RichText(text: TextSpan(
color: Colours.cF2,
),
_buildItem(widget.model),
Container(
margin:EdgeInsets.only(left: 15.w),
child: _buildListView(widget.model.commentAll != null ? widget.model.commentAll!:[])
),
Gaps.vGaps13,
Container(
width: double.infinity,
padding: EdgeInsets.symmetric(vertical: 5.w,horizontal: 10.w),
color: Colours.cF8,
child:Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(widget.model.chapterName??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),), TextSpan(text: '话题:',style: TextStyle(
Text('内容:${widget.model.quoteContent??''}',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),), fontSize: 14.w,
], height: 1.5.w,
color: Colours.c3,
)),
TextSpan(text: widget.model.title,style: TextStyle(
fontSize: 14.w,
height: 1.5.w,
color: Colours.c3,
fontWeight: Fonts.medium
)),
]
)),
Gaps.vGaps10,
Container(
height: 0.5.w,
color: Colours.cF2,
),
_buildItem(widget.model),
Container(
margin:EdgeInsets.only(left: 15.w),
child: _buildListView(widget.model.commentAll != null ? widget.model.commentAll!:[])
),
Gaps.vGaps13,
Container(
width: double.infinity,
padding: EdgeInsets.symmetric(vertical: 5.w,horizontal: 10.w),
color: Colours.cF8,
child:Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.model.chapterName??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),),
Text('内容:${widget.model.quoteContent??''}',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),),
],
)
) )
) ],
], ),
), ),
); );
} }
Widget _buildItem(DiscussModel model,{int type =0}){ Widget _buildItem(DiscussModel model,{int type =0}){
return Row( return Slidable(
crossAxisAlignment: CrossAxisAlignment.start, enabled: type ==0?false: model.isMy == 1 ? true : false,
children: [ endActionPane: ActionPane(
Container( motion: const ScrollMotion(),
margin: EdgeInsets.only(top: 10.w), children: [
child: ClipRRect( SlidableAction(
borderRadius: BorderRadius.circular(17.5.w), // An action can be bigger than the others.
child: Container( onPressed: (BuildContext context){
width: 35.w, if (widget.onTapDel !=null) widget.onTapDel!(model);
height: 35.w, },
color: Colors.red, backgroundColor: const Color(0xFFAE1414),
child: CustomImage.network(url: model.personPic??''), foregroundColor: Colors.white,
// icon: Icons.archive,
label: '删除',
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(top: 10.w),
child: ClipRRect(
borderRadius: BorderRadius.circular(17.5.w),
child: Container(
width: 35.w,
height: 35.w,
child: CustomImage.network(url: model.personPic??''),
),
), ),
), ),
), Expanded(
Expanded( child: Container(
child: Container( margin: EdgeInsets.only(left: 10.w,top: 10.w),
margin: EdgeInsets.only(left: 10.w,top: 10.w), child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ Row(
Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
children: [ Row(
Row( children: [
children: [ Text(model.personName??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),),
Text(model.personName??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),), Gaps.hGaps10,
Gaps.hGaps10, type ==1?const SizedBox(): Text('发起人',style: TextStyle(fontSize: 11.w,height: 1.5,color: AppTheme.primary),)
type ==1?const SizedBox(): Text('发起人',style: TextStyle(fontSize: 11.w,height: 1.5,color: AppTheme.primary),) ],
], ),
), Text(model.createTime??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),)
Text(model.createTime??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9),) ],
], ),
), type ==0? Column(
type ==0? Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ Row(
Row( children: [
children: [ Text(_showText(model),style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c3),),
Text(_showText(model),style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c3),), Text(_showStatus(model),style: TextStyle(fontSize: 13.w,height: 1.5,color: AppTheme.primary),),
Text(_showStatus(model),style: TextStyle(fontSize: 13.w,height: 1.5,color: AppTheme.primary),), ],
], ),
), Gaps.vGaps10,
Gaps.vGaps10, _buildImageGridView()
_buildImageGridView() ],
], )
) :RichText(text: TextSpan(
:RichText(text: TextSpan( children: [
children: [ TextSpan(text: '回复 ',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c3)),
TextSpan(text: '回复 ',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c3)), TextSpan(text: model.replacePersonName??'',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c9)),
TextSpan(text: model.replacePersonName??'',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c9)), TextSpan(text: ':${model.content?.text?.content??''}',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c3)),
TextSpan(text: ':${model.content?.text?.content??''}',style: TextStyle(fontSize: 13.w,height: 1.5,color: Colours.c3)), ]
] )),
)), SizedBox(height: 10.w,),
SizedBox(height: 10.w,), Row(
Row( children: [
children: [ Row(
Row( crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, children: [
children: [ GestureDetector(
GestureDetector( onTap: () async{
onTap: () async{ widget.controller?.commentLove(discussModel: model);
widget.controller?.commentLove(discussModel: model); widget.userDiscussDesController?.commentLove(discussModel: model);
}, },
child: SizedBox( child: SizedBox(
height: 20.w, height: 20.w,
width: 20.w, width: 20.w,
// color: Colors.green, // color: Colors.green,
child: Image.asset(model.isPraise ==0?'assets/images/unlove.png': 'assets/images/love.png',fit: BoxFit.cover,), child: Image.asset(model.isPraise ==0?'assets/images/unlove.png': 'assets/images/love.png',fit: BoxFit.cover,),
),
), ),
), Text(model.goodNum.toString(),style: TextStyle(fontSize:12.w,height: 1.5,color: Colours.c9))
Text(model.goodNum.toString(),style: TextStyle(fontSize:12.w,height: 1.5,color: Colours.c9)) ],
], ),
), Gaps.hGaps15,
Gaps.hGaps15, Row(
Row( children: [
children: [ GestureDetector(
GestureDetector( onTap:(){
onTap:(){ // _showKeyboard(context);
// _showKeyboard(context); // 阅读页讨论列表
widget.controller?.setShow(); widget.controller?.setShow();
widget.controller?.setDiscussModel(model); widget.controller?.setDiscussModel(model);
}, // 我的讨论详情页列表
child: Container( widget.userDiscussDesController?.setShow();
height: 25.w, widget.userDiscussDesController?.setDiscussModel(model);
width: 15.w, },
// color: Colors.yellow, child: Container(
child: Image.asset('assets/images/reply.png',height: 15.w,width: 15.w,fit: BoxFit.fitWidth,), height: 25.w,
width: 15.w,
// color: Colors.yellow,
child: Image.asset('assets/images/reply.png',height: 15.w,width: 15.w,fit: BoxFit.fitWidth,),
),
), ),
), SizedBox(width: 3.w,),
SizedBox(width: 3.w,), Text(model.replyNum.toString(),style: TextStyle(fontSize:12.w,height: 1.5,color: Colours.c9))
Text(model.replyNum.toString(),style: TextStyle(fontSize:12.w,height: 1.5,color: Colours.c9)) ],
], )
) ],
], )
) ],
], ),
), ),
), )
) ],
], ),
); );
} }
......
...@@ -24,16 +24,95 @@ class _BuildListPageState extends State<BuildListPage> with AutomaticKeepAliveCl ...@@ -24,16 +24,95 @@ class _BuildListPageState extends State<BuildListPage> with AutomaticKeepAliveCl
controller: controller.refreshController, controller: controller.refreshController,
onRefresh: controller.onRefresh, onRefresh: controller.onRefresh,
onLoading: controller.onLoading, onLoading: controller.onLoading,
child: ListView.builder( child: Stack(
itemBuilder: (BuildContext context,int index){ children: [
DiscussModel model = controller.discuss[index]; ListView.builder(
return BuildDiscuss( itemBuilder: (BuildContext context,int index){
model: model, DiscussModel model = controller.discuss[index];
bookId: widget.model.bookId.toString(), return BuildDiscuss(
); model: model,
}, bookId: widget.model.bookId.toString(),
itemCount: controller.discuss.length, userDiscussDesController: controller,
), onTapDel: (DiscussModel dModel){
controller.delComment(discussModel: dModel);
},
);
},
itemCount: controller.discuss.length,
),
Visibility(
visible: controller.showReply,
child: Positioned(
bottom: 0 ,
left: 0,
right: 0,
top: 0,
child: GestureDetector(
onTap: (){
controller.setShow();
},
child: Container(
color: const Color(0xFF000000).withOpacity(0.5),
child: SingleChildScrollView(
reverse: true,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){},
child: Container(
color: Colors.white,
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
autofocus: true,
maxLines: null,
controller: controller.replyInput,
decoration: InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
hintText: '请输入内容',
hintStyle:TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c9,),
filled: true,
fillColor: Colours.cF8,
),
),
),
Gaps.hGaps10,
GestureDetector(
onTap: (){
controller.submit();
controller.setShow();
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.w),
color: AppTheme.primary,
gradient: LinearGradient(
colors: [const Color(0xFFD53676).withOpacity(0.9),AppTheme.primary] , // 不可点击时的颜色,透明度为0.7
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
padding: EdgeInsets.symmetric(horizontal:13.5.w,vertical: 4.w),
child: Text('发表',style: TextStyle(fontSize: 14.w,fontWeight: Fonts.medium,color: Colors.white),),
),
)
],
),
),
),
),
),
),
),
),
)
],
)
), ),
); );
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论