123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- //
- // NYExaminationRoomViewController.m
- // jiaPei
- //
- // Created by Ning.ge on 2024/10/17.
- // Copyright © 2024 JCZ. All rights reserved.
- //
- #import "NYExaminationRoomViewController.h"
- #import "NYChartView.h"
- #import "NYQuestionContentView.h"
- @interface NYExaminationRoomViewController ()
- @property (weak, nonatomic) IBOutlet UIView *content_view;
- @property (weak, nonatomic) IBOutlet UIView *content01_view;
- @property (weak, nonatomic) IBOutlet UIView *right_view;
- @property (weak, nonatomic) IBOutlet UIView *center_view;
- @property (weak, nonatomic) IBOutlet UIView *right_bk_view;
- @property (weak, nonatomic) IBOutlet UIView *bottom_view;
- @property (weak, nonatomic) IBOutlet UIImageView *usericon_view;
- @property (weak, nonatomic) IBOutlet UILabel *username_label;
- @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
- @property (weak, nonatomic) IBOutlet UILabel *sex_label;
- @property (weak, nonatomic) IBOutlet UILabel *type_label;
- @property (weak, nonatomic) IBOutlet UILabel *km_label;
- @property (weak, nonatomic) IBOutlet UILabel *showtips_label;
- @property (weak, nonatomic) IBOutlet UIButton *previous_btn;
- @property (weak, nonatomic) IBOutlet UIButton *next_btn;
- @property (weak, nonatomic) IBOutlet UIButton *submit_btn;
- @property (weak, nonatomic) IBOutlet UIButton *image_btn;
- @property (weak, nonatomic) IBOutlet UIButton *image_big_btn;
- @property (nonatomic,weak) NYChartMatrixView *chartMatrixView;
- @property (nonatomic,strong) NYQuestionContentView *questionContentView;
- @property (nonatomic,strong) NYExaminationTipsViewController *examinationTipsViewController;
- @property (nonatomic,strong) NSArray *exercise_array;
- @property (nonatomic,assign) int index;
- //成绩
- @property (nonatomic,assign) NSInteger score;
- @end
- @implementation NYExaminationRoomViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- self.previous_btn.layer.borderWidth = 1.0f;
- self.previous_btn.layer.borderColor = UIColorHex(0x9A9B9D).CGColor;
- self.next_btn.layer.borderWidth = 1.0f;
- self.next_btn.layer.borderColor = UIColorHex(0x9A9B9D).CGColor;
- self.submit_btn.layer.borderWidth = 1.0f;
- self.submit_btn.layer.borderColor = UIColorHex(0x9A9B9D).CGColor;
-
- self.content01_view.layer.borderWidth = 1.0f;
- self.content01_view.layer.borderColor = UIColorHex(0xD9D9D9).CGColor;
- [self enterLandscapeFullScreen:UIInterfaceOrientationLandscapeLeft animated:YES];
- [self.view setNeedsLayout];
- [self.view layoutIfNeeded];
- [self initYDTQuestiondata];
- [self setUserLeft];
- [self setRightChartView];
- [self setupTimeLabel];
- [self setQuestionContentView];
- [self exerciseLoadData];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(optionDTNotification:) name:NYExerciseOptionDTNotification object:nil];
-
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)initYDTQuestiondata{
- self.score = 0;
- NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
- __block NSInteger num = 0;
- arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
- ydtQuestionModel.num = num;
- num ++;
- return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
- }].toArray;
- self.exercise_array = arr;
- self.index = 0;
- }
- - (void)exerciseLoadData{
- self.previous_btn.selected = NO;
- self.next_btn.selected = NO;
- self.previous_btn.userInteractionEnabled = YES;
- self.next_btn.userInteractionEnabled = YES;
- if(self.exercise_array.count>0){
- RQExerciseModel *exercise = self.exercise_array[self.index];
- [self.questionContentView readLodData:exercise];
- [self imageLoadData:exercise];
- [self showtipsLoadData:exercise];
- [self rightLoadData];
- }
- if(self.index==0){
- self.previous_btn.selected = YES;
- self.previous_btn.userInteractionEnabled = NO;
- self.next_btn.userInteractionEnabled = YES;
- }
- if(self.index==self.exercise_array.count-1){
- self.next_btn.selected = YES;
- self.previous_btn.userInteractionEnabled = YES;
- self.next_btn.userInteractionEnabled = NO;
- }
- }
- - (void)rightLoadData{
- self.chartMatrixView.selectIndex = self.index;
- }
- - (void)showtipsLoadData:(RQExerciseModel *)exerciseModel{
- NSString *typeString = @"";
- switch (exerciseModel.ydtQuestionModel.Type) {
- case 1:
- typeString = @"判断题";
- break;
- case 2:
- typeString = @"单选题";
- break;
- case 3:
- typeString = @"多选题";
- break;
- default:
- typeString = @"";
- break;
- }
- self.showtips_label.text = [NSString stringWithFormat:@"操作提示:%@",typeString];
- }
- - (void)imageLoadData:(RQExerciseModel *)exerciseModel{
- self.image_btn.hidden = YES;
- NSString *imageString = @"";
- if (RQStringIsNotEmpty(exerciseModel.ydtQuestionModel.media_url)) {
- if (RQStringIsNotEmpty(exerciseModel.ydtQuestionModel.sinaimg)) {
- imageString = exerciseModel.ydtQuestionModel.media_url;
- } else if (RQStringIsNotEmpty(exerciseModel.ydtQuestionModel.video_url)) {
- imageString = @"";
- } else {
- imageString = @"";
- }
- } else {
- imageString = @"";
- }
- if (RQStringIsNotEmpty(exerciseModel.ydtQuestionModel.sinaimg) || RQStringIsNotEmpty(exerciseModel.ydtQuestionModel.media_url)) {
- if (!RQObjectIsNil(exerciseModel.ydtQuestionModel.media_content)) {
- NSString *imageStr = [exerciseModel.ydtQuestionModel.media_content base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
- UIImage *sinaImage = [UIImage sd_imageWithData:[NSData dataWithBase64EncodedString:imageStr] scale:1 firstFrameOnly:YES];
- exerciseModel.ydtQuestionModel.sinaImage = sinaImage;
- } else {
- NSString *media_name;
- if(RQStringIsNotEmpty(exerciseModel.ydtQuestionModel.sinaimg)){//不为空
- media_name = exerciseModel.ydtQuestionModel.sinaimg;
- imageString = exerciseModel.ydtQuestionModel.sinaimg;
- }else{
- if ([exerciseModel.ydtQuestionModel.media_url containsString:@"https://"]) {
- media_name = [exerciseModel.ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
- }
- }
- //本地无数据-使用网络url-本地图片有水印 直接用url
- imageString = exerciseModel.ydtQuestionModel.media_url;
- }
-
- }
- if (RQStringIsNotEmpty(imageString)) {
- self.image_btn.hidden = NO;
- [self.image_btn yy_setImageWithURL:[NSURL URLWithString:imageString] forState:UIControlStateNormal placeholder:RQWebImagePlaceholder()];
- [self.image_big_btn yy_setImageWithURL:[NSURL URLWithString:imageString] forState:UIControlStateNormal placeholder:RQWebImagePlaceholder()];
- }
- }
- - (void)setUserLeft {
- @weakify(self)
- NSArray *titls = @[@"科目一",@"科目二",@"科目三",@"科目四"];
- self.usericon_view.layer.cornerRadius = 58*0.5;
- self.usericon_view.layer.masksToBounds = YES;
- [self.usericon_view yy_setImageWithURL:[NSURL URLWithString:RQ_USER_MANAGER.currentUser.photo] placeholder:RQWebAvatarImagePlaceholder() options:RQWebImageOptionAutomatic completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
- @strongify(self);
- if(image) {
- image = [image qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(54.f), RQ_FIT_HORIZONTAL(54.f)) resizingMode:QMUIImageResizingModeScaleAspectFill];
- image = [image qmui_imageWithBorderColor:UIColor.whiteColor borderWidth:1 cornerRadius:RQ_FIT_HORIZONTAL(54.f) / 2.f];
- self.usericon_view.image = image;
- }
- }];
- self.username_label.text = [NSString stringWithFormat:@"考生姓名:%@",RQ_USER_MANAGER.currentUser.userName];
- NSString *sexStr = @"女";
- if([RQ_USER_MANAGER.currentUser.sex isEqualToString:@"1"]){
- sexStr = @"男";
- }
- self.sex_label.text = [NSString stringWithFormat:@"性别:%@",sexStr];
- self.type_label.text = [NSString stringWithFormat:@"考试类型:%@",RQ_USER_MANAGER.currentUser.carType];
- self.km_label.text = [NSString stringWithFormat:@"科目:%@",titls[RQ_YDTQuestion_Module.subject]];
-
- }
- //题目-tableview
- - (void)setQuestionContentView {
- NYQuestionContentView *questionContentView = [[NYQuestionContentView alloc] init];
- [self.center_view addSubview:questionContentView];
- self.questionContentView = questionContentView;
- [questionContentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.center_view);
- make.bottom.mas_equalTo(self.bottom_view.mas_top);
- }];
- }
- - (void)setRightChartView {
- NSMutableArray *dataSource = [NSMutableArray array];
- UIColor *color = UIColorHex(0x3D3C38);
- for (int i=0; i<self.exercise_array.count; i++) {
- NSString *count = [NSString stringWithFormat:@"%d",i+1];
- [dataSource addObject:@{
- @"count":count,
- @"color":color
- }];
- }
- @weakify(self)
- NYChartMatrixView *chartMatrixView = [[NYChartMatrixView alloc] init];
- chartMatrixView.dataSource = dataSource;
- chartMatrixView.matrixItemClickBlock = ^(id _Nonnull obj, int index) {
- NSLog(@"点击了 cell=%@ index=%d",obj,index);
- @strongify(self)
- self.index = index;
- [self exerciseLoadData];
- };
- [self.right_bk_view addSubview:chartMatrixView];
- self.chartMatrixView = chartMatrixView;
- [chartMatrixView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self.right_bk_view);
- // make.centerY.mas_equalTo(self.view.mas_centerY);
- // make.height.mas_equalTo(KRealValue(401-20));
- }];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [chartMatrixView loadView];
- chartMatrixView.selectIndex = 0;
- });
- }
- //右-刷新
- - (void)rightChartViewLoadData {
- NSMutableArray *dataSource = [NSMutableArray array];
- for (int i=0; i<self.exercise_array.count; i++) {
- NSString *count = [NSString stringWithFormat:@"%d",i+1];
- RQExerciseModel *exercise = self.exercise_array[i];
- UIColor *color = UIColorHex(0x3D3C38);
- if(exercise.answerResultsType != RQAnswerResultsType_Unanswered) {//已答题
- count = [exercise.userAnswerStr stringByReplacingOccurrencesOfString:@"," withString:@""];
- if(exercise.answerResultsType == RQAnswerResultsType_Error) { // 回答错误
- color = UIColorHex(0xBC322D);
- }
- }
- [dataSource addObject:@{
- @"count":count,
- @"color":color
- }];
- }
- self.chartMatrixView.dataSource = dataSource;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.chartMatrixView loadView];
- });
- }
- - (void)setupTimeLabel{
- RQ_Exercise_Module.count = 45 * 60;
- [RQ_Exercise_Module startTimer];
- RAC(_timeLabel, text) = [RACObserve(RQ_Exercise_Module, count) map:^id _Nullable(id _Nullable value) {
- NSUInteger sec = RQ_Exercise_Module.count%60;
- NSUInteger min = RQ_Exercise_Module.count/60;
- NSString* sec0,*min0;
- sec0 = sec<10 ? @"0" : @"";
- min0 = min<10 ? @"0" : @"";
- return [NSString stringWithFormat:@"%@%lu:%@%lu",min0,(unsigned long)min,sec0,(unsigned long)sec];
- }];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.navigationController.navigationBar setHidden:YES];
- if (RQ_Exercise_Module.timer) {
- [RQ_Exercise_Module.timer setFireDate:[NSDate distantPast]];
- }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- if(!RQ_Exercise_Module.isShow_CatalogueView){
- if (RQ_Exercise_Module.timer) {
- [RQ_Exercise_Module.timer setFireDate:[NSDate distantFuture]];
- }
- }
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
- if(!RQ_Exercise_Module.isShow_CatalogueView){
- [RQ_Exercise_Module.timer invalidate];
- RQ_Exercise_Module.timer = nil;
- RQ_Exercise_Module.count = 0;
- RQ_Exercise_Module.beginDate = nil;
- }
- }
- - (NYExaminationTipsViewController *)examinationTipsViewController {
- if(!_examinationTipsViewController){
- _examinationTipsViewController = [[NYExaminationTipsViewController alloc ]init];
- }
- return _examinationTipsViewController;
- }
- - (IBAction)backAtciondo:(id)sender {
- [self.examinationTipsViewController showTypeTipsView:3 invView:self.view inModel:nil];
- }
- - (void)gobackAtciondo{
- [self.navigationController.navigationBar setHidden:NO];
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- - (void)enterLandscapeFullScreen:(UIInterfaceOrientation)orientation animated:(BOOL)animated {
- [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationUnknown] forKey:@"orientation"];
- NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
- [[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
- }
- //支持的方向
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;
- }
- - (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
- {
- return UIInterfaceOrientationPortrait;
- }
- #pragma mark ######事件######
- //上一题
- - (IBAction)previousActiondo:(id)sender {
- if(self.index<0)return;
- self.index--;
- [self exerciseLoadData];
- }
- //下一题
- - (IBAction)nextActiondo:(id)sender {
- if(self.index>self.exercise_array.count)return;
- self.index++;
- [self exerciseLoadData];
- }
- //交卷
- - (IBAction)submitActiondo:(id)sender {
- // self.exerciseModel.answerResultsType = RQAnswerResultsType_Error;
- NSPredicate *predicateE = [NSPredicate predicateWithFormat:@"answerResultsType == %@", @(RQAnswerResultsType_Error)];
- NSUInteger errorCount = [[self.exercise_array filteredArrayUsingPredicate:predicateE] count];
- NSPredicate *predicateC = [NSPredicate predicateWithFormat:@"answerResultsType == %@", @(RQAnswerResultsType_Correct)];
- NSUInteger correctount = [[self.exercise_array filteredArrayUsingPredicate:predicateC] count];
-
- NSInteger totalNum = self.exercise_array.count;
- NSInteger errorNum = errorCount;
- NSInteger rightNum = correctount;
- NSInteger hasdoNum = errorNum + rightNum;
- NSInteger undoNum = totalNum - hasdoNum;
- NSInteger perScore = 100 / totalNum;
- NSInteger score = rightNum * perScore;
- CGFloat progress = (hasdoNum * 1.00) / (totalNum * 1.00);
- BOOL isSuccess = (score >= 90);
- self.score = score;
-
- self.examinationTipsViewController.t1_centont_label.text = [NSString stringWithFormat:@"你当前考试答对%zd题,答错%zd题,未答%zd题",rightNum,errorNum,undoNum];
- self.examinationTipsViewController.t2_centont_label.text = isSuccess ? [NSString stringWithFormat:@"您本次模拟考试得%zd分。恭喜您及格了!",score]:[NSString stringWithFormat:@"您本次模拟考试得%zd分。不及格!祝你下次考试成功!",score];
- [self.examinationTipsViewController showTypeTipsView:1 invView:self.view inModel:nil];
- }
- //放大图片
- - (IBAction)imageBigActiondo:(UIButton *)sender {
- self.image_big_btn.hidden = ! self.image_big_btn.hidden;
- }
- //通知-事件-答题结果-交卷
- - (void)optionDTNotification:(NSNotification*)notif{
- int type = [notif.object intValue];
- if(type==0){//答对了
- [self nextActiondo:nil];//进入下一题
- [self rightChartViewLoadData];
- }else if(type==1){//答错了
- RQExerciseModel *exercise = self.exercise_array[self.index];
- [self.examinationTipsViewController showTypeTipsView:0 invView:self.view inModel:exercise];
- [self rightChartViewLoadData];
- }else if(type==2){//交卷
- NSUInteger sec = RQ_Exercise_Module.count%60;
- NSUInteger min = RQ_Exercise_Module.count/60;
- NSString* sec0,*min0;
- sec0 = sec<10 ? @"0" : @"";
- min0 = min<10 ? @"0" : @"";
- //提交做题记录
- NSInteger allTimeCount = (RQ_YDTQuestion_Module.carType == RQHomePageCarType_Motorcycle)? 30 * 60 : 45 * 60;
- NSInteger useCount = allTimeCount - min * 60 - sec;
- NSString *beginDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:RQ_Exercise_Module.beginDate];
- NSDate *endDte = [NSDate dateWithTimeInterval:useCount sinceDate:RQ_Exercise_Module.beginDate];
- NSString *endDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:endDte];
- @weakify(self)
- [[[RQ_HTTP_Service saveFavQuestionWithScore:self.score startDate:beginDateStr endDate:endDateStr] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
- NSLog(@"交卷成功-成绩%zd",self.score);
- } error:^(NSError * _Nullable error) {
- NSLog(@"交卷失败-成绩%zd",self.score);
- }];
- [self.examinationTipsViewController showTypeTipsView:2 invView:self.view inModel:nil];
- }else if(type==3){//关闭退出
- [self gobackAtciondo];
- }
- }
- @end
|