|
| 1 | +// |
| 2 | +// DoraemonJavaScriptDetailViewController.m |
| 3 | +// DoraemonKit |
| 4 | +// |
| 5 | +// Created by carefree on 2022/5/11. |
| 6 | +// |
| 7 | + |
| 8 | +#import "DoraemonJavaScriptDetailViewController.h" |
| 9 | +#import "DoraemonKit.h" |
| 10 | +#import "DoraemonDefine.h" |
| 11 | +#import "DoraemonToastUtil.h" |
| 12 | +#import "DoraemonCacheManager.h" |
| 13 | +#import "DoraemonJavaScriptManager.h" |
| 14 | + |
| 15 | +@interface DoraemonJavaScriptDetailViewController () |
| 16 | + |
| 17 | +@property (nonatomic, weak) UITextView *textView; |
| 18 | + |
| 19 | +@end |
| 20 | + |
| 21 | +@implementation DoraemonJavaScriptDetailViewController |
| 22 | + |
| 23 | +- (void)viewDidLoad { |
| 24 | + [super viewDidLoad]; |
| 25 | + |
| 26 | + self.title = DoraemonLocalizedString(@"脚本执行"); |
| 27 | + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(runScript)]; |
| 28 | + UIEdgeInsets edge = UIEdgeInsetsMake(10, 10, 0, 10); |
| 29 | + CGFloat width = self.view.bounds.size.width - edge.left - edge.right; |
| 30 | + CGFloat height = self.view.bounds.size.height - edge.top - edge.bottom; |
| 31 | + UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(edge.left, edge.top + IPHONE_NAVIGATIONBAR_HEIGHT, width, 30)]; |
| 32 | + titleLabel.text = DoraemonLocalizedString(@"JS代码"); |
| 33 | + |
| 34 | + UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(edge.left, CGRectGetMaxY(titleLabel.frame) + edge.top, width, height - 200)]; |
| 35 | + textView.layer.borderWidth = 1 / UIScreen.mainScreen.scale; |
| 36 | + textView.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
| 37 | + textView.layer.cornerRadius = 6; |
| 38 | + textView.font = [UIFont systemFontOfSize:16]; |
| 39 | + textView.textContainerInset = UIEdgeInsetsMake(8, 3, 8, 3); |
| 40 | + |
| 41 | + [self.view addSubview:titleLabel]; |
| 42 | + [self.view addSubview:textView]; |
| 43 | + self.textView = textView; |
| 44 | + |
| 45 | + if (self.key.length > 0) { |
| 46 | + self.textView.text = [DoraemonCacheManager.sharedInstance jsHistoricalRecordForKey:self.key]; |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +#pragma mark - Private |
| 51 | +- (void)runScript { |
| 52 | + NSString *value = self.textView.text; |
| 53 | + if (value.length == 0) { |
| 54 | + [DoraemonToastUtil showToastBlack:@"脚本不能为空" inView:self.view]; |
| 55 | + return; |
| 56 | + } |
| 57 | + [DoraemonCacheManager.sharedInstance saveJsHistoricalRecordWithText:value forKey:self.key]; |
| 58 | + [DoraemonManager.shareInstance hiddenHomeWindow]; |
| 59 | + [DoraemonJavaScriptManager.shareInstance evalJavaScript:value]; |
| 60 | +} |
| 61 | + |
| 62 | +@end |
0 commit comments