|
| 1 | +// |
| 2 | +// ProjectArchiveViewController.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Easeeeeeeeee on 2018/4/26. |
| 6 | +// Copyright © 2018年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "ProjectArchiveViewController.h" |
| 10 | +#import "Coding_NetAPIManager.h" |
| 11 | + |
| 12 | +#import <SDCAlertController.h> |
| 13 | +#import <SDCAlertView.h> |
| 14 | +#import <UIView+SDCAutoLayout.h> |
| 15 | +#import "ProjectDeleteAlertControllerVisualStyle.h" |
| 16 | + |
| 17 | +#import "Ease_2FA.h" |
| 18 | + |
| 19 | +@interface ProjectArchiveViewController ()<UITextFieldDelegate> |
| 20 | +@property (strong, nonatomic) SDCAlertController *alert; |
| 21 | + |
| 22 | +@end |
| 23 | + |
| 24 | +@implementation ProjectArchiveViewController |
| 25 | + |
| 26 | +- (void)viewDidLoad { |
| 27 | + [super viewDidLoad]; |
| 28 | + self.title = @"归档项目"; |
| 29 | + |
| 30 | + for (NSLayoutConstraint *cons in self.lines) { |
| 31 | + cons.constant = 0.5; |
| 32 | + } |
| 33 | + |
| 34 | + self.tableView.tableFooterView = [UIView new]; |
| 35 | + [self.tableView setSeparatorColor:[UIColor colorWithRGBHex:0xe5e5e5]]; |
| 36 | + self.tableView.backgroundColor = kColorTableSectionBg; |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| 41 | + return [UIView new]; |
| 42 | +} |
| 43 | + |
| 44 | +-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath |
| 45 | +{ |
| 46 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth]; |
| 47 | +} |
| 48 | + |
| 49 | +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 50 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| 51 | + if (indexPath.section != 1) { |
| 52 | + return; |
| 53 | + } |
| 54 | + [[Coding_NetAPIManager sharedManager] request_VerifyTypeWithBlock:^(VerifyType type, NSError *error) { |
| 55 | + if (!error) { |
| 56 | + [self showArchiveAlertWithType:type]; |
| 57 | + } |
| 58 | + }]; |
| 59 | +} |
| 60 | + |
| 61 | +- (void)showArchiveAlertWithType:(VerifyType)type{ |
| 62 | + |
| 63 | + if (self.alert) {//正在显示 |
| 64 | + return; |
| 65 | + } |
| 66 | + |
| 67 | + NSString *title, *message, *placeHolder; |
| 68 | + if (type == VerifyTypePassword) { |
| 69 | + title = @"需要验证密码"; |
| 70 | + message = @"这是一个危险的操作,请提供登录密码确认!"; |
| 71 | + placeHolder = @"请输入密码"; |
| 72 | + }else if (type == VerifyTypeTotp){ |
| 73 | + title = @"需要动态验证码"; |
| 74 | + message = @"这是一个危险操作,需要进行身份验证!"; |
| 75 | + placeHolder = @"请输入动态验证码"; |
| 76 | + }else{//不知道啥类型,不处理 |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + _alert = [SDCAlertController alertControllerWithTitle:title message:message preferredStyle:SDCAlertControllerStyleAlert]; |
| 81 | + |
| 82 | + UITextField *passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 0, 240.0, 30.0)]; |
| 83 | + passwordTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)]; |
| 84 | + passwordTextField.leftViewMode = UITextFieldViewModeAlways; |
| 85 | + passwordTextField.layer.borderColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.6].CGColor; |
| 86 | + passwordTextField.layer.borderWidth = 1; |
| 87 | + passwordTextField.secureTextEntry = (type == VerifyTypePassword); |
| 88 | + passwordTextField.backgroundColor = [UIColor whiteColor]; |
| 89 | + passwordTextField.placeholder = placeHolder; |
| 90 | + if (type == VerifyTypeTotp) { |
| 91 | + passwordTextField.text = [OTPListViewController otpCodeWithGK:[Login curLoginUser].global_key]; |
| 92 | + } |
| 93 | + passwordTextField.delegate = self; |
| 94 | + |
| 95 | + [_alert.contentView addSubview:passwordTextField]; |
| 96 | + |
| 97 | + NSDictionary* passwordViews = NSDictionaryOfVariableBindings(passwordTextField); |
| 98 | + |
| 99 | + [_alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[passwordTextField]-(>=14)-|" options:0 metrics:nil views:passwordViews]]; |
| 100 | + |
| 101 | + // Style |
| 102 | + _alert.visualStyle = [ProjectDeleteAlertControllerVisualStyle new]; |
| 103 | + |
| 104 | + // 添加密码框 |
| 105 | + // [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { |
| 106 | + // textField.secureTextEntry = YES; |
| 107 | + // }]; |
| 108 | + |
| 109 | + // 添加按钮 |
| 110 | + @weakify(self); |
| 111 | + _alert.actionLayout = SDCAlertControllerActionLayoutHorizontal; |
| 112 | + [_alert addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleDefault handler:^(SDCAlertAction *action) { |
| 113 | + @strongify(self); |
| 114 | + self.alert = nil; |
| 115 | + }]]; |
| 116 | + [_alert addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:^(SDCAlertAction *action) { |
| 117 | + @strongify(self); |
| 118 | + self.alert = nil; |
| 119 | + NSString *passCode = passwordTextField.text; |
| 120 | + if ([passCode length] > 0) { |
| 121 | + // 归档项目 |
| 122 | + [[Coding_NetAPIManager sharedManager] request_ArchiveProject_WithObj:self.project passCode:passCode type:type andBlock:^(Project *data, NSError *error) { |
| 123 | + if (!error) { |
| 124 | + [self.navigationController popToRootViewControllerAnimated:YES]; |
| 125 | + } |
| 126 | + }]; |
| 127 | + } |
| 128 | + }]]; |
| 129 | + |
| 130 | + [_alert presentWithCompletion:^{ |
| 131 | + [passwordTextField becomeFirstResponder]; |
| 132 | + }]; |
| 133 | +} |
| 134 | + |
| 135 | + |
| 136 | +-(BOOL)textFieldShouldReturn:(UITextField *)textField{ |
| 137 | + [textField resignFirstResponder]; |
| 138 | + return YES; |
| 139 | +} |
| 140 | + |
| 141 | +#pragma mark - Orientations |
| 142 | +- (BOOL)shouldAutorotate{ |
| 143 | + return UIInterfaceOrientationIsLandscape(self.interfaceOrientation); |
| 144 | +} |
| 145 | + |
| 146 | +- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { |
| 147 | + return UIInterfaceOrientationPortrait; |
| 148 | +} |
| 149 | + |
| 150 | +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { |
| 151 | + return UIInterfaceOrientationMaskPortrait; |
| 152 | +} |
| 153 | +@end |
0 commit comments