zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
//
//  PBSetViewController.m
//  IphoneBIMe
//
//  Created by zjf on 2020/7/23.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBSetViewController.h"
#import "PBChangePWController.h"
#import "PBLoginViewController.h"
#import <JPUSHService.h>
@interface PBSetViewController ()
@property (nonatomic, weak) UILabel *cacheSizeL;
@end
 
@implementation PBSetViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    [self setupUI];
    [self folderSize];
}
- (void)setupNav {
    self.title = @"设置";
    UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrow_left"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)];
    self.navigationItem.leftBarButtonItem = backNavItem;
}
- (void)backItemAction {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setupUI {
    self.title = @"设置";
    self.view.backgroundColor = PBColor(244, 245, 246);
    CGFloat topH = 20.f;
    if (IS_IPHONE_X) {
        topH = 20.f + 24.f;
    }
    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"card_bg"]];
    [self.view addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(topH);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.height.equalTo(@180);
    }];
    UILabel *nameL = [UILabel z_labelWithText:Realname Color:[UIColor whiteColor] isBold:YES Font:22];
    [self.view addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageV).offset(20);
        make.left.equalTo(imageV).offset(20);
        make.height.equalTo(@30);
        make.right.equalTo(imageV).offset(-100);
    }];
    
//    UILabel *companyL = [UILabel z_labelWithText:@"北京东晨工元科技发展有限公司" Color:[UIColor whiteColor] isBold:NO Font:14];
//    [self.view addSubview:companyL];
//    [companyL mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(imageV).offset(-20);
//        make.left.equalTo(imageV).offset(20);
//        make.right.equalTo(imageV).offset(-15);
//        make.height.equalTo(@20);
//    }];
    UIView *bgV = [[UIView alloc] init];
    bgV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgV];
    [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageV.mas_bottom).offset(20);
        make.left.equalTo(self.view).offset(12);
        make.right.equalTo(self.view).offset(-12);
        make.height.equalTo(@50);
    }];
    [bgV circleViewWithRadius:6];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changepwAction:)];
    bgV.userInteractionEnabled = YES;
    [bgV addGestureRecognizer:tap];
 
    UILabel *changepwL = [UILabel z_labelWithText:@"密码" Color:PBColor(97, 111, 125) isBold:NO Font:15];
    [self.view addSubview:changepwL];
    [changepwL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgV).offset(15);
        make.centerY.equalTo(bgV);
    }];
    UILabel *titleL = [UILabel z_labelWithText:@"修改密码" Color:PBColor(40, 58, 79) isBold:YES Font:16];
    [self.view addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgV).offset(-36);
        make.centerY.equalTo(bgV);
    }];
    UIImageView *rightImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"set_arrow_right"]];
    [self.view addSubview:rightImageV];
    [rightImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(16, 16));
        make.right.equalTo(bgV).offset(-10);
        make.centerY.equalTo(bgV);
    }];
    UIView *bg1V = [[UIView alloc] init];
    bg1V.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bg1V];
    [bg1V mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgV.mas_bottom).offset(8);
        make.left.equalTo(self.view).offset(12);
        make.right.equalTo(self.view).offset(-12);
        make.height.equalTo(@50);
    }];
    [bg1V circleViewWithRadius:6];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cacheAction:)];
    bg1V.userInteractionEnabled = YES;
    [bg1V addGestureRecognizer:tap1];
    
    UILabel *cacheL = [UILabel z_labelWithText:@"清空缓存" Color:PBColor(97, 111, 125) isBold:NO Font:15];
    [self.view addSubview:cacheL];
    [cacheL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bg1V).offset(15);
        make.centerY.equalTo(bg1V);
    }];
    UILabel *cacheSizeL = [UILabel z_labelWithText:@"34M" Color:PBColor(40, 58, 79) isBold:YES Font:16];
    [self.view addSubview:cacheSizeL];
    [cacheSizeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bg1V).offset(-15);
        make.centerY.equalTo(bg1V);
    }];
    
    UIButton *quitBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"quit"]];
    [quitBtn addTarget:self action:@selector(quitAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:quitBtn];
    CGFloat bottom = 10;
    if (IS_IPHONE_X) {
        bottom = 10 + IPHONE_X_BOTTOM;
    }
    [quitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-bottom);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.height.equalTo(@46);
    }];
    self.cacheSizeL = cacheSizeL;
}
- (void)folderSize{
    CGFloat folderSize = 0.0;
    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)firstObject];
    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath];
    NSLog(@"文件数:%ld",files.count);
    for(NSString *path in files) {
        NSString*filePath = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",path]];
  //累加
        folderSize += [[NSFileManager defaultManager]attributesOfItemAtPath:filePath error:nil].fileSize;
    }
    //转换为M为单位
    CGFloat sizeM = folderSize /1024.0/1024.0;
    self.cacheSizeL.text = [NSString stringWithFormat:@"%.2fM", sizeM];
}
- (void)changepwAction:(UITapGestureRecognizer *)tap {
    PBChangePWController  *changePwVC = [[PBChangePWController alloc] init];
    changePwVC.ChangePWCompleteBlock = ^{
        [self.navigationController popViewControllerAnimated:NO];
        if (self.ToLoginBlock) {
            self.ToLoginBlock();
        }
    };
    [self.navigationController pushViewController:changePwVC animated:YES];
}
- (void)cacheAction:(UITapGestureRecognizer *)tap {
    [self clearCache];
}
- (void)quitAction:(UIButton *)btn {
    [YJProgressHUD showProgress:@"正在退出" inView:self.view];
    NSFileManager *manager=[NSFileManager defaultManager];
    NSString *filepath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"login.plist"];//这里就是你将要删除的沙盒路径(.plist文件,名字
    [manager removeItemAtPath:filepath error:nil];
    [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
        NSLog(@"%zd--%@--%zd",iResCode,iAlias,seq);
    } seq:10];
    [[PBNetworkTools sharedTools] RemoveTokenAndCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
            [YJProgressHUD showMessage:@"退出登录失败" inView:self.view];
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if (networkModel.Ret == 1) {
            [YJProgressHUD hide];
            [self.navigationController popViewControllerAnimated:NO];
            if (self.ToLoginBlock) {
                self.ToLoginBlock();
            }
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
 
- (void)clearCache {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"将删除所有缓存数据" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *clearAction = [UIAlertAction actionWithTitle:@"清除缓存" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
        [YJProgressHUD showProgress:@"正在删除" inView:self.view];
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString * cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
        NSLog(@"%@",cachePath);
        NSDirectoryEnumerator *fileEnumerator = [fileManager enumeratorAtPath:cachePath];
        for (NSString *fileName in fileEnumerator) {
            NSString *filePath = [cachePath stringByAppendingPathComponent:fileName];
            [fileManager removeItemAtPath:filePath error:nil];
        }
        [YJProgressHUD showMessage:@"删除完成" inView:self.view];
        self.cacheSizeL.text = @"0M";
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    [alertVC addAction:clearAction];
    [alertVC addAction:cancelAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}
 
/*
#pragma mark - Navigation
 
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
 
@end