萤石云 iOSSDK,移植跨平台相关工程
Davin
2023-07-27 48c5a2c66c549d26fecadc6d2dad1924fdd1cc8b
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
//
//  HDLFVTempPassViewController.m
//  Ezviz
//
//  Created by 陈启扬 on 2022/4/22.
//  Copyright © 2022 hdl. All rights reserved.
//
 
#import "HDLEZCreatTempPassViewController.h"
#import "HDLEZCreateTemPassView.h"
#import "HDLEZInputViewController.h"
#import <FQDateTimeSDK/FQDateTimeSDK.h>
#import "HDLEZTempDetailViewController.h"
typedef enum {
    HDLEZPickTimeType_Effective=0, //生效
    HDLEZPickTimeType_Expire=1,//失效
}HDLEZPickTimeType;
 
@interface HDLEZCreatTempPassViewController ()<HDLEZInputViewControllerDelegate,FQDateTimePickerViewDelegate>
@property(nonatomic,strong)HDLEZCreateTemPassView *tempView; //临时密码view
 
@property (nonatomic, copy)NSString *selectedEffectiveTime;//已选择的生效时间
@property (nonatomic, copy)NSString *selectedExpireTime;//已选择的失效时间
 
@property(nonatomic,assign)HDLEZPickTimeType pickTimeType;//选择时间类型
 
@property(nonatomic,strong)HDLEZTemInfoModel *addTemPModel;//添加临时密码model
 
 
@end
 
@implementation HDLEZCreatTempPassViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self setTopBarViewWithTitle:HDLEZLocallizedString(@"device_temp_pass")];
    //保存按钮
    self.topBarView.rightButton.frame = CGRectMake(HDLEZ_APP_SCREEN_WIDTH-16-50, HDLEZ_APP_STATUS_BAR_HEIGHT+(44-20)/2, 50, 20);
    self.topBarView.rightButton.titleLabel.textAlignment=NSTextAlignmentRight;
    self.topBarView.rightBtnTitle=HDLEZLocallizedString(@"device_temp_save");
    [self.topBarView.rightButton addTarget:self action:@selector(saveTemp) forControlEvents:UIControlEventTouchUpInside];
 
    _addTemPModel=[[HDLEZTemInfoModel alloc] init];
    _addTemPModel.limitCount=@"-1";
    // Do any additional setup after loading the view.
}
 
-(void)addSubViews{
    
 
    
    //临时密码view
    _tempView=[[HDLEZCreateTemPassView alloc] init];
    [self.view addSubview:_tempView];
    [_tempView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(HDLEZ_APP_TOP_BAR_HEIGHT);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];
//    _tempView.temPassType=self.temPassType;
    __weak __typeof(self)weakSelf = self;
    _tempView.userV.clickBtn = ^{//点击使用人
        [weakSelf inputWithType:HDLEZInputType_User title:HDLEZLocallizedString(@"device_temp_user")];
    };
    _tempView.validTimeV.clickBtn = ^{//点击开始时间
        [weakSelf selectEffectiveTime];
    };
 
    _tempView.expireTimeV.clickBtn = ^{//点击结束时间
        [weakSelf selectExpirationTime];
    };
    
    _tempView.useCountV.clickBtn = ^{//点击使用次数
        [weakSelf inputWithType:HDLEZInputType_UseCount title:HDLEZLocallizedString(@"device_temp_use_times")];
    };
 
    
}
 
 
 
 
/*点击输入内容
 @param inputType 输入类型
 @param title 标题
 */
-(void)inputWithType:(HDLEZInputType)inputType title:(NSString *)title{
    HDLEZInputViewController *vc=[[HDLEZInputViewController alloc] init];
    vc.inputType=inputType;
    vc.navTitle=title;
    vc.inputDelegate=self;
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:vc animated:YES completion:nil];
}
 
/*点击了选择生效时间
 */
-(void)selectEffectiveTime{
    self.pickTimeType=HDLEZPickTimeType_Effective;
    [self showDatePicker];
}
 
/*点击了选择失效时间
 */
-(void)selectExpirationTime{
    self.pickTimeType=HDLEZPickTimeType_Expire;
    [self showDatePicker];
 
}
 
/*点击了保存按钮
 */
