Commit 129e6436b36625a82d4a953325746c4f34912aa2

Authored by iOS-Xiaowen
1 parent 0b368eaa

no message

CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageCell.h 0 → 100644
  1 +//
  2 +// CNLiveBindingManageCell.h
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +@class CNLiveBindingManageModel;
  13 +#define kCNLiveBindingManageCell @"CNLiveBindingManageCell"
  14 +
  15 +@class CNLiveBindingManageCell;
  16 +@protocol CNLiveBindingManageCellDelegate <NSObject>
  17 +//isBinding YES 绑定操作 NO 解除绑定操作
  18 +- (void)clickedBindingButton:(CNLiveBindingManageCell *)cell isBinding:(BOOL)isBinding;
  19 +
  20 +@end
  21 +
  22 +@interface CNLiveBindingManageCell : UITableViewCell
  23 +@property (nonatomic, strong) CNLiveBindingManageModel *model;
  24 +@property (nonatomic, weak) id<CNLiveBindingManageCellDelegate> delegate;
  25 +
  26 +@end
  27 +
  28 +NS_ASSUME_NONNULL_END
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageCell.m 0 → 100644
  1 +//
  2 +// CNLiveBindingManageCell.m
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveBindingManageCell.h"
  10 +#import <Masonry/Masonry.h>
  11 +#import "QMUIKit.h"
  12 +#import "CNLiveBaseKit.h"
  13 +#import <CNLiveRequestBastKit/CNLiveNetworking.h>
  14 +#import "CNLiveCategory.h"
  15 +
  16 +#import "CNLiveBindingManageModel.h"
  17 +#import "CNLiveBindingManageRequest.h"
  18 +
  19 +@interface CNLiveBindingManageCell()
  20 +@property (nonatomic, strong) UIImageView *icon;
  21 +@property (nonatomic, strong) UILabel *title;
  22 +@property (nonatomic, strong) UILabel *desc;
  23 +@property (nonatomic, strong) UIButton *manage;
  24 +@property (nonatomic, strong) UIView *line;
  25 +
  26 +@end
  27 +@implementation CNLiveBindingManageCell
  28 +static NSInteger const margin = 15;
  29 +
  30 +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  31 + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  32 + if (self) {
  33 + self.contentView.backgroundColor = [UIColor whiteColor];
  34 + [self createSubViews];
  35 + }
  36 + return self;
  37 +}
  38 +- (void)setModel:(CNLiveBindingManageModel *)model{
  39 + _model = model;
  40 + _icon.image = [self getImageWithImageName:model.image bundleName:@"CNLiveBMineModule" targetClass:[self class]];
  41 + _title.text = model.title;
  42 + _desc.text = model.desc;
  43 + if([model.isBinding isEqualToString:@"1"]){
  44 + _manage.backgroundColor = RGBOF(0xd9d9d9);
  45 + [_manage setTitle:@"已绑定" forState:UIControlStateNormal];
  46 +
  47 + }else{
  48 + _manage.backgroundColor = [UIColor colorWithRed:72/255.0 green:167/255.0 blue:249/255.0 alpha:1.0];
  49 + [_manage setTitle:@"未绑定" forState:UIControlStateNormal];
  50 +
  51 + }
  52 +
  53 +}
  54 +#pragma mark - setupUI
  55 +- (void)createSubViews {
  56 + [self.contentView addSubview:self.icon];
  57 + [self.contentView addSubview:self.title];
  58 + [self.contentView addSubview:self.desc];
  59 + [self.contentView addSubview:self.manage];
  60 + [self.contentView addSubview:self.line];
  61 +
  62 +}
  63 +
  64 +- (void)layoutSubviews {
  65 + [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
  66 + make.centerY.equalTo(self.contentView);
  67 + make.left.equalTo(self.contentView).offset(margin);
  68 + make.width.mas_equalTo(50);
  69 + make.height.mas_equalTo(50);
  70 + }];
  71 +
  72 + [self.manage mas_makeConstraints:^(MASConstraintMaker *make) {
  73 + make.centerY.equalTo(self.contentView);
  74 + make.right.equalTo(self.contentView.mas_right).offset(-margin);
  75 + make.width.mas_equalTo(70);
  76 + make.height.mas_equalTo(30);
  77 + }];
  78 +
  79 + [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  80 + make.top.equalTo(self.icon.mas_top);
  81 + make.left.equalTo(self.icon.mas_right).offset(margin);
  82 + make.right.equalTo(self.manage.mas_left).offset(-margin);
  83 + make.height.mas_equalTo(25);
  84 + }];
  85 +
  86 + [self.desc mas_makeConstraints:^(MASConstraintMaker *make) {
  87 + make.top.equalTo(self.title.mas_bottom);
  88 + make.left.equalTo(self.title.mas_left);
  89 + make.right.equalTo(self.title.mas_right);
  90 + make.height.mas_equalTo(25);
  91 + }];
  92 + [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
  93 + make.bottom.equalTo(self.contentView.mas_bottom).offset(-0.5);
  94 + make.left.equalTo(self.contentView.mas_left);
  95 + make.right.equalTo(self.contentView.mas_right);
  96 + make.height.mas_equalTo(0.5);
  97 + }];
  98 +}
  99 +
  100 +- (void)awakeFromNib {
  101 + [super awakeFromNib];
  102 + // Initialization code
  103 +}
  104 +
  105 +- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  106 + [super setSelected:selected animated:animated];
  107 +
  108 + // Configure the view for the selected state
  109 +}
  110 +
  111 +#pragma mark - Lazy Loading
  112 +- (UIImageView *)icon {
  113 + if (!_icon) {
  114 + _icon = [[UIImageView alloc] init];
  115 + _icon.contentMode = UIViewContentModeScaleAspectFill;
  116 + _icon.layer.cornerRadius = 25;
  117 + _icon.layer.masksToBounds = YES;
  118 + }
  119 + return _icon;
  120 +}
  121 +- (UILabel *)title {
  122 + if (!_title) {
  123 + _title = [[UILabel alloc] init];
  124 + _title.textColor = RGBOF(0x333333);
  125 + _title.font = UIFontCNMake(16);
  126 + _title.numberOfLines = 0;
  127 + }
  128 + return _title;
  129 +}
  130 +- (UILabel *)desc {
  131 + if (!_desc) {
  132 + _desc = [[UILabel alloc] init];
  133 + _desc.textColor = RGBOF(0x999999);
  134 + _desc.font = UIFontCNMake(12);
  135 + _desc.numberOfLines = 0;
  136 + }
  137 + return _desc;
  138 +}
  139 +- (UIButton *)manage {
  140 + if (!_manage) {
  141 + _manage = [UIButton buttonWithType:UIButtonTypeCustom];
  142 + _manage.backgroundColor = RGBOF(0xd9d9d9);
  143 + [_manage setTitle:@"已绑定" forState:UIControlStateNormal];
  144 + [_manage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  145 + _manage.titleLabel.font = UIFontCNMake(14);
  146 + _manage.layer.cornerRadius = 15;
  147 + _manage.layer.masksToBounds = YES;
  148 + [_manage addTarget:self action:@selector(manageDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  149 + }
  150 + return _manage;
  151 +}
  152 +
  153 +- (UIView *)line {
  154 + if (!_line) {
  155 + _line = [[UIView alloc] init];
  156 + _line.backgroundColor = RGBOF(0xeeeeee);
  157 + }
  158 + return _line;
  159 +}
  160 +
  161 +#pragma mark - Action
  162 +- (void)manageDidClicked:(UIButton *)btn{
  163 + if([self.model.thirdPartyPlat isEqualToString:@"10"]){
  164 + return;
  165 + }
  166 + if(![CNLiveNetworking isNetworking]){
  167 + [QMUITips showError:@"无法连接网络" inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  168 + return ;
  169 + }
  170 + btn.userInteractionEnabled = NO;
  171 + if (self.delegate && [self.delegate respondsToSelector:@selector(clickedBindingButton:isBinding:)]) {
  172 + [self.delegate clickedBindingButton:self isBinding:![self.model.isBinding isEqualToString:@"1"]];
  173 + btn.userInteractionEnabled = YES;
  174 +
  175 + }
  176 +}
  177 +
  178 +
  179 +@end
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageController.h 0 → 100644
  1 +//
  2 +// CNLiveBindingManageController.h
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +// 绑定管理
  9 +#import "CNCommonViewController.h"
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface CNLiveBindingManageController : CNCommonViewController
  14 +
  15 +@end
  16 +
  17 +NS_ASSUME_NONNULL_END
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageController.m 0 → 100644
  1 +//
  2 +// CNLiveBindingManageController.m
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveBindingManageController.h"
  10 +#import <Masonry/Masonry.h>
  11 +#import "QMUIKit.h"
  12 +
  13 +#import "CNLiveBaseKit.h"
  14 +#import "CNLiveNavigationBar.h"
  15 +
  16 +#import "CNLiveBindingManageHeaderView.h"
  17 +#import "CNLiveBindingManageCell.h"
  18 +#import "CNLiveBindingManageModel.h"
  19 +#import "CNLiveBindingManageRequest.h"
  20 +
  21 +@interface CNLiveBindingManageController ()<UITableViewDelegate, UITableViewDataSource,CNLiveBindingManageCellDelegate>
  22 +@property (nonatomic, strong) CNLiveNavigationBar *navigationBar;
  23 +@property (nonatomic, strong) UITableView *tableView;
  24 +@property (nonatomic, strong) NSArray *bindingData;
  25 +@property (nonatomic, strong) NSArray *unBindingData;
  26 +
  27 +@end
  28 +
  29 +@implementation CNLiveBindingManageController
  30 +#pragma mark - CNLiveBindingManageCellDelegate
  31 +- (void)clickedBindingButton:(CNLiveBindingManageCell *)cell isBinding:(BOOL)isBinding{
  32 + if(isBinding){
  33 + //绑定操作
  34 + [self requestBindingManage:cell.model];
  35 +
  36 + }else{
  37 + //解除绑定操作
  38 + UIAlertController *actionAlert1 = [UIAlertController alertControllerWithTitle:@"确定解除绑定?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  39 +
  40 + UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:NULL];
  41 + __weak typeof(self) weakSelf = self;
  42 + UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  43 + __strong typeof(weakSelf) strongSelf = weakSelf;
  44 + if(!strongSelf) return;
  45 + [strongSelf requestBindingManage:cell.model];
  46 +
  47 + }];
  48 + [action1 setValue:RGBOF(0x23D41E) forKey:@"_titleTextColor"];
  49 + [action2 setValue:RGBOF(0x23D41E) forKey:@"_titleTextColor"];
  50 +
  51 + [actionAlert1 addAction:action1];
  52 + [actionAlert1 addAction:action2];
  53 + [self presentViewController:actionAlert1 animated:YES completion:nil];
  54 + }
  55 +
  56 +}
  57 +- (void)requestBindingManage:(CNLiveBindingManageModel *)model{
  58 + switch (model.type) {
  59 + case CNLiveSendAuthRespWX:
  60 + {
  61 + if(![WXApi isWXAppInstalled]){
  62 + [QMUITips showWithText:@"未安装微信" inView:self.view hideAfterDelay:1.5];
  63 + return;
  64 + }
  65 + }
  66 + break;
  67 + case CNLiveSendAuthRespQQ:
  68 + {
  69 + if(![TencentOAuth iphoneQQInstalled]){
  70 + [QMUITips showWithText:@"未安装QQ" inView:self.view hideAfterDelay:1.5];
  71 + return;
  72 + }
  73 + }
  74 + break;
  75 + case CNLiveSendAuthRespWB:
  76 + {
  77 + if(![WeiboSDK isWeiboAppInstalled]){
  78 + [QMUITips showWithText:@"未安装微博" inView:self.view hideAfterDelay:1.5];
  79 + return;
  80 + }
  81 + }
  82 + break;
  83 + case CNLiveSendAuthRespApple:
  84 + {
  85 + }
  86 + break;
  87 + }
  88 + __weak typeof(self) weakSelf = self;
  89 + [CNLiveBindingManageRequest requestModel:model block:^(BOOL isSuccess, CNLiveBindingManageModel * _Nullable model, BOOL isBinding) {
  90 + __strong typeof(weakSelf) strongSelf = weakSelf;
  91 + if(!strongSelf) return;
  92 + if(isSuccess){
  93 + [strongSelf loadData];
  94 + }
  95 +
  96 + }];
  97 +}
  98 +#pragma mark - Data
  99 +- (void)loadData{
  100 + __weak typeof(self) weakSelf = self;
  101 + [CNLiveBindingManageRequest requestModels:^(NSArray * _Nullable bindingData, NSArray * _Nullable unBindingData) {
  102 + __strong typeof(weakSelf) strongSelf = weakSelf;
  103 + if(!strongSelf) return;
  104 + strongSelf.bindingData = bindingData;
  105 + strongSelf.unBindingData = unBindingData;
  106 + [strongSelf.tableView reloadData];
  107 + }];
  108 +
  109 +}
  110 +
  111 +- (void)viewWillAppear:(BOOL)animated{
  112 + [super viewWillAppear:animated];
  113 + self.navigationController.navigationBarHidden = YES;
  114 +}
  115 +
  116 +- (void)viewDidLoad {
  117 + [super viewDidLoad];
  118 + // Do any additional setup after loading the view.
  119 + self.view.backgroundColor = RGBOF(0xf4f4f4);
  120 + if (@available(iOS 11.0, *)) {
  121 + self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  122 + } else {
  123 + self.automaticallyAdjustsScrollViewInsets = NO;
  124 + }
  125 + [self loadData];
  126 + [self createUI];
  127 +
  128 +}
  129 +
  130 +- (void)createUI{
  131 + [self.view addSubview:self.navigationBar];
  132 + [self.view addSubview:self.tableView];
  133 +
  134 +}
  135 +
  136 +- (void)viewDidLayoutSubviews {
  137 + [super viewDidLayoutSubviews];
  138 + [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  139 + make.top.equalTo(self.view.mas_top).with.offset(kVerticalStatusHeight+44);
  140 + make.left.equalTo(self.view.mas_left).with.offset(0);
  141 + make.right.equalTo(self.view.mas_right).with.offset(-0);
  142 + make.bottom.equalTo(self.view.mas_bottom).with.offset(-0);
  143 +
  144 + }];
  145 +
  146 +}
  147 +
  148 +#pragma mark - UITableViewDataSource
  149 +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  150 + return 2;
  151 +
  152 +}
  153 +
  154 +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  155 + if(section == 0){
  156 + return self.bindingData.count;
  157 +
  158 + }else if(section == 1){
  159 + return self.unBindingData.count;
  160 +
  161 + }else{
  162 + return 0;
  163 + }
  164 +
  165 +}
  166 +
  167 +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  168 + return 80;
  169 +
  170 +}
  171 +
  172 +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  173 + CNLiveBindingManageCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveBindingManageCell forIndexPath:indexPath];
  174 + cell.selectionStyle = UITableViewCellSelectionStyleNone;
  175 + cell.delegate = self;
  176 + if(indexPath.section == 0){
  177 + if(self.bindingData.count > 0){
  178 + cell.model = self.bindingData[indexPath.row];
  179 + }
  180 +
  181 + }else if(indexPath.section == 1){
  182 + if(self.unBindingData.count > 0){
  183 + cell.model = self.unBindingData[indexPath.row];
  184 + }
  185 + }
  186 + return cell;
  187 +
  188 +}
  189 +
  190 +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  191 + return 40.0;
  192 +
  193 +}
  194 +- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  195 + return 0.0000001f;
  196 +
  197 +}
  198 +
  199 +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  200 + NSArray *array = @[@"您已绑定网家家手机号账号", @"其他绑定方式"];
  201 + CNLiveBindingManageHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kCNLiveBindingManageHeaderView];
  202 + header.text = array[section];
  203 + return header;
  204 +
  205 +}
  206 +
  207 +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  208 +
  209 +
  210 +}
  211 +
  212 +/*
  213 + #pragma mark - Navigation
  214 +
  215 + // In a storyboard-based application, you will often want to do a little preparation before navigation
  216 + - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  217 + // Get the new view controller using [segue destinationViewController].
  218 + // Pass the selected object to the new view controller.
  219 + }
  220 + */
  221 +#pragma mark - 响应方法
  222 +- (void)goBack {
  223 + if (self.presentingViewController != nil) {
  224 + [self dismissViewControllerAnimated:YES completion:nil];
  225 + }
  226 + else {
  227 + [self.navigationController popViewControllerAnimated:YES];
  228 + }
  229 +}
  230 +
  231 +#pragma mark - Lazy loading
  232 +- (CNLiveNavigationBar *)navigationBar {
  233 + if (!_navigationBar) {
  234 + _navigationBar = [CNLiveNavigationBar navigationBar];
  235 + _navigationBar.title.text = @"绑定管理";
  236 + __weak typeof(self) weakSelf = self;
  237 + _navigationBar.onClickLeftButton = ^{
  238 + [weakSelf goBack];
  239 + };
  240 + }
  241 + return _navigationBar;
  242 +}
  243 +
  244 +- (UITableView *)tableView {
  245 + if (!_tableView) {
  246 + _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  247 + _tableView.backgroundColor = RGBOF(0xf4f4f4);
  248 + _tableView.delegate = self;
  249 + _tableView.dataSource = self;
  250 + _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  251 + _tableView.showsVerticalScrollIndicator = NO;
  252 + _tableView.showsHorizontalScrollIndicator = NO;
  253 + _tableView.estimatedRowHeight = 0;
  254 + _tableView.estimatedSectionFooterHeight = 0;
  255 + _tableView.estimatedSectionHeaderHeight = 0;
  256 + [_tableView registerClass:[CNLiveBindingManageCell class] forCellReuseIdentifier:kCNLiveBindingManageCell];
  257 + [_tableView registerClass:[CNLiveBindingManageHeaderView class] forHeaderFooterViewReuseIdentifier:kCNLiveBindingManageHeaderView];
  258 +
  259 + }
  260 + return _tableView;
  261 +}
  262 +
  263 +@end
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageHeaderView.h 0 → 100644
  1 +//
  2 +// CNLiveBindingManageHeaderView.h
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +#define kCNLiveBindingManageHeaderView @"CNLiveBindingManageHeaderView"
  13 +
  14 +@interface CNLiveBindingManageHeaderView : UITableViewHeaderFooterView
  15 +@property (nonatomic, copy) NSString *text;
  16 +
  17 +@end
  18 +
  19 +NS_ASSUME_NONNULL_END
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageHeaderView.m 0 → 100644
  1 +//
  2 +// CNLiveBindingManageHeaderView.m
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveBindingManageHeaderView.h"
  10 +#import <Masonry/Masonry.h>
  11 +
  12 +@interface CNLiveBindingManageHeaderView()
  13 +@property (nonatomic, strong) UILabel *title;
  14 +
  15 +@end
  16 +@implementation CNLiveBindingManageHeaderView
  17 +static NSInteger const margin = 15;
  18 +
  19 +- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
  20 + if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
  21 + //在这里向contentView添加控件
  22 + self.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1.0];
  23 + [self createSubviews];
  24 + [self xw_layoutSubviews];
  25 +
  26 + }
  27 + return self;
  28 +}
  29 +- (void)setText:(NSString *)text{
  30 + _text = text;
  31 + _title.text = text;
  32 +}
  33 +
  34 +#pragma mark - setupUI
  35 +- (void)createSubviews {
  36 + [self.contentView addSubview:self.title];
  37 +
  38 +}
  39 +
  40 +- (void)xw_layoutSubviews {
  41 + [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  42 + make.top.equalTo(self.contentView);
  43 + make.left.equalTo(self.contentView.mas_left).offset(margin);
  44 + make.right.equalTo(self.contentView.mas_right).offset(-margin);
  45 + make.bottom.equalTo(self.contentView.mas_bottom);
  46 +
  47 + }];
  48 +
  49 +}
  50 +
  51 +/*
  52 +// Only override drawRect: if you perform custom drawing.
  53 +// An empty implementation adversely affects performance during animation.
  54 +- (void)drawRect:(CGRect)rect {
  55 + // Drawing code
  56 +}
  57 +*/
  58 +
  59 +#pragma mark - Lazy Loading
  60 +- (UILabel *)title {
  61 + if (!_title) {
  62 + _title = [[UILabel alloc] init];
  63 + _title.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
  64 + _title.font = [UIFont systemFontOfSize:14];
  65 + _title.numberOfLines = 0;
  66 + }
  67 + return _title;
  68 +}
  69 +
  70 +@end
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageModel.h 0 → 100644
  1 +//
  2 +// CNLiveBindingManageModel.h
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "CNLiveShareImageManager.h"
  11 +
  12 +NS_ASSUME_NONNULL_BEGIN
  13 +
  14 +@interface CNLiveBindingManageModel : NSObject
  15 +@property (nonatomic, copy) NSString *title;
  16 +@property (nonatomic, copy) NSString *desc;
  17 +@property (nonatomic, copy) NSString *image;
  18 +@property (nonatomic, copy) NSString *isBinding;//是否绑定
  19 +
  20 +@property (nonatomic, copy) NSString *thirdPartyPlat;
  21 +@property (nonatomic, copy) NSString *thirdPartyId;
  22 +@property (nonatomic, assign) CNLiveSendAuthResp type;
  23 +
  24 +
  25 +@end
  26 +
  27 +NS_ASSUME_NONNULL_END
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageModel.m 0 → 100644
  1 +//
  2 +// CNLiveBindingManageModel.m
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveBindingManageModel.h"
  10 +
  11 +@implementation CNLiveBindingManageModel
  12 +- (CNLiveSendAuthResp)type{
  13 + CNLiveSendAuthResp type = CNLiveSendAuthRespWX;
  14 +
  15 + if([self.thirdPartyPlat isEqualToString:@"1"]){
  16 + type = CNLiveSendAuthRespWB;
  17 +
  18 + }else if ([self.thirdPartyPlat isEqualToString:@"2"]){
  19 + type = CNLiveSendAuthRespQQ;
  20 +
  21 + }else if([self.thirdPartyPlat isEqualToString:@"3"]){
  22 + type = CNLiveSendAuthRespWX;
  23 +
  24 + }else if([self.thirdPartyPlat isEqualToString:@"5"]){
  25 + type = CNLiveSendAuthRespApple;
  26 +
  27 + }
  28 + return type;
  29 +
  30 +}
  31 +
  32 +@end
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageRequest.h 0 → 100644
  1 +//
  2 +// CNLiveBindingManageRequest.h
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +@class CNLiveBindingManageModel;
  13 +
  14 +typedef void (^CNLiveBindingResponseBlock)(BOOL isSuccess, CNLiveBindingManageModel * _Nullable model, BOOL isBinding);
  15 +typedef void (^CNLiveBindingArrayBlock)(NSArray * _Nullable bindingData, NSArray * _Nullable unBindingData);
  16 +
  17 +@interface CNLiveBindingManageRequest : NSObject
  18 +/**
  19 + * @abstract 绑定/解除绑定
  20 + *
  21 + * @param model 模型
  22 + * @param block 回调
  23 + */
  24 ++ (void)requestModel:(CNLiveBindingManageModel *)model block:(CNLiveBindingResponseBlock)block;
  25 +
  26 +/**
  27 + * @abstract 获取绑定数据
  28 + *
  29 + * @param block 回调
  30 + */
  31 ++ (void)requestModels:(CNLiveBindingArrayBlock)block;
  32 +
  33 +@end
  34 +
  35 +NS_ASSUME_NONNULL_END
