feat: 收到的赞

This commit is contained in:
guozhigq
2024-06-16 17:53:46 +08:00
parent 1ebbdfb6ca
commit b5ff6d1418
15 changed files with 636 additions and 24 deletions

View File

@ -545,4 +545,7 @@ class Api {
/// 回复我的
static const String messageReplyAPi = '/x/msgfeed/reply';
/// 收到的赞
static const String messageLikeAPi = '/x/msgfeed/like';
}

View File

@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:math';
import 'package:dio/dio.dart';
import 'package:pilipala/models/msg/like.dart';
import 'package:pilipala/models/msg/reply.dart';
import '../models/msg/account.dart';
import '../models/msg/session.dart';
@ -256,7 +257,30 @@ class MsgHttp {
'data': MessageReplyModel.fromJson(res.data['data']),
};
} catch (err) {
print(err);
return {'status': false, 'date': [], 'msg': err.toString()};
}
} else {
return {'status': false, 'date': [], 'msg': res.data['message']};
}
}
// 收到的赞
static Future messageLike({
int? id,
int? likeTime,
}) async {
var params = {
if (id != null) 'id': id,
if (likeTime != null) 'like_time': likeTime,
};
var res = await Request().get(Api.messageLikeAPi, data: params);
if (res.data['code'] == 0) {
try {
return {
'status': true,
'data': MessageLikeModel.fromJson(res.data['data']),
};
} catch (err) {
return {'status': false, 'date': [], 'msg': err.toString()};
}
} else {

183
lib/models/msg/like.dart Normal file
View File

@ -0,0 +1,183 @@
class MessageLikeModel {
MessageLikeModel({
this.latest,
this.total,
});
Latest? latest;
Total? total;
factory MessageLikeModel.fromJson(Map<String, dynamic> json) =>
MessageLikeModel(
latest: json["latest"] == null ? null : Latest.fromJson(json["latest"]),
total: json["total"] == null ? null : Total.fromJson(json["total"]),
);
}
class Latest {
Latest({
this.items,
this.lastViewAt,
});
List? items;
int? lastViewAt;
factory Latest.fromJson(Map<String, dynamic> json) => Latest(
items: json["items"],
lastViewAt: json["last_view_at"],
);
}
class Total {
Total({
this.cursor,
this.items,
});
Cursor? cursor;
List<MessageLikeItem>? items;
factory Total.fromJson(Map<String, dynamic> json) => Total(
cursor: Cursor.fromJson(json['cursor']),
items: json["items"] == null
? []
: json["items"].map<MessageLikeItem>((e) {
return MessageLikeItem.fromJson(e);
}).toList(),
);
}
class Cursor {
Cursor({
this.id,
this.isEnd,
this.time,
});
int? id;
bool? isEnd;
int? time;
factory Cursor.fromJson(Map<String, dynamic> json) => Cursor(
id: json['id'],
isEnd: json['is_end'],
time: json['time'],
);
}
class MessageLikeItem {
MessageLikeItem({
this.id,
this.users,
this.item,
this.counts,
this.likeTime,
this.noticeState,
this.isExpand = false,
});
int? id;
List<MessageLikeUser>? users;
MessageLikeItemItem? item;
int? counts;
int? likeTime;
int? noticeState;
bool isExpand;
factory MessageLikeItem.fromJson(Map<String, dynamic> json) =>
MessageLikeItem(
id: json["id"],
users: json["users"] == null
? []
: json["users"].map<MessageLikeUser>((e) {
return MessageLikeUser.fromJson(e);
}).toList(),
item: json["item"] == null
? null
: MessageLikeItemItem.fromJson(json["item"]),
counts: json["counts"],
likeTime: json["like_time"],
noticeState: json["notice_state"],
);
}
class MessageLikeUser {
MessageLikeUser({
this.mid,
this.fans,
this.nickname,
this.avatar,
this.midLink,
this.follow,
});
int? mid;
int? fans;
String? nickname;
String? avatar;
String? midLink;
bool? follow;
factory MessageLikeUser.fromJson(Map<String, dynamic> json) =>
MessageLikeUser(
mid: json["mid"],
fans: json["fans"],
nickname: json["nickname"],
avatar: json["avatar"],
midLink: json["mid_link"],
follow: json["follow"],
);
}
class MessageLikeItemItem {
MessageLikeItemItem({
this.itemId,
this.pid,
this.type,
this.business,
this.businessId,
this.replyBusinessId,
this.likeBusinessId,
this.title,
this.desc,
this.image,
this.uri,
this.detailName,
this.nativeUri,
this.ctime,
});
int? itemId;
int? pid;
String? type;
String? business;
int? businessId;
int? replyBusinessId;
int? likeBusinessId;
String? title;
String? desc;
String? image;
String? uri;
String? detailName;
String? nativeUri;
int? ctime;
factory MessageLikeItemItem.fromJson(Map<String, dynamic> json) =>
MessageLikeItemItem(
itemId: json["item_id"],
pid: json["pid"],
type: json["type"],
business: json["business"],
businessId: json["business_id"],
replyBusinessId: json["reply_business_id"],
likeBusinessId: json["like_business_id"],
title: json["title"],
desc: json["desc"],
image: json["image"],
uri: json["uri"],
detailName: json["detail_name"],
nativeUri: json["native_uri"],
ctime: json["ctime"],
);
}

View File

@ -0,0 +1,3 @@
import 'package:get/get.dart';
class MessageAtController extends GetxController {}

View File

@ -0,0 +1,4 @@
library message_at;
export './controller.dart';
export './view.dart';

View File

@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
class MessageAtPage extends StatefulWidget {
const MessageAtPage({super.key});
@override
State<MessageAtPage> createState() => _MessageAtPageState();
}
class _MessageAtPageState extends State<MessageAtPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('@我的'),
),
);
}
}

