这是基于vue-vben-admin 模板适用于abp Vnext的前端管理项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

74 lines
2.1 KiB

import 'package:core/dependency/index.dart';
import 'package:get/get.dart';
import 'package:core/models/request.dart';
import 'package:core/services/subscription.service.dart';
import 'package:notifications/proxy/index.dart';
import '../../models/index.dart';
import '../../services/index.dart';
class NotifierManageController extends GetxController {
NotificationService get _notificationService => injector.get();
NotificationStateService get _stateService => injector.get();
SubscriptionService get _subscriptionService => injector.get();
final Rx<NotificationState> _state = Rx<NotificationState>(NotificationState(
isEnabled: true,
groups: []));
NotificationState get state => _state.value;
void _updateState() {
_state.value = _stateService.state;
_stateService.getNotificationState$()
.listen((state$) {
_state.update((val) {
val = state$;
});
});
}
void onSubscribed(Notification notification, bool isSubscribe) {
_stateService.changeLoadingState(notification, true);
var requestOptions = RequestOptions();
Stream<void> subscribe$;
if (isSubscribe) {
subscribe$ = _notificationService
.subscribe(notification.name, requestOptions: requestOptions)
.asStream();
} else {
subscribe$ = _notificationService
.unSubscribe(notification.name, requestOptions: requestOptions)
.asStream();
}
_subscriptionService.subscribeOnce(subscribe$,
done: () {
_stateService.changeSubscribedState(notification, isSubscribe);
_stateService.changeLoadingState(notification, false);
},
cancel: () {
if (super.isClosed) {
// 页面退出时需要取消网络请求
requestOptions.cancel();
// 页面退出时需要改变加载状态
_stateService.changeLoadingState(notification, false);
}
},
);
}
void onNotificationEnabled(bool isEnabled) {
_stateService.subscribeAll(isEnabled);
}
@override
void onInit() {
super.onInit();
_updateState();
}
@override
void onClose() {
_subscriptionService.closeAll();
super.onClose();
}
}