浏览代码

Merge branch 'master' of http://10.1.235.20:3000/ipu/ios-share

liuql6 5 年之前
父节点
当前提交
06fb41d01f

+ 46 - 13
WadeMobileFunc/WadeMobileFunc/IPUGrayPlugin.m

@ -7,6 +7,7 @@
7 7
//
8 8
9 9
#import "IPUGrayPlugin.h"
10
#import <WadeMobile/WadeMobile.h>
10 11
11 12
@implementation IPUGrayPlugin
12 13
@ -58,23 +59,36 @@
58 59
            UIAlertController* alert = nil;
59 60
            if ([isGrayUser isEqualToString:@"0"]) {
60 61
                if ([userFlag isEqualToString:@"1"]){//主应用子应用从灰度切换到生产
61
                    [self alert:alert message:@"发现正式版本,选择更新后将关闭应用,请重新打开" userFlag:isGrayUser requestHost:grayRequestHost requestPath:grayRequestPath resourceHost:grayResourceHost isExit:YES];
62
                    alert = [UIAlertController alertControllerWithTitle:nil
63
                            message:@"发现新版本,选择更新后将关闭应用,请重新打开"  preferredStyle:UIAlertControllerStyleAlert];
64
                    [self addActionWithAlert:alert UserFlag:isGrayUser RequestHost:grayRequestHost RequestPath:grayRequestPath ResourceHost:grayResourceHost IsExit:YES];
62 65
                }
63
                else if ([userFlag isEqualToString:@"2"]){//主应用子应用切换到生产
64
                    [self alert:alert message:@"发现正式版本,选择更新后将关闭应用,请重新打开" userFlag:isGrayUser requestHost:grayRequestHost requestPath:grayRequestPath resourceHost:grayResourceHost isExit:YES];
66
                else if ([userFlag isEqualToString:@"2"]){//子应用从灰度切换到生产(强制)
67
                    [self setGrayIsGrayUser:isGrayUser grayRequestHost:grayRequestHost grayRequestPath:grayRequestPath grayResourceHost:grayResourceHost];
65 68
                }
66 69
            }
67 70
            else if ([isGrayUser isEqualToString:@"1"]){
68 71
                if ([userFlag isEqualToString:@"0"]) {//主应用子应用从生产切换到灰度
69
                    [self alert:alert message:@"发现新版本,选择更新后将关闭应用,请重新打开" userFlag:isGrayUser requestHost:grayRequestHost requestPath:grayRequestPath resourceHost:grayResourceHost isExit:YES];
72
                    alert = [UIAlertController alertControllerWithTitle:nil
73
                            message:@"发现新版本,选择更新后将关闭应用,请重新打开"  preferredStyle:UIAlertControllerStyleAlert];
74
                    [self addActionWithAlert:alert UserFlag:isGrayUser RequestHost:grayRequestHost RequestPath:grayRequestPath ResourceHost:grayResourceHost IsExit:YES];
70 75
                }
71 76
                else if ([userFlag isEqualToString:@"2"]){//主应用切换到灰度
72
                    [self alert:alert message:@"发现新版本,选择更新后将关闭应用,请重新打开" userFlag:isGrayUser requestHost:grayRequestHost requestPath:grayRequestPath resourceHost:grayResourceHost isExit:YES];
77
                    alert = [UIAlertController alertControllerWithTitle:nil
78
                            message:@"发现新版本,选择更新后将关闭应用,请重新打开"  preferredStyle:UIAlertControllerStyleAlert];
79
                    [self addActionWithAlert:alert UserFlag:isGrayUser RequestHost:grayRequestHost RequestPath:grayRequestPath ResourceHost:grayResourceHost IsExit:YES];
73 80
                }
74 81
            }
75 82
            else if ([isGrayUser isEqualToString:@"2"]){
76 83
                if ([userFlag isEqualToString:@"0"]) {//子应用切换到灰度
77
                    [self alert:alert message:@"子应用发现新版本,选择更新后将加载新版本" userFlag:isGrayUser requestHost:grayRequestHost requestPath:grayRequestPath resourceHost:grayResourceHost isExit:NO];
84
                    alert = [UIAlertController alertControllerWithTitle:nil
85
                            message:@"发现新版本,请选择是否更新"  preferredStyle:UIAlertControllerStyleAlert];
86
                    [self addActionWithAlert:alert UserFlag:isGrayUser RequestHost:grayRequestHost RequestPath:grayRequestPath ResourceHost:grayResourceHost IsExit:NO];
87
                }
88
                if ([userFlag isEqualToString:@"1"]) {//主应用切生产,子应用切灰度
89
                    alert = [UIAlertController alertControllerWithTitle:nil
90
                            message:@"发现新版本,选择更新后将关闭应用,请重新打开"  preferredStyle:UIAlertControllerStyleAlert];
91
                    [self addActionWithAlert:alert UserFlag:isGrayUser RequestHost:grayRequestHost RequestPath:grayRequestPath ResourceHost:grayResourceHost IsExit:YES];
78 92
                }
79 93
            }
80 94
            
@ -83,14 +97,26 @@
83 97
                    
84 98
                }];
