123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- //
- // SettingViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/21.
- //
- #import "SettingViewController.h"
- #import "SettingBodyView.h"
- #import "RCConnectionManager.h"
- #import "LoginViewController.h"
- #import "AppDelegate.h"
- #import "CustomNavViewController.h"
- #import "JPUSHService.h"
- #import "KSBaseWKWebViewController.h"
- #import "ModifyNameViewController.h"
- #import "ModifyViewController.h"
- #import "ModifyPhoneCheckController.h"
- #import "KSChoosePicker.h"
- #import "KSMediaManager.h"
- #import "FeedbackViewController.h"
- #import "AboutUsViewController.h"
- #import "UserInfoManager.h"
- #import "AddressListViewController.h"
- #import "KSFullDatePicker.h"
- @interface SettingViewController ()
- @property (nonatomic, strong) SettingBodyView *bodyView;
- @property (nonatomic, strong) NSString *userSex;
- @property (nonatomic, strong) KSMediaManager *mediaManager;
- @property (nonatomic, strong) UserInfo *mineInfo;
- @property (nonatomic, strong) NSString *birthday;
- @end
- @implementation SettingViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"设置"];
- [self configUI];
- [self requestUserMessage];
- }
- - (void)requestUserMessage {
-
- [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
- self.mineInfo = userInfo;
- [self configMessage];
- }];
- }
- - (void)configMessage {
- if (![NSString isEmptyString:self.mineInfo.avatar]) {
- [self.bodyView.userAvatal sd_setImageWithURL:[NSURL URLWithString:[self.mineInfo.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- }
- else {
- [self.bodyView.userAvatal setImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- }
- self.bodyView.nickNameLabel.text = [NSString returnNoNullStringWithString:self.mineInfo.username];
- NSString *userSex = @"";
- if ([self.mineInfo.gender isEqualToString:@"1"]) {
- userSex = @"男";
- self.userSex = @"1";
- }
- else {
- userSex = @"女";
- self.userSex = @"0";
- }
- self.bodyView.genderLabel.text = userSex;
- self.bodyView.phoneLabel.text = [NSString returnNoNullStringWithString:self.mineInfo.phone];
- NSString *authStatus = @"";
- if (USER_MANAGER.hasAuth) {
- authStatus = @"已认证";
- }
- else {
- authStatus = @"未认证";
- }
- self.bodyView.authStatusLabel.text = authStatus;
- if ([NSString isEmptyString:self.mineInfo.birthdate]) {
- self.bodyView.birthdayLabel.text = @"未设置";
- }
- else {
- self.bodyView.birthdayLabel.text = [[self.mineInfo.birthdate componentsSeparatedByString:@" "] firstObject];
- }
-
- }
- - (void)configUI {
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.view.mas_top);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- }];
- self.bodyView = [SettingBodyView shareInstance];
- CGFloat height = [self.bodyView getViewHeight];
- CGFloat viewHeight = height > KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin ? height : KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin;
- [self.scrollView addSubview:self.bodyView];
- [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.right.left.mas_equalTo(self.view);
- make.height.mas_equalTo(viewHeight);
- }];
- [self.scrollView setContentSize:CGSizeMake(kScreenWidth, viewHeight)];
- KSWeakSelf(weakSelf);
- [self.bodyView settingAction:^(SETTINGACTION type) {
- [weakSelf operationAction:type];
- }];
- }
- - (void)operationAction:(SETTINGACTION)type {
- switch (type) {
- case SETTINGACTION_AVATAL: // 头像
- {
- [self chooseImage];
- }
- break;
- case SETTINGACTION_NAME:
- {
- ModifyNameViewController *nameCtrl = [[ModifyNameViewController alloc] init];
- nameCtrl.preNickName = self.mineInfo.username;
- MJWeakSelf;
- [nameCtrl successCallback:^{
- [weakSelf requestUserMessage];
- }];
- [self.navigationController pushViewController:nameCtrl animated:YES];
- }
- break;
- case SETTINGACTION_SEX:
- {
- [self showModifySexAlert];
- }
- break;
- case SETTINGACTION_PHONE:
- {
- ModifyPhoneCheckController *checkCtrl = [[ModifyPhoneCheckController alloc] init];
- [self.navigationController pushViewController:checkCtrl animated:YES];
- }
- break;
- case SETTINGACTION_PWD:
- {
- ModifyViewController *modifyVC = [[ModifyViewController alloc] init];
- [self.navigationController pushViewController:modifyVC animated:YES];
- }
- break;
- case SETTINGACTION_VEFI: // 实名认证
- {
-
- }
- break;
- case SETTINGACTION_ADDRESS:
- {
- AddressListViewController *ctrl = [[AddressListViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case SETTINGACTION_ONLINECHECK:
- {
-
- }
- break;
- case SETTINGACTION_PRIVACY:
- {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/privacyProtocol"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- break;
- case SETTINGACTION_FEEEDBACK:
- {
- FeedbackViewController *ctrl = [[FeedbackViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case SETTINGACTION_ABOUTUS:
- {
- AboutUsViewController *aboutUs = [[AboutUsViewController alloc] init];
- [self.navigationController pushViewController:aboutUs animated:YES];
- }
- break;
- case SETTINGACTION_LOGOUT: // 退出登录
- {
- [self logoutAction];
- }
- break;
- case SETTINGACTION_BIRTHDAY:
- {
- [self chooseBirthDay];
- }
- break;
- default:
- break;
- }
- }
- - (void)chooseBirthDay {
- MJWeakSelf;
- KSFullDatePicker *datePicker = [[KSFullDatePicker alloc] initWithTitle:@"" date:[NSDate date] pickMode:KSDATEPICKER_MODE_DAY selectDateBlock:^(NSString *date) {
- [weakSelf.bodyView.birthdayLabel setText:date];
- weakSelf.birthday = date;
- [weakSelf modifyUserMessage:nil gender:self.userSex birthday:date];
- } cancleBlock:^{
-
- }];
- [datePicker show];
- }
- - (void)chooseImage {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = 1;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- UIImage *sendImg = [imageArray lastObject];
- [weakSelf updateWithUserLogo:sendImg];
- }];
- [self.mediaManager pushImagePickerController];
- }
- - (void)updateWithUserLogo:(UIImage *)image {
- NSData *imgData = [UIImage turnsImaegDataByImage:image];
- [KSNetworkingManager multiImageUpload:KS_POST imgDataArray:@[imgData] success:^(NSArray * _Nonnull dics) {
- NSDictionary *dic = [dics lastObject];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSDictionary *result = [dic dictionaryValueForKey:@"data"];
- NSString *avatar = [result stringValueForKey:@"url"];
- [self modifyUserMessage:avatar gender:nil birthday:nil];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- }];
- }
- - (void)modifyUserMessage:(NSString *)imgUrl gender:(NSString *)gender birthday:(NSString *)birthday {
- NSString *userName = nil;
- [self showhud];
- [KSNetworkingManager modifyUserMessage:KS_POST avatal:imgUrl gender:gender username:userName birthdate:birthday success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- [self MBPShow:@"修改成功"];
- [self requestUserMessage];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- - (void)showModifySexAlert {
- NSString *titleString = @"选择性别";
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:titleString preferredStyle:IS_IPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
- NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:titleString];
- [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0f] range:NSMakeRange(0, titleString.length)];
- [titleAtt addAttribute:NSForegroundColorAttributeName value:HexRGB(0x999999) range:NSMakeRange(0, titleString.length)];
- [alertVC setValue:titleAtt forKey:@"attributedMessage"];
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- self.bodyView.genderLabel.text = @"男";
- self.userSex = @"1";
- [self modifyUserSex];
- }];
- [actionOne setValue:THEMECOLOR forKey:@"_titleTextColor"];
- [alertVC addAction:actionOne];
- UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- self.bodyView.genderLabel.text = @"女";
- self.userSex = @"0";
- [self modifyUserSex];
- }];
- [actionTwo setValue:THEMECOLOR forKey:@"_titleTextColor"];
- [alertVC addAction:actionTwo];
-
- UIAlertAction *cancleAlert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alertVC addAction:cancleAlert];
- [cancleAlert setValue:HexRGB(0x444444) forKey:@"_titleTextColor"];
- alertVC.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:alertVC animated:true completion:nil];
- }
- - (void)modifyUserSex {
- // 更新性别
- [self modifyUserMessage:nil gender:self.userSex birthday:nil];
- }
- - (void)logoutAction {
- [KSNetworkingManager logoutRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- [self clearSource];
- } faliure:^(NSError * _Nonnull error) {
- [self clearSource];
- }];
- }
- - (void)clearSource {
- [RCConnectionManager shareManager].isNeedJoin = NO;
- [RCConnectionManager shareManager].isNeedShowMessage = NO;
- [[RCIM sharedRCIM] logout];
- [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
- // 取消推送别名
- [JPUSHService deleteAlias:nil seq:0];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:TokenKey];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:Token_type];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:RefreshToken];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:RongTokenKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
- [KSNetworkingManager clearRequestHeader];
- LoginViewController *loginVC = [[LoginViewController alloc] init];
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:loginVC];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- appDelegate.window.rootViewController = navCtrl;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|