View File

@ -0,0 +1,30 @@
import 'package:get/get.dart';
import 'package:pilipala/http/msg.dart';
import 'package:pilipala/models/msg/like.dart';
class MessageLikeController extends GetxController {
Cursor? cursor;
RxList<MessageLikeItem> likeItems = <MessageLikeItem>[].obs;
Future queryMessageLike({String type = 'init'}) async {
if (cursor != null && cursor!.isEnd == true) {
return {};
}
var params = {
if (type == 'onLoad') 'id': cursor!.id,
if (type == 'onLoad') 'likeTime': cursor!.time,
};
var res = await MsgHttp.messageLike(
id: params['id'], likeTime: params['likeTime']);
if (res['status']) {
cursor = res['data'].total.cursor;
likeItems.addAll(res['data'].total.items);
}
return res;
}
Future expandedUsersAvatar(i) async {
likeItems[i].isExpand = !likeItems[i].isExpand;
likeItems.refresh();
}
}

View File

@ -0,0 +1,4 @@
library message_like;
export './controller.dart';
export './view.dart';

View File

@ -0,0 +1,319 @@
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/http/search.dart';
import 'package:pilipala/models/msg/like.dart';
import 'package:pilipala/utils/utils.dart';
import 'controller.dart';
class MessageLikePage extends StatefulWidget {
const MessageLikePage({super.key});
@override
State<MessageLikePage> createState() => _MessageLikePageState();
}
class _MessageLikePageState extends State<MessageLikePage> {
final MessageLikeController _messageLikeCtr =
Get.put(MessageLikeController());
late Future _futureBuilderFuture;
final ScrollController scrollController = ScrollController();
@override
void initState() {
super.initState();
_futureBuilderFuture = _messageLikeCtr.queryMessageLike();
scrollController.addListener(
() async {
if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent - 200) {
EasyThrottle.throttle('follow', const Duration(seconds: 1), () {
_messageLikeCtr.queryMessageLike(type: 'onLoad');
});
}
},
);
}
@override
void dispose() {
scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('收到的赞'),
),
body: RefreshIndicator(
onRefresh: () async {
await _messageLikeCtr.queryMessageLike(type: 'init');
},
child: FutureBuilder(
future: _futureBuilderFuture,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data == null) {
return const SizedBox();
}
if (snapshot.data['status']) {
final likeItems = _messageLikeCtr.likeItems;
return Obx(
() => ListView.separated(
controller: scrollController,
itemBuilder: (context, index) => LikeItem(
item: likeItems[index],
index: index,
messageLikeCtr: _messageLikeCtr,
),
itemCount: likeItems.length,
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 66,
endIndent: 14,
height: 1,
color: Colors.grey.withOpacity(0.1),
);
},
),
);
} else {
// 请求错误
return CustomScrollView(
slivers: [
HttpError(
errMsg: snapshot.data['msg'],
fn: () {
setState(() {
_futureBuilderFuture =
_messageLikeCtr.queryMessageLike();
});
},
)
],
);
}
} else {
return const SizedBox();
}
},
),
),
);
}
}
class LikeItem extends StatelessWidget {
final MessageLikeItem item;
final int index;
final MessageLikeController messageLikeCtr;
const LikeItem(
{super.key,
required this.item,
required this.index,
required this.messageLikeCtr});
@override
Widget build(BuildContext context) {
Color outline = Theme.of(context).colorScheme.outline;
final nickNameList = item.users!.map((e) => e.nickname).take(2).toList();
int usersLen = item.users!.length > 3 ? 3 : item.users!.length;
final String bvid = item.item!.uri!.split('/').last;
// 页码
final String page =
item.item!.nativeUri!.split('page=').last.split('&').first;
// 根评论id
final String commentRootId =
item.item!.nativeUri!.split('comment_root_id=').last.split('&').first;
// 二级评论id
final String commentSecondaryId =
item.item!.nativeUri!.split('comment_secondary_id=').last;
return InkWell(
onTap: () async {
try {
final int cid = await SearchHttp.ab2c(bvid: bvid);
final String heroTag = Utils.makeHeroTag(bvid);
Get.toNamed<dynamic>(
'/video?bvid=$bvid&cid=$cid',
arguments: <String, String?>{
'pic': '',
'heroTag': heroTag,
},
);
} catch (_) {
SmartDialog.showToast('视频可能失效了');
}
},
child: Stack(
children: [
Padding(
padding: const EdgeInsets.all(14),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
if (usersLen == 1) {
final String heroTag =
Utils.makeHeroTag(item.users!.first.mid);
Get.toNamed('/member?mid=${item.users!.first.mid}',
arguments: {
'face': item.users!.first.avatar,
'heroTag': heroTag
});
} else {
messageLikeCtr.expandedUsersAvatar(index);
}
},
// 多个头像层叠
child: SizedBox(
width: 50,
height: 50,
child: Stack(
children: [
for (var i = 0; i < usersLen; i++)
Positioned(
top: i % 2 * (50 / (usersLen >= 2 ? 2 : 1)),
left: i / 2 * (50 / (usersLen >= 2 ? 2 : 1)),
child: NetworkImgLayer(
width: 50 / (usersLen >= 2 ? 2 : 1),
height: 50 / (usersLen >= 2 ? 2 : 1),
type: 'avatar',
src: item.users![i].avatar,
),
),
],
),
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(TextSpan(children: [
TextSpan(text: nickNameList.join('')),
const TextSpan(text: ' '),
if (item.users!.length > 1)
TextSpan(
text: '等总计${item.users!.length}',
style: TextStyle(color: outline),
),
TextSpan(
text: '赞了我的评论',
style: TextStyle(color: outline),
),
])),
const SizedBox(height: 4),
Text(
Utils.dateFormat(item.likeTime!, formatType: 'detail'),
style: TextStyle(color: outline),
),
],
),
),
const SizedBox(width: 25),
if (item.item!.type! == 'reply')
Container(
width: 60,
height: 60,
padding: const EdgeInsets.all(4),
child: Text(
item.item!.title!,
maxLines: 4,
style: const TextStyle(fontSize: 12, letterSpacing: 0.3),
overflow: TextOverflow.ellipsis,
),
),
if (item.item!.type! == 'video')
NetworkImgLayer(
width: 60,
height: 60,
src: item.item!.image,
),
],
),
),
Positioned(
top: 0,
right: 0,
bottom: 0,
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
width: item.isExpand ? Get.size.width - 74 : 0,
color: Theme.of(context).colorScheme.secondaryContainer,
child: ListView.builder(
itemCount: item.users!.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int i) {
return Padding(
padding: EdgeInsets.fromLTRB(i == 0 ? 12 : 4, 8, 4, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
final String heroTag =
Utils.makeHeroTag(item.users![i].mid);
Get.toNamed(
'/member?mid=${item.users![i].mid}',
arguments: {
'face': item.users![i].avatar,
'heroTag': heroTag
},
);
},
child: NetworkImgLayer(
width: 42,
height: 42,
type: 'avatar',
src: item.users![i].avatar,
),
),
const SizedBox(height: 6),
SizedBox(
width: 68,
child: Text(
textAlign: TextAlign.center,
item.users![i].nickname!,
maxLines: 1,
overflow: TextOverflow.clip,
style: TextStyle(color: outline),
),
),
],
),
);
},
),
),
),
Positioned(
top: 0,
left: 0,
bottom: 0,
child: GestureDetector(
onTap: () {
messageLikeCtr.expandedUsersAvatar(index);
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
width: item.isExpand ? 74 : 0,
color: Colors.black.withOpacity(0.3),
),
),
),
],
),
);
}
}