85 99
            }
100
        }else{//环境未发生切换
101
            if ([isGrayUser isEqualToString:@"1"]) {//1切1
102
                NSString * localResourceHost = [[NSUserDefaults standardUserDefaults] valueForKey:@"GRAY_RESOURCE_HOST"];
103
                NSString * localRequestHost = [[NSUserDefaults standardUserDefaults] valueForKey:@"GRAY_REQUEST_HOST"];
104
                NSString * localRequestPath = [[NSUserDefaults standardUserDefaults] valueForKey:@"GRAY_REQUEST_PATH"];
105
                if ((![localRequestHost isEqualToString:grayRequestHost]) || (![localRequestPath isEqualToString:grayRequestPath]) || (![localResourceHost isEqualToString:grayResourceHost])) {
106
                    UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil
107
                            message:@"发现新版本,选择更新后将关闭应用,请重新打开"  preferredStyle:UIAlertControllerStyleAlert];
108
                    [self addActionWithAlert:alert UserFlag:isGrayUser RequestHost:grayRequestHost RequestPath:grayRequestPath ResourceHost:grayResourceHost IsExit:YES];
109
                    [[self getViewController] presentViewController:alert animated:YES completion:^{
110
                        
111
                    }];
112
                }
113
            }
86 114
        }
87 115
    }
88 116
}
89 117
    
