BlackListController.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // BlackListController.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/5/22.
  6. //
  7. #import "BlackListController.h"
  8. #import "FriendListCell.h"
  9. #import "FriendNetApi.h"
  10. @interface BlackListController ()<UITableViewDelegate,UITableViewDataSource>
  11. @property (nonatomic, strong) UITableView * tableView;
  12. @property (nonatomic, strong) NSMutableArray * dataArray;
  13. @end
  14. @implementation BlackListController
  15. #pragma mark lifecycle
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self configUI];
  19. [self getBlackcListData];
  20. }
  21. - (void)viewWillAppear:(BOOL)animated{
  22. [self setNavigationBarHidden:NO animated:NO];
  23. }
  24. - (void)viewWillDisappear:(BOOL)animated{
  25. [self setNavigationBarHidden:YES animated:NO];
  26. }
  27. #pragma mark UI
  28. - (void)configUI{
  29. [self setNavigationBarHidden:NO animated:YES];
  30. [self setNavigationTitle:NSLocalizedString(@"userCenter-heimdan", @"")];
  31. // 设置导航栏背景色
  32. [self setNavigationBarBackgroundColor:UIColor.clearColor];
  33. // 设置标题颜色和字体
  34. [self setNavigationTitleColor:[UIColor whiteColor] font:SYSBFONT(18)];
  35. // 设置返回按钮
  36. [self setBackButtonTitle:@""];
  37. [self setBackButtonColor:[UIColor whiteColor]];
  38. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  39. [self.view addSubview:bgImageView];
  40. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.right.top.bottom.mas_equalTo(0);
  42. }];
  43. [self.view addSubview:self.tableView];
  44. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.mas_equalTo(SCREEN_TOP+10);
  46. make.left.right.bottom.mas_equalTo(0);
  47. }];
  48. }
  49. #pragma mark api
  50. - (void)getBlackcListData{
  51. [FriendNetApi getblackList:@{} succ:^(int code, NSDictionary * _Nullable result) {
  52. NSLog(@"blackList result:%@",result);
  53. if (code == 200) {
  54. [self.dataArray addObjectsFromArray:result[@"data"]];
  55. [self.tableView reloadData];
  56. }
  57. } fail:^(NSError * _Nonnull error) {
  58. }];
  59. }
  60. - (void)removeFromBlacklist:(NSDictionary *)user{
  61. [FriendNetApi removeFromBlacklistWithId:user[@"id"] succ:^(int code, NSDictionary * _Nullable result) {
  62. if (code == 200) {
  63. [self.dataArray removeObject:user];
  64. [self.tableView reloadData];
  65. }
  66. } fail:^(NSError * _Nonnull error) {
  67. }];
  68. }
  69. #pragma mark tableView delegate
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  71. return self.dataArray.count;
  72. }
  73. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  74. return 70;
  75. }
  76. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  77. FriendListCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(FriendListCell.class) forIndexPath:indexPath];
  78. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  79. cell.backgroundColor = [UIColor clearColor];
  80. [cell fillWithData:self.dataArray[indexPath.row]];
  81. return cell;
  82. }
  83. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
  84. weakSelf(self);
  85. NSDictionary * user = self.dataArray[indexPath.row];
  86. // 创建删除操作
  87. UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
  88. title:NSLocalizedString(@"GroupCtr-yichu", @"")
  89. handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  90. // 更新数据
  91. [weakself removeFromBlacklist:user];
  92. // 告诉系统操作已完成
  93. completionHandler(YES);
  94. }];
  95. // 设置删除按钮颜色
  96. deleteAction.backgroundColor = [UIColor redColor];
  97. // 创建配置并返回
  98. UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
  99. config.performsFirstActionWithFullSwipe = YES; // 完全滑动直接执行删除
  100. return config;
  101. }
  102. #pragma mark emptyDataset
  103. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  104. return [[NSAttributedString alloc] initWithString:NSLocalizedString(@"Common_nodata", @"")];
  105. }
  106. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{
  107. return -100.f;
  108. }
  109. #pragma mark lazy
  110. - (UITableView *)tableView{
  111. if (!_tableView) {
  112. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  113. _tableView.delegate = self;
  114. _tableView.dataSource = self;
  115. _tableView.backgroundColor = UIColor.clearColor;
  116. [_tableView registerClass:FriendListCell.class forCellReuseIdentifier:NSStringFromClass(FriendListCell.class)];
  117. }
  118. return _tableView;
  119. }
  120. - (NSMutableArray *)dataArray{
  121. if (!_dataArray) {
  122. _dataArray = [NSMutableArray array];
  123. }
  124. return _dataArray;
  125. }
  126. #pragma mark statusBar
  127. - (UIStatusBarStyle)preferredStatusBarStyle{
  128. return UIStatusBarStyleLightContent;
  129. }
  130. @end