MineViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. //
  2. // MineViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "MineViewController.h"
  8. #import "MineNavView.h"
  9. #import "MineBodyView.h"
  10. #import "SettingViewController.h"
  11. #import "KSBaseWKWebViewController.h"
  12. #import "NetworkingCheckController.h"
  13. #import "DeviceCheckView.h"
  14. #import "KSEnterLiveroomManager.h"
  15. #import "UserInfoManager.h"
  16. #import "StudentInfoModel.h"
  17. #import "MyCourseViewController.h"
  18. #import "HomeworkListViewController.h"
  19. #import "UserSettingViewController.h"
  20. #import "KSScanViewController.h"
  21. #import "KSPremissionAlert.h"
  22. #import "RecordCheckManager.h"
  23. #import "FeedbackViewController.h"
  24. #import "UserInfoManager.h"
  25. @interface MineViewController ()<UIScrollViewDelegate>
  26. @property (nonatomic, strong) MineNavView *navView;
  27. @property (nonatomic, strong) MineBodyView *bodyView;
  28. @property (nonatomic, strong) DeviceCheckView *checkView;
  29. @property (nonatomic, strong) StudentInfoModel *mineInfo;
  30. @end
  31. @implementation MineViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. self.ks_prefersNavigationBarHidden = YES;
  36. [self configUI];
  37. }
  38. - (void)configUI {
  39. UIImage *bgImage = [UIImage imageNamed:@"mine_navBg"];
  40. CGFloat height = bgImage.size.height / bgImage.size.width * kScreenWidth;
  41. UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
  42. imageView.frame = CGRectMake(0, 0, kScreenWidth, height);
  43. [self.view addSubview:imageView];
  44. self.scrollView.backgroundColor = [UIColor clearColor];
  45. self.scrollView.delegate = self;
  46. [self.view addSubview:self.navView];
  47. [self.view bringSubviewToFront:self.scrollView];
  48. [self.view bringSubviewToFront:self.navView];
  49. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.width.mas_equalTo(KPortraitWidth);
  51. make.right.top.mas_equalTo(self.view);
  52. make.height.mas_equalTo(kNaviBarHeight);
  53. }];
  54. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  55. make.top.mas_equalTo(self.view.mas_top);
  56. make.left.right.mas_equalTo(self.view);
  57. make.bottom.mas_equalTo(self.view.mas_bottom);
  58. }];
  59. UIView *headView = [[UIView alloc] init];
  60. headView.backgroundColor = [UIColor clearColor];
  61. [self.scrollView addSubview:headView];
  62. [headView mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.mas_equalTo(self.scrollView.mas_top);
  64. make.left.right.mas_equalTo(self.view);
  65. make.height.mas_equalTo(kNaviBarHeight);
  66. }];
  67. // bodyView;
  68. _bodyView = [MineBodyView shareInstance];
  69. [self.scrollView addSubview:_bodyView];
  70. CGFloat contentMinHeight = [_bodyView getViewHeight];
  71. CGFloat contentHeight = kScreenHeight - kTabBarHeight - kNaviBarHeight;
  72. CGFloat viewHeight = contentMinHeight > contentHeight ? contentMinHeight : contentHeight;
  73. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.mas_equalTo(headView.mas_bottom);
  75. make.left.right.mas_equalTo(self.view);
  76. make.height.mas_equalTo(viewHeight);
  77. make.bottom.mas_equalTo(self.scrollView.mas_bottom);
  78. }];
  79. MJWeakSelf;
  80. [_bodyView operationCallback:^(MINEVIEWTYPE type) {
  81. [weakSelf operationAction:type];
  82. }];
  83. }
  84. - (void)viewWillAppear:(BOOL)animated {
  85. [super viewWillAppear:animated];
  86. if ([self checkIsLoginToLoginView:YES]) {
  87. [self requsetUserMessage];
  88. [self requestUserMemo];
  89. }
  90. }
  91. - (void)requsetUserMessage {
  92. [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  93. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  94. self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  95. NSString *rongToken = UserDefault(RongTokenKey);
  96. if ([NSString isEmptyString:rongToken]) {
  97. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  98. }
  99. [self refreshView];
  100. }
  101. else {
  102. [self MBPShow:MESSAGEKEY];
  103. }
  104. } faliure:^(NSError * _Nonnull error) {
  105. }];
  106. }
  107. - (void)requestUserMemo {
  108. [[UserInfoManager shareInstance] requsetconfigCallback:^(BOOL success) {
  109. [self refreshBodyView:success];
  110. }];
  111. }
  112. - (void)refreshBodyView:(BOOL)isMember {
  113. self.bodyView.isMember = isMember;
  114. CGFloat contentMinHeight = [_bodyView getViewHeight];
  115. [self.bodyView mas_updateConstraints:^(MASConstraintMaker *make) {
  116. make.height.mas_equalTo(contentMinHeight);
  117. }];
  118. }
  119. - (void)refreshView {
  120. [self.bodyView configWithSource:self.mineInfo];
  121. }
  122. - (void)operationAction:(MINEVIEWTYPE)type {
  123. switch (type) {
  124. case MINEVIEWTYPE_MEMBER: // member center
  125. {
  126. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  127. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberCenter"];
  128. [self.navigationController pushViewController:ctrl animated:YES];
  129. }
  130. break;
  131. case MINEVIEWTYPE_COURSE:
  132. {
  133. MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
  134. [self.navigationController pushViewController:ctrl animated:YES];
  135. }
  136. break;
  137. case MINEVIEWTYPE_HOMEWORK:
  138. {
  139. HomeworkListViewController *ctrl = [[HomeworkListViewController alloc] init];
  140. [self.navigationController pushViewController:ctrl animated:YES];
  141. }
  142. break;
  143. case MINEVIEWTYPE_MUSIC:
  144. {
  145. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  146. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/music-personal"];
  147. [self.navigationController pushViewController:ctrl animated:YES];
  148. }
  149. break;
  150. case MINEVIEWTYPE_RECORD: // 评测记录
  151. {
  152. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  153. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberRecord"];
  154. [self.navigationController pushViewController:ctrl animated:YES];
  155. }
  156. break;
  157. case MINEVIEWTYPE_ORDER:
  158. {
  159. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  160. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/goodsOrder"];
  161. [self.navigationController pushViewController:ctrl animated:YES];
  162. }
  163. break;
  164. case MINEVIEWTYPE_DEAL:
  165. {
  166. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  167. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/tradeRecord"];
  168. [self.navigationController pushViewController:ctrl animated:YES];
  169. }
  170. break;
  171. case MINEVIEWTYPE_NETWORK:
  172. {
  173. NetworkingCheckController *checkVC = [[NetworkingCheckController alloc] init];
  174. [self.navigationController pushViewController:checkVC animated:YES];
  175. }
  176. break;
  177. case MINEVIEWTYPE_DEVICE:
  178. {
  179. [self.checkView showAlert];
  180. }
  181. break;
  182. case MINEVIEWTYPE_HELP:
  183. {
  184. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  185. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/helpCenter"];
  186. [self.navigationController pushViewController:webCtrl animated:YES];
  187. }
  188. break;
  189. case MINEVIEWTYPE_FINISHCOURSE:
  190. {
  191. MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
  192. [self.navigationController pushViewController:ctrl animated:YES];
  193. }
  194. break;
  195. case MINEVIEWTYPE_UNFINISHCOURSE:
  196. {
  197. MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
  198. [self.navigationController pushViewController:ctrl animated:YES];
  199. }
  200. break;
  201. case MINEVIEWTYPE_FOLLOW:
  202. {
  203. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  204. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherFollow"];
  205. [self.navigationController pushViewController:webCtrl animated:YES];
  206. }
  207. break;
  208. case MINEVIEWTYPE_USER:
  209. {
  210. UserSettingViewController *ctrl = [[UserSettingViewController alloc] init];
  211. [self.navigationController pushViewController:ctrl animated:YES];
  212. }
  213. break;
  214. case MINEVIEWTYPE_FEEDBACK:
  215. {
  216. FeedbackViewController *ctrl = [[FeedbackViewController alloc] init];
  217. [self.navigationController pushViewController:ctrl animated:YES];
  218. }
  219. break;
  220. case MINEVIEWTYPE_TICKET:
  221. {
  222. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  223. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/coupons"];
  224. [self.navigationController pushViewController:webCtrl animated:YES];
  225. }
  226. break;
  227. case MINEVIEWTYPE_CONTACT:
  228. {
  229. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  230. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/contactus"];
  231. [self.navigationController pushViewController:webCtrl animated:YES];
  232. }
  233. break;
  234. default:
  235. break;
  236. }
  237. }
  238. #pragma mark --- lazying
  239. - (MineNavView *)navView {
  240. if (!_navView) {
  241. _navView = [MineNavView shareInstance];
  242. MJWeakSelf;
  243. [_navView mineNavAction:^(MINENAV_ACTION action) {
  244. if (action == MINENAV_ACTION_SETTING) {
  245. [weakSelf settingAction];
  246. }
  247. else {
  248. [weakSelf scanAction];
  249. }
  250. }];
  251. }
  252. return _navView;
  253. }
  254. - (void)scanAction {
  255. // 判断是否有权限
  256. PREMISSIONTYPE albumEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
  257. if (albumEnable == PREMISSIONTYPE_YES) { // 如果有权限
  258. KSScanViewController *ctrl = [[KSScanViewController alloc] init];
  259. [self.navigationController pushViewController:ctrl animated:YES];
  260. }
  261. else {
  262. if (albumEnable == PREMISSIONTYPE_NO) {
  263. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  264. }
  265. }
  266. }
  267. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  268. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  269. } confirm:^{
  270. [self openSettingView];
  271. }];
  272. }
  273. - (void)openSettingView {
  274. if (@available(iOS 10, *)) {
  275. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  276. } else {
  277. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  278. }
  279. }
  280. - (DeviceCheckView *)checkView {
  281. if (!_checkView) {
  282. _checkView = [DeviceCheckView shareInstance];
  283. }
  284. return _checkView;
  285. }
  286. - (void)settingAction {
  287. SettingViewController *ctrl = [[SettingViewController alloc] init];
  288. [self.navigationController pushViewController:ctrl animated:YES];
  289. }
  290. - (void)dealloc {
  291. [[NSNotificationCenter defaultCenter] removeObserver:self];
  292. }
  293. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  294. CGFloat space = scrollView.contentOffset.y;
  295. if (space >= kNaviBarHeight) {
  296. self.navView.backgroundColor = [UIColor whiteColor];
  297. self.navView.lineView.hidden = NO;
  298. }
  299. else {
  300. self.navView.lineView.hidden = YES;
  301. CGFloat rate = space / kNaviBarHeight < 0 ? 0 : space / kNaviBarHeight;
  302. self.navView.backgroundColor = HexRGBAlpha(0xffffff, rate);
  303. }
  304. }
  305. /*
  306. #pragma mark - Navigation
  307. // In a storyboard-based application, you will often want to do a little preparation before navigation
  308. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  309. // Get the new view controller using [segue destinationViewController].
  310. // Pass the selected object to the new view controller.
  311. }
  312. */
  313. @end