View File

@ -113,6 +113,7 @@ class ReplyItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
Color outline = Theme.of(context).colorScheme.outline;
final String heroTag = Utils.makeHeroTag(item.user!.mid);
final String bvid = item.item!.uri!.split('/').last;
// 页码
@ -167,15 +168,11 @@ class ReplyItem extends StatelessWidget {
const TextSpan(text: ' '),
if (item.item!.type! == 'video')
TextSpan(
text: '对我的视频发表了评论',
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
),
text: '对我的视频发表了评论', style: TextStyle(color: outline)),
if (item.item!.type! == 'reply')
TextSpan(
text: '回复了我的评论',
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
style: TextStyle(color: outline),
),
])),
const SizedBox(height: 6),
@ -188,8 +185,7 @@ class ReplyItem extends StatelessWidget {
const SizedBox(height: 2),
Text(
item.item!.targetReplyContent!,
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
style: TextStyle(color: outline),
),
],
const SizedBox(height: 4),
@ -197,21 +193,15 @@ class ReplyItem extends StatelessWidget {
children: [
Text(
Utils.dateFormat(item.replyTime!, formatType: 'detail'),
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
style: TextStyle(color: outline),
),
const SizedBox(width: 16),
Text(
'回复',
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
),
Text('回复', style: TextStyle(color: outline)),
],
)
],
),
),
// Spacer(),
const SizedBox(width: 25),
if (item.item!.type! == 'reply')
Container(
@ -221,10 +211,7 @@ class ReplyItem extends StatelessWidget {
child: Text(
item.item!.rootReplyContent!,
maxLines: 4,
style: const TextStyle(
fontSize: 12,
letterSpacing: 0.3,
),
style: const TextStyle(fontSize: 12, letterSpacing: 0.3),
overflow: TextOverflow.ellipsis,
),
),

View File

@ -0,0 +1,3 @@
import 'package:get/get.dart';
class MessageSystemController extends GetxController {}

View File

@ -0,0 +1,4 @@
library message_system;
export './controller.dart';
export './view.dart';

View File

@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
class MessageSystemPage extends StatefulWidget {
const MessageSystemPage({super.key});
@override
State<MessageSystemPage> createState() => _MessageSystemPageState();
}
class _MessageSystemPageState extends State<MessageSystemPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('系统通知'),
),
);
}
}

