mod: 系统消息
This commit is contained in:
@ -555,6 +555,10 @@ class Api {
|
|||||||
static const String messageSystemAPi =
|
static const String messageSystemAPi =
|
||||||
'${HttpString.messageBaseUrl}/x/sys-msg/query_unified_notify';
|
'${HttpString.messageBaseUrl}/x/sys-msg/query_unified_notify';
|
||||||
|
|
||||||
|
/// 系统通知 个人
|
||||||
|
static const String userMessageSystemAPi =
|
||||||
|
'${HttpString.messageBaseUrl}/x/sys-msg/query_user_notify';
|
||||||
|
|
||||||
/// 系统通知标记已读
|
/// 系统通知标记已读
|
||||||
static const String systemMarkRead =
|
static const String systemMarkRead =
|
||||||
'${HttpString.messageBaseUrl}/x/sys-msg/update_cursor';
|
'${HttpString.messageBaseUrl}/x/sys-msg/update_cursor';
|
||||||
|
@ -330,4 +330,27 @@ class MsgHttp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future messageSystemAccount() async {
|
||||||
|
var res = await Request().get(Api.userMessageSystemAPi, data: {
|
||||||
|
'csrf': await Request.getCsrf(),
|
||||||
|
'page_size': 20,
|
||||||
|
'build': 0,
|
||||||
|
'mobi_app': 'web',
|
||||||
|
});
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
'data': res.data['data']['system_notify_list']
|
||||||
|
.map<MessageSystemModel>((e) => MessageSystemModel.fromJson(e))
|
||||||
|
.toList(),
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
return {'status': false, 'date': [], 'msg': err.toString()};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {'status': false, 'date': [], 'msg': res.data['message']};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ class MessageSystemModel {
|
|||||||
int? cursor;
|
int? cursor;
|
||||||
int? type;
|
int? type;
|
||||||
String? title;
|
String? title;
|
||||||
Map? content;
|
dynamic content;
|
||||||
Source? source;
|
Source? source;
|
||||||
String? timeAt;
|
String? timeAt;
|
||||||
int? cardType;
|
int? cardType;
|
||||||
@ -45,7 +45,9 @@ class MessageSystemModel {
|
|||||||
cursor: jsons["cursor"],
|
cursor: jsons["cursor"],
|
||||||
type: jsons["type"],
|
type: jsons["type"],
|
||||||
title: jsons["title"],
|
title: jsons["title"],
|
||||||
content: json.decode(jsons["content"]),
|
content: isValidJson(jsons["content"])
|
||||||
|
? json.decode(jsons["content"])
|
||||||
|
: jsons["content"],
|
||||||
source: Source.fromJson(jsons["source"]),
|
source: Source.fromJson(jsons["source"]),
|
||||||
timeAt: jsons["time_at"],
|
timeAt: jsons["time_at"],
|
||||||
cardType: jsons["card_type"],
|
cardType: jsons["card_type"],
|
||||||
@ -75,3 +77,12 @@ class Source {
|
|||||||
logo: json["logo"],
|
logo: json["logo"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isValidJson(String str) {
|
||||||
|
try {
|
||||||
|
json.decode(str);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.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/system.dart';
|
import 'package:pilipala/models/msg/system.dart';
|
||||||
@ -5,18 +6,44 @@ import 'package:pilipala/models/msg/system.dart';
|
|||||||
class MessageSystemController extends GetxController {
|
class MessageSystemController extends GetxController {
|
||||||
RxList<MessageSystemModel> systemItems = <MessageSystemModel>[].obs;
|
RxList<MessageSystemModel> systemItems = <MessageSystemModel>[].obs;
|
||||||
|
|
||||||
Future queryMessageSystem({String type = 'init'}) async {
|
Future<void> queryAndProcessMessages({String type = 'init'}) async {
|
||||||
var res = await MsgHttp.messageSystem();
|
// 并行调用两个接口
|
||||||
if (res['status']) {
|
var results = await Future.wait([
|
||||||
if (type == 'init') {
|
queryMessageSystem(type: type),
|
||||||
systemItems.value = res['data'];
|
queryMessageSystemAccount(type: type),
|
||||||
} else {
|
]);
|
||||||
systemItems.addAll(res['data']);
|
|
||||||
}
|
// 对返回的数据进行处理
|
||||||
|
var systemRes = results[0];
|
||||||
|
var accountRes = results[1];
|
||||||
|
|
||||||
|
if (systemRes['status'] || accountRes['status']) {
|
||||||
|
// 处理返回的数据
|
||||||
|
List<MessageSystemModel> combinedData = [
|
||||||
|
...systemRes['data'],
|
||||||
|
...accountRes['data']
|
||||||
|
];
|
||||||
|
combinedData.sort((a, b) => b.cursor!.compareTo(a.cursor!));
|
||||||
|
systemItems.addAll(combinedData);
|
||||||
|
systemItems.refresh();
|
||||||
if (systemItems.isNotEmpty) {
|
if (systemItems.isNotEmpty) {
|
||||||
systemMarkRead(systemItems.first.cursor!);
|
systemMarkRead(systemItems.first.cursor!);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(systemRes['msg'] ?? accountRes['msg']);
|
||||||
}
|
}
|
||||||
|
return systemRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取系统消息
|
||||||
|
Future queryMessageSystem({String type = 'init'}) async {
|
||||||
|
var res = await MsgHttp.messageSystem();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取系统消息 个人
|
||||||
|
Future queryMessageSystemAccount({String type = 'init'}) async {
|
||||||
|
var res = await MsgHttp.messageSystemAccount();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class _MessageSystemPageState extends State<MessageSystemPage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_futureBuilderFuture = _messageSystemCtr.queryMessageSystem();
|
_futureBuilderFuture = _messageSystemCtr.queryAndProcessMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -31,7 +31,7 @@ class _MessageSystemPageState extends State<MessageSystemPage> {
|
|||||||
),
|
),
|
||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
await _messageSystemCtr.queryMessageSystem();
|
await _messageSystemCtr.queryAndProcessMessages();
|
||||||
},
|
},
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: _futureBuilderFuture,
|
future: _futureBuilderFuture,
|
||||||
@ -42,7 +42,6 @@ class _MessageSystemPageState extends State<MessageSystemPage> {
|
|||||||
}
|
}
|
||||||
if (snapshot.data['status']) {
|
if (snapshot.data['status']) {
|
||||||
final systemItems = _messageSystemCtr.systemItems;
|
final systemItems = _messageSystemCtr.systemItems;
|
||||||
print(systemItems.length);
|
|
||||||
return Obx(
|
return Obx(
|
||||||
() => ListView.separated(
|
() => ListView.separated(
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
@ -115,7 +114,7 @@ class SystemItem extends StatelessWidget {
|
|||||||
style: TextStyle(color: Theme.of(context).colorScheme.outline),
|
style: TextStyle(color: Theme.of(context).colorScheme.outline),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
Text(item.content!['web']),
|
Text(item.content is String ? item.content : item.content!['web']),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user