90
-(void)alert:(UIAlertController *)alert message:(NSString *)message userFlag:(NSString *)userFlag requestHost:(NSString *)requestHost requestPath:(NSString *)requestPath resourceHost:(NSString *)resourceHost isExit:(BOOL)isExit{
91
        alert = [UIAlertController alertControllerWithTitle:nil
92
                                                    message:message  preferredStyle:UIAlertControllerStyleAlert];
93
        UIAlertAction* confirmAction = [UIAlertAction actionWithTitle:@"马上更新"     style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
118
-(void)addActionWithAlert:(UIAlertController *)alert UserFlag:(NSString *)userFlag RequestHost:(NSString *)requestHost RequestPath:(NSString *)requestPath ResourceHost:(NSString *)resourceHost IsExit:(BOOL)isExit{
119
        UIAlertAction* confirmAction = [UIAlertAction actionWithTitle:@"立即更新"     style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
94 120
            [self setGrayIsGrayUser:userFlag grayRequestHost:requestHost grayRequestPath:requestPath grayResourceHost:resourceHost];
95 121
            if (isExit) {
96 122
                exit(0);
@ -106,13 +132,13 @@
106 132
-(void)setGrayIsGrayUser:(NSString *)isGrayUser grayRequestHost:(NSString *)grayRequestHost grayRequestPath:(NSString *)grayRequestPath grayResourceHost:(NSString *)grayResourceHost{
107 133
    [[NSUserDefaults standardUserDefaults] setValue:isGrayUser forKey:@"IS_GRAY_USER"];
108 134
    if ([isGrayUser isEqualToString:@"1"]) {//灰度用户
109
        if (grayRequestHost) {
135
        if (![self isNullWithString:grayRequestHost]) {
110 136
            [[NSUserDefaults standardUserDefaults] setValue:grayRequestHost forKey:@"GRAY_REQUEST_HOST"];
111 137
        }
112
        if (grayRequestPath) {
138
        if (![self isNullWithString:grayRequestPath]) {
113 139
            [[NSUserDefaults standardUserDefaults] setValue:grayRequestPath forKey:@"GRAY_REQUEST_PATH"];
114 140
        }
115
        if (grayResourceHost) {
141
        if (![self isNullWithString:grayResourceHost]) {
116 142
            [[NSUserDefaults standardUserDefaults] setValue:grayResourceHost forKey:@"GRAY_RESOURCE_HOST"];
117 143
        }
118 144
    }else{
@ -123,4 +149,11 @@
123 149
    [[NSUserDefaults standardUserDefaults] synchronize];
124 150
}
125 151
152
-(BOOL)isNullWithString:(NSString *)str{
153
    if (str!=nil && ![str isEqualToString:@""]  && ![str isEqualToString:@"<null>"]  && ![str isEqualToString:@"(null)"]  && ![str isEqualToString:@"null"]) {
154
        return NO;
155
    }
156
    return YES;
157
}
158
126 159
@end

+ 5 - 1
WadeMobileFunc/WadeMobileFunc/WDFImageCache.m

@ -285,7 +285,11 @@ static char imageURLKey;
285 285
 */
286 286
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
287 287
{
288
    [super callback:@"0"];
288
    if (error) {
289
        [super callback:@"1"];
290
    }else{
291
        [super callback:@"0"];
292
    }
289 293
}
290 294
291 295
@end

+ 5 - 0
WadeMobileFunc/WadeMobileFunc/WDFMobileBasic.h

@ -97,4 +97,9 @@
97 97
// 打开指定URL
98 98
- (BOOL)openUrl:(NSString *)url;
99 99
100
/*
101
 设置状态栏颜色
102
 */
103
-(void)resetStatusBarColor:(NSArray *)param;
104
100 105
@end

+ 15 - 0
WadeMobileFunc/WadeMobileFunc/WDFMobileBasic.m

@ -13,6 +13,8 @@
13 13
#import <AddressBookUI/AddressBookUI.h>
14 14
#import <WadeMobile/IpuAlertView.h>
15 15
#import <WadeMobile/WDStringUtility.h>
16
#import <WadeMobile/WDCommonTool.h>
17
#import <WadeMobile/WDViewController.h>
16 18
17 19
//ip
18 20
#import <ifaddrs.h>
@ -440,6 +442,19 @@
440 442
            break;
441 443
    }
442 444
}
445
#pragma mark - 设置状态栏颜色
446
/*
447
 设置状态栏颜色
448
 */
449
-(void)resetStatusBarColor:(NSArray *)param{
450
    WDViewController *vc = (WDViewController *)[self getViewController];
451
    NSString *colorStr = nil;
452
    if (param && param.count>0 && param[0]!=[NSNull null]) {
453
        colorStr = param[0];
454
    }
455
    UIColor *color = [WDCommonTool convertHexToColor:colorStr];
456
    [vc setStatusBarColor:color];
457
}
443 458
444 459
@end
445 460

+ 36 - 0
WadeMobileFunc/WadeMobileFunc/WDFTipsHUD.h

@ -22,6 +22,42 @@
22 22
 params[1]:提示框显示的时长(可为空,默认持续1秒)
23 23
 */
24 24
-(void)showTextHUD:(NSArray *)params;
25
26
/*
27
 外部JS访问:显示一个可动态配置的弹出框,内容与确认按钮必须显示,标题与取消按钮通过参数配置决定是否显示
28
 params[0]:提示框内容(字符串类型,不能为空)
29
 params[1]:提示框标题(字符串类型,可以为空)
30
 params[2]:是否显示两个按钮“取消、确认”供选择(布尔类型,true—取消、确认,false—确认)
31
 params[3]:提示框文字颜色设置(数组类型,第一个为普通颜色值,第二个为提亮颜色值)
32
 */
33
-(void)showCustomAlert:(NSArray *)params;
34
35
/*
36
 外部JS访问:显示一个带输入框的弹出框,内容、输入框、“取消、提交”按钮是必须显示的,标题通过参数配置决定是否显示
37
 params[0]:提示框内容(字符串类型,不能为空)
38
 params[1]:提示框标题(字符串类型,可以为空)
39
 params[2]:输入文字内容是否为暗文(布尔类型,true为暗文,false为明文)
40
 params[3]:提示框文字颜色设置(数组类型,第一个为普通颜色值,第二个为提亮颜色值)
41
 */
42
-(void)showInputAlert:(NSArray *)params;
43
44
/*
45
 外部JS访问:显示一个带“成功图标+文字”的提示框,持续指定时长后隐藏
46
 params[0]:提示框显示的时长(可为空,默认持续2秒)
47
 */
48
-(void)showSuccessHUD:(NSArray *)params;
49
50
/*
51
 外部JS访问:显示一个带“失败图标+文字”的提示框,持续指定时长后隐藏
52
 params[0]:提示框显示的时长(可为空,默认持续2秒)
53
 */
54
-(void)showFailHUD:(NSArray *)params;
55
56
/*
57
 内部IOS访问:显示一个自定义视图
58
 */
59
-(void)showHUDWithCustomView:(UIView *)view;
60
25 61
/*
26 62
 内部IOS访问:显示一个带文字的提示框,持续指定时长后隐藏
27 63
 */

+ 414 - 9
WadeMobileFunc/WadeMobileFunc/WDFTipsHUD.m

@ -7,6 +7,20 @@
7 7
//
8 8
9 9
#import "WDFTipsHUD.h"
10
#import <WadeMobile/UIViewAdditions.h>
11
#import <WadeMobile/WDCommonTool.h>
12
//屏幕高度
13
#define deviceHeight ([[UIScreen mainScreen] bounds].size.height)
14
//屏幕宽度
15
#define deviceWidth ([[UIScreen mainScreen] bounds].size.width)
16
17
@interface WDFTipsHUD()
18
{
19
    UITextField *inputField;
20
}
21
22
23
@end
10 24
11 25
@implementation WDFTipsHUD
12 26
@ -15,10 +29,9 @@
15 29
 */
16 30
-(void)showLoadingHUD:(NSArray *)params{
17 31
    WDViewController *vc = (WDViewController *)[self getViewController];
18
    if (vc.ipuHud==nil) {
19
        IPUProgressHUD *hud = [[IPUProgressHUD alloc] initWithView:vc.view];
20
        [vc.view addSubview:hud];
21
    }
32
    vc.ipuHud = nil;
33
    vc.ipuHud = [[IPUProgressHUD alloc] initWithView:vc.view];
34
    [vc.view addSubview:vc.ipuHud];
22 35
    vc.ipuHud.mode = IPUProgressHUDModeIndeterminate;
23 36
    vc.ipuHud.margin = 20.0f;
24 37
    vc.ipuHud.labelText = nil;
@ -44,7 +57,7 @@
44 57
            return;
45 58
        }
46 59
        NSString *txt = params[0];
47
        NSTimeInterval time = 1;
60
        NSTimeInterval time = 2;
48 61
        if (params.count>1 && params[1]!=[NSNull null]) {
49 62
            NSString *timeStr = params[1];
50 63
            time = timeStr.doubleValue;
@ -53,14 +66,353 @@
53 66
    }
54 67
}
55 68
/*
69
 外部JS访问:showCustomAlert插件显示一个可动态配置的弹出框,内容与确认按钮必须显示,标题与取消按钮通过参数配置决定是否显示
70
 params[0]:提示框内容(字符串类型,不能为空)
71
 params[1]:提示框标题(字符串类型,可以为空)
72
 params[2]:是否显示两个按钮“取消、确认”供选择(布尔类型,true—取消、确认,false—确认)
73
 params[3]:提示框文字颜色设置(数组类型,第一个为普通颜色值,第二个为提亮颜色值)
74
 */
75
-(void)showCustomAlert:(NSArray *)params{
76
    NSString *text = nil;
77
    NSString *title = nil;
78
    BOOL isChooseAlert = false;
79
    NSArray *colors = nil;
80
    if (params && params.count>0) {
81
        if (params[0]==[NSNull null]) {
82
            return;
83
        }
84
        text = params[0];
85
        if (params.count>1 && params[1]!=[NSNull null]) {
86
            title = params[1];
87
        }
88
        if (params.count>2 && params[2]!=[NSNull null]) {
89
            isChooseAlert = [params[2] boolValue];
90
        }
91
        if (params.count>3 && params[3]!=[NSNull null]) {
92
            colors = params[3];
93
        }
94
    }
95
    
96
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 0, deviceWidth-100, 204)];
97
    if (title==nil) {
98
        view.frame = CGRectMake(50, 0, deviceWidth-100, 140);
99
    }
100
    view.layer.cornerRadius = 2;
101
    
102
    //标题控件
103
    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, view.width, 64)];
104
    titleLbl.font = [UIFont boldSystemFontOfSize:20];
105
    titleLbl.textAlignment = NSTextAlignmentCenter;
106
    if (colors && colors.count>0) {
107
        titleLbl.textColor = [WDCommonTool convertHexToColor:colors[0]];
108
    }else{
109
        titleLbl.textColor = [WDCommonTool convertHexToColor:@"#061B36"];
110
    }
111
    [view addSubview:titleLbl];
112
    if (title) {
113
        titleLbl.hidden = NO;
114
        titleLbl.text = title;
115
    }else{
116
        titleLbl.hidden = YES;
117
    }
118
    
119
    //内容控件
120
    UILabel *contentLbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, view.width-40, 0)];
121
    contentLbl.font = [UIFont systemFontOfSize:16];
122
    if (colors && colors.count>0) {
123
        contentLbl.textColor = [WDCommonTool convertHexToColor:colors[0]];
124
    }else{
125
        contentLbl.textColor = [WDCommonTool convertHexToColor:@"#061B36"];
126
    }
127
    //换行
128
    contentLbl.numberOfLines = 0;
129
    contentLbl.lineBreakMode = NSLineBreakByWordWrapping;
130
    contentLbl.text = text;
131
    //设置行距
132
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
133
    paragraphStyle.lineSpacing = 5;
134
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
135
    [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
136
    contentLbl.attributedText = [[NSAttributedString alloc] initWithString:contentLbl.text attributes:attributes];
137
    [view addSubview:contentLbl];
138
    CGSize size = [contentLbl.text sizeWithFont: contentLbl.font constrainedToSize:CGSizeMake(contentLbl.width,200)];
139
    //计算文字行数
140
    CGSize size1 = [@"一行文字高度" sizeWithFont: contentLbl.font constrainedToSize:CGSizeMake(contentLbl.width,200)];
141
    int textRow = size.height/size1.height-1;
142
    if (size.height>20) {
143
        contentLbl.textAlignment = NSTextAlignmentLeft;
144
    }else{
145
        contentLbl.textAlignment = NSTextAlignmentCenter;
146
    }
147
    if (title) {
148
        CGRect rect = contentLbl.frame;
149
        rect.origin.y = titleLbl.bottom;
150
        rect.size.height = size.height+5*textRow;//加上间距高度
151
        contentLbl.frame = rect;
152
        view.frame = CGRectMake(50, 0, deviceWidth-100, titleLbl.height+contentLbl.height+30+60);
153
    }else{
154
        CGRect rect = contentLbl.frame;
155
        rect.origin.y = 30;
156
        rect.size.height = size.height+5*textRow;
157
        contentLbl.frame = rect;
158
        view.frame = CGRectMake(50, 0, deviceWidth-100, 30+contentLbl.height+30+60);
159
    }
160
    
161
    //横线
162
    UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(0, view.height-60, view.width, 0.5)];
163
    if (colors && colors.count>0) {
164
        hLine.backgroundColor = [WDCommonTool convertHexToColor:colors[0]];
165
    }else{
166
        hLine.backgroundColor = [WDCommonTool convertHexToColor:@"#061B36"];
167
    }
168
    [view addSubview:hLine];
169
    
170
    if (isChooseAlert) {//可选择弹出框
171
        //竖线
172
        UIView *vLine = [[UIView alloc] initWithFrame:CGRectMake(view.width/2, view.height-59.5, 0.5, 59.5)];
173
        if (colors && colors.count>0) {
174
            vLine.backgroundColor = [WDCommonTool convertHexToColor:colors[0]];
175
        }else{
176
            vLine.backgroundColor = [WDCommonTool convertHexToColor:@"#061B36"];
177
        }
178
        [view addSubview:vLine];
179
        
180
        UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
181
        cancelBtn.frame = CGRectMake(0, view.height-59.5, view.width/2, vLine.height);
182
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
183
        if (colors && colors.count>0) {
184
            [cancelBtn setTitleColor:[WDCommonTool convertHexToColor:colors[0]] forState:UIControlStateNormal];
185
        }else{
186
            [cancelBtn setTitleColor:[WDCommonTool convertHexToColor:@"#061B36"] forState:UIControlStateNormal];
187
        }
188
        cancelBtn.titleLabel.font = [UIFont systemFontOfSize:18];
189
        [cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
190
        [view addSubview:cancelBtn];
191
        
192
        UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
193
        addBtn.frame = CGRectMake(view.width/2, view.height-59.5, view.width/2, vLine.height);
194
        [addBtn setTitle:@"确定" forState:UIControlStateNormal];
195
        if (colors && colors.count>1) {
196
            [addBtn setTitleColor:[WDCommonTool convertHexToColor:colors[1]] forState:UIControlStateNormal];
197
        }else{
198
            [addBtn setTitleColor:[WDCommonTool convertHexToColor:@"#07B57A"] forState:UIControlStateNormal];
199
        }
200
        addBtn.titleLabel.font = [UIFont systemFontOfSize:18];
201
        [addBtn addTarget:self action:@selector(okAction:) forControlEvents:UIControlEventTouchUpInside];
202
        [view addSubview:addBtn];
203
    }else{
204
        UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
205
        addBtn.frame = CGRectMake(0, view.height-59.5, view.width, 59.5);
206
        [addBtn setTitle:@"确定" forState:UIControlStateNormal];
207
        if (colors && colors.count>1) {
208
            [addBtn setTitleColor:[WDCommonTool convertHexToColor:colors[1]] forState:UIControlStateNormal];
209
        }else{
210
            [addBtn setTitleColor:[WDCommonTool convertHexToColor:@"#07B57A"] forState:UIControlStateNormal];
211
        }
212
        addBtn.titleLabel.font = [UIFont systemFontOfSize:18];
213
        [addBtn addTarget:self action:@selector(okAction:) forControlEvents:UIControlEventTouchUpInside];
214
        [view addSubview:addBtn];
215
    }
216
    
217
    [self showHUDWithCustomView:view];
218
}
219
/*
220
 外部JS访问:显示一个带输入框的弹出框,内容、输入框、“取消、提交”按钮是必须显示的,标题通过参数配置决定是否显示
221
 params[0]:提示框内容(字符串类型,不能为空)
222
 params[1]:提示框标题(字符串类型,可以为空)
223
 params[2]:输入文字内容是否为暗文(布尔类型,true为暗文,false为明文)
224
 params[3]:提示框文字颜色设置(数组类型,第一个为普通颜色值,第二个为提亮颜色值)
225
 */
226
-(void)showInputAlert:(NSArray *)params{
227
    NSString *text = nil;
228
    NSString *title = nil;
229
    BOOL isSecure = false;
230
    NSArray *colors = nil;
231
    if (params && params.count>0) {
232
        if (params[0]==[NSNull null]) {
233
            return;
234
        }
235
        text = params[0];
236
        if (params.count>1 && params[1]!=[NSNull null]) {
237
            title = params[1];
238
        }
239
        if (params.count>2 && params[2]!=[NSNull null]) {
240
            isSecure = [params[2] boolValue];
241
        }
242
        if (params.count>3 && params[3]!=[NSNull null]) {
243
            colors = params[3];
244
        }
245
    }
246
    
247
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 0, deviceWidth-100, 204)];
248
    view.frame = CGRectMake(50, 0, deviceWidth-100, 140);