View File

@ -18,19 +18,19 @@ class WhisperController extends GetxController {
{
'icon': Icons.alternate_email,
'title': '@ 我的',
'path': '',
'path': '/messageAt',
'count': 0,
},
{
'icon': Icons.thumb_up_outlined,
'title': '收到的赞',
'path': '',
'path': '/messageLike',
'count': 0,
},
{
'icon': Icons.notifications_none_outlined,
'title': '系统通知',
'path': '',
'path': '/messageSystem',
'count': 0,
}
].obs;

View File

@ -4,7 +4,10 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/pages/follow_search/view.dart';
import 'package:pilipala/pages/message/at/index.dart';
import 'package:pilipala/pages/message/like/index.dart';
import 'package:pilipala/pages/message/reply/index.dart';
import 'package:pilipala/pages/message/system/index.dart';
import 'package:pilipala/pages/setting/pages/logs.dart';
import '../pages/about/index.dart';
@ -181,6 +184,13 @@ class Routes {
name: '/actionMenuSet', page: () => const ActionMenuSetPage()),
// 回复我的
CustomGetPage(name: '/messageReply', page: () => const MessageReplyPage()),
// @我的
CustomGetPage(name: '/messageAt', page: () => const MessageAtPage()),
// 收到的赞
CustomGetPage(name: '/messageLike', page: () => const MessageLikePage()),
// 系统通知
CustomGetPage(
name: '/messageSystem', page: () => const MessageSystemPage()),
];
}