萤石云 iOSSDK,移植跨平台相关工程
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//
//  HDLFVTempPassViewController.m
//  Ezviz
//
//  Created by 陈启扬 on 2022/4/22.
//  Copyright © 2022 hdl. All rights reserved.
//
 
#import "HDLFVTempPassViewController.h"
#import "HDLFVCreateTemPassView.h"
#import "HDLFVCommonButton.h"
#import "PGDatePickManager.h"
#import "HDLFVImageDetail.h"
#import "HDLFVVisitorRecordViewController.h"
#import "HDLFVAlert.h"
#import "HDLFVAddTemPassModel.h"
#import "HDLFVCancleTemPModel.h"
#import "HDLFVHttpRequestManager.h"
 
typedef enum {
    HDLFVPickTimeType_Effective=0, //生效
    HDLFVPickTimeType_Expire=1,//失效
}HDLFVPickTimeType;
 
@interface HDLFVTempPassViewController ()<PGDatePickerDelegate>
@property(nonatomic,strong)HDLFVCreateTemPassView *tempView; //临时密码view
@property (nonatomic, strong)HDLFVCommonButton *sureBtn;//确认按钮
 
@property(nonatomic,strong)PGDatePicker *datePicker;//时间选择器
 
@property (nonatomic, copy)NSString *selectedEffectiveTime;//已选择的生效时间
@property (nonatomic, copy)NSString *selectedExpireTime;//已选择的失效时间
 
@property(nonatomic,assign)HDLFVPickTimeType pickTimeType;//选择时间类型
 
@property(nonatomic,strong)HDLFVImageDetail * imgD;//
 
@property(nonatomic,strong)HDLFVAddTemPassModel *addTemPModel;//添加临时密码model
@property(nonatomic,strong)HDLFVCancleTemPModel *cancleTemPModel;//取消临时密码model
 
 
@end
 
@implementation HDLFVTempPassViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self setTopBarViewWithTitle:HDLFVLocalizedString(@"Visitor Invitation")];
    
    if (self.temPassType==HDLFVTemPassType_Generate) {
        self.rightBtnTitle=HDLFVLocalizedString(@"Visitor Record");
    }
 
    // Do any additional setup after loading the view.
}
 
-(void)addSubViews{
    
    //确认添加按钮
    _sureBtn=[[HDLFVCommonButton alloc] init];
    [self.view addSubview:_sureBtn];
    [_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.bottom.equalTo(self.view).offset(-APP_TAB_BOTTOM_HEIGHT-20);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo(HDLFVGetRealWidth(220));
    }];
    if (self.temPassType==HDLFVTemPassType_Detail) {
        _sureBtn.titleName=HDLFVLocalizedString(@"Cancle Visitor Credentials");
    }else{
        _sureBtn.titleName=HDLFVLocalizedString(@"Generate Visitor Credentials");
    }
    [_sureBtn addTarget:self action:@selector(sure) forControlEvents:UIControlEventTouchDown];
    
 
    
    //临时密码view
    _tempView=[[HDLFVCreateTemPassView alloc] init];
    [self.view addSubview:_tempView];
    [_tempView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(APP_TOP_BAR_HEIGHT);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(_sureBtn.mas_top).offset(-5);
    }];
    _tempView.temPassType=self.temPassType;
    WeakSelf(weakSelf);
    _tempView.validTimeV.clickBtn = ^{
        [weakSelf selectEffectiveTime];
    };
    
    _tempView.expireTimeV.clickBtn = ^{
        [weakSelf selectExpirationTime];
    };
    
    _tempView.temPassInputV.clickBtn = ^{
        [weakSelf genarateTemPass];
    };
    
    _tempView.clickQRCodeBlock = ^(UIImage * _Nonnull image) {
        [weakSelf tapQRCode:image];
    };
    
    _tempView.longTapQRCodeBlock = ^(UIImage * _Nonnull image) {
        [weakSelf longTapQRCode:image];
 
    };
    
    //展示临时凭证详情
    if (self.temPassType==HDLFVTemPassType_Detail) {
        
        _tempView.phoneInputV.inputTextF.text=self.temPdetailModel.phone;
        _tempView.temPassInputV.inputTextF.text=self.temPdetailModel.tempPwd;
//        _tempView.useTimesInputV.inputTextF.text=self.temPdetailModel.useCount;
        _tempView.validTimeV.contentL.text=[Constants turnDateString:self.temPdetailModel.validBeginTime toFormater:[NSString stringWithFormat:@"yyyy%@MM%@dd%@ HH:mm",HDLFVLocalizedString(@"Y"),HDLFVLocalizedString(@"M"),HDLFVLocalizedString(@"D")]];
        _tempView.expireTimeV.contentL.text=[Constants turnDateString:self.temPdetailModel.validEndTime toFormater:[NSString stringWithFormat:@"yyyy%@MM%@dd%@ HH:mm",HDLFVLocalizedString(@"Y"),HDLFVLocalizedString(@"M"),HDLFVLocalizedString(@"D")]];
 
        _tempView.QRCodeImageV.image=[Constants creatCIQRCodeImage:_tempView.temPassInputV.inputTextF.text];
        self.selectedEffectiveTime=self.temPdetailModel.validBeginTime;
        self.selectedExpireTime=self.temPdetailModel.validEndTime;
        [_tempView showQRCode:YES];
        HDLFVLog(@"tempId吧:%@",self.temPdetailModel.ID);
 
        //判断是否过期
//        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//          [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
//        NSDate *date = [dateFormatter dateFromString:self.temPdetailModel.validEndTime];
//        if ([Constants compareOneDay:[NSDate date] withAnotherDay:date]==1) {
//            _tempView.isInvalid=YES;
//        }
        
        if (!self.temPdetailModel.status) {
            HDLFVLog(@"密码无效");
            _tempView.isInvalid=YES;
            [_sureBtn setHidden:YES];
        }
 
    }
    
}
 
