ASBaseViewController.m 11 KB

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