123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634 |
- //
- // IncomeCountViewController.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/26.
- //
- #import "IncomeCountViewController.h"
- #import "IncomeCountTopView.h"
- #import <WebKit/WebKit.h>
- #import "KSMutilDatePicker.h"
- #import "IncomeCountBottomView.h"
- #import <AuthChallengeManager.h>
- // WKWebView 内存不释放的问题解决
- @interface KSWeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler>
- //WKScriptMessageHandler 这个协议类专门用来处理JavaScript调用原生OC的方法
- @property (nonatomic, weak) id<WKScriptMessageHandler> scriptDelegate;
- - (instancetype)initWithDelegate:(id<WKScriptMessageHandler>)scriptDelegate;
- @end
- @implementation KSWeakWebViewScriptMessageDelegate
- - (instancetype)initWithDelegate:(id<WKScriptMessageHandler>)scriptDelegate {
- self = [super init];
- if (self) {
- _scriptDelegate = scriptDelegate;
- }
- return self;
- }
- #pragma mark - WKScriptMessageHandler
- //遵循WKScriptMessageHandler协议,必须实现如下方法,然后把方法向外传递
- //通过接收JS传出消息的name进行捕捉的回调方法
- - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
-
- if ([self.scriptDelegate respondsToSelector:@selector(userContentController:didReceiveScriptMessage:)]) {
- [self.scriptDelegate userContentController:userContentController didReceiveScriptMessage:message];
- }
- }
- @end
- @interface IncomeCountViewController ()<WKUIDelegate,WKNavigationDelegate,WKScriptMessageHandler>
- @property (nonatomic, strong) IncomeCountTopView *topView;
- @property (nonatomic, strong) UIView *bottomView;
- @property (nonatomic, strong) WKWebView *myWebView;
- @property (nonatomic, strong) IncomeCountBottomView *roundView;
- @property (nonatomic, strong) WKWebView *bottomWebView;;
- @property (nonatomic, strong) NSURL *fileUrl;
- @property (nonatomic, strong) KSMutilDatePicker *datePicker;
- @property (nonatomic, strong) NSString *chooseDate;
- @property (nonatomic, strong) NSString *salary;
- @property (nonatomic, strong) NSString *total;
- @property (nonatomic, assign) BOOL isYear;
-
- @property (nonatomic, strong) NSArray *sourceArray;
- @property (nonatomic, assign) BOOL hasLoad;
- @property (nonatomic, strong) UIView *emptyView;
- @property (nonatomic, assign) CGFloat totalAmount;
- @property (nonatomic, strong) NSDictionary *parmDic;
- @end
- @implementation IncomeCountViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"收入统计"];
- [self configUI];
- [self requestData];
- }
- - (void)configUI {
- self.scrollView.backgroundColor = [UIColor clearColor];
- self.scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight- iPhoneXSafeBottomMargin);
- [self.scrollView addSubview:self.topView];
- [self.scrollView addSubview:self.myWebView];
-
- [self.scrollView addSubview:self.roundView];
- [self.roundView.bgView addSubview:self.bottomWebView];
- [self.bottomWebView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.bottom.left.mas_equalTo(self.roundView.bgView);
- }];
- [self.scrollView addSubview:self.bottomView];
- NSDate *currentDate = [NSDate date];
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy"];
- NSString *dateStr = [dateFormatter stringFromDate:currentDate];
- self.chooseDate = dateStr;
- self.topView.dateLabel.text = [NSString stringWithFormat:@"%@年", dateStr];
- self.isYear = YES;
-
- CGFloat height = CGRectGetMaxY(self.bottomView.frame) + 20;
- self.scrollView.contentSize = CGSizeMake(kScreenWidth, height);
- }
- - (void)showEmptyView:(BOOL)isShow {
- if (isShow) {
- if (![self.view.subviews containsObject:self.emptyView]) {
- [self.view addSubview:self.emptyView];
- }
- self.roundView.hidden = YES;
- }
- else {
- if ([self.view.subviews containsObject:self.emptyView]) {
- [self.emptyView removeFromSuperview];
- }
- self.roundView.hidden = NO;
- }
- }
- - (void)requestData {
- NSString *timeType = self.isYear ? @"YEAR" : @"MONTH";
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager accountTotalRequest:KS_POST dateTime:self.chooseDate timeType:timeType success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *returnValue = [dic ks_dictionaryValueForKey:@"data"];
- self.topView.totalSalary.text = [NSString formatMoneyDoubleNum:[returnValue ks_floatValueForKey:@"totalInAmount"]];
- NSArray *sourceArray = [returnValue ks_arrayValueForKey:@"infoList"];
- if (sourceArray != nil && sourceArray.count > 0) {
- [self showEmptyView:NO];
- if (self.hasLoad) {
- [self configMessage:sourceArray headSource:returnValue];
- }
- else {
- self.sourceArray = sourceArray;
- self.parmDic = returnValue;
- }
- }
- else {
- [self showEmptyView:YES];
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- }];
- }
- - (void)configMessage:(NSArray *)source headSource:(NSDictionary *)parmDic {
- // 顶部数据
- NSMutableArray *descArray = [NSMutableArray array];
- NSMutableArray *amountArray = [NSMutableArray array];
- NSMutableArray *rateArray = [NSMutableArray array];
- float practiceAmount = [parmDic ks_floatValueForKey:@"practiceAmount"];
- NSString *practiceDescString = @"陪练课";
- [descArray addObject:practiceDescString];
- [amountArray addObject:[NSString stringWithFormat:@"%.2f",practiceAmount]];
-
- float liveAmount = [parmDic ks_floatValueForKey:@"liveAmount"];
- NSString *liveDesc = @"直播课";
- [descArray addObject:liveDesc];
- [amountArray addObject:[NSString stringWithFormat:@"%.2f",liveAmount]];
-
- float videoAmount = [parmDic ks_floatValueForKey:@"videoAmount"];
- NSString *videoDesc = @"视频课";
- [descArray addObject:videoDesc];
- [amountArray addObject:[NSString stringWithFormat:@"%.2f",videoAmount]];
-
- float musicAmount = [parmDic ks_floatValueForKey:@"musicAmount"];
- NSString *musicDesc = @"乐谱";
- [descArray addObject:musicDesc];
- [amountArray addObject:[NSString stringWithFormat:@"%.2f",musicAmount]];
-
- [self.topView configSource:descArray amountArray:amountArray];
-
- float practiceRate = [parmDic ks_floatValueForKey:@"practiceRate"];
- [rateArray addObject:[NSString stringWithFormat:@"%.2f",practiceRate]];
-
- float liveRate = [parmDic ks_floatValueForKey:@"liveRate"];
- [rateArray addObject:[NSString stringWithFormat:@"%.2f",liveRate]];
-
- float videoRate = [parmDic ks_floatValueForKey:@"videoRate"];
- [rateArray addObject:[NSString stringWithFormat:@"%.2f",videoRate]];
-
- float musicRate = [parmDic ks_floatValueForKey:@"musicRate"];
- [rateArray addObject:[NSString stringWithFormat:@"%.2f",musicRate]];
-
- NSArray *colorArray = @[@"#5B8FF9",
- @"#2DC7AA",
- @"#91DD1C",
- @"#FFA92C"];
- // configSource:
- NSMutableArray *keyArray = [NSMutableArray array];
- NSMutableArray *valueArray = [NSMutableArray array];
-
- NSMutableArray *practiceArray = [NSMutableArray array];
- NSMutableArray *practiceAmountArray = [NSMutableArray array];
-
- NSMutableArray *liveArray = [NSMutableArray array];
- NSMutableArray *liveAmountArray = [NSMutableArray array];
-
- NSMutableArray *videoArray = [NSMutableArray array];
- NSMutableArray *videoAmountArray = [NSMutableArray array];
-
- NSMutableArray *musicArray = [NSMutableArray array];
- NSMutableArray *musicAmountArray = [NSMutableArray array];
- for (NSDictionary *dic in source) {
-
- float practiceAmount = [dic ks_floatValueForKey:@"practiceAmount"];
- NSString *practiceDescString = @"陪练课";
- [practiceAmountArray addObject:[NSString stringWithFormat:@"%.2f",practiceAmount]];
- [practiceArray addObject:practiceDescString];
-
- float liveAmount = [dic ks_floatValueForKey:@"liveAmount"];
- NSString *liveDesc = @"直播课";
- [liveAmountArray addObject:[NSString stringWithFormat:@"%.2f",liveAmount]];
- [liveArray addObject:liveDesc];
-
- float videoAmount = [dic ks_floatValueForKey:@"videoAmount"];
- NSString *videoDesc = @"视频课";
- [videoAmountArray addObject:[NSString stringWithFormat:@"%.2f",videoAmount]];
- [videoArray addObject:videoDesc];
-
- float musicAmount = [dic ks_floatValueForKey:@"musicAmount"];
- NSString *musicDesc = @"乐谱";
- [musicAmountArray addObject:[NSString stringWithFormat:@"%.2f",musicAmount]];
- [musicArray addObject:musicDesc];
- }
- [valueArray addObject:practiceAmountArray];
- [valueArray addObject:liveAmountArray];
- [valueArray addObject:videoAmountArray];
- [valueArray addObject:musicAmountArray];
-
- for (NSDictionary *dic in source) {
- NSString *bottomValue = @"";
- if (_isYear) {
- bottomValue = [NSString stringWithFormat:@"%@月",[[[dic ks_stringValueForKey:@"timeStr"] componentsSeparatedByString:@"-"] lastObject]];
- }
- else {
- bottomValue = [NSString stringWithFormat:@"%@日",[[[dic ks_stringValueForKey:@"timeStr"] componentsSeparatedByString:@"-"] lastObject]];
- }
- [keyArray addObject:bottomValue];
- }
-
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- [parm setValue:@{@"show":@(NO)} forKey:@"title"];
- [parm setValue:@{@"trigger": @"axis"} forKey:@"tooltip"];
- [parm setValue:@{@"show": @(NO)} forKey:@"legend"];
- [parm setValue:@{
- @"left": @"3%",
- @"right": @"5%",
- @"bottom": @"3%",
- @"containLabel": @(YES)
- } forKey:@"grid"];
- [parm setValue:@{
- @"type": @"category",
- @"boundaryGap": @(NO),
- @"data":keyArray,
- @"axisLine" : @{@"lineStyle":@{@"color": @"#8C8C8C",}},
- } forKey:@"xAxis"];
- [parm setValue:@{@"feature": @{@"saveAsImage": @{@"show":@(NO)}}} forKey:@"toolbox"];
- [parm setValue:@{@"type": @"value",
- @"splitLine":@{
- @"lineStyle":@{@"color": @[@"#E2E2E2"]},
- @"axisLine":@{@"lineStyle":@{@"color": @"#8C8C8C"}}
- },
- } forKey:@"yAxis"];
-
- [parm setValue:@{@"lineStyle":@{ @"width": @2}} forKey:@"emphasis"];
- [parm setValue:@[@{@"type" : @"inside",
- @"throttle" : keyArray.count > 15 ? @(50) : @(100),
- }] forKey:@"dataZoom"];
-
- NSMutableArray *fillColorArray = [NSMutableArray array];
- NSMutableArray *seriesArray = [NSMutableArray array];
- for (int i = 0; i < descArray.count && i < colorArray.count; i++) {
- NSString *fillColor = colorArray[i];
- [fillColorArray addObject:fillColor];
- NSArray *amountDetailArray = valueArray[i];
- NSString *desc = descArray[i];
- NSDictionary *serier = @{@"symbol":@"circle",
- @"name": desc,
- @"type": @"line",
- @"data": amountDetailArray,
- @"emphasis":@{@"lineStyle" : @{@"width": @1}},
- @"lineStyle":@{ @"width": @1},
- };
- [seriesArray addObject:serier];
- }
- // 根据返回数据生成颜色和显示数据
- [parm setValue:fillColorArray forKey:@"color"];
- [parm setValue:seriesArray forKey:@"series"];
-
- [self postMessage:parm inWebView:self.myWebView];
-
-
- NSMutableDictionary *secondParm = [NSMutableDictionary dictionary];
- [secondParm setValue:@{@"feature":@{@"saveAsImage":@{@"show":@(NO)}}}
- forKey:@"toolbox"];
- [secondParm setValue:@{@"borderWidth" : @0,
- @"formatter":@"{b} : {c} ({d}%)",
- @"padding":@3,
- @"position":@[@"30%",@"30%"],
- @"textStyle": @{@"fontSize": @12},
- @"trigger":@"item",
- }
- forKey:@"tooltip"];
-
- NSMutableArray *bottomFillColorArray = [NSMutableArray array];
- NSMutableArray *dataArray = [NSMutableArray array];
- for (int i = 0; i < descArray.count && i < colorArray.count; i++) {
-
- NSString *fillColor = colorArray[i];
- [bottomFillColorArray addObject:fillColor];
- NSString *desc = descArray[i];
- NSNumber *amount = amountArray[i];
- NSDictionary *data = @{@"name":desc,
- @"value":amount,
- };
- [dataArray addObject:data];
- }
-
- [secondParm setValue:fillColorArray forKey:@"color"];
- [secondParm setValue:@[@{@"type":@"pie",
- @"radius":@[@"50%",@"80%"],
- @"avoidLabelOverlap" : @(NO),
- @"label" : @{@"show": @(NO)},
- @"data" :dataArray}]
- forKey:@"series"];
- [self postMessage:secondParm inWebView:self.bottomWebView];
- [self.roundView configSource:descArray amountArray:rateArray];
- }
- - (void)postMessage:(NSDictionary *)parm inWebView:(WKWebView *)webView {
- NSString *jsString = [parm mj_JSONString];
- [webView evaluateJavaScript:[NSString stringWithFormat:@"loadEcharts('%@')", jsString] completionHandler:nil];
-
- }
- // 5 页面加载完成之后调用
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
- NSLog(@"5-------页面加载完成之后调用");
-
- if (_hasLoad == NO) {
- _hasLoad = YES;
- if (self.sourceArray != nil) {
- [self configMessage:self.sourceArray headSource:self.parmDic];
- }
- }
- }
- #pragma mark - WKScriptMessageHandler
- - (void)userContentController:(WKUserContentController *)userContentController
- didReceiveScriptMessage:(WKScriptMessage *)message {
-
- }
- - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *_Nullable))completionHandler
- {
- dispatch_queue_t queue = dispatch_queue_create("webViewChallengeQueue", NULL);
- dispatch_async(queue, ^{
- if (SSL_AUTH) {
- NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
- NSURLCredential *customCredential = nil;
-
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
- // 默认信任
- customCredential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
- disposition = NSURLSessionAuthChallengeUseCredential;
- }
- else if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]) {
- // client authentication
- SecIdentityRef identity = NULL;
- SecTrustRef trust = NULL;
- if ([AuthChallengeManager extractIdentity:&identity andTrust:&trust filePath:CERT_PATH]) {
- SecCertificateRef certificate = NULL;
- SecIdentityCopyCertificate(identity, &certificate);
- const void*certs[] = {certificate};
- CFArrayRef certArray =CFArrayCreate(kCFAllocatorDefault, certs,1,NULL);
- customCredential =[NSURLCredential credentialWithIdentity:identity certificates:(__bridge NSArray*)certArray persistence:NSURLCredentialPersistencePermanent];
- disposition = NSURLSessionAuthChallengeUseCredential;
- // 释放 CFArrayRef 和 SecCertificateRef
- CFRelease(certArray);
- CFRelease(certificate);
- }
- }
-
- if (completionHandler) {
- completionHandler(disposition, customCredential);
- }
- }
- else {
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
- if (challenge.previousFailureCount == 0) {
- NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
- completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
- } else {
- completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
- }
- }
- else {
- completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
- }
- }
- });
- }
- #pragma mark ---- lazying
- - (WKWebView *)myWebView {
- if (!_myWebView) {
- WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- config.selectionGranularity = WKSelectionGranularityDynamic;
- config.processPool = [IncomeCountViewController singleWkProcessPool];
- config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
- //自定义的WKScriptMessageHandler 是为了解决内存不释放的问题
- KSWeakWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[KSWeakWebViewScriptMessageDelegate alloc] initWithDelegate:self];
- //这个类主要用来做native与JavaScript的交互管理
- WKUserContentController * wkUController = [[WKUserContentController alloc] init];
- [wkUController addScriptMessageHandler:weakScriptMessageDelegate name:@"DAYA"];
- config.userContentController = wkUController;
-
- WKPreferences *preferences = [WKPreferences new];
- // 是否支出javaScript
- preferences.javaScriptEnabled = YES;
- //不通过用户交互,是否可以打开窗口
- preferences.javaScriptCanOpenWindowsAutomatically = YES;
- config.preferences = preferences;
- _myWebView = [[WKWebView alloc] initWithFrame:CGRectMake(12, 190, kScreenWidth - 24, 240) configuration:config];
- _myWebView.UIDelegate = self;
- _myWebView.navigationDelegate = self;
- _myWebView.scrollView.bounces = NO;
- [self loadSource];
-
- }
- return _myWebView;
- }
- - (WKWebView *)bottomWebView {
- if (!_bottomWebView) {
- WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- config.selectionGranularity = WKSelectionGranularityDynamic;
- config.processPool = [IncomeCountViewController singleWkProcessPool];
- config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
- //自定义的WKScriptMessageHandler 是为了解决内存不释放的问题
- KSWeakWebViewScriptMessageDelegate *weakScriptMessageDelegate = [[KSWeakWebViewScriptMessageDelegate alloc] initWithDelegate:self];
- //这个类主要用来做native与JavaScript的交互管理
- WKUserContentController * wkUController = [[WKUserContentController alloc] init];
- [wkUController addScriptMessageHandler:weakScriptMessageDelegate name:@"DAYA"];
- config.userContentController = wkUController;
-
- WKPreferences *preferences = [WKPreferences new];
- // 是否支出javaScript
- preferences.javaScriptEnabled = YES;
- //不通过用户交互,是否可以打开窗口
- preferences.javaScriptCanOpenWindowsAutomatically = YES;
- config.preferences = preferences;
- _bottomWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
- _bottomWebView.UIDelegate = self;
- _bottomWebView.navigationDelegate = self;
- _bottomWebView.scrollView.bounces = NO;
- [self loadBottomWebSource];
-
- }
- return _bottomWebView;
- }
- - (UIView *)emptyView {
- if (!_emptyView) {
- CGFloat width = kScreenWidth - 24;
- _emptyView = [[UIView alloc] initWithFrame:CGRectMake(12, 190, width, 240)];
- _emptyView.backgroundColor = [UIColor whiteColor];
- UIImageView *emptyImage = [[UIImageView alloc] initWithFrame:CGRectMake((width - 140) / 2.0f, 30, 140, 140)];
- [emptyImage setImage:[UIImage imageNamed:@"wd_img_zwsj"]];
- [_emptyView addSubview:emptyImage];
-
- UILabel *label = [[UILabel alloc] init];
- label.frame = CGRectMake(0, CGRectGetMaxY(emptyImage.frame)+10, width, 20);
- label.font = [UIFont systemFontOfSize:14.0f];
- label.textColor = HexRGB(0x999999);
- label.textAlignment = NSTextAlignmentCenter;
- label.numberOfLines = 1;
- label.text = @"暂无数据";
- [_emptyView addSubview:label];
- }
- return _emptyView;
- }
- - (void)loadSource {
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"stacked_line_chart" ofType:@"html"];
- [_myWebView loadFileURL:[NSURL fileURLWithPath:filePath] allowingReadAccessToURL:[NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]];
- }
- - (void)loadBottomWebSource {
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"stacked_line_chart" ofType:@"html"];
- [_bottomWebView loadFileURL:[NSURL fileURLWithPath:filePath] allowingReadAccessToURL:[NSURL fileURLWithPath:[NSBundle mainBundle].bundlePath]];
- }
- - (IncomeCountTopView *)topView {
- if (!_topView) {
- _topView = [IncomeCountTopView shareInstance];
- _topView.frame = CGRectMake(0, 0, kScreenWidth, 220);
- MJWeakSelf;
- [_topView chooseDateCallback:^{
- [weakSelf showPickerView];
- }];
- }
- return _topView;
- }
- - (IncomeCountBottomView *)roundView {
- if (!_roundView) {
- _roundView = [IncomeCountBottomView shareInstance];
- _roundView.frame = CGRectMake(12, CGRectGetMaxY(self.myWebView.frame), kScreenWidth - 24, 250);
- }
- return _roundView;
- }
- - (UIView *)bottomView {
- if (!_bottomView) {
- CGFloat width = kScreenWidth - 24;
- _bottomView = [[UIView alloc] init];
- _bottomView.frame = CGRectMake(12, CGRectGetMaxY(self.roundView.frame), width, 20);
- _bottomView.backgroundColor = [UIColor whiteColor];
- UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, width, 20) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = CGRectMake(0, 0, width, 20);
- maskLayer.path = path.CGPath;
- _bottomView.layer.mask = maskLayer;
- }
- return _bottomView;
- }
- - (KSMutilDatePicker *)datePicker {
- if (!_datePicker) {
- MJWeakSelf;
- // 最大时间 now
- // 最小时间 2021-03
- NSString *minLimitStr = @"2021-03";
- NSDateFormatter *outputFormatter = [NSObject getDateformatter];
- [outputFormatter setDateFormat:@"yyyy-MM"];
- NSDate *minDate = [outputFormatter dateFromString:minLimitStr];
- _datePicker = [[KSMutilDatePicker alloc] initWithTitle:@"选择时间" date:[NSDate date] maxLimitDate:[NSDate date] minLimitDate:minDate selectDateBlock:^(NSString * _Nonnull date, NSString * _Nonnull descDate) {
- [weakSelf.topView changeArrowStatus:NO];
- [weakSelf finishChooseDate:date disc:descDate];
- } cancleBolck:^{
- [weakSelf.topView changeArrowStatus:NO];
- }];
- }
- return _datePicker;
- }
- - (void)finishChooseDate:(NSString *)dateStr disc:(NSString *)descStr {
- self.topView.dateLabel.text = descStr;
- if ([dateStr containsString:@"-"]) {
- self.isYear = NO;
- self.chooseDate = dateStr;
- }
- else {
- self.isYear = YES;
- self.chooseDate = dateStr;
- }
- [self requestData];
- }
- - (void)showPickerView {
- [self.datePicker show];
- }
- + (WKProcessPool*)singleWkProcessPool {
- static WKProcessPool *sharedPool;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedPool = [[WKProcessPool alloc] init];
- });
- return sharedPool;
- }
- - (NSDictionary *)convertJsonStringToNSDictionary:(NSString *)jsonString {
- if (jsonString == nil) {
- return nil;
- }
- NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
- NSError *error;
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
- if (error) {
- NSLog(@"jsonString解析失败:%@", error);
- return nil;
- }
- return json;
- }
- - (void)dealloc {
- [[_myWebView configuration].userContentController removeScriptMessageHandlerForName:@"DAYA"];
- [_myWebView loadHTMLString:@"" baseURL:nil];
- [_myWebView removeFromSuperview];
- _myWebView = nil;
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
- [[NSURLCache sharedURLCache] setDiskCapacity:0];
- [[NSURLCache sharedURLCache] setMemoryCapacity:0];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|