//点击导航栏右边按钮
-(void)clickRightBtn{
    HDLFVLog(@"点击了右边按钮");
    HDLFVVisitorRecordViewController *vc=[[HDLFVVisitorRecordViewController alloc] init];
    [self.navigationController setNavigationBarHidden:YES];
    [self.navigationController pushViewController:vc animated:YES];
}
 
 
/*点击了生成临时密码
 */
-(void)genarateTemPass{
    HDLFVLog(@"点击生成动态码");
    _tempView.temPassInputV.inputTextF.text=[FVTool randomNumerWithCount:6];
 
}
 
/*点击了选择生效时间
 */
-(void)selectEffectiveTime{
    self.pickTimeType=HDLFVPickTimeType_Effective;
    [self showDatePicker];
}
 
/*点击了选择失效时间
 */
-(void)selectExpirationTime{
    self.pickTimeType=HDLFVPickTimeType_Expire;
    [self showDatePicker];
 
}
 
/*点击了确认按钮
 */
-(void)sure{
    if (_tempView.phoneInputV.inputTextF.text.length==0||_tempView.phoneInputV.inputTextF.text.length!=11) {
        [HDLToast showTostWithMessage:HDLFVLocalizedString(@"Please enter a correct phone number")];
        return;
    }
    if (_tempView.temPassInputV.inputTextF.text.length!=6) {
        [HDLToast showTostWithMessage:HDLFVLocalizedString(@"Input 6-digits temporary password")];
        return;
    }
//    if (_tempView.useTimesInputV.inputTextF.text.length==0) {
//        [HDLToast showTostWithMessage:HDLFVLocalizedString(@"Input usage times")];
//        return;
//    }
    if (self.selectedEffectiveTime.length==0) {
        [HDLToast showTostWithMessage:HDLFVLocalizedString(@"Please select a effective time")];
        return;
    }
    if (self.selectedExpireTime.length==0) {
        [HDLToast showTostWithMessage:HDLFVLocalizedString(@"Please select a expire time")];
        return;
    }
    
    WeakSelf(weakSelf);
    HDLFVAlert *alert=[[HDLFVAlert alloc] init];
    if (self.temPassType==HDLFVTemPassType_Generate) {
        self.addTemPModel=[[HDLFVAddTemPassModel alloc] init];
        self.addTemPModel.homeId=[HDLFVHttpRequestManager sharedInstance].currentUserId;
        self.addTemPModel.phone=_tempView.phoneInputV.inputTextF.text;
        self.addTemPModel.tempPwd=_tempView.temPassInputV.inputTextF.text;
        self.addTemPModel.useCount=@"10000";
//        _addTemPModel.deviceId=_deviceId;
        self.addTemPModel.validBeginTime=self.selectedEffectiveTime;
        self.addTemPModel.validEndTime=self.selectedExpireTime;
 
        HDLFVLog(@"生成:%@",self.addTemPModel);
 
        [alert showAlertWithTitle:HDLFVLocalizedString(@"Tips") message:HDLFVLocalizedString(@"After confirmation, the visitor QR code will be generated, and the 6-digit dynamic digital password SMS will also be sent to the visitor's mobile phone.") height:158 cancle:^{
        } sure:^{
            HDLFVLog(@"点击了确认");
            [weakSelf generateCredentials];
        }];
    }else{
        [alert showAlertWithTitle:HDLFVLocalizedString(@"Tips") message:HDLFVLocalizedString(@"You are canceling visitor credentials") height:158 cancle:^{
        } sure:^{
            HDLFVLog(@"点击了确认");
            [weakSelf cancleCredentials];
        }];
    }
    
}
 
/*点击了二维码
 */
-(void)tapQRCode:(UIImage *)QRImage{
    HDLFVLog(@"点击了二维码");
    _imgD=[[HDLFVImageDetail alloc] init];
    [_imgD showImage:QRImage describe:HDLFVLocalizedString(@"Long press the QR code to save the QR code to the album")];
 
}
 
/*长按二维码
 */
-(void)longTapQRCode:(UIImage*)QRCImage{
 
    [Constants saveImageToPhotosAlbum:QRCImage];
}
 
/*展示时间选择器
 */
