feat: 未读消息计数
This commit is contained in:
@ -539,4 +539,7 @@ class Api {
|
|||||||
/// 关闭会话
|
/// 关闭会话
|
||||||
static const String removeSession =
|
static const String removeSession =
|
||||||
'${HttpString.tUrl}/session_svr/v1/session_svr/remove_session';
|
'${HttpString.tUrl}/session_svr/v1/session_svr/remove_session';
|
||||||
|
|
||||||
|
/// 消息未读数
|
||||||
|
static const String unread = '${HttpString.tUrl}/x/im/web/msgfeed/unread';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -225,4 +225,16 @@ class MsgHttp {
|
|||||||
return {'status': false, 'date': [], 'msg': res.data['message']};
|
return {'status': false, 'date': [], 'msg': res.data['message']};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future unread() async {
|
||||||
|
var res = await Request().get(Api.unread);
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
'data': res.data['data'],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {'status': false, 'date': [], 'msg': res.data['message']};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/http/msg.dart';
|
import 'package:pilipala/http/msg.dart';
|
||||||
import 'package:pilipala/models/msg/account.dart';
|
import 'package:pilipala/models/msg/account.dart';
|
||||||
@ -7,6 +8,38 @@ class WhisperController extends GetxController {
|
|||||||
RxList<SessionList> sessionList = <SessionList>[].obs;
|
RxList<SessionList> sessionList = <SessionList>[].obs;
|
||||||
RxList<AccountListModel> accountList = <AccountListModel>[].obs;
|
RxList<AccountListModel> accountList = <AccountListModel>[].obs;
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
|
RxList noticesList = [
|
||||||
|
{
|
||||||
|
'icon': Icons.message_outlined,
|
||||||
|
'title': '回复我的',
|
||||||
|
'path': '',
|
||||||
|
'count': 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'icon': Icons.alternate_email,
|
||||||
|
'title': '@ 我的',
|
||||||
|
'path': '',
|
||||||
|
'count': 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'icon': Icons.thumb_up_outlined,
|
||||||
|
'title': '收到的赞',
|
||||||
|
'path': '',
|
||||||
|
'count': 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'icon': Icons.notifications_none_outlined,
|
||||||
|
'title': '系统通知',
|
||||||
|
'path': '',
|
||||||
|
'count': 0,
|
||||||
|
}
|
||||||
|
].obs;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
unread();
|
||||||
|
super.onInit();
|
||||||
|
}
|
||||||
|
|
||||||
Future querySessionList(String? type) async {
|
Future querySessionList(String? type) async {
|
||||||
if (isLoading) return;
|
if (isLoading) return;
|
||||||
@ -77,4 +110,16 @@ class WhisperController extends GetxController {
|
|||||||
sessionList.removeWhere((p0) => p0.talkerId == talkerId);
|
sessionList.removeWhere((p0) => p0.talkerId == talkerId);
|
||||||
sessionList.refresh();
|
sessionList.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 消息未读数
|
||||||
|
void unread() async {
|
||||||
|
var res = await MsgHttp.unread();
|
||||||
|
if (res['status']) {
|
||||||
|
noticesList[0]['count'] = res['data']['reply'];
|
||||||
|
noticesList[1]['count'] = res['data']['at'];
|
||||||
|
noticesList[2]['count'] = res['data']['like'];
|
||||||
|
noticesList[3]['count'] = res['data']['sys_msg'];
|
||||||
|
noticesList.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/common/constants.dart';
|
||||||
import 'package:pilipala/common/skeleton/skeleton.dart';
|
import 'package:pilipala/common/skeleton/skeleton.dart';
|
||||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
@ -44,66 +45,66 @@ class _WhisperPageState extends State<WhisperPage> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('消息'),
|
title: const Text('消息'),
|
||||||
),
|
),
|
||||||
body: Column(
|
body: RefreshIndicator(
|
||||||
children: [
|
|
||||||
// LayoutBuilder(
|
|
||||||
// builder: (BuildContext context, BoxConstraints constraints) {
|
|
||||||
// // 在这里根据父级容器的约束条件构建小部件树
|
|
||||||
// return Padding(
|
|
||||||
// padding: const EdgeInsets.only(left: 20, right: 20),
|
|
||||||
// child: SizedBox(
|
|
||||||
// height: constraints.maxWidth / 5,
|
|
||||||
// child: GridView.count(
|
|
||||||
// primary: false,
|
|
||||||
// crossAxisCount: 4,
|
|
||||||
// padding: const EdgeInsets.all(0),
|
|
||||||
// childAspectRatio: 1.25,
|
|
||||||
// children: [
|
|
||||||
// Column(
|
|
||||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
// mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
// children: [
|
|
||||||
// SizedBox(
|
|
||||||
// width: 36,
|
|
||||||
// height: 36,
|
|
||||||
// child: IconButton(
|
|
||||||
// style: ButtonStyle(
|
|
||||||
// padding:
|
|
||||||
// MaterialStateProperty.all(EdgeInsets.zero),
|
|
||||||
// backgroundColor:
|
|
||||||
// MaterialStateProperty.resolveWith((states) {
|
|
||||||
// return Theme.of(context)
|
|
||||||
// .colorScheme
|
|
||||||
// .primary
|
|
||||||
// .withOpacity(0.1);
|
|
||||||
// }),
|
|
||||||
// ),
|
|
||||||
// onPressed: () {},
|
|
||||||
// icon: Icon(
|
|
||||||
// Icons.message_outlined,
|
|
||||||
// size: 18,
|
|
||||||
// color: Theme.of(context).colorScheme.primary,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// const SizedBox(height: 6),
|
|
||||||
// const Text('回复我的', style: TextStyle(fontSize: 13))
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
Expanded(
|
|
||||||
child: RefreshIndicator(
|
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
|
_whisperController.unread();
|
||||||
await _whisperController.onRefresh();
|
await _whisperController.onRefresh();
|
||||||
},
|
},
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
child: FutureBuilder(
|
child: Column(
|
||||||
|
children: [
|
||||||
|
LayoutBuilder(
|
||||||
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
|
// 在这里根据父级容器的约束条件构建小部件树
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 20, right: 20),
|
||||||
|
child: SizedBox(
|
||||||
|
height: constraints.maxWidth / 4,
|
||||||
|
child: Obx(
|
||||||
|
() => GridView.count(
|
||||||
|
primary: false,
|
||||||
|
crossAxisCount: 4,
|
||||||
|
padding: const EdgeInsets.all(0),
|
||||||
|
children: [
|
||||||
|
..._whisperController.noticesList.map((element) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: () => {},
|
||||||
|
onLongPress: () {},
|
||||||
|
borderRadius: StyleString.mdRadius,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Badge(
|
||||||
|
isLabelVisible: element['count'] > 0,
|
||||||
|
label: Text(element['count'] > 99
|
||||||
|
? '99+'
|
||||||
|
: element['count'].toString()),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
child: Icon(
|
||||||
|
element['icon'],
|
||||||
|
size: 21,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(element['title'])
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
FutureBuilder(
|
||||||
future: _futureBuilderFuture,
|
future: _futureBuilderFuture,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
@ -120,8 +121,7 @@ class _WhisperPageState extends State<WhisperPage> {
|
|||||||
itemBuilder: (_, int i) {
|
itemBuilder: (_, int i) {
|
||||||
return SessionItem(
|
return SessionItem(
|
||||||
sessionItem: sessionList[i],
|
sessionItem: sessionList[i],
|
||||||
changeFucCall: () =>
|
changeFucCall: () => sessionList.refresh(),
|
||||||
sessionList.refresh(),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
separatorBuilder:
|
separatorBuilder:
|
||||||
@ -181,11 +181,10 @@ class _WhisperPageState extends State<WhisperPage> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user