// // PBMineView.m // IphoneBIMe // // Created by zjf on 2018/7/17. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBMineView.h" #import static NSString *const CellID = @"CellID"; @interface PBMineView() @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