-(void)showDatePicker{
    PGDatePickManager *datePickManager = [[PGDatePickManager alloc]init];
    datePickManager.isShadeBackgroud = true;
    self.datePicker = datePickManager.datePicker;
    self.datePicker.delegate = self;
 
    datePickManager.confirmButtonTextColor=HDLFV_COLOR_TEXT_LIGHT_BLUE;
    datePickManager.confirmButtonFont=HDLFV_Get_FontRegularWithSize(HDLFV_FontSize_16);
    datePickManager.headerViewBackgroundColor=HDLFV_COLOR_NAV_BACKGROUND;
    datePickManager.cancelButtonTextColor=HDLFV_COLOR_TEXT_TITLE_GRAY;
    datePickManager.cancelButtonFont=HDLFV_Get_FontRegularWithSize(HDLFV_FontSize_16);
 
    self.datePicker.datePickerMode = PGDatePickerModeDateHourMinute;
    [self presentViewController:datePickManager animated:false completion:nil];
 
}
 
/*生成临时凭证
 */
-(void)generateCredentials{
    WeakSelf(weakSelf);
    [HDLFVHUD showHudInView:self.view];
    [[HDLFVHttpRequestManager sharedInstance] addTemPassWithAddTemPassModel:self.addTemPModel success:^(NSString *_Nullable tempId) {
        [HDLFVHUD  hideHUDForView:weakSelf.view];
        [weakSelf generateTempSuccess:tempId];
    } fail:^(NSError * _Nullable error) {
        [HDLFVHUD  hideHUDForView:weakSelf.view];
        [HDLToast showTostWithMessage:error.localizedDescription];
    }];
}
 
/*取消临时凭证
 */
-(void)cancleCredentials{
    WeakSelf(weakSelf);
    [HDLFVHUD showHudInView:self.view];
    _cancleTemPModel=[[HDLFVCancleTemPModel alloc] init];
    _cancleTemPModel.homeId=[HDLFVHttpRequestManager sharedInstance].currentUserId;
    HDLFVLog(@"tempId:%@",self.temPdetailModel.ID);
    _cancleTemPModel.ID=self.temPdetailModel.ID;
    [[HDLFVHttpRequestManager sharedInstance] deleteTemPassWithAddTemPassModel:_cancleTemPModel success:^{
        [HDLFVHUD  hideHUDForView:weakSelf.view];
        [weakSelf cancleTempSuccess];
    } fail:^(NSError * _Nullable error) {
        [HDLFVHUD  hideHUDForView:weakSelf.view];
        [HDLToast showTostWithMessage:error.localizedDescription];
    }];
}
 
/*生成临时凭证成功
 */
-(void)generateTempSuccess:(NSString*)tempId{
    [_tempView showQRCode:YES];
    _tempView.QRCodeImageV.image=[Constants creatCIQRCodeImage:_tempView.temPassInputV.inputTextF.text];
    _tempView.temPassType=HDLFVTemPassType_Detail;
    HDLFVLog(@"tempId:%@",tempId);
    self.temPdetailModel=[[HDLFVTemPDetailModel alloc] init];
    self.temPdetailModel.ID=tempId;
    _sureBtn.titleName=HDLFVLocalizedString(@"Cancle Visitor Credentials");
    self.temPassType=HDLFVTemPassType_Detail;
}
 
/*取消临时凭证成功
 */
-(void)cancleTempSuccess{
    if (_isShowDetail) {
        [[NSNotificationCenter defaultCenter] postNotificationName:HDLFVNotificationChangeTemP object:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
//
//        _tempView.temPassType=HDLFVTemPassType_Generate;
//        _sureBtn.titleName=HDLFVLocalizedString(@"Generate Visitor Credentials");
//        self.temPassType=HDLFVTemPassType_Generate;
    }
}
 
 
#pragma PGDatePickerDelegate
- (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents {
    
    NSString *sendTimeStr=[NSString stringWithFormat:@"%ld-%@-%@ %@:%@:00",dateComponents.year,[Constants autoFillZero:dateComponents.month],[Constants autoFillZero:dateComponents.day],[Constants autoFillZero:dateComponents.hour],[Constants autoFillZero:dateComponents.minute]];//请求接口格式的时间
    NSString *showTimeStr=[NSString stringWithFormat:@"%ld%@%@%@%@%@ %@:%@",dateComponents.year,HDLFVLocalizedString(@"Y"),[Constants autoFillZero:dateComponents.month],HDLFVLocalizedString(@"M"),[Constants autoFillZero:dateComponents.day],HDLFVLocalizedString(@"D"),[Constants autoFillZero:dateComponents.hour],[Constants autoFillZero:dateComponents.minute]];//展示格式的时间
    
    if (self.pickTimeType==HDLFVPickTimeType_Effective) {
        self.selectedEffectiveTime=sendTimeStr;
        _tempView.validTimeV.contentL.text=showTimeStr;
    }else{
        self.selectedExpireTime=sendTimeStr;
        _tempView.expireTimeV.contentL.text=showTimeStr;
 
    }
    
}
@end