UserConterController.m 12 KB

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