RQProfileLogouItemViewModel.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // RQProfileLogouItemViewModel.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/8/2.
  6. //
  7. #import "RQProfileLogouItemViewModel.h"
  8. @interface RQProfileLogouItemViewModel ()
  9. /// 退出登录的命令
  10. @property (nonatomic, readwrite, strong) RACCommand *logoutCommand;
  11. /// 注销账号的命令
  12. @property (nonatomic, readwrite, strong) RACCommand *signoutCommand;
  13. @end
  14. @implementation RQProfileLogouItemViewModel
  15. - (instancetype)initWithTitle:(NSString *)title {
  16. if (self = [super init]) {
  17. self.title = title;
  18. self.rowHeight = RQ_FIT_HORIZONTAL(82.f);
  19. }
  20. return self;
  21. }
  22. /// 退出登录的命令
  23. - (RACCommand *)logoutCommand {
  24. if (!_logoutCommand) {
  25. _logoutCommand =[[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
  26. /// 删除账号
  27. [SAMKeychain deleteRawLogin];
  28. /// 先退出用户
  29. [RQ_USER_MANAGER logoutUser];
  30. return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
  31. /// 延迟一段时间
  32. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  33. /// 这里切换 到账号登录的界面
  34. [RQNotificationCenter postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogout)}];
  35. [subscriber sendNext:nil];
  36. [subscriber sendCompleted];
  37. });
  38. return [RACDisposable disposableWithBlock:^{
  39. }];
  40. }];
  41. }];
  42. }
  43. return _logoutCommand;
  44. }
  45. /// 退出登录的命令
  46. - (RACCommand *)signoutCommand {
  47. if (!_signoutCommand) {
  48. _signoutCommand =[[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
  49. /// 删除账号
  50. [SAMKeychain deleteRawLogin];
  51. /// 先退出用户
  52. [RQ_USER_MANAGER logoutUser];
  53. return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
  54. /// 延迟一段时间
  55. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  56. /// 这里切换 到账号登录的界面
  57. [RQNotificationCenter postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogout)}];
  58. [subscriber sendNext:nil];
  59. [subscriber sendCompleted];
  60. });
  61. return [RACDisposable disposableWithBlock:^{
  62. }];
  63. }];
  64. }];
  65. }
  66. return _signoutCommand;
  67. }
  68. - (NSString *)itemClassName {
  69. return @"RQProfileLogoutCell";
  70. }
  71. @end