ResultViewController.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. //
  2. // ViewController.m
  3. // phoneTest
  4. //
  5. // Created by Ray on 01/09/2017.
  6. //
  7. //
  8. #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  9. #import "ResultViewController.h"
  10. #import "FullyShowViewController.h"
  11. #import "RANetwork.h"
  12. #import "RAUtils.h"
  13. #import "JLRefreshHeader.h"
  14. #import "JLRefreshFooter.h"
  15. #import "OrderDetailViewController.h"
  16. #import "KVViewController.h"
  17. #import <QuickLook/QuickLook.h>
  18. #import "config.h"
  19. #import "RAConvertor.h"
  20. static const int delta = 25;
  21. @interface ResultViewController () <JLRefreshDelegate,QLPreviewControllerDataSource,QLPreviewControllerDelegate>
  22. @property (nonatomic,strong) QLPreviewController *quickLook;
  23. @property (nonatomic,copy) NSString *documentPath;
  24. @property (nonatomic,assign) NSInteger offset;
  25. @property (nonatomic,strong) NSDictionary *params;
  26. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *w_constraint;
  27. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *h_constraint;
  28. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *trail_constraint;
  29. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *lead_constraint;
  30. @end
  31. @implementation ResultViewController
  32. - (void)labelClick {
  33. NSLog(@"underlineLabel被点击了");
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. // self.labelTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapAction:)];
  38. //
  39. // self.labelTap.numberOfTouchesRequired = 1; //手指数
  40. // self.labelTap.numberOfTapsRequired = 2; //tap次数
  41. //
  42. //
  43. //
  44. //
  45. // self.cellDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellDoubleTapAction:)];
  46. //
  47. // self.cellDoubleTap.numberOfTouchesRequired = 1; //手指数
  48. // self.cellDoubleTap.numberOfTapsRequired = 2; //tap次数
  49. // UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
  50. // action:nil];
  51. // singleFingerOne.numberOfTouchesRequired = 1; //手指数
  52. // singleFingerOne.numberOfTapsRequired = 1; //tap次数
  53. //
  54. //
  55. // singleFingerTwo.delegate = self;
  56. self.label = [UILabel new];
  57. // NSString* Path = [[NSBundle mainBundle] pathForResource:@"layout.json" ofType:nil];
  58. //
  59. // NSData *data = [NSData dataWithContentsOfFile:Path];
  60. // self.content_layout = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
  61. //
  62. //
  63. // Path = [[NSBundle mainBundle] pathForResource:@"data.json" ofType:nil];
  64. //
  65. // data = [NSData dataWithContentsOfFile:Path];
  66. // self.content_data = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
  67. // int width=[self.content_layout[@"header"][@"width"] intValue];
  68. // if(width<self.tableview.frame.size.width)
  69. // width=self.tableview.frame.size.width;
  70. //
  71. // CGRect frame = CGRectMake(self.tableview.frame.origin.x, self.tableview.frame.origin.y, width, self.tableview.frame.size.height);
  72. // self.tableview.frame=frame;
  73. // self.scrollview.contentSize=self.tableview.frame.size;
  74. // Do any additional setup after loading the view, typically from a nib.
  75. self.automaticallyAdjustsScrollViewInsets = NO;
  76. [self setupNavigationBar];
  77. [self setupTableRefreshView];
  78. [self loadContent];
  79. }
  80. -(void)cellDoubleTapAction:(UIGestureRecognizer*)gestureRecognizer
  81. {
  82. NSLog(@"cell double tap");
  83. UITableViewCell* cell = (UITableViewCell*)[gestureRecognizer view];
  84. NSIndexPath* indexPath=[self.tableview indexPathForCell:cell];
  85. //strongSelf.content_action
  86. if(self.content_action!=nil)
  87. {
  88. if(self.content_action.count==1)
  89. {
  90. NSDictionary* action =self.content_action.firstObject;
  91. NSString * module = action[@"module"];
  92. if([module isEqualToString:@"quick_look"])
  93. {
  94. // +(NSString*)download_file : (NSMutableDictionary*) params url:(NSString*) url
  95. NSMutableDictionary *params = action[@"params"];
  96. NSString* URL =action[@"url"];
  97. __weak typeof(self) weakSelf = self;
  98. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  99. NSString *path = [RANetwork download_file:params url:URL];
  100. weakSelf.documentPath = path;
  101. if (path) {
  102. dispatch_async(dispatch_get_main_queue(), ^{
  103. [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  104. });
  105. }
  106. });
  107. }
  108. else if([module isEqualToString:@"kv_detail"])
  109. {
  110. NSMutableDictionary *params = [NSMutableDictionary new];
  111. params[@"query_id"] = self.params[@"query_id"];
  112. NSMutableDictionary *criteria =[NSMutableDictionary new];
  113. for(NSString* key in [action[@"params"] allKeys] )
  114. {
  115. NSArray* item =self.content_data[[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  116. int idx =[action[@"params"][key] intValue];
  117. criteria[key]=item[ idx];
  118. }
  119. params[@"criteria"]=[RAConvertor dict2string:action[@"params"]] ;
  120. UIAlertView * waitalert = [RAUtils waiting_alert:@"Loading..." title:@"Please wait"];
  121. __weak typeof(self) weakself = self;
  122. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  123. NSDictionary* json =[RANetwork kv_detail:params];
  124. dispatch_async(dispatch_get_main_queue(), ^{
  125. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  126. if([[json valueForKey:@"result"] intValue]==2)
  127. {
  128. KVViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"KVViewController"];
  129. vc.content = [json mutableCopy];
  130. [weakself.navigationController pushViewController:vc animated:NO];
  131. // weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
  132. //
  133. // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
  134. //
  135. //
  136. // [weakself download_success];
  137. // [weakself.editorTable reloadData];
  138. }
  139. else
  140. {
  141. [RAUtils message_alert:json[@"msg"] title:nil controller:weakself] ;
  142. }
  143. });
  144. });
  145. }
  146. else if([module isEqualToString:@"order_detail"])
  147. {
  148. OrderDetailViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController"];
  149. vc.url_type = URL_REMOTE;
  150. vc.request_url=URL_ORDER_DETAIL;
  151. vc.params = [NSMutableDictionary dictionary];
  152. // NSString *path = [[NSBundle mainBundle] pathForResource:@"search_ui.json" ofType:nil];
  153. // NSData *data = [NSData dataWithContentsOfFile:path];
  154. // vc.content_data_download = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
  155. [self.navigationController pushViewController:vc animated:NO];
  156. return;
  157. }
  158. }
  159. else
  160. {
  161. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Menu" message:nil preferredStyle:UIAlertControllerStyleAlert];
  162. //block代码块取代了delegate
  163. __weak typeof(self) weakSelf = self;
  164. for(int i=0;i<self.content_action.count;i++)
  165. {
  166. NSMutableDictionary* json = self.content_action[i];
  167. NSString* title =json[@"title"];
  168. NSString* module = json[@"module"];
  169. NSMutableDictionary* add_params = json[@"params"];
  170. UIAlertAction *actioni = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  171. if([module isEqualToString:@"quick_look"])
  172. {
  173. // +(NSString*)download_file : (NSMutableDictionary*) params url:(NSString*) url
  174. NSMutableDictionary *params = json[@"params"];
  175. NSString* URL =json[@"url"];
  176. __weak typeof(self) weakSelf = self;
  177. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  178. NSString *path = [RANetwork download_file:params url:URL];
  179. weakSelf.documentPath = path;
  180. if (path) {
  181. dispatch_async(dispatch_get_main_queue(), ^{
  182. [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  183. });
  184. }
  185. });
  186. }
  187. else if([module isEqualToString:@"kv_detail"])
  188. {
  189. NSMutableDictionary *params = json[@"params"];
  190. UIAlertView * waitalert = [RAUtils waiting_alert:@"Loading..." title:@"Please wait"];
  191. __weak typeof(self) weakself = self;
  192. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  193. NSDictionary* json =[RANetwork kv_detail:params];
  194. dispatch_async(dispatch_get_main_queue(), ^{
  195. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  196. if([[json valueForKey:@"result"] intValue]==2)
  197. {
  198. KVViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"KVViewController"];
  199. vc.content = [json mutableCopy];
  200. [weakself.navigationController pushViewController:vc animated:NO];
  201. // weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
  202. //
  203. // weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
  204. //
  205. //
  206. // [weakself download_success];
  207. // [weakself.editorTable reloadData];
  208. }
  209. else
  210. {
  211. [RAUtils message_alert:json[@"msg"] title:nil controller:weakself] ;
  212. }
  213. });
  214. });
  215. }
  216. else if([module isEqualToString:@"order_detail"])
  217. {
  218. OrderDetailViewController *vc = [[UIStoryboard storyboardWithName:@"Detail" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDetailViewController"];
  219. vc.url_type = URL_REMOTE;
  220. vc.request_url=URL_ORDER_DETAIL;
  221. vc.params = [NSMutableDictionary dictionary];
  222. // NSString *path = [[NSBundle mainBundle] pathForResource:@"search_ui.json" ofType:nil];
  223. // NSData *data = [NSData dataWithContentsOfFile:path];
  224. // vc.content_data_download = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
  225. [self.navigationController pushViewController:vc animated:NO];
  226. return;
  227. }
  228. // DebugLog(@"Cancel");
  229. // if([actiontype isEqualToString:@"download"])
  230. // {
  231. // [weakSelf Export:add_params];
  232. // }
  233. // else if([actiontype isEqualToString:@"save"])
  234. // {
  235. // }
  236. }];
  237. [alertControl addAction:actioni];
  238. }
  239. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  240. // DebugLog(@"Cancel");
  241. }];
  242. [alertControl addAction:actionCancel];
  243. [self presentViewController:alertControl animated:NO completion:nil];
  244. }
  245. }
  246. }
  247. -(void)labelTapAction:(UIGestureRecognizer*)gestureRecognizer
  248. {
  249. NSLog(@"label touched");
  250. UILabel* label = (UILabel*)[gestureRecognizer view];
  251. self.label.text = label.text;
  252. [self.label sizeToFit];
  253. if(self.label.frame.size.width>label.frame.size.width||self.label.frame.size.height>label.frame.size.height)
  254. {
  255. FullyShowViewController *fullVC = [ self.storyboard instantiateViewControllerWithIdentifier:@"fullyShowViewController"];
  256. fullVC.text = label.text;
  257. fullVC.preferredContentSize = CGSizeMake(200, 240);
  258. fullVC.modalPresentationStyle=UIModalPresentationPopover;
  259. UIPopoverPresentationController* popPc = fullVC.popoverPresentationController;
  260. popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
  261. popPc.sourceView = label;
  262. popPc.delegate = self;
  263. [self presentViewController:fullVC animated:true completion:nil];
  264. }
  265. }
  266. - (void)didReceiveMemoryWarning {
  267. [super didReceiveMemoryWarning];
  268. // Dispose of any resources that can be recreated.
  269. }
  270. - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  271. }
  272. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  273. {
  274. // auto resizing
  275. // self.scrollview.contentSize=self.tableview.frame.size;
  276. // auto layout
  277. // int width=[self.content_layout[@"header"][@"width"] intValue];
  278. // if(width<self.view.frame.size.width)
  279. // width=self.view.frame.size.width;
  280. // self.w_constraint.constant = width - CGRectGetWidth(self.view.bounds);
  281. // self.h_constraint.constant = 0;
  282. [self updateTableFrame];
  283. }
  284. #pragma mark - TableView DataSource
  285. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  286. return [self.content_data[@"count"] intValue];
  287. }
  288. //- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  289. //{
  290. // return 1;
  291. //}
  292. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  293. {
  294. int height=[self.content_layout[@"header"][@"height"] intValue];
  295. if(height==0)
  296. height=44;
  297. return height;
  298. }
  299. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  300. {
  301. NSArray* arr_col=self.content_layout[@"header"][@"col"];
  302. NSString* value =self.content_layout[@"header"][@"f_color"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  303. if(value==nil)
  304. value=@"";
  305. unsigned long fcolor = strtoul([value UTF8String],0,16);
  306. value =self.content_layout[@"header"][@"bg_color"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  307. if(value==nil)
  308. value=@"";
  309. unsigned long bgcolor = strtoul([value UTF8String],0,16);
  310. UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  311. myView.backgroundColor = UIColorFromRGB(bgcolor);
  312. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  313. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  314. myView.layer.shadowOffset = CGSizeMake(0, 0);
  315. myView.layer.shadowOpacity = 0.5;
  316. myView.layer.shadowRadius = 2.0;
  317. int x=0;//[self.content_layout[@"header"][@"margin_l"] intValue];
  318. int y=0;//[self.content_layout[@"header"][@"margin_t"] intValue];;
  319. int height = [self.content_layout[@"header"][@"height"] intValue];
  320. for(int i=0;i<arr_col.count;i++)
  321. {
  322. int width = [arr_col[i][@"width"] intValue];
  323. UILabel *headerlabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
  324. headerlabel.textColor=UIColorFromRGB(fcolor);//UIColor.blackColor;
  325. headerlabel.backgroundColor = [UIColor clearColor];
  326. headerlabel.text=arr_col[i][@"name"];
  327. headerlabel.textAlignment= [self get_TextHAlign:arr_col[i][@"h_align"] ];
  328. headerlabel.font = [UIFont boldSystemFontOfSize:20];
  329. // [headerlabel sizeToFit];
  330. headerlabel.layer.borderWidth=0.5;
  331. [myView addSubview:headerlabel];
  332. x+=width;
  333. }
  334. myView.autoresizesSubviews=true;
  335. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  336. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  337. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  338. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  339. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  340. //
  341. return myView;
  342. }
  343. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  344. {
  345. int height=[self.content_layout[@"row"][@"height"] intValue];
  346. if(height==0)
  347. height=44;
  348. return height;
  349. }
  350. -(NSTextAlignment) get_TextHAlign:(NSString*)textHAlign
  351. {
  352. if([textHAlign.lowercaseString isEqualToString:@"center"])
  353. return NSTextAlignmentCenter;
  354. else if([textHAlign.lowercaseString isEqualToString:@"left"])
  355. return NSTextAlignmentLeft;
  356. else if([textHAlign.lowercaseString isEqualToString:@"right"])
  357. return NSTextAlignmentRight;
  358. return NSTextAlignmentLeft;
  359. }
  360. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  361. {
  362. {
  363. NSString *CellIdentifier = @"tCell";
  364. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  365. for(UIGestureRecognizer* g in cell.gestureRecognizers)
  366. [ cell removeGestureRecognizer:g];
  367. // cell gesture
  368. // [cell removeGestureRecognizer:self.cellDoubleTap];
  369. for(UIView* v in cell.subviews)
  370. {
  371. for(UIGestureRecognizer* g in v.gestureRecognizers)
  372. [ v removeGestureRecognizer:g];
  373. [v removeFromSuperview];
  374. }
  375. // cell.detailTextLabel.text=@"detail";
  376. // cell.textLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row];
  377. UITapGestureRecognizer *cellDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellDoubleTapAction:)];
  378. cellDoubleTap.numberOfTouchesRequired = 1; //手指数
  379. cellDoubleTap.numberOfTapsRequired = 2; //tap次数
  380. [cell addGestureRecognizer:cellDoubleTap];
  381. NSArray* arr_col=self.content_layout[@"header"][@"col"];
  382. NSArray* item =self.content_data[[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  383. NSString* value =self.content_layout[@"row"][@"f_color"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  384. if(value==nil)
  385. value=@"";
  386. unsigned long fcolor = strtoul([value UTF8String],0,16);
  387. value =self.content_layout[@"row"][@"color_0"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  388. if(value==nil)
  389. value=@"";
  390. unsigned long color0 = strtoul([value UTF8String],0,16);
  391. value =self.content_layout[@"row"][@"color_1"];//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  392. if(value==nil)
  393. value=@"";
  394. unsigned long color1 = strtoul([value UTF8String],0,16);
  395. int x=0;//[self.content_layout[@"header"][@"margin_l"] intValue];
  396. int y=0;//[self.content_layout[@"header"][@"margin_t"] intValue];;
  397. int height = [self.content_layout[@"row"][@"height"] intValue];
  398. for(int i=0;i<arr_col.count;i++)
  399. {
  400. int width = [arr_col[i][@"width"] intValue];;
  401. UILabel *vallabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
  402. vallabel.textColor=UIColorFromRGB(fcolor);//UIColor.blackColor;
  403. vallabel.backgroundColor = [UIColor clearColor];
  404. vallabel.text=item[i];
  405. vallabel.textAlignment= [self get_TextHAlign:arr_col[i][@"h_align"] ];
  406. vallabel.layer.borderWidth=0.5;
  407. // UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTapAction:)];
  408. UITapGestureRecognizer* labelTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapAction:)];
  409. labelTap.numberOfTouchesRequired = 1; //手指数
  410. labelTap.numberOfTapsRequired = 1; //tap次数
  411. [vallabel addGestureRecognizer:labelTap];
  412. [labelTap requireGestureRecognizerToFail:cellDoubleTap];
  413. // [vallabel addGestureRecognizer:self.cellDoubleTap];
  414. vallabel.userInteractionEnabled = YES;
  415. // [vallabel becomeFirstResponder];
  416. // vallabel.delegate = self;
  417. // [statuslabel sizeToFit];
  418. [cell addSubview:vallabel];
  419. x+=width;
  420. }
  421. if(indexPath.row%2==0)
  422. cell.backgroundColor=UIColorFromRGB(color0);//[UIColor whiteColor];
  423. else
  424. cell.backgroundColor=UIColorFromRGB(color1);//[UIColor lightGrayColor];
  425. return cell;
  426. }
  427. }
  428. //#pragma mark - TouchLabel Delegate
  429. //- (void)touchLabel:(TouchLabel *)touchLabel touchesWtihTag:(NSInteger)tag
  430. //{
  431. //
  432. //}
  433. //-(void) empty
  434. //{
  435. //
  436. //}
  437. #pragma mark - UIPopoverPresentationControllerDelegate Delegate
  438. //实现该代理方法,返回UIModalPresentationNone值,可以在iPhone设备实现popover效果
  439. -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
  440. return UIModalPresentationNone;//不适配(不区分ipad或iPhone)
  441. }
  442. #pragma mark - TableView Delegate
  443. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  444. {
  445. NSLog(@"cell selected");
  446. }
  447. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  448. return UITableViewCellEditingStyleDelete;
  449. }
  450. #pragma mark - Public
  451. - (void)setQueryParams:(NSDictionary *)params {
  452. self.params = params;
  453. }
  454. #pragma mark - Private
  455. - (void)setupTableRefreshView {
  456. self.tableview.jl_header = [[JLRefreshHeader alloc] init];
  457. self.tableview.jl_header.refreshDelegate = self;
  458. self.tableview.jl_footer = [[JLRefreshFooter alloc] init];
  459. self.tableview.jl_footer.refreshDelegate = self;
  460. }
  461. - (void)setupNavigationBar {
  462. UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStylePlain target:self action:@selector(MenuClick:)];
  463. self.navigationItem.rightBarButtonItem = menuItem;
  464. }
  465. - (void)MenuClick:(UIBarButtonItem *)sender {
  466. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Menu" message:nil preferredStyle:UIAlertControllerStyleAlert];
  467. //block代码块取代了delegate
  468. __weak typeof(self) weakSelf = self;
  469. for(int i=0;i<self.content_menu.count;i++)
  470. {
  471. NSMutableDictionary* json = self.content_menu[i];
  472. NSString* title =json[@"title"];
  473. NSString* actiontype = json[@"action"];
  474. NSMutableDictionary* add_params = json[@"params"];
  475. UIAlertAction *actioni = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  476. // DebugLog(@"Cancel");
  477. if([actiontype isEqualToString:@"download"])
  478. {
  479. [weakSelf Export:add_params];
  480. }
  481. else if([actiontype isEqualToString:@"save"])
  482. {
  483. }
  484. }];
  485. [alertControl addAction:actioni];
  486. }
  487. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  488. // DebugLog(@"Cancel");
  489. }];
  490. [alertControl addAction:actionCancel];
  491. [self presentViewController:alertControl animated:NO completion:nil];
  492. }
  493. -(void)Export:(NSDictionary*) add_params
  494. {
  495. if(self.download_query )
  496. {
  497. self.documentPath = self.download_query;
  498. [self.navigationController pushViewController:self.quickLook animated:NO];
  499. return;
  500. }
  501. __weak typeof(self) weakSelf = self;
  502. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  503. NSMutableDictionary *params = self.params.mutableCopy;
  504. if(add_params!=nil)
  505. [params addEntriesFromDictionary:add_params];
  506. NSString *path = [RANetwork download_query:params];
  507. weakSelf.download_query = path;
  508. weakSelf.documentPath = path;
  509. if (path) {
  510. dispatch_async(dispatch_get_main_queue(), ^{
  511. [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  512. });
  513. }
  514. });
  515. }
  516. - (void)downloadItemClick:(UIBarButtonItem *)sender {
  517. if(self.download_query )
  518. {
  519. self.documentPath = self.download_query;
  520. [self.navigationController pushViewController:self.quickLook animated:NO];
  521. return;
  522. }
  523. __weak typeof(self) weakSelf = self;
  524. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  525. NSMutableDictionary *params = self.params.mutableCopy;
  526. NSString *path = [RANetwork download_query:params];
  527. weakSelf.download_query = path;
  528. weakSelf.documentPath = path;
  529. if (path) {
  530. dispatch_async(dispatch_get_main_queue(), ^{
  531. [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:NO];
  532. });
  533. }
  534. });
  535. }
  536. - (NSInteger)resultItemCount {
  537. return [[self.content_data objectForKey:@"count"] integerValue];
  538. }
  539. - (void)loadContent {
  540. [self loadContentWithOption:0 Complete:nil];
  541. }
  542. /**
  543. * 0: init load
  544. * 1: refresh
  545. * 2: load more
  546. */
  547. - (void)loadContentWithOption:(int)option Complete:(void (^)(int result,int count))finish {
  548. if (self.params) {
  549. NSMutableDictionary *dic = self.params.mutableCopy;
  550. switch (option) {
  551. case 0:
  552. case 1: {
  553. self.offset = 0;
  554. self.content_layout =nil;
  555. self.content_action = nil;
  556. self.content_menu = nil;
  557. self.content_data = nil;
  558. }
  559. break;
  560. case 2: {
  561. self.offset = [self resultItemCount];
  562. }
  563. break;
  564. }
  565. // dic[@"criteria"] = self.params;
  566. [dic setObject:@(self.offset) forKey:@"offset"];
  567. [dic setObject:@(delta) forKey:@"limit"];
  568. // dic[@"criteria"] = [NSArray arrayWithObjects:@"aaa",@"bbb", nil];
  569. __weak typeof(self) weakSelf = self;
  570. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  571. NSDictionary *contentDic = [RANetwork query:dic];
  572. NSInteger result = [[contentDic objectForKey:@"result"] integerValue];
  573. dispatch_async(dispatch_get_main_queue(), ^{
  574. if (weakSelf) {
  575. __strong typeof(weakSelf) strongSelf = weakSelf;
  576. if (result == RESULT_TRUE) {
  577. strongSelf.content_layout = [contentDic objectForKey:@"layout"];
  578. strongSelf.content_action = [contentDic objectForKey:@"row_action"];
  579. strongSelf.content_menu = [[contentDic objectForKey:@"menu"] mutableCopy];
  580. if(strongSelf.content_data==nil)
  581. strongSelf.content_data = [NSMutableDictionary new];
  582. NSMutableDictionary* newdata = [[contentDic objectForKey:@"data"] mutableCopy];
  583. for(int dc = 0;dc<[newdata[@"count"] intValue];dc++)
  584. {
  585. NSMutableDictionary * newdata_item = newdata[[NSString stringWithFormat:@"item_%d",dc]];
  586. strongSelf.content_data[[NSString stringWithFormat:@"item_%d",[strongSelf.content_data[@"count"] intValue] ]] = newdata_item;
  587. strongSelf.content_data[@"count"] = @([strongSelf.content_data[@"count"] intValue]+1);
  588. }
  589. // strongSelf.content_data = [contentDic objectForKey:@"data"];
  590. [strongSelf updateTableFrame];
  591. [strongSelf.tableview reloadData];
  592. } else {
  593. [RAUtils message_alert:[contentDic objectForKey:@"err_msg"] title:@"Warning" controller:strongSelf];
  594. }
  595. if (finish) {
  596. finish((int)result,(int)[self resultItemCount]);
  597. }
  598. }
  599. });
  600. });
  601. }
  602. }
  603. - (void)updateTableFrame {
  604. // auto resizing
  605. // int width=[self.content_layout[@"header"][@"width"] intValue];
  606. // if(width<self.tableview.frame.size.width)
  607. // width=self.tableview.frame.size.width;
  608. //
  609. // CGRect frame = CGRectMake(self.tableview.frame.origin.x, self.tableview.frame.origin.y, width, self.tableview.frame.size.height);
  610. // self.tableview.frame=frame;
  611. // self.scrollview.contentSize=self.tableview.frame.size;
  612. // auto layout
  613. int width=[self.content_layout[@"header"][@"width"] intValue];
  614. if(width<self.view.frame.size.width)
  615. width=self.view.frame.size.width;
  616. self.w_constraint.constant = width - CGRectGetWidth(self.view.bounds);
  617. self.h_constraint.constant = 0;
  618. // 约束修改后立即重新布局
  619. [self.view layoutIfNeeded];
  620. if (@available(iOS 11.0,*)) {
  621. UIEdgeInsets edgeInsets = [self.view safeAreaInsets];
  622. CGFloat left = edgeInsets.left;
  623. CGFloat right = edgeInsets.right;
  624. self.lead_constraint.constant = left;
  625. self.trail_constraint.constant = right;
  626. /*
  627. * lead 和 trail改变之前
  628. * scrollview.size.width = self.view.size.width;
  629. * 改变后
  630. * scrollview.size.width = self.view.size.width - left - right;
  631. * 由于w_contraint本质上是根据scrolliew.size.width决定,实际上使用self.view.size.width计算得到
  632. * 所以w_contraint需要 +left +right补偿偏差。
  633. */
  634. self.w_constraint.constant += left + right;
  635. // 约束修改后立即重新布局
  636. [self.view layoutIfNeeded];
  637. }
  638. }
  639. #pragma mark - RefreshDelegate
  640. - (void)jl_pullRefresh:(JLRefreshBasis *)refresh state:(JLRefreshState)state percentage:(float)percentage {
  641. if ([refresh isEqual:self.tableview.jl_header]) {
  642. }
  643. if (refresh == self.tableview.jl_footer) {
  644. }
  645. }
  646. - (void)jl_endRefresh:(JLRefreshBasis *)refresh {
  647. // state == idle
  648. // refresh UI
  649. [self.tableview reloadData];
  650. if (refresh == self.tableview.jl_footer && refresh.state == JLRefreshStateNoMore) {
  651. }
  652. }
  653. - (void)jl_beginRefresh:(JLRefreshBasis *)refresh {
  654. // state == refreshing
  655. // load data
  656. // finish loading data
  657. int option = 0;
  658. if ([refresh isEqual:self.tableview.jl_header]) {
  659. option = 1;
  660. }
  661. if (refresh == self.tableview.jl_footer) {
  662. if(refresh.state==JLRefreshStateNoMore) //数据取完不再加载
  663. return;
  664. option = 2;
  665. }
  666. __weak typeof(self) weakSelf = self;
  667. [self loadContentWithOption:option Complete:^(int result, int count) {
  668. if ([refresh isEqual:weakSelf.tableview.jl_header]) {
  669. [weakSelf.tableview.jl_header performSelector:@selector(endRefresh)];
  670. }
  671. if (refresh == weakSelf.tableview.jl_footer) {
  672. [weakSelf.tableview.jl_footer performSelector:@selector(endRefresh)];
  673. if (result == 2 && count < delta) {
  674. [weakSelf.tableview.jl_footer performSelector:@selector(noMoreData)];
  675. }
  676. }
  677. }];
  678. }
  679. #pragma mark - Quick Look
  680. - (QLPreviewController *)quickLook {
  681. if (!_quickLook)
  682. {
  683. _quickLook = [[QLPreviewController alloc] init];
  684. _quickLook.delegate = self;
  685. _quickLook.dataSource = self;
  686. }
  687. else
  688. {
  689. [_quickLook reloadData];
  690. }
  691. return _quickLook;
  692. }
  693. #pragma mark - QuickLook Data Source
  694. - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
  695. return 1;
  696. }
  697. - (id <QLPreviewItem>) previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
  698. return [NSURL fileURLWithPath:self.documentPath];
  699. }
  700. #pragma mark - QuickLook Delegate
  701. - (void) previewControllerDidDismiss:(QLPreviewController *)controller {
  702. }
  703. /**
  704. * 文件内部链接点击不进行外部跳转
  705. */
  706. - (BOOL) previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id<QLPreviewItem>)item {
  707. return NO;
  708. }
  709. @end