3030#import " pop.h"
3131#import " FRDLivelyButton.h"
3232#import " StartImagesManager.h"
33+ #import " ZXScanCodeViewController.h"
34+ #import " WebViewController.h"
3335
3436@interface Project_RootViewController ()<UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate>
3537@property (strong , nonatomic ) NSMutableDictionary *myProjectsDict;
@@ -98,7 +100,8 @@ - (void)viewDidLoad
98100 // 添加搜索框
99101 _mySearchBar = ({
100102 MainSearchBar *searchBar = [[MainSearchBar alloc ] initWithFrame: CGRectMake (60 ,7 , kScreen_Width -115 , 31 )];
101- [searchBar setPlaceholder: @" 项目/任务/讨论/冒泡等" ];
103+ [searchBar setContentMode: UIViewContentModeLeft];
104+ [searchBar setPlaceholder: @" 搜索" ];
102105 searchBar.delegate = self;
103106 searchBar.layer .cornerRadius =15 ;
104107 searchBar.layer .masksToBounds =TRUE ;
@@ -108,6 +111,7 @@ - (void)viewDidLoad
108111 [searchBar setTintColor: [UIColor whiteColor ]];
109112 [searchBar insertBGColor: [UIColor colorWithHexString: @" 0xffffff" ]];
110113 [searchBar setHeight: 30 ];
114+ [searchBar.scanBtn addTarget: self action: @selector (scanBtnClicked ) forControlEvents: UIControlEventTouchUpInside];
111115 searchBar;
112116 });
113117 __weak typeof (_myCarousel) weakCarousel = _myCarousel;
@@ -601,6 +605,53 @@ - (void)updateFilteredContentForSearchString:(NSString *)searchString{
601605 self.searchResults = [[self .searchResults filteredArrayUsingPredicate: finalCompoundPredicate] mutableCopy ];
602606}
603607
608+ #pragma mark scan QR-Code
609+ - (void )scanBtnClicked {
610+ ZXScanCodeViewController *vc = [ZXScanCodeViewController new ];
611+ __weak typeof (self) weakSelf = self;
612+ vc.scanResultBlock = ^(ZXScanCodeViewController *vc, NSString *resultStr){
613+ [weakSelf dealWithScanResult: resultStr ofVC: vc];
614+ };
615+ [self .navigationController pushViewController: vc animated: YES ];
616+ }
617+
618+ - (void )dealWithScanResult : (NSString *)resultStr ofVC : (ZXScanCodeViewController *)vc {
619+ UIViewController *nextVC = [BaseViewController analyseVCFromLinkStr: resultStr];
620+ NSURL *URL = [NSURL URLWithString: resultStr];
621+ if (nextVC) {
622+ [self .navigationController pushViewController: nextVC animated: YES ];
623+ }else if (URL){
624+ UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle: @" 提示" message: [NSString stringWithFormat: @" 可能存在风险,是否打开此链接?\n 「%@ 」" , resultStr]];
625+ [alertV bk_setCancelButtonWithTitle: @" 取消" handler: nil ];
626+ [alertV bk_addButtonWithTitle: @" 打开链接" handler: nil ];
627+ [alertV bk_setWillDismissBlock: ^(UIAlertView *al, NSInteger index) {
628+ if (index == 1 ) {
629+ [[UIApplication sharedApplication ] openURL: URL];
630+ }
631+ [self .navigationController popViewControllerAnimated: YES ];
632+ }];
633+ [alertV show ];
634+ }else if (resultStr.length > 0 ){
635+ UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle: @" 提示" message: [NSString stringWithFormat: @" 已识别此二维码内容为:\n 「%@ 」" , resultStr]];
636+ [alertV bk_setCancelButtonWithTitle: @" 取消" handler: nil ];
637+ [alertV bk_addButtonWithTitle: @" 复制链接" handler: nil ];
638+ [alertV bk_setWillDismissBlock: ^(UIAlertView *al, NSInteger index) {
639+ if (index == 1 ) {
640+ [[UIPasteboard generalPasteboard ] setString: resultStr];
641+ }
642+ [self .navigationController popViewControllerAnimated: YES ];
643+ }];
644+ [alertV show ];
604645
646+ }else {
647+ UIAlertView *alertV = [UIAlertView bk_alertViewWithTitle: @" 无效条码" message: @" 未检测到条码信息" ];
648+ [alertV bk_addButtonWithTitle: @" 重试" handler: ^{
649+ if (![vc isScaning ]) {
650+ [vc startScan ];
651+ }
652+ }];
653+ [alertV show ];
654+ }
655+ }
605656
606657@end
0 commit comments