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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// ICRLoginViewController.m
// XFFruit
//
// Created by Xummer on 3/22/15.
// Copyright (c) 2015 Xummer. All rights reserved.
//
#import "ICRLoginViewController.h"
#import "ICRLoginContentView.h"
#import "GXFFunctionDB.h"
#import "GXFFunctionDBHelper.h"
#define LOGIN_CONTAINER_LEFT_MARGIN (20)
#define LOGIN_CONTAINER_HEIGHT (450)
@interface ICRLoginViewController ()
{
CGFloat m_fDefaultContainerY;
}
@property (strong, nonatomic) ICRLoginContentView *m_containerView;
@end
@implementation ICRLoginViewController
#pragma mark - Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setupSubviews];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
if (m_fDefaultContainerY == 0) {
m_fDefaultContainerY = _m_containerView.y;
}
}
- (void)viewWillAppear:(BOOL)animated {}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
[notiCenter addObserver:self
selector:@selector(inputTextEditChanged:)
name:UITextFieldTextDidChangeNotification
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
[notiCenter removeObserver:self];
}
#pragma mark - Private Method
- (void)setupSubviews {
UIImageView *bg = [[UIImageView alloc] initWithFrame:self.view.bounds];
bg.image = [UIImage imageNamed:@"LoginBG"];
[bg autoresizingWithStrechFullSize];
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(onBGTapped:)];
bg.userInteractionEnabled = YES;
[bg addGestureRecognizer:tapGesture];
[self.view addSubview:bg];
self.m_containerView =
[[ICRLoginContentView alloc] initWithFrame:(CGRect){
.origin.x = LOGIN_CONTAINER_LEFT_MARGIN,
.origin.y = (self.view.height - LOGIN_CONTAINER_HEIGHT) * .5f,
.size.width = self.view.width - 2 * LOGIN_CONTAINER_LEFT_MARGIN,
.size.height = LOGIN_CONTAINER_HEIGHT
}
showCCode:YES];
[_m_containerView autoresizingWithVerticalCenter];
[_m_containerView.m_loginBtn addTarget:self
action:@selector(onLoginTapped:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_m_containerView];
#if DEBUG
// self.m_containerView.m_cCodeTextF.text = @"A93jie957lK";
// self.m_containerView.m_userNameTextF.text = @"kevin";
// self.m_containerView.m_passwordTextF.text = @"aaa";
//@"http://218.244.151.129:7580/cruiser-server/rest"
// self.m_containerView.m_cCodeTextF.text = @"211534962";
// self.m_containerView.m_userNameTextF.text = @"admin";
// self.m_containerView.m_passwordTextF.text = @"thoradmin";
//@"http://122.224.171.126:7280/cruiser-server/rest"
self.m_containerView.m_cCodeTextF.text = @"923";
self.m_containerView.m_userNameTextF.text = @"admin";
self.m_containerView.m_passwordTextF.text = @"thoradmin";
[self.m_containerView checkLoginEnable];
#else
#endif
}
#pragma mark - Logic
#pragma mark - Actions
- (void)onBGTapped:(__unused id)sender {
[self.view endEditing:YES];
}
- (void)onLoginTapped:(__unused id)sender {
//
NSString *nsRegisterCode = self.m_containerView.m_cCodeTextF.text;
NSString *nsUserName = self.m_containerView.m_userNameTextF.text;
NSString *nsPassword = [self.m_containerView.m_passwordTextF.text uppercaseMD5String];
// NSString *nsRegisterCode = @"211534962";
// NSString *nsUserName = @"admin";
// NSString *nsPassword = @"thoradmin";
void(^succ)(id) = ^(id data) {
ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
userUtil.bAutoLogin = @( [_m_containerView isAutoLogin] );
[userUtil saveArchive];
ICRAppViewControllerManager *mgr =
[ICRAppViewControllerManager getAppViewControllerManager];
[mgr openMainFrame];
#pragma 可以开新线程 ,待优化
//当登陆成功时就建立功能数据表
[[GXFFunctionDB sharedInstance]createTables];
//完成对初始化数据书库的操作
if (![[GXFFunctionDBHelper sharedInstance] successInsertOriginFunctions]) {
[[GXFFunctionDBHelper sharedInstance] insertAllOriginFunctions];
}
if (![[GXFFunctionDBHelper sharedInstance] sucessInsertOriginDisplayFunctions]) {
[[GXFFunctionDBHelper sharedInstance] insertAllOriginDisplayFunctions];
}
//更改功能权限
for (int count = 0; count < userUtil.permissions.count; count ++) {
GXFFunction *function = [[GXFFunctionDB sharedInstance]functionSelectWithId:[userUtil.permissions[count] integerValue]];
if (function.Id) {
function.hasPermission = 1;
[[GXFFunctionDB sharedInstance] updateFunctionHasPermissionWithId:function];
}
}
//配置功能 不是默认配置
NSUserDefaults *f_default = [NSUserDefaults standardUserDefaults];
BOOL noDefault = [[f_default objectForKey:@"noDefault"] integerValue] > 0 ? YES : NO;
if (!noDefault) {
[[GXFFunctionDB sharedInstance]defaultdisplayFunctions];
}
};
void(^fail)(id) = ^(id data) {
[IBTLoadingView showTips:data];
};
ICRHTTPController *httpCtrl = [ICRHTTPController sharedController];
[httpCtrl doLoginWithUserName:nsUserName
password:nsPassword
registerCode:nsRegisterCode
success:succ
failure:fail];
}
#pragma mark - TextObserver
- (void)inputTextEditChanged:(NSNotification *)obj {
[self.m_containerView checkLoginEnable];
}
#pragma mark - Keyboard
- (void)keyboardWillShow:(NSNotification *)note {
// get keyboard size and loctaion
CGRect keyboardBounds;
[[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
// Need to translate the bounds to account for rotation.
keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
// animations settings
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:[duration doubleValue]];
[UIView setAnimationCurve:[curve intValue]];
// set views with new info
self.m_containerView.y = - 50.0f;
// commit animations
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)note {
NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
// animations settings
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:[duration doubleValue]];
[UIView setAnimationCurve:[curve intValue]];
// set views with new info
self.m_containerView.y = m_fDefaultContainerY;
// commit animations
[UIView commitAnimations];
}
@end