SettingViewController.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // SettingViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/21.
  6. //
  7. #import "SettingViewController.h"
  8. #import "SettingBodyView.h"
  9. #import "KSBaseWKWebViewController.h"
  10. #import "FeedbackViewController.h"
  11. #import "AboutUsViewController.h"
  12. #import "UserInfoManager.h"
  13. #import "AddressListViewController.h"
  14. #import "UserAuthViewController.h"
  15. #import "LoginViewController.h"
  16. #import "AppDelegate.h"
  17. #import "CustomNavViewController.h"
  18. #import "JPUSHService.h"
  19. #import "AccountDeleteViewController.h"
  20. #import "UnbindTenantViewController.h"
  21. #import "TenantUnbindDetailViewController.h"
  22. #import "CoursewareDownloadManager.h"
  23. @interface SettingViewController ()
  24. @property (nonatomic, strong) SettingBodyView *bodyView;
  25. @property (nonatomic, strong) NSString *userSex;
  26. @end
  27. @implementation SettingViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view.
  31. [self allocTitle:@"设置"];
  32. [self configUI];
  33. }
  34. - (void)viewWillAppear:(BOOL)animated {
  35. [super viewWillAppear:animated];
  36. [self requestUserMemo];
  37. }
  38. - (void)requestUserMemo {
  39. [[UserInfoManager shareInstance] requsetconfigCallback:^(BOOL success) {
  40. [self refreshBodyView:success];
  41. }];
  42. }
  43. - (void)refreshBodyView:(BOOL)isMember {
  44. self.bodyView.isMember = isMember;
  45. }
  46. - (void)configUI {
  47. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  48. make.left.right.mas_equalTo(self.view);
  49. make.top.mas_equalTo(self.view.mas_top);
  50. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  51. }];
  52. self.bodyView = [SettingBodyView shareInstance];
  53. CGFloat viewHeight = KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin;
  54. [self.scrollView addSubview:self.bodyView];
  55. [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.mas_equalTo(self.scrollView.mas_top);
  57. make.right.left.mas_equalTo(self.view);
  58. make.height.mas_equalTo(viewHeight);
  59. }];
  60. [self.scrollView setContentSize:CGSizeMake(kScreenWidth, viewHeight)];
  61. KSWeakSelf(weakSelf);
  62. [self.bodyView settingAction:^(SETTINGACTION type) {
  63. [weakSelf operationAction:type];
  64. }];
  65. }
  66. - (void)operationAction:(SETTINGACTION)type {
  67. switch (type) {
  68. case SETTINGACTION_ADDRESS:
  69. {
  70. AddressListViewController *ctrl = [[AddressListViewController alloc] init];
  71. [self.navigationController pushViewController:ctrl animated:YES];
  72. }
  73. break;
  74. case SETTINGACTION_ONLINECHECK:
  75. {
  76. }
  77. break;
  78. case SETTINGACTION_PRIVACY:
  79. {
  80. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  81. webCtrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/privacyProtocol"];
  82. [self.navigationController pushViewController:webCtrl animated:YES];
  83. }
  84. break;
  85. case SETTINGACTION_FEEEDBACK:
  86. {
  87. FeedbackViewController *ctrl = [[FeedbackViewController alloc] init];
  88. [self.navigationController pushViewController:ctrl animated:YES];
  89. }
  90. break;
  91. case SETTINGACTION_ABOUTUS:
  92. {
  93. AboutUsViewController *aboutUs = [[AboutUsViewController alloc] init];
  94. [self.navigationController pushViewController:aboutUs animated:YES];
  95. }
  96. break;
  97. case SETTINGACTION_LOGOUT:
  98. {
  99. [self logoutAction];
  100. }
  101. break;
  102. case SETTINGACTION_DELETEACCOUNT:
  103. {
  104. [self toDelteAccountView];
  105. }
  106. break;
  107. case SETTINGACTION_MUSICCHECK:
  108. {
  109. // /#/review-list
  110. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  111. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/review-list"];
  112. [self.navigationController pushViewController:ctrl animated:YES];
  113. }
  114. break;
  115. case SETTINGACTION_UNBIND:
  116. {
  117. [self checkUnbindStatus];
  118. }
  119. break;
  120. case SETTINGACTION_CLEARCACHE:
  121. {
  122. [self clearCache];
  123. }
  124. break;
  125. default:
  126. break;
  127. }
  128. }
  129. //
  130. - (void)clearCache {
  131. if (COURSEWARE_MANAGER.isDownloading) { // 如果在下载 取消
  132. [COURSEWARE_MANAGER cancleDownloadCourseware];
  133. }
  134. NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  135. NSString *bundlePath = [documentsPath stringByAppendingPathComponent:@"CoursewarePath"];
  136. NSFileManager *fileManager = [NSFileManager defaultManager];
  137. BOOL isExist = [fileManager fileExistsAtPath:bundlePath];
  138. if (isExist) {
  139. BOOL isSuccess = [fileManager removeItemAtPath:bundlePath error:nil];
  140. if (isSuccess) {
  141. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"清理完成"];
  142. }
  143. }
  144. else {
  145. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"清理完成"];
  146. }
  147. }
  148. /**
  149. */
  150. - (void)checkUnbindStatus {
  151. [LOADING_MANAGER showHUD];
  152. [KSNetworkingManager unbindTenantDetailRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  153. [LOADING_MANAGER removeHUD];
  154. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  155. NSDictionary *parm = [dic ks_dictionaryValueForKey:@"data"];
  156. if (parm) {
  157. NSString *reson = [parm ks_stringValueForKey:@"unbindReason"];
  158. [self showUnbindDetail:reson tenantName:[parm ks_stringValueForKey:@"tenantName"]];
  159. }
  160. else {
  161. [self toUnbindTenantView];
  162. }
  163. }
  164. else {
  165. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  166. }
  167. } faliure:^(NSError * _Nonnull error) {
  168. [LOADING_MANAGER removeHUD];
  169. }];
  170. }
  171. - (void)toUnbindTenantView {
  172. UnbindTenantViewController *ctrl = [[UnbindTenantViewController alloc] init];
  173. [self.navigationController pushViewController:ctrl animated:YES];
  174. }
  175. - (void)showUnbindDetail:(NSString *)reson tenantName:(NSString *)tenantName {
  176. TenantUnbindDetailViewController *ctrl = [[TenantUnbindDetailViewController alloc] init];
  177. [ctrl configTenantName:tenantName desc:reson];
  178. [self.navigationController pushViewController:ctrl animated:YES];
  179. }
  180. - (void)toDelteAccountView {
  181. AccountDeleteViewController *detailView = [[AccountDeleteViewController alloc] init];
  182. [self.navigationController pushViewController:detailView animated:YES];
  183. }
  184. - (void)logoutAction {
  185. [KSNetworkingManager logoutRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  186. [self clearSource];
  187. } faliure:^(NSError * _Nonnull error) {
  188. [self clearSource];
  189. }];
  190. }
  191. - (void)clearSource {
  192. [APPLOGIN_MANAGER logoutAction];
  193. }
  194. /*
  195. #pragma mark - Navigation
  196. // In a storyboard-based application, you will often want to do a little preparation before navigation
  197. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  198. // Get the new view controller using [segue destinationViewController].
  199. // Pass the selected object to the new view controller.
  200. }
  201. */
  202. @end