DeleteAccountController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. //
  2. // DeleteAccountController.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/5/11.
  6. //
  7. #import "DeleteAccountController.h"
  8. #import "UDManager.h"
  9. #import "UserNetApi.h"
  10. #import "UserNetApi.h"
  11. @interface DeleteAccountController ()
  12. @property (nonatomic, strong) UIStackView * titleStackView;
  13. @property (nonatomic, strong) UILabel * passwordTitle;
  14. @property (nonatomic, strong) UILabel * codeTitle;
  15. @property (nonatomic, strong) UITextField * passwordTextfield;
  16. @property (nonatomic, strong) UITextField * codeTextfield;
  17. @property (nonatomic, strong) UIButton * getCodeBtn;
  18. @property (nonatomic, strong) UIButton * deleteBtn;
  19. @property (nonatomic, strong) NSMutableDictionary * userInfo;
  20. @property (nonatomic, strong) NSTimer *timer;
  21. @property (nonatomic, assign) NSInteger remainingSeconds;
  22. @end
  23. @implementation DeleteAccountController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // 创建一个点击手势
  27. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  28. // 将手势添加到主视图上
  29. [self.view addGestureRecognizer:tap];
  30. [self configUI];
  31. }
  32. -(void)dismissKeyboard{
  33. NSLog(@"dismissKeyboard");
  34. [self.view endEditing:YES];
  35. }
  36. - (void)configUI{
  37. [self setNavigationTitle:NSLocalizedString(@"userCenter-zhuxiaozh", @"")];
  38. // 设置导航栏背景色
  39. [self setNavigationBarBackgroundColor:UIColor.clearColor];
  40. // 设置标题颜色和字体
  41. [self setNavigationTitleColor:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:16]];
  42. // 设置返回按钮
  43. [self setBackButtonTitle:@""];
  44. [self setBackButtonColor:[UIColor whiteColor]];
  45. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  46. [self.view addSubview:bgImageView];
  47. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.right.top.bottom.mas_equalTo(0);
  49. }];
  50. [self.view addSubview:self.titleStackView];
  51. [self.titleStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.height.mas_equalTo(128);
  53. make.left.mas_equalTo(20);
  54. make.top.mas_equalTo(SCREEN_TOP+48);
  55. }];
  56. [self.view addSubview:self.passwordTextfield];
  57. [self.passwordTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.height.mas_equalTo(50);
  59. make.left.mas_equalTo(104);
  60. make.right.mas_equalTo(-30);
  61. make.centerY.mas_equalTo(self.passwordTitle.mas_centerY);
  62. }];
  63. [self.view addSubview:self.codeTextfield];
  64. [self.codeTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.height.mas_equalTo(50);
  66. make.left.mas_equalTo(104);
  67. make.right.mas_equalTo(-30);
  68. make.centerY.mas_equalTo(self.codeTitle.mas_centerY);
  69. }];
  70. [self.view addSubview:self.getCodeBtn];
  71. [self.getCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.size.mas_equalTo(CGSizeMake(125, 46));
  73. make.right.mas_equalTo(-20);
  74. make.top.mas_equalTo(self.codeTextfield.mas_bottom).offset(30);
  75. }];
  76. [self.view addSubview:self.deleteBtn];
  77. [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.height.mas_equalTo(46);
  79. make.left.mas_equalTo(20);
  80. make.right.mas_equalTo(-20);
  81. make.top.mas_equalTo(self.getCodeBtn.mas_bottom).offset(30);
  82. }];
  83. }
  84. #pragma mark event
  85. - (void)getCodeButtonClicked{
  86. //发送验证码
  87. [UserNetApi getEmailcodereset:self.userInfo[@"username"] succ:^(int code, NSDictionary * _Nullable res) {
  88. NSLog(@"result:%@",res);
  89. if ([res jk_hasKey:@"code"] && [res[@"code"] isEqual: @200]) {
  90. // 开始倒计时
  91. self.remainingSeconds = 60;
  92. [self startTimer];
  93. // 禁用按钮并改变样式
  94. self.getCodeBtn.enabled = NO;
  95. [self.getCodeBtn setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
  96. [self.getCodeBtn setTitle:[NSString stringWithFormat:@"%@(%ld)",NSLocalizedString(@"Sign-wangjimm", @"验证码"), (long)self.remainingSeconds] forState:UIControlStateDisabled];
  97. // [AlertHelper showAlertWithTitle:@"" message:NSLocalizedString(@"Sign-yanzhengmts", @"") cancelButtonTitle:NSLocalizedString(@"Common_getIt", @"") confirmButtonTitle:nil completion:^(NSInteger buttonIndex) {
  98. //
  99. // }];
  100. }else{
  101. [MBProgressHUD showWithText:res[@"msg"]];
  102. }
  103. } fail:^(NSError * _Nonnull error) {
  104. NSLog(@"error:%@",error);
  105. [MBProgressHUD showWithText:NSLocalizedString(@"Login_network_alter", @"")];
  106. }];
  107. }
  108. - (void)deleteAccountButtonClicked{
  109. if (self.passwordTextfield.text.length == 0) {
  110. [MBProgressHUD showWithText:NSLocalizedString(@"Sign-passw-note", @"")];
  111. return;
  112. }
  113. if (self.codeTextfield.text.length == 0) {
  114. [MBProgressHUD showWithText:NSLocalizedString(@"Sign-qingsryzm", @"")];
  115. return;
  116. }
  117. // [AlertHelper showAlertWithTitle:NSLocalizedString(@"Common_tips", @"") message:NSLocalizedString(@"Security_deleteAccount_alter", @"") cancelButtonTitle:NSLocalizedString(@"Common_cancel", @"") confirmButtonTitle:NSLocalizedString(@"Common_deleteAccount", @"") completion:^(NSInteger buttonIndex) {
  118. //
  119. // if (buttonIndex == 0) {
  120. // [self deleteAccount];
  121. // }
  122. // }];
  123. }
  124. #pragma mark api
  125. - (void)deleteAccount{
  126. NSDictionary * param = @{
  127. @"username":self.userInfo[@"username"],
  128. @"password":self.passwordTextfield.text,
  129. @"code":self.codeTextfield.text,
  130. @"uuid":@""
  131. };
  132. [UserNetApi zhuxiaozhanghao:param succ:^(int code, NSDictionary * _Nullable res) {
  133. if ([res jk_hasKey:@"msg"]) {
  134. [MBProgressHUD showWithText:res[@"msg"]];
  135. }
  136. if ([res jk_hasKey:@"code"] && [res[@"code"] isEqual:@200]) {
  137. // [UDManager.shareInstance removeUDManager:gkeytoken];
  138. // [UDManager.shareInstance removeUDManager:dkuserloginId];
  139. // [UDManager.shareInstance removeUDManager:dkuserinfo];
  140. //// [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  141. // [[LoginStateManager sharedManager] clearLoginStatus];
  142. }
  143. } fail:^(NSError * _Nonnull error) {
  144. NSLog(@"error%@",error);
  145. }];
  146. }
  147. #pragma mark timer
  148. - (void)startTimer {
  149. if (!self.timer) {
  150. self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
  151. target:self
  152. selector:@selector(updateTimer:)
  153. userInfo:nil
  154. repeats:YES];
  155. [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
  156. }
  157. }
  158. - (void)updateTimer:(NSTimer *)timer {
  159. self.remainingSeconds--;
  160. if (self.remainingSeconds <= 0) {
  161. [self stopTimer];
  162. // 恢复按钮状态
  163. self.getCodeBtn.enabled = YES;
  164. [self.getCodeBtn setTitle:NSLocalizedString(@"Sign-huoquyzm", @"") forState:UIControlStateNormal];
  165. } else {
  166. [self.getCodeBtn setTitle:[NSString stringWithFormat:@"%@(%ld)",NSLocalizedString(@"Sign-wangjimm", @"验证码"), (long)self.remainingSeconds] forState:UIControlStateDisabled];
  167. }
  168. }
  169. - (void)stopTimer {
  170. if (self.timer) {
  171. [self.timer invalidate];
  172. self.timer = nil;
  173. }
  174. }
  175. - (void)dealloc {
  176. [self stopTimer];
  177. }
  178. #pragma mark lazy
  179. - (UIStackView *)titleStackView{
  180. if (!_titleStackView) {
  181. _titleStackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.passwordTitle,self.codeTitle]];
  182. _titleStackView.axis = UILayoutConstraintAxisVertical;
  183. _titleStackView.alignment = UIStackViewAlignmentFill;
  184. _titleStackView.distribution = UIStackViewDistributionEqualSpacing;
  185. _titleStackView.spacing = 64;
  186. }
  187. return _titleStackView;
  188. }
  189. - (UILabel *)passwordTitle{
  190. if (!_passwordTitle) {
  191. _passwordTitle = [[UILabel alloc] init];
  192. _passwordTitle.text = NSLocalizedString(@"Common_password", @"");
  193. _passwordTitle.textColor = UIColor.whiteColor;
  194. _passwordTitle.font = SYSFONT(16);
  195. }
  196. return _passwordTitle;
  197. }
  198. - (UILabel *)codeTitle{
  199. if (!_codeTitle) {
  200. _codeTitle = [[UILabel alloc] init];
  201. _codeTitle.text = NSLocalizedString(@"Sign-wangjimm", @"");
  202. _codeTitle.textColor = UIColor.whiteColor;
  203. _codeTitle.font = SYSFONT(16);
  204. }
  205. return _codeTitle;
  206. }
  207. - (UITextField *)passwordTextfield{
  208. if (!_passwordTextfield) {
  209. _passwordTextfield = [[UITextField alloc] init];
  210. _passwordTextfield.textColor = UIColor.whiteColor;
  211. _passwordTextfield.borderStyle = UITextBorderStyleNone;
  212. _passwordTextfield.layer.borderWidth = 1.f;
  213. _passwordTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  214. _passwordTextfield.layer.cornerRadius = 5.f;
  215. _passwordTextfield.secureTextEntry = YES;
  216. _passwordTextfield.leftViewMode = UITextFieldViewModeAlways;
  217. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  218. _passwordTextfield.leftView = leftView;
  219. }
  220. return _passwordTextfield;
  221. }
  222. - (UITextField *)codeTextfield{
  223. if (!_codeTextfield) {
  224. _codeTextfield = [[UITextField alloc] init];
  225. _codeTextfield.textColor = UIColor.whiteColor;
  226. _codeTextfield.borderStyle = UITextBorderStyleNone;
  227. _codeTextfield.layer.borderWidth = 1.f;
  228. _codeTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  229. _codeTextfield.layer.cornerRadius = 5.f;
  230. _codeTextfield.leftViewMode = UITextFieldViewModeAlways;
  231. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  232. _codeTextfield.leftView = leftView;
  233. }
  234. return _codeTextfield;
  235. }
  236. - (UIButton *)getCodeBtn{
  237. if (!_getCodeBtn) {
  238. _getCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  239. [_getCodeBtn setBackgroundColor:globalColor(GCTypeGreen)];
  240. [_getCodeBtn setTitle:NSLocalizedString(@"Sign-huoquyzm", @"") forState:UIControlStateNormal];
  241. [_getCodeBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  242. _getCodeBtn.titleLabel.font = SYSMFONT(14);
  243. _getCodeBtn.layer.cornerRadius = 5.f;
  244. _getCodeBtn.layer.masksToBounds = YES;
  245. [_getCodeBtn addTarget:nil action:@selector(getCodeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  246. }
  247. return _getCodeBtn;
  248. }
  249. - (UIButton *)deleteBtn{
  250. if (!_deleteBtn) {
  251. _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  252. [_deleteBtn setBackgroundColor:globalColor(GCTypeGreen)];
  253. [_deleteBtn setTitle:NSLocalizedString(@"userCenter-zhuxiaozh", @"") forState:UIControlStateNormal];
  254. [_deleteBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  255. _deleteBtn.titleLabel.font = SYSMFONT(16);
  256. _deleteBtn.layer.cornerRadius = 5.f;
  257. _deleteBtn.layer.masksToBounds = YES;
  258. [_deleteBtn addTarget:nil action:@selector(deleteAccountButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  259. }
  260. return _deleteBtn;
  261. }
  262. - (NSMutableDictionary *)userInfo{
  263. if (!_userInfo) {
  264. _userInfo = [NSMutableDictionary dictionaryWithDictionary:[UDManager.shareInstance getDDManager:dkuserinfo]];
  265. }
  266. return _userInfo;
  267. }
  268. #pragma mark statusBar
  269. - (UIStatusBarStyle)preferredStatusBarStyle{
  270. return UIStatusBarStyleLightContent;
  271. }
  272. @end