249
    view.layer.cornerRadius = 2;
250
    
251
    //标题控件
252
    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, view.width, 64)];
253
    titleLbl.font = [UIFont boldSystemFontOfSize:20];
254
    titleLbl.textAlignment = NSTextAlignmentCenter;
255
    if (colors && colors.count>0) {
256
        titleLbl.textColor = [WDCommonTool convertHexToColor:colors[0]];
257
    }else{
258
        titleLbl.textColor = [WDCommonTool convertHexToColor:@"#061B36"];
259
    }
260
    titleLbl.text = title;
261
    [view addSubview:titleLbl];
262
    
263
    //内容控件
264
    UILabel *contentLbl = [[UILabel alloc] initWithFrame:CGRectMake(20, titleLbl.bottom, view.width-40, 0)];
265
    contentLbl.font = [UIFont systemFontOfSize:16];
266
    if (colors && colors.count>0) {
267
        contentLbl.textColor = [WDCommonTool convertHexToColor:colors[0]];
268
    }else{
269
        contentLbl.textColor = [WDCommonTool convertHexToColor:@"#061B36"];
270
    }
271
    //换行
272
    contentLbl.numberOfLines = 0;
273
    contentLbl.lineBreakMode = NSLineBreakByWordWrapping;
274
    contentLbl.text = text;
