123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- //
- // NYFailSpecialExerciseDetailsViewModel.m
- // jiaPei
- //
- // Created by Ning.ge on 2024/12/12.
- // Copyright © 2024 JCZ. All rights reserved.
- //
- #import "NYFailSpecialExerciseDetailsViewModel.h"
- #import "RQVideoModule.h"
- @interface NYFailSpecialExerciseDetailsViewModel ()
- @property (nonatomic, readwrite, assign) RQHomePageSubjectType homePageSubjectType;
- @property (nonatomic, readwrite, strong) NSDictionary *dataDicts;
- @property (nonatomic, readwrite, strong) NSDictionary *titleDict;
- @property (nonatomic, readwrite, strong) NSMutableDictionary *datakeyDicts;
- @end
- @implementation NYFailSpecialExerciseDetailsViewModel
- #pragma mark - Public Method
- - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params {
- if (self = [super initWithServices:services params:params]) {
- self.homePageSubjectType = [params[RQHomePageSubjectTypeKey] integerValue];
- self.title = params[RQHomePageSpTitleKey];
- }
- return self;
- }
- - (void)initialize {
- [super initialize];
- [self loadPointData];
- [self loadKeyDicts];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self rq_configureData];
- });
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self postVideoDate];
- });
-
- }
- - (void)postVideoDate {
- NYFailSpecialVideoGroupViewModel *model = [self.dataSource firstObject];
- if(model.videoDate.vipPublicityMediumUrl.length>0){
- VideosItem *videosItem = [[VideosItem alloc ] init];
- videosItem.video_url = model.videoDate.vipPublicityMediumUrl;
- videosItem.coverFileUrl = model.videoDate.poster;
- videosItem.title = model.videoDate.endButtonText;
- videosItem.videoDescribe = model.videoDate.endButtonText;
- videosItem.videoType = RQVideoType_Default;
- videosItem.permission = 1;
- videosItem.subject = 0;//科目一
- [RQNotificationCenter postNotificationName:RQPlayVideoUrlNotification object:@{
- RQPlayVideoItemKey : videosItem,
- RQPlayVideoItemArrKey : @[videosItem],
- }];
- }
- }
- #pragma mark - ConfigureData
- - (void)rq_configureData {
- /// 数据源
- RAC(self, dataSource) = [RACSignal
- combineLatest:@[RACObserve(RQ_USER_MANAGER, isCykh)]
- reduce:^(NSNumber *isCykh) {
- NYFailSpecialVideoGroupViewModel *group0 = [NYFailSpecialVideoGroupViewModel groupViewModel];
- NSString *keyStr = self.titleDict[self.title];
- NYFailGroupPointDataModel *model = self.datakeyDicts[keyStr];
- group0.videoDate = model.videoDate;
- if(model.videoDate.vipPublicityMediumUrl.length>0){
- group0.headerHeight = RQ_FIT_HORIZONTAL(218);
- }else{
- group0.headerHeight = 0;
- }
-
- //[NYFailGroupPointDataModel modelWithDictionary:self.dataDicts[keyStr]];
- NSMutableArray *mt_array = @[].mutableCopy;//解析json 数据daocell
- if(model){
- int indx = 1;
- for (NYFailItemPointDataModel *item in model.pointData) {
- NYFailSpecialExerciseDetailItemModel *itemModel = [[NYFailSpecialExerciseDetailItemModel alloc] initWithTitle:keyStr dataModel:item];
- itemModel.itemPointTitle = [NSString stringWithFormat:@"考点%d",indx];
- [mt_array addObject:itemModel];
- indx++;
- }
- }
- group0.itemViewModels = mt_array;
- return @[group0];
- }];
- }
- - (void)loadKeyDicts {
- // @weakify(self)
- if(self.datakeyDicts.count>0)return;
- self.datakeyDicts = [NSMutableDictionary dictionary];
- for (NSString *key in self.titleDict.allKeys) {
- NSString *key_value = self.titleDict[key];
- NYFailGroupPointDataModel *model = [NYFailGroupPointDataModel modelWithDictionary:self.dataDicts[key_value]];
- for (NYFailItemPointDataModel *item in model.pointData) {
- if(item.showType.intValue == 1) continue;
- if(item.con.count>0){//手势
- __block CGFloat itop_yOffset = 0; // 初始偏移量
- __block CGFloat yOffset = 0; // 初始偏移量
- __block CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整)
- CGFloat imgW = (RQ_SCREEN_WIDTH-22*2);
- for (int i= 0; i<item.con.count; i++) {
- NYFailItemPointDataCon *con = item.con[i];
- if(![con.title isEqualToString:@""]){
- itop_yOffset += cellHeight;
- item.iviewH += itop_yOffset;
- NSString *img_url = con.image;
- if(img_url.length>0){
- __block CGSize imageSize = CGSizeMake(imgW,cellHeight);
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- // 处理耗时操作的代码块...
- imageSize = [UIImage getImageSizeWithURL:img_url];
- //通知主线程刷新
- dispatch_async(dispatch_get_main_queue(), ^{
- //回调或者说是通知主线程刷新,
- if (imageSize.width == 0 || imageSize.height == 0) {
- cellHeight = imgW * (175.f / 345.f);
- } else {
- cellHeight = imgW * (imageSize.height / imageSize.width);
- }
- yOffset += cellHeight;
- item.imgsH = yOffset;
- });
- });
- item.imgsH = yOffset;
- }
- }
- if(con.questions.count>0){
- CGFloat cellH = 0.f;
- for(int z = 0; z<con.questions.count; z++){//文字 + 图片
- NYFailItemPointDataQuesImage *img = con.questions[z];
- NSString *title_str = img.subTitle;
- NSString *img_url = img.image;
- if(title_str.length>0){
- cellH +=35.f;
- }
- if(img_url.length>0){
- __block CGSize imageSize = CGSizeMake(imgW,cellHeight);
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- // 处理耗时操作的代码块...
- imageSize = [UIImage getImageSizeWithURL:img_url];
- //通知主线程刷新
- dispatch_async(dispatch_get_main_queue(), ^{
- //回调或者说是通知主线程刷新,
- if (imageSize.width == 0 || imageSize.height == 0) {
- cellHeight = imgW * (175.f / 345.f);
- } else {
- cellHeight = imgW * (imageSize.height / imageSize.width);
- }
- yOffset += cellHeight+12.f;
- item.imgsH = yOffset+60.f;
- });
- });
- item.imgsH = yOffset;
- }
- }
- // item.iviewH = cellH + 45.f;
- }
-
- }
-
- }
- if(item.tagquestions.count>0){//拘留
- CGFloat cellH = 0.f;
- for (int i= 0; i<item.tagquestions.count; i++) {
- NYFailItemPointDataQuestions *itemData = item.tagquestions[i];
- NSLog(@"tag=========%@",itemData.tag);
- for (int z= 0; z<itemData.tagCon.count; z++) {
- NYFailItemPointDataQuesTexts *texts = itemData.tagCon[z];
- NSString *title_str = texts.subTitle;
- CGSize str_size = [title_str rq_sizeWithFont:[UIFont boldSystemFontOfSize:15.f] limitWidth:(RQ_SCREEN_WIDTH-22*2)];
- if(str_size.height>cellH){
- cellH += str_size.height + 12.f;
- }else{
- cellH +=35.f;
- }
- if(texts.quesItem.count>0){
- cellH += 22.f*texts.quesItem.count;
- }
- }
- }
- item.iviewH = cellH + 45.f+45.f*item.tagquestions.count;
- }
- if(item.iquestions.count>0){//拘留
- __block CGFloat yOffset = 0; // 初始偏移量
- __block CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整)
- CGFloat imgW = (RQ_SCREEN_WIDTH-22*2);
- for (int i= 0; i<item.iquestions.count; i++) {
- NYFailItemPointDataQuesImage *img = item.iquestions[i];
- NSString *img_url = img.image;
- __block CGSize imageSize = CGSizeMake(imgW,cellHeight);
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- // 处理耗时操作的代码块...
- imageSize = [UIImage getImageSizeWithURL:img_url];
- //通知主线程刷新
- dispatch_async(dispatch_get_main_queue(), ^{
- //回调或者说是通知主线程刷新,
- if (imageSize.width == 0 || imageSize.height == 0) {
- cellHeight = imgW * (175.f / 345.f);
- } else {
- cellHeight = imgW * (imageSize.height / imageSize.width);
- }
- yOffset += cellHeight+4.f;
- item.imgsH = yOffset;
- });
- });
- }
- }
- if(item.fquestions.count>0){//罚款//周期
- CGFloat cellH = 0.f;
- for (int i= 0; i<item.fquestions.count; i++) {
- NYFailItemPointDataQuesTexts *texts = item.fquestions[i];
- NSString *title_str = texts.subTitle;
- CGSize str_size = [title_str rq_sizeWithFont:[UIFont boldSystemFontOfSize:15.f] limitWidth:(RQ_SCREEN_WIDTH-22*2)];
- if(str_size.height>cellH){
- cellH += str_size.height + 12.f;
- }else{
- cellH +=35.f;
- }
- if(texts.quesItem.count>0){
- cellH += 22.f*texts.quesItem.count;
- }
- }
- item.iviewH = cellH + 20.f;
- }
- if(item.questions.quesTexts.count>0){
- CGFloat cellH = 0.f;
- for (int i= 0; i<item.questions.quesTexts.count; i++) {
- NYFailItemPointDataQuesTexts *texts = item.questions.quesTexts[i];
- NSString *title_str = texts.subTitle;
- CGSize str_size = [title_str rq_sizeWithFont:[UIFont boldSystemFontOfSize:15.f] limitWidth:(RQ_SCREEN_WIDTH-22*2)];
- if(str_size.height>cellH){
- cellH += str_size.height + 12.f;
- }else{
- cellH +=35.f;
- }
- if(texts.quesItem.count>0){
- cellH += 22.f*texts.quesItem.count;
- }
- }
- item.iviewH = cellH + 20.f;
- }
- if(item.questions.images.count > 0){
- __block CGFloat yOffset = 0; // 初始偏移量
- __block CGFloat cellHeight = 35.f; // 每个 Cell 的高度(根据实际设计调整)
- CGFloat imgW = (RQ_SCREEN_WIDTH-22*2);
- for (int i= 0; i<item.questions.images.count; i++) {
- NSString *img_url = item.questions.images[i];
- __block CGSize imageSize = CGSizeMake(imgW,cellHeight);
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- // 处理耗时操作的代码块...
- imageSize = [UIImage getImageSizeWithURL:img_url];
- //通知主线程刷新
- dispatch_async(dispatch_get_main_queue(), ^{
- //回调或者说是通知主线程刷新,
- if (imageSize.width == 0 || imageSize.height == 0) {
- cellHeight = imgW * (175.f / 345.f);
- } else {
- cellHeight = imgW * (imageSize.height / imageSize.width);
- }
- yOffset += cellHeight;
- item.imgsH = yOffset;
- });
- });
- }
- }
- }
- self.datakeyDicts[key_value] = model;
- }
- }
- // 加载 JSON 文件并解析
- - (void)loadPointData {
- // 获取资源文件路径
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"pointData" ofType:@"json"];
- if (filePath) {
- // 读取文件数据
- NSData *data = [NSData dataWithContentsOfFile:filePath];
- if (data) {
- NSError *error = nil;
- // 使用 JSONSerialization 解析 JSON 数据
- self.dataDicts = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
- NSLog(@"%@",self.dataDicts.allKeys);
- if (error) {
- NSLog(@"JSON解析错误: %@", error.localizedDescription);
- }
- } else {
- NSLog(@"文件读取失败");
- }
- } else {
- NSLog(@"文件路径未找到");
- }
- }
- - (NSDictionary *)titleDict{
- if(!_titleDict){
- _titleDict = @{@"扣分":@"koufen",
- @"驾驶证":@"jiashizheng",
- @"罚款":@"fakuan",
- @"判刑扣留":@"juliu",
- @"安全常识":@"anquanchangshi",
- @"交警手势":@"shoushi",
- @"周期":@"zhouqi",
- @"特殊天气":@"tianqi",
- @"速度灯光":@"dengguang",
- @"通行原则":@"tongxing"};
- }
- return _titleDict;
- }
- @end
|