UserConterController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 "FilePreviewer.h"
  20. #import "GDBManager.h"
  21. #import <AdSupport/AdSupport.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. [[FilePreviewer shared] previewFileWithLocalPath:@"" remoteURL:getURL(privacyPolicy) fromViewController:self];
  186. }
  187. }
  188. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  189. return 1;
  190. }
  191. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  192. return _cellDatas.count;
  193. }
  194. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  195. return 52.0;
  196. }
  197. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  198. CGFloat height =10.0;
  199. if(section==1){
  200. height =0.0;
  201. }
  202. return height;
  203. }
  204. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  205. CGFloat height =10.0;
  206. if(section==1){
  207. height =0.0;
  208. }
  209. UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, height)];
  210. view.backgroundColor = [UIColor clearColor];
  211. return view;
  212. }
  213. #pragma mark allactions
  214. -(void)tuichudengl{
  215. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认"
  216. message:@"确定要退出登录吗?"
  217. preferredStyle:UIAlertControllerStyleAlert];
  218. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"
  219. style:UIAlertActionStyleCancel
  220. handler:^(UIAlertAction * action) {
  221. // 点击取消后的操作
  222. }];
  223. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"
  224. style:UIAlertActionStyleDefault
  225. handler:^(UIAlertAction * action) {
  226. [self logoutAccaut];
  227. // 点击确定后的操作
  228. }];
  229. [alert addAction:cancelAction];
  230. [alert addAction:okAction];
  231. [self presentViewController:alert animated:YES completion:nil];
  232. }
  233. -(void)logoutAccaut{
  234. [UserNetApi logout:nil succ:^(int code, NSDictionary * res) {
  235. NSLog(@"res:%@",res);
  236. [[NSNotificationCenter defaultCenter] postNotificationName: nkonLogoutSucc object:nil];
  237. } fail:^(NSError * _Nonnull error) {
  238. NSLog(@"");
  239. }];
  240. }
  241. #pragma mark private
  242. -(void)getUserinfo{
  243. NSString *token = [UDManager.shareInstance getSDManager:gkeytoken];
  244. if([token isKindOfClass:[NSString class]]&&token.length>10){
  245. [UserNetApi getUserinfo:^(int code, NSDictionary * res) {
  246. NSLog(@"%d", code);
  247. NSNumber *gcode=res[@"code"];
  248. NSDictionary *data=res[@"data"];
  249. NSLog(@"%@", res);
  250. if([gcode intValue]!=200){
  251. NSLog(@"%@",res[@"msg"]);
  252. // [MBProgressHUD showWithText:@"登录异常,请重新登录"];
  253. return;
  254. }
  255. NSDictionary *ps = @{@"avatar": data[@"avatar"]?:@"",
  256. @"deptId": data[@"deptId"]?:@"",
  257. //@"domainId":data[@"domainId"],
  258. @"email":data[@"email"]?:@"",
  259. @"id":data[@"id"]?:@"",
  260. @"mobile":data[@"mobile"]?:@"",
  261. @"name":data[@"name"]?:@"",
  262. //@"platformType":data[@"platformType"]?:@"",
  263. //@"registrationId":data[@"registrationId"]?:@"",
  264. @"sex":data[@"sex"]?:@"",
  265. //@"tgbotAdmin":data[@"tgbotAdmin"],
  266. //@"tgbotName":data[@"tgbotName"],
  267. //@"tgbotTk":data[@"tgbotTk"]?:@"",
  268. @"username":data[@"username"]?:@"",
  269. //@"uuid":data[@"uuid"],
  270. //@"voipTk":data[@"voipTk"]?:@""
  271. };
  272. if([gcode intValue]==200){
  273. NSLog(@"ps:%@",ps);
  274. [UDManager.shareInstance setSDManager:ps[@"id"] key:dkuserId];
  275. [UDManager.shareInstance setDDManager:ps key:dkuserinfo];
  276. [self showUserData];
  277. }
  278. else{
  279. [self logoutAccaut];
  280. }
  281. } fail:^(NSError * _Nonnull error) {
  282. NSLog(@"%@", error);
  283. }];
  284. }
  285. }
  286. -(void)showUserData{
  287. NSDictionary *userinfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  288. _nameLb.text = userinfo[@"name"];
  289. _qianmLb.alpha = 0;
  290. NSURL *av = [NSURL URLWithString:userinfo[@"avatar"]];
  291. _avatar.layer.cornerRadius = 41.0;
  292. _avatar.layer.borderWidth = 1.0;
  293. _avatar.layer.borderColor = [UIColor whiteColor].CGColor;
  294. [_avatar sd_setImageWithURL:av placeholderImage:[UIImage imageNamed:@"Avatar"]];
  295. }
  296. #pragma mark statusBar
  297. - (UIStatusBarStyle)preferredStatusBarStyle{
  298. return UIStatusBarStyleLightContent;
  299. }
  300. @end