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