275
    //设置行距
276
    NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
277
    paragraphStyle.lineSpacing = 5;
278
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
279
    [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
280
    contentLbl.attributedText = [[NSAttributedString alloc] initWithString:contentLbl.text attributes:attributes];
281
    [view addSubview:contentLbl];
282
    CGSize size = [contentLbl.text sizeWithFont: contentLbl.font constrainedToSize:CGSizeMake(contentLbl.width,200)];
283
    //计算文字行数
284
    CGSize size1 = [@"一行文字高度" sizeWithFont: contentLbl.font constrainedToSize:CGSizeMake(contentLbl.width,200)];
285
    int textRow = size.height/size1.height-1;
286
    if (textRow>0) {
287
        contentLbl.textAlignment = NSTextAlignmentLeft;
288
    }else{
289
        contentLbl.textAlignment = NSTextAlignmentCenter;
290
    }
291
    CGRect rect = contentLbl.frame;
292
    rect.origin.y = titleLbl.bottom;
293
    rect.size.height = size.height+5*textRow;//加上间距高度
294
    contentLbl.frame = rect;
295
    
296
    //输入框
297
    inputField = [[UITextField alloc] initWithFrame:CGRectMake(20, contentLbl.bottom+20, view.width-40, 40)];
298
    if (colors && colors.count>1) {
299
        inputField.layer.borderColor = [WDCommonTool convertHexToColor:colors[1]].CGColor;
300
    }else{
301
        inputField.layer.borderColor = [WDCommonTool convertHexToColor:@"#061B36"].CGColor;
302
    }
303
    inputField.layer.borderWidth = 1;
304
    inputField.layer.cornerRadius = 2;
305
    inputField.textColor = contentLbl.textColor;
306
    inputField.font = contentLbl.font;
307
    inputField.secureTextEntry = isSecure;
308
    [view addSubview:inputField];
309
    
310
    //横线
311
    UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(0, inputField.bottom+30, view.width, 0.5)];
