ASBaseViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. //
  2. // ASBaseViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/4/24.
  6. //
  7. #import "ASBaseViewController.h"
  8. #import "AppDelegate.h"
  9. @interface ASBaseViewController ()
  10. @property (nonatomic, strong) UIImageView *leftImgV;
  11. @property (nonatomic, strong) UITextField *searchTf;
  12. @property (nonatomic, strong) UIButton *tfBt;
  13. @property (nonatomic, copy) btnClickBlock tapSearchBlock;
  14. @property (nonatomic, strong) UIButton *backBt;
  15. @property (nonatomic, strong) UIButton *searchNavBt;
  16. @property (nonatomic, copy) btnClickBlock nav_searchBlock;
  17. @property (nonatomic, strong) UIView *emptyV;
  18. @property (nonatomic, strong) UILabel *emptylb;
  19. @end
  20. @implementation ASBaseViewController
  21. - (void)toHomeVc {
  22. if (self.navigationController != nil) {
  23. [self.navigationController popToRootViewControllerAnimated:false];
  24. }
  25. QMUITabBarViewController *tabVC = (QMUITabBarViewController *)((AppDelegate *)UIApplication.sharedApplication.delegate).window.rootViewController;
  26. tabVC.selectedIndex = 0;
  27. }
  28. - (void)popAndToLogin {
  29. QMUITabBarViewController *tabVC = (QMUITabBarViewController *)((AppDelegate *)UIApplication.sharedApplication.delegate).window.rootViewController;
  30. tabVC.selectedIndex = 0;
  31. UITabBar *tabbar = tabVC.tabBar;
  32. if (tabbar.items.count > 2) {
  33. UITabBarItem *temp = tabbar.items[2];
  34. temp.qmui_badgeInteger = 0;
  35. }
  36. UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}];
  37. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC];
  38. uikitNavController.navigationBar.hidden = YES;
  39. uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen;
  40. [tabVC presentViewController:uikitNavController animated:YES completion:nil];
  41. }
  42. - (void)toLoginVC {
  43. UIViewController *loginC = [[CTMediator sharedInstance] Login_LoginC:@{}];
  44. QMUINavigationController *uikitNavController = [[QMUINavigationController alloc] initWithRootViewController:loginC];
  45. uikitNavController.navigationBar.hidden = YES;
  46. uikitNavController.modalPresentationStyle = UIModalPresentationFullScreen;
  47. [self presentViewController:uikitNavController animated:YES completion:nil];
  48. }
  49. - (void)setTitleStr:(NSString *)titleStr {
  50. _titleStr = titleStr;
  51. self.nav_titleLB.text = _titleStr;
  52. }
  53. - (void)hiddenEmpty {
  54. self.emptyV.hidden = true;
  55. }
  56. - (void)setEmptyTip:(NSString *)tipStr {
  57. self.emptylb.text = tipStr;
  58. }
  59. - (void)showEmptyV:(UIView *)v {
  60. if (self.emptyV.superview == v) {
  61. self.emptyV.hidden = false;
  62. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  63. return;
  64. }
  65. if (v == nil) {
  66. [self.view addSubview:self.emptyV];
  67. [self.emptyV mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(self.customNavBar.mas_bottom);
  69. make.leading.trailing.bottom.equalTo(self.view);
  70. }];
  71. } else {
  72. [v addSubview:self.emptyV];
  73. [self.emptyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  74. make.edges.equalTo(v);
  75. make.width.height.equalTo(v);
  76. }];
  77. }
  78. self.emptyV.hidden = false;
  79. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  80. dispatch_async(dispatch_get_main_queue(), ^{
  81. [UIView viewAddHorColorBg:self.emptyV colorArr:@[
  82. (id)_E0FFF5.CGColor,
  83. (id)Col_FFF.CGColor
  84. ] startP:CGPointMake(0.5, 0.25) endP:CGPointMake(0.5, 1)];
  85. [self.emptyV bringSubviewToFront:self.emptylb];
  86. });
  87. }
  88. - (void)viewDidLoad {
  89. [super viewDidLoad];
  90. [self addBaseNav];
  91. self.navigationController.navigationBar.hidden = true;
  92. self.customNavBar.backgroundColor = Col_FFF;
  93. self.view.backgroundColor = _F8F8F8;
  94. }
  95. - (void)viewWillAppear:(BOOL)animated {
  96. [super viewWillAppear:animated];
  97. self.tabBarController.tabBar.hidden = self.navigationController.viewControllers.count > 1;
  98. }
  99. - (void)viewWillDisappear:(BOOL)animated {
  100. [super viewWillAppear:animated];
  101. }
  102. - (void)setNavRightSearch:(btnClickBlock)nav_searchAction {
  103. self.nav_searchBlock = nav_searchAction;
  104. [self.customNavBar addSubview:self.searchNavBt];
  105. [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.width.height.equalTo(@44);
  107. make.trailing.equalTo(self.customNavBar).offset(-10);
  108. make.centerY.equalTo(self.customNavBar);
  109. }];
  110. }
  111. - (void)ucHomeStyle:(btnClickBlock)tapSearch {
  112. self.tapSearchBlock = tapSearch;
  113. [self.customNavBar addSubview:self.leftImgV];
  114. [self.customNavBar addSubview:self.searchTf];
  115. [self.customNavBar addSubview:self.tfBt];
  116. [self.leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.leading.equalTo(self.customNavBar).offset(20);
  118. make.width.equalTo(@140);
  119. make.height.equalTo(@43.5);
  120. make.centerY.equalTo(self.customNavBar);
  121. }];
  122. [self.searchTf mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.leading.equalTo(self.leftImgV.mas_trailing).offset(20);
  124. make.height.equalTo(@36);
  125. make.centerY.equalTo(self.leftImgV);
  126. make.trailing.equalTo(self.customNavBar).offset(-10);
  127. }];
  128. [self.tfBt mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.edges.equalTo(self.searchTf);
  130. }];
  131. }
  132. - (void)addBaseNav {
  133. [self.view addSubview:self.statusBgV];
  134. [self.view addSubview:self.customNavBar];
  135. [self.customNavBar addSubview:self.nav_bottomLineV];
  136. self.statusBgV.frame = CGRectMake(0, 0, KScreenWidth, kStatusBarH);
  137. self.customNavBar.frame = CGRectMake(0, kStatusBarH, KScreenWidth, kCustomNavBarH);
  138. self.nav_bottomLineV.frame = CGRectMake(0, kCustomNavBarH-1, KScreenWidth, 1);
  139. [self.customNavBar addSubview:self.backBt];
  140. [self.customNavBar addSubview:self.nav_titleLB];
  141. [self.backBt mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.leading.equalTo(self.customNavBar).offset(10);
  143. make.centerY.equalTo(self.customNavBar);
  144. make.width.height.equalTo(@44);
  145. }];
  146. [self.nav_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.center.equalTo(self.customNavBar);
  148. make.width.equalTo(self.customNavBar).offset(-120);
  149. make.height.equalTo(@40);
  150. }];
  151. self.backBt.hidden = true;
  152. if (self.navigationController.viewControllers.count > 1) {
  153. self.backBt.hidden = false;
  154. }
  155. [self.emptyV addSubview:self.emptylb];
  156. [self.emptylb mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.leading.equalTo(self.emptyV).offset(30);
  158. make.trailing.equalTo(self.emptyV).offset(-30);
  159. make.centerY.equalTo(self.emptyV).offset(-30);
  160. make.top.greaterThanOrEqualTo(self.emptyV).offset(20);
  161. }];
  162. }
  163. // MARK: - actions
  164. - (void)searchBtAction {
  165. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  166. [self presentViewController:vc animated:true completion:nil];
  167. if (self.tapSearchBlock) {
  168. self.tapSearchBlock();
  169. }
  170. }
  171. // MARK: - subVs
  172. - (UIView *)emptyV {
  173. if (!_emptyV) {
  174. UIView *v = [UIView baseV];
  175. v.backgroundColor = Col_FFF;
  176. v.hidden = true;
  177. _emptyV = v;
  178. }
  179. return _emptyV;
  180. }
  181. - (UILabel *)emptylb {
  182. if (!_emptylb) {
  183. UILabel *lb = [UILabel baseLb];
  184. lb.font = [UIFont fontWithName:Rob_Medium size:72];
  185. lb.textAlignment = NSTextAlignmentCenter;
  186. lb.numberOfLines = 0;
  187. lb.text = @"No Data";
  188. lb.textColor = _043632;
  189. _emptylb = lb;
  190. }
  191. return _emptylb;
  192. }
  193. - (UIView *)statusBgV {
  194. if (!_statusBgV) {
  195. UIView *v = [UIView baseV];
  196. v.backgroundColor = _32CFB0;
  197. _statusBgV = v;
  198. }
  199. return _statusBgV;
  200. }
  201. - (UIView *)customNavBar {
  202. if (!_customNavBar) {
  203. UIView *v = [UIView baseV];
  204. v.backgroundColor = _32CFB0;
  205. _customNavBar = v;
  206. }
  207. return _customNavBar;
  208. }
  209. - (UIView *)nav_bottomLineV {
  210. if (!_nav_bottomLineV) {
  211. UIView *v = [UIView baseV];
  212. v.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.05];
  213. _nav_bottomLineV = v;
  214. }
  215. return _nav_bottomLineV;
  216. }
  217. - (UIImageView *)leftImgV {
  218. if (!_leftImgV) {
  219. UIImageView *v = [UIImageView baseImgV];
  220. v.image = [UIImage imageNamed:@"nav_icon"];
  221. _leftImgV = v;
  222. }
  223. return _leftImgV;
  224. }
  225. - (UITextField *)searchTf {
  226. if (!_searchTf) {
  227. UITextField *tf = [[UITextField alloc] init];
  228. tf.borderStyle = UITextBorderStyleNone;
  229. UIView *leftV = [[UIView alloc] init];
  230. leftV.backgroundColor = UIColor.clearColor;
  231. UIImageView *imgV = [UIImageView baseImgV];
  232. imgV.backgroundColor = UIColor.clearColor;
  233. imgV.image = [UIImage imageNamed:@"nav_search"];
  234. leftV.frame = CGRectMake(0, 0, 44, 36);
  235. imgV.frame = CGRectMake(10, 6, 24, 24);
  236. [leftV addSubview:imgV];
  237. tf.leftView = leftV;
  238. tf.leftViewMode = UITextFieldViewModeAlways;
  239. tf.backgroundColor = _F5F5F5;
  240. tf.layer.cornerRadius = 5;
  241. tf.layer.masksToBounds = true;
  242. _searchTf = tf;
  243. }
  244. return _searchTf;
  245. }
  246. - (UIButton *)tfBt {
  247. if (!_tfBt) {
  248. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  249. [bt addTarget:self action:@selector(searchBtAction) forControlEvents:UIControlEventTouchUpInside];
  250. _tfBt = bt;
  251. }
  252. return _tfBt;
  253. }
  254. - (UIButton *)backBt {
  255. if (!_backBt) {
  256. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  257. [bt setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
  258. [bt addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  259. _backBt = bt;
  260. }
  261. return _backBt;
  262. }
  263. - (UILabel *)nav_titleLB {
  264. if (!_nav_titleLB) {
  265. UILabel *lb = [[UILabel alloc] init];
  266. lb.font = [UIFont fontWithName:Rob_Regular size:20];
  267. lb.textAlignment = NSTextAlignmentCenter;
  268. lb.textColor = Col_000;
  269. _nav_titleLB = lb;
  270. }
  271. return _nav_titleLB;
  272. }
  273. - (void)backAction {
  274. [self.navigationController popViewControllerAnimated:true];
  275. }
  276. - (UIButton *)searchNavBt {
  277. if (!_searchNavBt) {
  278. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  279. [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal];
  280. [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside];
  281. _searchNavBt = bt;
  282. }
  283. return _searchNavBt;
  284. }
  285. // MARK: - actions
  286. - (void)search_navAction {
  287. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  288. [self presentViewController:vc animated:true completion:nil];
  289. if (self.nav_searchBlock) {
  290. self.nav_searchBlock();
  291. }
  292. }
  293. @end