// // RQProfileLogouItemViewModel.m // SDJK // // Created by 张嵘 on 2021/8/2. // #import "RQProfileLogouItemViewModel.h" @interface RQProfileLogouItemViewModel () /// 退出登录的命令 @property (nonatomic, readwrite, strong) RACCommand *logoutCommand; /// 注销账号的命令 @property (nonatomic, readwrite, strong) RACCommand *signoutCommand; @end @implementation RQProfileLogouItemViewModel - (instancetype)initWithTitle:(NSString *)title { if (self = [super init]) { self.title = title; self.rowHeight = RQ_FIT_HORIZONTAL(82.f); } return self; } /// 退出登录的命令 - (RACCommand *)logoutCommand { if (!_logoutCommand) { _logoutCommand =[[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) { /// 删除账号 [SAMKeychain deleteRawLogin]; /// 先退出用户 [RQ_USER_MANAGER logoutUser]; return [RACSignal createSignal:^RACDisposable *(id subscriber) { /// 延迟一段时间 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ /// 这里切换 到账号登录的界面 [RQNotificationCenter postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogout)}]; [subscriber sendNext:nil]; [subscriber sendCompleted]; }); return [RACDisposable disposableWithBlock:^{ }]; }]; }]; } return _logoutCommand; } /// 退出登录的命令 - (RACCommand *)signoutCommand { if (!_signoutCommand) { _signoutCommand =[[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) { /// 删除账号 [SAMKeychain deleteRawLogin]; /// 先退出用户 [RQ_USER_MANAGER logoutUser]; return [RACSignal createSignal:^RACDisposable *(id subscriber) { /// 延迟一段时间 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ /// 这里切换 到账号登录的界面 [RQNotificationCenter postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogout)}]; [subscriber sendNext:nil]; [subscriber sendCompleted]; }); return [RACDisposable disposableWithBlock:^{ }]; }]; }]; } return _signoutCommand; } - (NSString *)itemClassName { return @"RQProfileLogoutCell"; } @end