... ...
CNLiveBMineModule/Classes/Setting/BindingManage/CNLiveBindingManageRequest.m 0 → 100644
  1 +//
  2 +// CNLiveBindingManageRequest.m
  3 +// CNLiveBMineModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/9/10.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveBindingManageRequest.h"
  10 +#import "QMUIKit.h"
  11 +#import <CNLiveRequestBastKit/CNLiveNetworking.h>
  12 +#import "CNUserInfoManager.h"
  13 +#import "CNLiveEnvironment.h"
  14 +
  15 +#import "CNLiveBindingManageModel.h"
  16 +
  17 +#import "CNLiveShareImageManager.h"
  18 +
  19 +@implementation CNLiveBindingManageRequest
  20 ++ (void)requestModel:(CNLiveBindingManageModel *)model block:(CNLiveBindingResponseBlock)block{
  21 + if([model.isBinding isEqualToString:@"1"]){
  22 + //解除绑定操作
  23 + [CNLiveBindingManageRequest requestUnBindingModel:model block:^(BOOL isSuccess, CNLiveBindingManageModel * _Nullable model, BOOL isBinding) {
  24 + block?block(isSuccess, model, isBinding):@"";
  25 + }];
  26 + }
  27 + else{
  28 + //绑定操作
  29 + [CNLiveBindingManageRequest requestBindingModel:model block:^(BOOL isSuccess, CNLiveBindingManageModel * _Nullable model, BOOL isBinding) {
  30 + block?block(isSuccess, model, isBinding):@"";
  31 + }];
  32 + }
  33 +}
  34 +
  35 +// 绑定操作
  36 ++ (void)requestBindingModel:(CNLiveBindingManageModel *)model block:(CNLiveBindingResponseBlock)block{
  37 + __weak typeof(self) weakSelf = self;
  38 + // 获取第三方id
  39 + [CNLiveShareImageManager send:model.type authRespBlock:^(CNLiveSendAuthResp type, CNLiveThirdPartyModel *userInfo, NSError *error) {
  40 + __strong typeof(weakSelf) strongSelf = weakSelf;
  41 + if(!strongSelf) return;
  42 + if(error){
  43 + if(error.code == 10000){
  44 + //用户取消
  45 + }else{
  46 + [QMUITips showWithText:@"绑定失败" inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  47 + }
  48 + return ;
  49 + }
  50 + if(userInfo.thirdPartyId&&![userInfo.thirdPartyId isEqualToString:@""]){
  51 + // 发起绑定请求
  52 + model.thirdPartyId = userInfo.thirdPartyId;
  53 + [strongSelf sendBindingModel:model block:block];
  54 +
  55 + }else{
  56 + [QMUITips showWithText:@"绑定失败" inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  57 +
  58 + }
  59 +
  60 + }];
  61 +
  62 +}
  63 +
  64 ++ (void)sendBindingModel:(CNLiveBindingManageModel *)model block:(CNLiveBindingResponseBlock)block{
  65 + NSDictionary *params = @{
  66 + @"uid":CNUserShareModel.uid?CNUserShareModel.uid:@"",
  67 + @"thirdPartyPlat":model.thirdPartyPlat?model.thirdPartyPlat:@"",
  68 + @"thirdPartyId":model.thirdPartyId?model.thirdPartyId:@"",
  69 + @"token":CNUserShareModel.token?CNUserShareModel.token:@"",
  70 + @"clientPlat":@"i"};
  71 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  72 + [CNLiveNetworking setupShowDataResult:NO];
  73 +
  74 + __weak typeof(self) weakSelf = self;
  75 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNLoginBind3rdUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  76 + __strong typeof(weakSelf) strongSelf = weakSelf;
  77 + if(!strongSelf) return;
  78 +
  79 + if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
  80 + //绑定,并更新本地数据
  81 + CNLiveBindingManageModel *bindingModel = [strongSelf updateBindingModel:model isBinding:@"1"];
  82 + block?block(YES, bindingModel, YES):@"";
  83 + }
  84 + else if([responseObject isKindOfClass:[NSDictionary class]]) {
  85 + [QMUITips showWithText:responseObject[@"errorMessage"] inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  86 + block?block(NO, nil, NO):@"";
  87 + }
  88 + else{
  89 + [QMUITips showWithText:@"绑定失败" inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  90 + block?block(NO, nil, NO):@"";
  91 + }
  92 +
  93 + }];
  94 +}
  95 +
  96 +// 解除绑定操作
  97 ++ (void)requestUnBindingModel:(CNLiveBindingManageModel *)model block:(CNLiveBindingResponseBlock)block{
  98 + NSDictionary *params = @{
  99 + @"uid":CNUserShareModel.uid?CNUserShareModel.uid:@"",
  100 + @"thirdPartyPlat":model.thirdPartyPlat?model.thirdPartyPlat:@"",
  101 + @"thirdPartyId":model.thirdPartyId?model.thirdPartyId:@"",
  102 + @"token":CNUserShareModel.token?CNUserShareModel.token:@"",
  103 + @"clientPlat":@"i"};
  104 +
  105 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  106 + [CNLiveNetworking setupShowDataResult:NO];
  107 +
  108 + __weak typeof(self) weakSelf = self;
  109 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNLoginUnBind3rdUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  110 + __strong typeof(weakSelf) strongSelf = weakSelf;
  111 + if(!strongSelf) return;
  112 +
  113 + if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
  114 + //解除绑定,并更新本地数据
  115 + CNLiveBindingManageModel *unbindingModel = [strongSelf updateBindingModel:model isBinding:@"0"];
  116 + block?block(YES, unbindingModel, NO):@"";
  117 + }
  118 + else if ([responseObject isKindOfClass:[NSDictionary class]]) {
  119 + [QMUITips showWithText:responseObject[@"errorMessage"] inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  120 + block?block(NO, nil, NO):@"";
  121 + }
  122 + else{
  123 + [QMUITips showWithText:@"解除绑定失败" inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  124 + block?block(NO, nil, NO):@"";
  125 + }
  126 +
  127 + }];
  128 +
  129 +}
  130 +
  131 +//改变绑定数据
  132 ++ (CNLiveBindingManageModel *)updateBindingModel:(CNLiveBindingManageModel *)model isBinding:(NSString *)isBinding{
  133 + if([isBinding isEqualToString:@"0"]){
  134 + //解除绑定
  135 + model.isBinding = @"0";
  136 + //微博
  137 + if([model.thirdPartyPlat isEqualToString:@"1"]){
  138 + CNUserShareModel.sinaUid = @"";
  139 +
  140 + }
  141 + //qq
  142 + else if([model.thirdPartyPlat isEqualToString:@"2"]){
  143 + CNUserShareModel.qqUid = @"";
  144 +
  145 + }
  146 + //微信
  147 + else if([model.thirdPartyPlat isEqualToString:@"3"]){
  148 + CNUserShareModel.wxUid = @"";
  149 +
  150 + }
  151 + //苹果
  152 + else if([model.thirdPartyPlat isEqualToString:@"5"]){
  153 + CNUserShareModel.appleUid = @"";
  154 +
  155 + }
  156 + [QMUITips showWithText:@"解除绑定成功" inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  157 + return model;
  158 + }
  159 + else if ([isBinding isEqualToString:@"1"]){
  160 + //添加绑定
  161 + model.isBinding = @"1";
  162 + //微博
  163 + if([model.thirdPartyPlat isEqualToString:@"1"]){
  164 + CNUserShareModel.sinaUid = model.thirdPartyId;
  165 +
  166 + }
  167 + //qq
  168 + else if([model.thirdPartyPlat isEqualToString:@"2"]){
  169 + CNUserShareModel.qqUid = model.thirdPartyId;
  170 +
  171 + }
  172 + //微信
  173 + else if([model.thirdPartyPlat isEqualToString:@"3"]){
  174 + CNUserShareModel.wxUid = model.thirdPartyId;
  175 +
  176 + }
  177 + //苹果
  178 + else if([model.thirdPartyPlat isEqualToString:@"5"]){
  179 + CNUserShareModel.appleUid = model.thirdPartyId;
  180 +
  181 + }
  182 + [QMUITips showWithText:@"绑定成功" inView:([UIApplication sharedApplication].delegate).window hideAfterDelay:1.5];
  183 + return model;
  184 +
  185 + }
  186 + return nil;
  187 +
  188 +}
  189 +
  190 +//请求绑定数据
  191 ++ (void)requestModels:(CNLiveBindingArrayBlock)block{
  192 + NSMutableArray *bindingData = [[NSMutableArray alloc] init];
  193 + NSMutableArray *unBindingData = [[NSMutableArray alloc] init];
  194 + CNLiveBindingManageModel *tmodel = [[CNLiveBindingManageModel alloc]init];
  195 + tmodel.title = @"手机号";
  196 + tmodel.image = @"mine_telephone";
  197 + NSString *mobile = [CNUserShareModel.mobile stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
  198 + tmodel.desc = mobile;
  199 + tmodel.isBinding = @"1";
  200 + tmodel.thirdPartyPlat = @"10";
  201 + tmodel.thirdPartyId = CNUserShareModel.uid;
  202 + [bindingData addObject:tmodel];
  203 +
  204 + CNLiveBindingManageModel *wmodel = [[CNLiveBindingManageModel alloc]init];
  205 + wmodel.title = @"微信";
  206 + wmodel.image = @"mine_wechat";
  207 + wmodel.thirdPartyPlat = @"3";
  208 +
  209 + if(CNUserShareModel.wxUid&&![CNUserShareModel.wxUid isEqualToString:@""]){
  210 + wmodel.desc = @"已绑定微信";
  211 + wmodel.thirdPartyId = CNUserShareModel.wxUid;
  212 + wmodel.isBinding = @"1";
  213 + }else{
  214 + wmodel.desc = @"未绑定微信";
  215 + wmodel.isBinding = @"0";
  216 + }
  217 + [unBindingData addObject:wmodel];
  218 +
  219 + CNLiveBindingManageModel *qmodel = [[CNLiveBindingManageModel alloc]init];
  220 + qmodel.title = @"QQ";
  221 + qmodel.image = @"mine_qq";
  222 + qmodel.thirdPartyPlat = @"2";
  223 + if(CNUserShareModel.qqUid&&![CNUserShareModel.qqUid isEqualToString:@""]){
  224 + qmodel.desc = @"已绑定QQ";
  225 + qmodel.thirdPartyId = CNUserShareModel.qqUid;
  226 + qmodel.isBinding = @"1";
  227 + }else{
  228 + qmodel.desc = @"未绑定QQ";
  229 + qmodel.isBinding = @"0";
  230 + }
  231 + [unBindingData addObject:qmodel];
  232 +
  233 + CNLiveBindingManageModel *smodel = [[CNLiveBindingManageModel alloc]init];
  234 + smodel.title = @"微博";
  235 + smodel.image = @"mine_weibo";
  236 + smodel.thirdPartyPlat = @"1";
  237 + if(CNUserShareModel.sinaUid&&![CNUserShareModel.sinaUid isEqualToString:@""]){
  238 + smodel.desc = @"已绑定微博";
  239 + smodel.thirdPartyId = CNUserShareModel.sinaUid;
  240 + smodel.isBinding = @"1";
  241 + }else{
  242 + smodel.desc = @"未绑定微博";
  243 + smodel.isBinding = @"0";
  244 + }
  245 + [unBindingData addObject:smodel];
  246 +
  247 + CNLiveBindingManageModel *amodel = [[CNLiveBindingManageModel alloc]init];
  248 + amodel.title = @"苹果账号";
  249 + amodel.image = @"mine_apple";
  250 + amodel.thirdPartyPlat = @"5";
  251 + if(CNUserShareModel.appleUid&&![CNUserShareModel.appleUid isEqualToString:@""]){
  252 + amodel.desc = @"已绑定苹果账号";
  253 + amodel.thirdPartyId = CNUserShareModel.appleUid;
  254 + amodel.isBinding = @"1";
  255 + }else{
  256 + amodel.desc = @"未绑定苹果账号";
  257 + amodel.isBinding = @"0";
  258 + }
  259 + [unBindingData addObject:amodel];
  260 +
  261 + block?block(bindingData,unBindingData):@"";
  262 +}
  263 +
  264 +@end
... ...