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
//
//  PBMineView.m
//  IphoneBIMe
//
//  Created by zjf on 2018/7/17.
//  Copyright © 2018年 ProBIM. All rights reserved.
//
 
#import "PBMineView.h"
#import <JPUSHService.h>
static NSString *const CellID = @"CellID";
@interface PBMineView()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataList;
@property (nonatomic, weak) UILabel *nameL;
@end
@implementation PBMineView
 
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
 
- (void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    UIImageView *bgImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Mine_img_bg"]];
    [self addSubview:bgImageV];
    int bgImageVH;
    if (IS_IPHONE_X) {
        bgImageVH = 193 + 44;
    }else {
        bgImageVH = 193;
    }
    [bgImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(@(bgImageVH));
    }];
    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Mine_user_icon"]];
    int top;
    if (IS_IPHONE_X) {
        top = 50 + 44;
    }else {
        top = 50;
    }
    [self addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(top);
        make.size.mas_equalTo(CGSizeMake(80, 80));
        make.centerX.equalTo(self);
    }];
    UILabel *nameL = [UILabel z_labelWithText:@"" Color:[UIColor z_colorWithR:65 G:127 B:205] isBold:NO Font:20];
    self.nameL = nameL;
    [self addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageV.mas_bottom).offset(20);
        make.centerX.equalTo(imageV);
    }];
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor z_colorWithR:215 G:215 B:215];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgImageV.mas_bottom);
        make.left.right.equalTo(self);
        make.height.equalTo(@1);
    }];
    self.tableView = [[UITableView alloc] init];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellID];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 50;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:self.tableView];
    CGFloat height;
    if (IS_IPHONE_X) {
        height = 50.f + 34.f;
    }else {
        height = 50.0f;
    }
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView.mas_bottom).offset(20);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self).offset(-height);
    }];
    UIButton *LogOutBtn = [UIButton z_textButton:@"退出登录" fontSize:20.0 normalColor:SensitiveColor];
    [LogOutBtn addTarget:self action:@selector(LogOutAction:) forControlEvents:UIControlEventTouchUpInside];
    LogOutBtn.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242];
    [self addSubview:LogOutBtn];
    [LogOutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.height.equalTo(@50);
        make.top.equalTo(self.tableView.mas_bottom);
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dict = self.dataList[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:[dict valueForKey:@"imageName"]];
    cell.textLabel.text = [dict valueForKey:@"title"];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.customDelegate respondsToSelector:@selector(LeftMenuViewClick:)]) {
        [self.customDelegate LeftMenuViewClick:indexPath.row];
    }
}
 
- (NSMutableArray *)dataList {
    if (_dataList == nil) {
        _dataList = [[NSMutableArray alloc] init];
        NSDictionary *dict = @{
                               @"imageName":@"Mine_change_password",
                               @"title":@"修改密码"
                               };
        NSDictionary *dict1 = @{
                                @"imageName":@"Mine_clear_cache",
                                @"title":@"清除缓存"
                                };
        [_dataList addObject:dict];
        [_dataList addObject:dict1];
    }
    return _dataList;
}
 
//退出登录
- (void)LogOutAction:(UIButton *)button {
    [YJProgressHUD showProgress:@"正在退出" inView:self];
    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];
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if (networkModel.Ret == 1) {
            [YJProgressHUD hide];
            if ([self.customDelegate respondsToSelector:@selector(LeftMenuViewClick:)]) {
                [self.customDelegate LeftMenuViewClick:10];
            }
        }else {
            [YJProgressHUD showMessage:@"退出登录失败" inView:self];
        }
    }];
}
 
- (void)setRealName:(NSString *)realName {
    _realName = realName;
    self.nameL.text = realName;
}
@end