312
    if (colors && colors.count>0) {
313
        hLine.backgroundColor = [WDCommonTool convertHexToColor:colors[0]];
314
    }else{
315
        hLine.backgroundColor = [WDCommonTool convertHexToColor:@"#061B36"];
316
    }
317
    [view addSubview:hLine];
318
    
319
    //竖线
320
    UIView *vLine = [[UIView alloc] initWithFrame:CGRectMake(view.width/2, hLine.bottom, 0.5, 59.5)];
321
    if (colors && colors.count>0) {
322
        vLine.backgroundColor = [WDCommonTool convertHexToColor:colors[0]];
323
    }else{
324
        vLine.backgroundColor = [WDCommonTool convertHexToColor:@"#061B36"];
325
    }
326
    [view addSubview:vLine];
327
    
328
    //取消按钮
329
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
330
    cancelBtn.frame = CGRectMake(0, hLine.bottom, view.width/2, vLine.height);
331
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
332
    if (colors && colors.count>0) {
333
        [cancelBtn setTitleColor:[WDCommonTool convertHexToColor:colors[0]] forState:UIControlStateNormal];
334
    }else{
335
        [cancelBtn setTitleColor:[WDCommonTool convertHexToColor:@"#061B36"] forState:UIControlStateNormal];
336
    }
