ModifyPWDSecondViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. //
  2. // ModifyPWDSecondViewController.m
  3. //
  4. //
  5. // Created by APPLE on 2023/9/19.
  6. //
  7. #import "ModifyPWDSecondViewController.h"
  8. #import <Masonry.h>
  9. #import "mineViewController.h"
  10. @interface ModifyPWDSecondViewController (){
  11. NSString *pwd;
  12. UILabel *pointView0;
  13. UILabel *pointView1;
  14. UILabel *pointView2;
  15. UILabel *pointView3;
  16. UILabel *topLabel;
  17. UIButton *keyBoardBtn0;
  18. }
  19. @end
  20. @implementation ModifyPWDSecondViewController
  21. @synthesize oldPWD;
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. pwd = @"";
  26. [self drawAnyView];
  27. }
  28. - (void)drawAnyView{
  29. [self.navigationBar setHidden:YES];
  30. [self.toolBar setHidden:YES];
  31. [self.view setBackgroundColor:HWF5F7FAColor];
  32. /*添加取消按钮*/
  33. UIButton *cancelStepBtn = [[UIButton alloc] init];
  34. [cancelStepBtn setTitle:NSLocalizedString(@"other_cancel",nil) forState:(UIControlStateNormal)];
  35. [cancelStepBtn setTitleColor:HWFFD315Color forState:(UIControlStateNormal)];
  36. [cancelStepBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  37. [cancelStepBtn addTarget:self
  38. action:@selector(goSetHome)
  39. forControlEvents:(UIControlEventTouchUpInside)];
  40. [self.view addSubview:cancelStepBtn];
  41. [cancelStepBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.right.mas_equalTo(-10.f);
  43. make.width.mas_equalTo(58.f);
  44. make.top.mas_equalTo(5.f + H_STATE_BAR);
  45. make.height.mas_equalTo(32.f);
  46. }];
  47. /*上一步按钮*/
  48. UIButton *upStepBtn = [[UIButton alloc] init];
  49. [upStepBtn setTitle:NSLocalizedString(@"guide_set_pwd_up_step",nil) forState:(UIControlStateNormal)];
  50. [upStepBtn setTitleColor:HWFFD315Color forState:(UIControlStateNormal)];
  51. [upStepBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  52. [upStepBtn addTarget:self.navigationController
  53. action:@selector(popViewControllerAnimated:)
  54. forControlEvents:(UIControlEventTouchUpInside)];
  55. upStepBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  56. [self.view addSubview:upStepBtn];
  57. [upStepBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(10.f);
  59. make.width.mas_equalTo(100.f);
  60. make.top.mas_equalTo(5.f + H_STATE_BAR);
  61. make.height.mas_equalTo(32.f);
  62. }];
  63. /*设置密码标题*/
  64. topLabel = [[UILabel alloc] init];
  65. [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  66. [topLabel setTextColor:HW333333Color];
  67. [topLabel setTextAlignment:(NSTextAlignmentCenter)];
  68. [topLabel setText:NSLocalizedString(@"guide_set_pwd_makesure_title",nil)];
  69. [self.view addSubview:topLabel];
  70. [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.mas_equalTo(20);
  72. make.right.mas_equalTo(-20);
  73. make.top.mas_equalTo(99.f + H_STATE_BAR);
  74. }];
  75. CGFloat w_pwd = 24.f;
  76. CGFloat h_pwd = 24.f;
  77. CGFloat pointFont = 20.f;
  78. /*密码视图*/
  79. pointView0 = [[UILabel alloc] init];
  80. [pointView0 setTextColor:HW0A132BColor];
  81. [pointView0 setBackgroundColor:HWE3E8F1Color];
  82. [pointView0 setClipsToBounds:YES];
  83. [pointView0 setTextAlignment:(NSTextAlignmentCenter)];
  84. [pointView0 setFont:[UIFont systemFontOfSize:pointFont]];
  85. [pointView0.layer setCornerRadius:w_pwd/2.f];
  86. [self.view addSubview:pointView0];
  87. [pointView0 mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.equalTo(self.view.mas_centerX).offset((0-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  89. make.height.mas_equalTo(h_pwd);
  90. make.width.mas_equalTo(w_pwd);
  91. make.top.mas_equalTo(151.f + H_STATE_BAR);
  92. }];
  93. pointView1 = [[UILabel alloc] init];
  94. [pointView1 setTextColor:HW0A132BColor];
  95. [pointView1 setBackgroundColor:HWE3E8F1Color];
  96. [pointView1 setClipsToBounds:YES];
  97. [pointView1 setTextAlignment:(NSTextAlignmentCenter)];
  98. [pointView1 setFont:[UIFont systemFontOfSize:pointFont]];
  99. [pointView1.layer setCornerRadius:w_pwd/2.f];
  100. [self.view addSubview:pointView1];
  101. [pointView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.equalTo(self.view.mas_centerX).offset((1-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  103. make.height.mas_equalTo(h_pwd);
  104. make.width.mas_equalTo(w_pwd);
  105. make.top.mas_equalTo(151.f + H_STATE_BAR);
  106. }];
  107. pointView2 = [[UILabel alloc] init];
  108. [pointView2 setTextColor:HW0A132BColor];
  109. [pointView2 setBackgroundColor:HWE3E8F1Color];
  110. [pointView2 setClipsToBounds:YES];
  111. [pointView2 setTextAlignment:(NSTextAlignmentCenter)];
  112. [pointView2 setFont:[UIFont systemFontOfSize:pointFont]];
  113. [pointView2.layer setCornerRadius:w_pwd/2.f];
  114. [self.view addSubview:pointView2];
  115. [pointView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.left.equalTo(self.view.mas_centerX).offset((2-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  117. make.height.mas_equalTo(h_pwd);
  118. make.width.mas_equalTo(w_pwd);
  119. make.top.mas_equalTo(151.f + H_STATE_BAR);
  120. }];
  121. pointView3 = [[UILabel alloc] init];
  122. [pointView3 setTextColor:HW0A132BColor];
  123. [pointView3 setBackgroundColor:HWE3E8F1Color];
  124. [pointView3 setClipsToBounds:YES];
  125. [pointView3 setTextAlignment:(NSTextAlignmentCenter)];
  126. [pointView3 setFont:[UIFont systemFontOfSize:pointFont]];
  127. [pointView3.layer setCornerRadius:w_pwd/2.f];
  128. [self.view addSubview:pointView3];
  129. [pointView3 mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.left.equalTo(self.view.mas_centerX).offset((3-2)*(w_pwd+w_pwd) + w_pwd/2.f);
  131. make.height.mas_equalTo(h_pwd);
  132. make.width.mas_equalTo(w_pwd);
  133. make.top.mas_equalTo(151.f + H_STATE_BAR);
  134. }];
  135. /*下方绘制键盘按钮*/
  136. UIView *bgViewForNumberBoard = [[UIView alloc] init];
  137. [bgViewForNumberBoard setBackgroundColor:[UIColor clearColor]];
  138. CGFloat w_bgViewForNumberBoard = SCREEN_W - 2*22.f*AUTOSCALE;
  139. CGFloat h_bgViewForNumberBoard = 330.f;
  140. [self.view addSubview:bgViewForNumberBoard];
  141. [bgViewForNumberBoard mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.left.mas_equalTo(22.f*AUTOSCALE);
  143. make.height.mas_equalTo(h_bgViewForNumberBoard);
  144. make.width.mas_equalTo(w_bgViewForNumberBoard);
  145. make.bottom.mas_equalTo(-70.f);
  146. }];
  147. CGFloat w_key_btn = w_bgViewForNumberBoard/3.f;
  148. CGFloat h_key_btn = h_bgViewForNumberBoard/4.f;
  149. /*绘制键盘 1~9*/
  150. for (NSInteger nFori = 0; nFori < 9; nFori++) {
  151. CGFloat x_key_btn = (nFori%3)*w_key_btn;
  152. CGFloat y_key_btn = (nFori/3)*h_key_btn;
  153. UIButton *keyBoardBtn = [[UIButton alloc] init];
  154. [keyBoardBtn setBackgroundColor:[UIColor clearColor]];
  155. [keyBoardBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  156. [keyBoardBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  157. [keyBoardBtn setTitle:[NSString stringWithFormat:@"%ld",nFori+1] forState:(UIControlStateNormal)];
  158. [keyBoardBtn addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  159. [bgViewForNumberBoard addSubview:keyBoardBtn];
  160. [keyBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.left.mas_equalTo(x_key_btn);
  162. make.top.mas_equalTo(y_key_btn);
  163. make.width.mas_equalTo(w_key_btn);
  164. make.height.mas_equalTo(h_key_btn);
  165. }];
  166. }
  167. /*删除按钮*/
  168. UIButton *deleteBoardBtn = [[UIButton alloc] init];
  169. [deleteBoardBtn setBackgroundColor:[UIColor clearColor]];
  170. [deleteBoardBtn addTarget:self action:@selector(deleteBoardBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  171. [deleteBoardBtn setImage:[UIImage imageNamed:@"key_board_delete"] forState:(UIControlStateNormal)];
  172. [bgViewForNumberBoard addSubview:deleteBoardBtn];
  173. [deleteBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  174. make.left.mas_equalTo(0);
  175. make.bottom.mas_equalTo(0);
  176. make.width.mas_equalTo(w_key_btn);
  177. make.height.mas_equalTo(h_key_btn);
  178. }];
  179. /*0*/
  180. keyBoardBtn0 = [[UIButton alloc] init];
  181. [keyBoardBtn0 setBackgroundColor:[UIColor clearColor]];
  182. [keyBoardBtn0 setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
  183. [keyBoardBtn0 setTitleColor:COLOR_PACEHOLDER forState:(UIControlStateDisabled)];
  184. [keyBoardBtn0.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
  185. [keyBoardBtn0 setTitle:@"0" forState:(UIControlStateNormal)];
  186. [keyBoardBtn0 addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  187. keyBoardBtn0.enabled = NO;
  188. [bgViewForNumberBoard addSubview:keyBoardBtn0];
  189. [keyBoardBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.left.mas_equalTo(w_key_btn);
  191. make.bottom.mas_equalTo(0);
  192. make.width.mas_equalTo(w_key_btn);
  193. make.height.mas_equalTo(h_key_btn);
  194. }];
  195. /*OK*/
  196. UIButton *keyBoardBtnOK = [[UIButton alloc] init];
  197. [keyBoardBtnOK setBackgroundColor:[UIColor clearColor]];
  198. [keyBoardBtnOK setTitleColor:HWFFD315Color forState:(UIControlStateNormal)];
  199. [keyBoardBtnOK.titleLabel setFont:[UIFont boldSystemFontOfSize:30.f]];
  200. [keyBoardBtnOK setTitle:@"OK" forState:(UIControlStateNormal)];
  201. [keyBoardBtnOK addTarget:self action:@selector(keyBoardBtnOKPressed) forControlEvents:(UIControlEventTouchUpInside)];
  202. [bgViewForNumberBoard addSubview:keyBoardBtnOK];
  203. [keyBoardBtnOK mas_makeConstraints:^(MASConstraintMaker *make) {
  204. make.left.mas_equalTo(2*w_key_btn);
  205. make.bottom.mas_equalTo(0);
  206. make.width.mas_equalTo(w_key_btn);
  207. make.height.mas_equalTo(h_key_btn);
  208. }];
  209. }
  210. - (void)deleteBoardBtnPressed{
  211. if (pwd.length > 0){
  212. NSInteger numberLength = pwd.length;
  213. if (numberLength == 1){
  214. [pointView0 setText:@""];
  215. [pointView0 setBackgroundColor:HWE3E8F1Color];
  216. self->keyBoardBtn0.enabled = NO;
  217. }else if (numberLength == 2){
  218. [pointView1 setText:@""];
  219. [pointView1 setBackgroundColor:HWE3E8F1Color];
  220. }else if (numberLength == 3){
  221. [pointView2 setText:@""];
  222. [pointView2 setBackgroundColor:HWE3E8F1Color];
  223. }else if (numberLength == 4){
  224. [pointView3 setText:@""];
  225. [pointView3 setBackgroundColor:HWE3E8F1Color];
  226. }
  227. pwd = [pwd substringToIndex:numberLength-1];
  228. }
  229. }
  230. - (void)keyBoardBtnOKPressed{
  231. if (pwd.length == 4){
  232. if ([pwd isEqualToString:oldPWD]) {
  233. /*设置密码成功*/
  234. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  235. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
  236. [dict setObject:pwd forKey:Const_Have_Add_Device_PWD];
  237. [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
  238. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  239. //有设备了先去做链接准备 // 80bec9c5
  240. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  241. if(SNStr){
  242. KWeakSelf
  243. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  244. [[netWorkManager shareInstance] updateCardInfoBySN:SNStr withPwdStr:pwd didNetEnd:^(NSInteger didSuc) {
  245. [weakSelf removeNewIndicator];
  246. if(didSuc){
  247. [[iToast makeText:NSLocalizedString(@"logo_set_pwd_success",nil)] show];
  248. /*返回设置首页*/
  249. [weakSelf goSetHome];
  250. }
  251. else{
  252. }
  253. }];
  254. }
  255. }
  256. }else{
  257. /*提示密码不一致*/
  258. [topLabel setText:NSLocalizedString(@"guide_set_pwd_no_same",nil)];
  259. }
  260. }
  261. }
  262. - (void)goSetHome{
  263. for (UIViewController *vc in [self.navigationController viewControllers]) {
  264. if ([vc isKindOfClass:[mineViewController class]]){
  265. [self.navigationController popToViewController:vc animated:YES];
  266. [[NSNotificationCenter defaultCenter] postNotificationName:showTabbarNotification object:nil];/*发送通知*/
  267. break;
  268. }
  269. }
  270. }
  271. - (void)keyBoardBtnPressed:(id)sender{
  272. UIButton *btn = (UIButton *)sender;
  273. NSString *selectNumberStr = btn.titleLabel.text;
  274. if (pwd.length < 4){
  275. NSInteger numberLength = pwd.length;
  276. if (numberLength == 0){
  277. [pointView0 setText:selectNumberStr];
  278. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  279. [self->pointView0 setBackgroundColor:HW0A132BColor];
  280. self->keyBoardBtn0.enabled = YES;
  281. });
  282. }else if (numberLength == 1){
  283. [pointView1 setText:selectNumberStr];
  284. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  285. [self->pointView1 setBackgroundColor:HW0A132BColor];
  286. });
  287. }else if (numberLength == 2){
  288. [pointView2 setText:selectNumberStr];
  289. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  290. [self->pointView2 setBackgroundColor:HW0A132BColor];
  291. });
  292. }else if (numberLength == 3){
  293. [pointView3 setText:selectNumberStr];
  294. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  295. [self->pointView3 setBackgroundColor:HW0A132BColor];
  296. });
  297. }
  298. pwd = [pwd stringByAppendingString:selectNumberStr];
  299. }
  300. }
  301. /*
  302. #pragma mark - Navigation
  303. // In a storyboard-based application, you will often want to do a little preparation before navigation
  304. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  305. // Get the new view controller using [segue destinationViewController].
  306. // Pass the selected object to the new view controller.
  307. }
  308. */
  309. @end