feat: 未读动态计数
This commit is contained in:
@ -467,4 +467,7 @@ class Api {
|
|||||||
/// page_size
|
/// page_size
|
||||||
static const getSeasonDetailApi =
|
static const getSeasonDetailApi =
|
||||||
'/x/polymer/web-space/seasons_archives_list';
|
'/x/polymer/web-space/seasons_archives_list';
|
||||||
|
|
||||||
|
/// 获取未读动态数
|
||||||
|
static const getUnreadDynamic = '/x/web-interface/dynamic/entrance';
|
||||||
}
|
}
|
||||||
|
|||||||
17
lib/http/common.dart
Normal file
17
lib/http/common.dart
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import 'index.dart';
|
||||||
|
|
||||||
|
class CommonHttp {
|
||||||
|
static Future unReadDynamic() async {
|
||||||
|
var res = await Request().get(Api.getUnreadDynamic,
|
||||||
|
data: {'alltype_offset': 0, 'video_offset': '', 'article_offset': 0});
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {'status': true, 'data': res.data['data']['dyn_basic_infos']};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
'status': false,
|
||||||
|
'data': [],
|
||||||
|
'msg': res.data['message'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:pilipala/http/common.dart';
|
||||||
import 'package:pilipala/pages/dynamics/index.dart';
|
import 'package:pilipala/pages/dynamics/index.dart';
|
||||||
import 'package:pilipala/pages/home/view.dart';
|
import 'package:pilipala/pages/home/view.dart';
|
||||||
import 'package:pilipala/pages/media/index.dart';
|
import 'package:pilipala/pages/media/index.dart';
|
||||||
@ -28,6 +29,7 @@ class MainController extends GetxController {
|
|||||||
size: 21,
|
size: 21,
|
||||||
),
|
),
|
||||||
'label': "首页",
|
'label': "首页",
|
||||||
|
'count': 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'icon': const Icon(
|
'icon': const Icon(
|
||||||
@ -39,6 +41,7 @@ class MainController extends GetxController {
|
|||||||
size: 21,
|
size: 21,
|
||||||
),
|
),
|
||||||
'label': "动态",
|
'label': "动态",
|
||||||
|
'count': 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'icon': const Icon(
|
'icon': const Icon(
|
||||||
@ -50,6 +53,7 @@ class MainController extends GetxController {
|
|||||||
size: 21,
|
size: 21,
|
||||||
),
|
),
|
||||||
'label': "媒体库",
|
'label': "媒体库",
|
||||||
|
'count': 0,
|
||||||
}
|
}
|
||||||
].obs;
|
].obs;
|
||||||
final StreamController<bool> bottomBarStream =
|
final StreamController<bool> bottomBarStream =
|
||||||
@ -59,6 +63,8 @@ class MainController extends GetxController {
|
|||||||
late bool hideTabBar;
|
late bool hideTabBar;
|
||||||
late PageController pageController;
|
late PageController pageController;
|
||||||
int selectedIndex = 0;
|
int selectedIndex = 0;
|
||||||
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
RxBool userLogin = false.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -67,6 +73,9 @@ class MainController extends GetxController {
|
|||||||
Utils.checkUpdata();
|
Utils.checkUpdata();
|
||||||
}
|
}
|
||||||
hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: true);
|
hideTabBar = setting.get(SettingBoxKey.hideTabBar, defaultValue: true);
|
||||||
|
var userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
userLogin.value = userInfo != null;
|
||||||
|
getUnreadDynamic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBackPressed(BuildContext context) {
|
void onBackPressed(BuildContext context) {
|
||||||
@ -83,4 +92,28 @@ class MainController extends GetxController {
|
|||||||
}
|
}
|
||||||
SystemNavigator.pop(); // 退出应用
|
SystemNavigator.pop(); // 退出应用
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getUnreadDynamic() async {
|
||||||
|
if (!userLogin.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int dynamicItemIndex =
|
||||||
|
navigationBars.indexWhere((item) => item['label'] == "动态");
|
||||||
|
var res = await CommonHttp.unReadDynamic();
|
||||||
|
var data = res['data'];
|
||||||
|
if (dynamicItemIndex != -1) {
|
||||||
|
navigationBars[dynamicItemIndex]['count'] =
|
||||||
|
data == null ? 0 : data.length; // 修改 count 属性为新的值
|
||||||
|
}
|
||||||
|
navigationBars.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearUnread() async {
|
||||||
|
int dynamicItemIndex =
|
||||||
|
navigationBars.indexWhere((item) => item['label'] == "动态");
|
||||||
|
if (dynamicItemIndex != -1) {
|
||||||
|
navigationBars[dynamicItemIndex]['count'] = 0; // 修改 count 属性为新的值
|
||||||
|
}
|
||||||
|
navigationBars.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
|
|
||||||
void setIndex(int value) async {
|
void setIndex(int value) async {
|
||||||
feedBack();
|
feedBack();
|
||||||
_mainController.pageController!.jumpToPage(value);
|
_mainController.pageController.jumpToPage(value);
|
||||||
var currentPage = _mainController.pages[value];
|
var currentPage = _mainController.pages[value];
|
||||||
if (currentPage is HomePage) {
|
if (currentPage is HomePage) {
|
||||||
if (_homeController.flag) {
|
if (_homeController.flag) {
|
||||||
@ -67,6 +67,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
|
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
|
||||||
}
|
}
|
||||||
_dynamicController.flag = true;
|
_dynamicController.flag = true;
|
||||||
|
_mainController.clearUnread();
|
||||||
} else {
|
} else {
|
||||||
_dynamicController.flag = false;
|
_dynamicController.flag = false;
|
||||||
}
|
}
|
||||||
@ -118,36 +119,48 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
|||||||
curve: Curves.easeInOutCubicEmphasized,
|
curve: Curves.easeInOutCubicEmphasized,
|
||||||
duration: const Duration(milliseconds: 500),
|
duration: const Duration(milliseconds: 500),
|
||||||
offset: Offset(0, snapshot.data ? 0 : 1),
|
offset: Offset(0, snapshot.data ? 0 : 1),
|
||||||
child: enableMYBar
|
child: Obx(
|
||||||
? NavigationBar(
|
() => enableMYBar
|
||||||
onDestinationSelected: (value) => setIndex(value),
|
? NavigationBar(
|
||||||
selectedIndex: _mainController.selectedIndex,
|
onDestinationSelected: (value) => setIndex(value),
|
||||||
destinations: <Widget>[
|
selectedIndex: _mainController.selectedIndex,
|
||||||
..._mainController.navigationBars.map((e) {
|
destinations: <Widget>[
|
||||||
return NavigationDestination(
|
..._mainController.navigationBars.map((e) {
|
||||||
icon: e['icon'],
|
return NavigationDestination(
|
||||||
selectedIcon: e['selectIcon'],
|
icon: Badge(
|
||||||
label: e['label'],
|
label: Text(e['count'].toString()),
|
||||||
);
|
padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
|
||||||
}).toList(),
|
isLabelVisible: e['count'] > 0,
|
||||||
],
|
child: e['icon'],
|
||||||
)
|
),
|
||||||
: BottomNavigationBar(
|
selectedIcon: e['selectIcon'],
|
||||||
currentIndex: _mainController.selectedIndex,
|
label: e['label'],
|
||||||
onTap: (value) => setIndex(value),
|
);
|
||||||
iconSize: 16,
|
}).toList(),
|
||||||
selectedFontSize: 12,
|
],
|
||||||
unselectedFontSize: 12,
|
)
|
||||||
items: [
|
: BottomNavigationBar(
|
||||||
..._mainController.navigationBars.map((e) {
|
currentIndex: _mainController.selectedIndex,
|
||||||
return BottomNavigationBarItem(
|
onTap: (value) => setIndex(value),
|
||||||
icon: e['icon'],
|
iconSize: 16,
|
||||||
activeIcon: e['selectIcon'],
|
selectedFontSize: 12,
|
||||||
label: e['label'],
|
unselectedFontSize: 12,
|
||||||
);
|
items: [
|
||||||
}).toList(),
|
..._mainController.navigationBars.map((e) {
|
||||||
],
|
return BottomNavigationBarItem(
|
||||||
),
|
icon: Badge(
|
||||||
|
label: Text(e['count'].toString()),
|
||||||
|
padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
|
||||||
|
isLabelVisible: e['count'] > 0,
|
||||||
|
child: e['icon'],
|
||||||
|
),
|
||||||
|
activeIcon: e['selectIcon'],
|
||||||
|
label: e['label'],
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user