337
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:18];
338
    [cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
339
    [view addSubview:cancelBtn];
340
    
341
    //提交按钮
342
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
343
    addBtn.frame = CGRectMake(view.width/2, hLine.bottom, view.width/2, vLine.height);
344
    [addBtn setTitle:@"提交" forState:UIControlStateNormal];
345
    if (colors && colors.count>1) {
346
        [addBtn setTitleColor:[WDCommonTool convertHexToColor:colors[1]] forState:UIControlStateNormal];
347
    }else{
348
        [addBtn setTitleColor:[WDCommonTool convertHexToColor:@"#07B57A"] forState:UIControlStateNormal];
349
    }
350
    addBtn.titleLabel.font = [UIFont systemFontOfSize:18];
351
    [addBtn addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];
352
    [view addSubview:addBtn];
353
    
354
    view.frame = CGRectMake(50, 0, deviceWidth-100, titleLbl.height+contentLbl.height+20+inputField.height+30+60);
355
    
356
    [self showHUDWithCustomView:view];
357
}
358
/*
359
 外部JS访问:显示一个带“成功图标+文字”的提示框,持续指定时长后隐藏
360
 params[0]:提示框显示的时长(可为空,默认持续2秒)
361
 */
362
-(void)showSuccessHUD:(NSArray *)params{
363
    NSTimeInterval time = 2;
364
    if (params && params.count>0 && params[0]!=[NSNull null]) {
365
        NSString *timeStr = params[0];
366
        time = timeStr.doubleValue;
367
    }
368
    
369
    NSString *bundlestring = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/WadeMobileFuncBundle.bundle"];
370
    NSBundle *bundle = [NSBundle bundleWithPath:bundlestring];
371
    UIImage *successImg = [UIImage imageNamed:@"success" inBundle:bundle compatibleWithTraitCollection:nil];
372
    
373
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 95)];
374
    view.layer.cornerRadius = 5;
375
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, view.width, view.height)];
376
    imgView.image = successImg;
377
    [view addSubview:imgView];
378
    
379
    [self showHUDWithImageView:view DisplayTime:time];
380
    
