UserConterController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. //
  2. // UserConterController.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/6.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "UserConterController.h"
  9. #import "SecurityController.h"
  10. #import "FavoritesController.h"
  11. #import "BlackListController.h"
  12. #import "ChatSettingController.h"
  13. #import "config.h"
  14. #import <SDWebImage/UIImageView+WebCache.h>
  15. #import "UDManager.h"
  16. #import "UserNetApi.h"
  17. #import "ZhanghaoCntroller.h"
  18. #import "PersonalInfoController.h"
  19. #import "GDBManager.h"
  20. #import "WebViewController.h"
  21. #import "LoginStateManager.h"
  22. @interface UserConterController()<UITableViewDelegate,UITableViewDataSource>
  23. @property (weak, nonatomic) IBOutlet UIImageView *avatar;
  24. @property (weak, nonatomic) IBOutlet UILabel *nameLb;
  25. @property (weak, nonatomic) IBOutlet UILabel *qianmLb;
  26. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  27. @property(nonatomic, strong) NSMutableArray *cellDatas;
  28. @end
  29. @implementation UserConterController
  30. -(void)viewDidLoad{
  31. [super viewDidLoad];
  32. [self initCellData];
  33. [self initsubView];
  34. }
  35. - (void)viewWillAppear:(BOOL)animated{
  36. [self setNavigationBarHidden:YES animated:YES];
  37. NSLog(@"viewWillAppear------------");
  38. [self getUserinfo];
  39. }
  40. -(void)initsubView{
  41. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellT"];
  42. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"tuichu"];
  43. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  44. _tableView.backgroundColor = [UIColor clearColor];
  45. _tableView.delegate =self;
  46. _tableView.dataSource = self;
  47. [self showUserData];
  48. }
  49. -(void)initCellData{
  50. NSDictionary *d1 =@{
  51. @"name":@"userCenter-gerenxinx",
  52. @"image":@"wgerenxx",
  53. };
  54. NSDictionary *d2 =@{
  55. @"name":@"userCenter-qiehuanyy",
  56. @"image":@"wqiehyy",
  57. };
  58. NSDictionary *d3 =@{
  59. @"name":@"userCenter-zitidax",
  60. @"image":@"wzitidx",
  61. };
  62. NSDictionary *d4 =@{
  63. @"name":@"userCenter-zhanghaoaq",
  64. @"image":@"wzitidx",
  65. };
  66. NSDictionary *d7 =@{
  67. @"name":@"userCenter-shoucjia",
  68. @"image":@"wscjia",
  69. };
  70. NSDictionary *d8 =@{
  71. @"name":@"userCenter-heimdan",
  72. @"image":@"wheimd",
  73. };
  74. NSDictionary *d9 =@{
  75. @"name":@"userCenter-liaotsz",
  76. @"image":@"wliaotsz",
  77. };
  78. NSDictionary *d10 =@{
  79. @"name":@"userCenter-yinsizhc",
  80. @"image":@"wyinsisz",
  81. };
  82. NSDictionary *d11 =@{
  83. @"name":@"userCenter-tianjiabmd",
  84. @"image":@"wbaimdan",
  85. };
  86. NSDictionary *d14 =@{
  87. @"name":@"userCenter-tuichudl",
  88. @"image":@"",
  89. };
  90. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  91. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  92. NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
  93. NSDictionary *d15 =@{
  94. @"name":[NSString stringWithFormat:@"版本号:%@(%@)",app_Version,app_build],
  95. @"image":@"",
  96. };
  97. _cellDatas = [[NSMutableArray alloc] init];
  98. [_cellDatas addObject:d1];
  99. // [_cellDatas addObject:d2];
  100. // [_cellDatas addObject:d3];
  101. [_cellDatas addObject:d4];
  102. [_cellDatas addObject:d7];
  103. [_cellDatas addObject:d8];
  104. [_cellDatas addObject:d9];
  105. [_cellDatas addObject:d10];
  106. // [_cellDatas addObject:d11];
  107. [_cellDatas addObject:d14];
  108. [_cellDatas addObject:d15];
  109. }
  110. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  111. NSInteger section =indexPath.section;
  112. NSString *cellT =@"cellT";
  113. if(section>=_cellDatas.count-2){
  114. cellT =@"tuichu";
  115. }
  116. UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellT forIndexPath:indexPath];
  117. if(cell==nil){
  118. cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellT];
  119. }
  120. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  121. cell.backgroundColor = [UIColor clearColor];
  122. NSDictionary *time =_cellDatas[section];
  123. NSString *title = NSLocalizedString(time[@"name"], @"");
  124. if(section>=_cellDatas.count-2){
  125. CGRect ctfrm = cell.contentView.frame;
  126. UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, ctfrm.size.width, 52)];
  127. titleLb.text =title;
  128. titleLb.textColor = [UIColor whiteColor];
  129. titleLb.textAlignment = NSTextAlignmentCenter;
  130. titleLb.font = [UIFont systemFontOfSize:17.0f];
  131. [cell.contentView addSubview:titleLb];
  132. }
  133. else{
  134. cell.imageView.image = [UIImage imageNamed:time[@"image"]];
  135. cell.textLabel.text =title;
  136. cell.textLabel.textColor = [UIColor whiteColor];
  137. UIImageView *right = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow-right"]];
  138. CGRect ctfrm = cell.contentView.frame;
  139. right.frame = CGRectMake(ctfrm.size.width-30, 21, 20, 20);
  140. [cell.contentView addSubview:right];
  141. }
  142. cell.contentView.layer.borderWidth = 0.5f;
  143. cell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  144. cell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  145. return cell;
  146. }
  147. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  148. if(indexPath.section==_cellDatas.count-2){
  149. [self tuichudengl];
  150. }
  151. if (indexPath.section == 0) {
  152. NSLog(@"111111---------");
  153. PersonalInfoController * personalInfoVc = [[PersonalInfoController alloc] init];
  154. personalInfoVc.hidesBottomBarWhenPushed = YES;
  155. // personalInfoVc.infoRefreshBlock = ^{
  156. // NSDictionary *userinfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  157. // weakself.nameLb.text = userinfo[@"name"];
  158. // [weakself.avatar sd_setImageWithURL:getURL(userinfo[@"avatar"]) placeholderImage:kImageMake(@"Avatar")];
  159. // };
  160. [self.navigationController pushViewController:personalInfoVc animated:YES];
  161. }
  162. if(indexPath.section==1){
  163. SecurityController * securityVc = [[SecurityController alloc] init];
  164. securityVc.hidesBottomBarWhenPushed = YES;
  165. [self.navigationController pushViewController:securityVc animated:YES];
  166. }
  167. if (indexPath.section == 2) {
  168. FavoritesController * favoritesVc = [[FavoritesController alloc] init];
  169. favoritesVc.hidesBottomBarWhenPushed = YES;
  170. [self.navigationController pushViewController:favoritesVc animated:YES];
  171. }
  172. if (indexPath.section == 3) {
  173. BlackListController * blackListVc = [[BlackListController alloc] init];
  174. blackListVc.hidesBottomBarWhenPushed = YES;
  175. [self.navigationController pushViewController:blackListVc animated:YES];
  176. }
  177. if (indexPath.section == 4) {
  178. ChatSettingController * chatSettingVc = [[ChatSettingController alloc] init];
  179. chatSettingVc.hidesBottomBarWhenPushed = YES;
  180. [self.navigationController pushViewController:chatSettingVc animated:YES];
  181. }
  182. if (indexPath.section == 5) {
  183. WebViewController *webVC = [[WebViewController alloc] initWithURL:getURL(privacyPolicy)];
  184. [self.navigationController pushViewController:webVC animated:YES];
  185. }
  186. }
  187. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  188. return 1;
  189. }
  190. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  191. return _cellDatas.count;
  192. }
  193. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  194. return 52.0;
  195. }
  196. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  197. CGFloat height =10.0;
  198. if(section==1){
  199. height =0.0;
  200. }
  201. return height;
  202. }
  203. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  204. CGFloat height =10.0;
  205. if(section==1){
  206. height =0.0;
  207. }
  208. UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, height)];
  209. view.backgroundColor = [UIColor clearColor];
  210. return view;
  211. }
  212. #pragma mark allactions
  213. -(void)tuichudengl{
  214. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认"
  215. message:@"确定要退出登录吗?"
  216. preferredStyle:UIAlertControllerStyleAlert];
  217. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"
  218. style:UIAlertActionStyleCancel
  219. handler:^(UIAlertAction * action) {
  220. // 点击取消后的操作
  221. }];
  222. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"
  223. style:UIAlertActionStyleDefault
  224. handler:^(UIAlertAction * action) {
  225. [self logoutAccaut];
  226. // 点击确定后的操作
  227. }];
  228. [alert addAction:cancelAction];
  229. [alert addAction:okAction];
  230. [self presentViewController:alert animated:YES completion:nil];
  231. }
  232. -(void)logoutAccaut{
  233. [[LoginStateManager sharedManager] logout];
  234. }
  235. #pragma mark private
  236. -(void)getUserinfo{
  237. NSString *token = [UDManager.shareInstance getSDManager:gkeytoken];
  238. if([token isKindOfClass:[NSString class]]&&token.length>10){
  239. [UserNetApi getUserinfo:^(int code, NSDictionary * res) {
  240. NSLog(@"%d", code);
  241. NSNumber *gcode=res[@"code"];
  242. NSDictionary *data=res[@"data"];
  243. NSLog(@"%@", res);
  244. if([gcode intValue]!=200){
  245. NSLog(@"%@",res[@"msg"]);
  246. // [MBProgressHUD showWithText:@"登录异常,请重新登录"];
  247. return;
  248. }
  249. NSDictionary *ps = @{@"avatar": data[@"avatar"]?:@"",
  250. @"deptId": data[@"deptId"]?:@"",
  251. //@"domainId":data[@"domainId"],
  252. @"email":data[@"email"]?:@"",
  253. @"id":data[@"id"]?:@"",
  254. @"mobile":data[@"mobile"]?:@"",
  255. @"name":data[@"name"]?:@"",
  256. //@"platformType":data[@"platformType"]?:@"",
  257. //@"registrationId":data[@"registrationId"]?:@"",
  258. @"sex":data[@"sex"]?:@"",
  259. //@"tgbotAdmin":data[@"tgbotAdmin"],
  260. //@"tgbotName":data[@"tgbotName"],
  261. //@"tgbotTk":data[@"tgbotTk"]?:@"",
  262. @"username":data[@"username"]?:@"",
  263. //@"uuid":data[@"uuid"],
  264. //@"voipTk":data[@"voipTk"]?:@""
  265. };
  266. if([gcode intValue]==200){
  267. NSLog(@"ps:%@",ps);
  268. [UDManager.shareInstance setSDManager:ps[@"id"] key:dkuserId];
  269. [UDManager.shareInstance setDDManager:ps key:dkuserinfo];
  270. [self showUserData];
  271. }
  272. else{
  273. [self logoutAccaut];
  274. }
  275. } fail:^(NSError * _Nonnull error) {
  276. NSLog(@"%@", error);
  277. }];
  278. }
  279. }
  280. -(void)showUserData{
  281. NSDictionary *userinfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  282. _nameLb.text = userinfo[@"name"];
  283. _qianmLb.alpha = 0;
  284. NSURL *av = [NSURL URLWithString:userinfo[@"avatar"]];
  285. _avatar.layer.cornerRadius = 41.0;
  286. _avatar.layer.borderWidth = 1.0;
  287. _avatar.layer.borderColor = [UIColor whiteColor].CGColor;
  288. [_avatar sd_setImageWithURL:av placeholderImage:[UIImage imageNamed:@"Avatar"]];
  289. }
  290. #pragma mark statusBar
  291. - (UIStatusBarStyle)preferredStatusBarStyle{
  292. return UIStatusBarStyleLightContent;
  293. }
  294. @end