-(void)saveTemp{
    if (!_addTemPModel.userName||_addTemPModel.userName.length==0) {//未输入使用人
        HDLEZLog(@"未输入使用人:%@",_addTemPModel.userName);
        [self.view makeToast:HDLEZLocallizedString(@"device_temp_please_input_user_name")
                        duration:1.5
                        position:@"center"];
        return;
    }
    
    if (!_addTemPModel.beginTime||_addTemPModel.beginTime.length==0) {//未选择开始时间
        [self.view makeToast:HDLEZLocallizedString(@"device_temp_please_select_begin_time")
                        duration:1.5
                        position:@"center"];
        return;
    }
    
    if (!_addTemPModel.endTime||_addTemPModel.endTime.length==0) {//未选择结束时间
        [self.view makeToast:HDLEZLocallizedString(@"device_temp_please_select_end_time")
                        duration:1.5
                        position:@"center"];
        return;
    }
    
    if ([HDLEZConstants compareOneDay:[NSDate dateWithTimeIntervalSince1970:[self.addTemPModel.endTime integerValue]] withAnotherDay:[NSDate dateWithTimeIntervalSince1970:[self.addTemPModel.beginTime integerValue]]]==-1) {//结束时间早于开始时间
        [self.view makeToast:HDLEZLocallizedString(@"device_temp_please_end_time_should_later")
                        duration:1.5
                        position:@"center"];
        return;
    }
 
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    __weak __typeof(self)weakSelf = self;
    [[EZHttpUtil sharedManager] addTempByHDL:self.addTemPModel deviceId:self.deviceId completion:^(ResponseData * _Nonnull responseData) {
        HDLEZLog(@"添加密码结果:%@",responseData.data);
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        if (responseData.success) {
            [[NSNotificationCenter defaultCenter] postNotificationName:HDLEZNotificationChangeTemP object:nil];
            HDLEZTemInfoModel *tempInfo=[HDLEZTemInfoModel yy_modelWithDictionary:responseData.data];
            [weakSelf toTempDetailVWithTempInfo:tempInfo];
        }else{
            [weakSelf.view makeToast:responseData.message
                            duration:1.5
                            position:@"center"];
        }
    }];
    
}
 
/*跳转免密详情页
 */
-(void)toTempDetailVWithTempInfo:(HDLEZTemInfoModel*)tempInfo{
    HDLEZTempDetailViewController *vc=[[HDLEZTempDetailViewController alloc] init];
    vc.temPdetailModel=tempInfo;
    vc.deviceId=self.deviceId;
    [self.navigationController pushViewController:vc animated:YES];
}
 
/*展示时间选择器
 */
-(void)showDatePicker{
    FQDateTimePickerView *pickerView = [[FQDateTimePickerView alloc] init];
    pickerView.delegate = self;    //遵循代理
    pickerView.pickerModel = FQDateTimePickerModelDateTime;    //日期模式
    pickerView.cancelColor = HDLEZ_COLOR_TEXT_LIGHT_GRAY;    //取消颜色
    pickerView.confirmColor = HDLEZ_COLOR_TEXT_LIGHT_BLUE;    //确定颜色
    pickerView.cancelText=HDLEZLocallizedString(@"device_temp_cancle");
    pickerView.confirmText=HDLEZLocallizedString(@"device_temp_sure");
    pickerView.unitsData=@[HDLEZLocallizedString(@"device_temp_unit_year"),HDLEZLocallizedString(@"device_temp_unit_month"),HDLEZLocallizedString(@"device_temp_unit_date"),HDLEZLocallizedString(@"device_temp_unit_hour"),HDLEZLocallizedString(@"device_temp_unit_minute"),HDLEZLocallizedString(@"device_temp_unit_minute")];
 
    pickerView.minDate = [NSDate new];    //最小时间
 
    [pickerView showPicker];    //展示
}
 
 
 
/*时间转string
 @param date 时间
 */
-(NSString *)turnDate:(NSDate*)date{
    return [HDLEZConstants timeStrWithFormate:[NSString stringWithFormat:@"yyyy%@MM%@dd%@ HH:mm",HDLEZLocallizedString(@"device_temp_year"),HDLEZLocallizedString(@"device_temp_month"),HDLEZLocallizedString(@"device_temp_date")] data:date];
}
 
#pragma FQDateTimePickerViewDelegate
/// 确认操作
/// @param date 日期NSDate
/// @param dateStr 日期NSString
/// @param target 用于区分pickerView
- (void)confirmActionWithDate:(NSDate *)date withDateString:(NSString *)dateStr withTarget:(NSInteger)target{
    HDLEZLog(@"选择的时间:%.f",[date timeIntervalSince1970]);
    if (self.pickTimeType==HDLEZPickTimeType_Effective) {//选择生效时间
        _tempView.validTimeV.contentL.text=[self turnDate:date];
        self.addTemPModel.beginTime=[NSString stringWithFormat:@"%.f",[date timeIntervalSince1970]];
    }else{//选择结束时间
        _tempView.expireTimeV.contentL.text=[self turnDate:date];
        self.addTemPModel.endTime=[NSString stringWithFormat:@"%.f",[date timeIntervalSince1970]];
    }
}
 
#pragma HDLEZInputViewControllerDelegate
/*输入了内容
 @param content 内容
 @param inputType 输入类型
 */
-(void)inputContent:(NSString *)content inputType:(HDLEZInputType)inputType{
    if (inputType==HDLEZInputType_User) {
        _tempView.userV.contentL.text=content;
        self.addTemPModel.userName=content;
    }else{
        _tempView.useCountV.contentL.text=content;
        self.addTemPModel.limitCount=content;
        if (content.length==0) {
            _tempView.useCountV.contentL.text=HDLEZLocallizedString(@"device_temp_unlimited_times");
            self.addTemPModel.limitCount=@"-1";
        }
    }
}
@end