381
}
382
/*
383
 外部JS访问:显示一个带“失败图标+文字”的提示框,持续指定时长后隐藏
384
 params[0]:提示框显示的时长(可为空,默认持续2秒)
385
 */
386
-(void)showFailHUD:(NSArray *)params{
387
    NSTimeInterval time = 2;
388
    if (params && params.count>0 && params[0]!=[NSNull null]) {
389
        NSString *timeStr = params[0];
390
        time = timeStr.doubleValue;
391
    }
392
    
393
    NSString *bundlestring = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/WadeMobileFuncBundle.bundle"];
394
    NSBundle *bundle = [NSBundle bundleWithPath:bundlestring];
395
    UIImage *successImg = [UIImage imageNamed:@"fail" inBundle:bundle compatibleWithTraitCollection:nil];
396
    
397
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 95)];
398
    view.layer.cornerRadius = 5;
399
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, view.width, view.height)];
400
    imgView.layer.cornerRadius = 5;
401
    imgView.image = successImg;
402
    [view addSubview:imgView];
403
    
404
    [self showHUDWithImageView:view DisplayTime:time];
405
}
406
407
#pragma mark - ios method
408
/*
56 409
 内部IOS访问:显示一个带文字的提示框,持续指定时长后隐藏
57 410
 */
58 411
-(void)showHUDWithText:(NSString *)txt DisplayTime:(NSTimeInterval)time{
59 412
    WDViewController *vc = (WDViewController *)[self getViewController];
60
    if (vc.ipuHud==nil) {
61
        IPUProgressHUD *hud = [[IPUProgressHUD alloc] initWithView:vc.view];
62
        [vc.view addSubview:hud];
63
    }
413
    vc.ipuHud = nil;
414
    vc.ipuHud = [[IPUProgressHUD alloc] initWithView:vc.view];
415
    [vc.view addSubview:vc.ipuHud];
64 416
    vc.ipuHud.mode = IPUProgressHUDModeText;
65 417
    vc.ipuHud.margin = 12.f;
66 418
    vc.ipuHud.labelText = txt;
@ -68,4 +420,57 @@
68 420
    [vc.ipuHud hide:YES afterDelay:time];//延迟time时长后隐藏
69 421
}
70 422
423
/*
424
 内部IOS访问:显示一个自定义视图
425
 */
426
-(void)showHUDWithCustomView:(UIView *)view{
427
    WDViewController *vc = (WDViewController *)[self getViewController];
428
    vc.ipuHud = nil;
429
    vc.ipuHud = [[IPUProgressHUD alloc] initWithView:vc.view];
430
    [vc.view addSubview:vc.ipuHud];
431
    vc.ipuHud.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
432
    vc.ipuHud.color = [UIColor whiteColor];
433
    vc.ipuHud.mode = IPUProgressHUDModeCustomView;
434
    vc.ipuHud.customView = view;
435
    [vc.ipuHud show:YES];//显示hud
436
}
437
438
/*
439
 内部IOS访问:显示一个自定义视图
440
 */
441
-(void)showHUDWithImageView:(UIView *)view DisplayTime:(NSTimeInterval)time{
442
    WDViewController *vc = (WDViewController *)[self getViewController];
443
    vc.ipuHud = nil;
444
    vc.ipuHud = [[IPUProgressHUD alloc] initWithView:vc.view];
445
    [vc.view addSubview:vc.ipuHud];
446
    vc.ipuHud.mode = IPUProgressHUDModeCustomView;
447
    vc.ipuHud.customView = view;
448
    [vc.ipuHud show:YES];//显示hud
449
    [vc.ipuHud hide:YES afterDelay:time];//延迟time时长后隐藏
450
}
451
452
#pragma mark - click action
453
-(void)cancelAction:(UIButton *)sender{
454
    WDViewController *vc = (WDViewController *)[self getViewController];
455
    if (vc.ipuHud) {
456
        [vc.ipuHud hide:YES];
457
    }
458
}
459
460
-(void)okAction:(UIButton *)sender{
461
    WDViewController *vc = (WDViewController *)[self getViewController];
462
    if (vc.ipuHud) {
463
        [vc.ipuHud hide:YES];
464
    }
465
    [super callback:@"1"];
466
}
467
468
-(void)submitAction:(UIButton *)sender{
469
    WDViewController *vc = (WDViewController *)[self getViewController];
470
    if (vc.ipuHud) {
471
        [vc.ipuHud hide:YES];
472
    }
473
    [super callback:inputField.text];
474
}
475
71 476
@end