组件化分享

2019-04-17  本文已影响0人  BoomLee

1.设计思想

1.1.为什么要做组件化
1.2.什么是组件化

顾名思义就是把一个大的 App 拆成一个个小的组件,相互之间不直接引用,然后通过主工程将项目所需要的组件组合起来

1.3.改造前的方案
1.4.改造后的方案

目前现有的业务已经稳定,各组件间的接口调用不会发生大的变化,所以可以进行大范围的改造。

2.一些概念

2.1. scheme

参考:易车平台化scheme规范
🌰:bitauto.yicheapp://yicheApp/carmodel/zongshu?carId=543&cityId=201
构成:scheme://host/path1/path2/...?query

2.2. category

3.实际应用

🌰:搜索模块结果页点击图集跳转到车型模块图集页

项目需要引入BPTRoute

pod 'BPTRoute'
一、响应方

首先创建车型模块的category库(目前放在了一起),创建BPTMediator的category

BPTMediator+BPChoseSelegate

实现接口

/**
 图集新

 @param param
  @{@"modelId":12367,   //车系id
   @"groupId":1,         //图集类型(1:外观  2:前排  3:后排  4:官方  5:图解)
   @"photoId":@"",      //选中图片Id
   @"styleId":@"",      //车款id
   @"colorId":@"",      //颜色id
   @"innerColorId":@""} //内饰颜色id
 
 Exampe:
 
 [BPTRouteShared bptRouteOpenUrl:@"bitauto.yicheapp://yicheApp/xuanche/galleryAggregate" query:@{@"modelId":@"",@"groupId":@""}];
 
 */
- (void)xuanchegalleryAggregate:(nullable NSDictionary *)param;

- (void)xuanchegalleryAggregate:(nullable NSDictionary *)param{
     [BPTRouteShared bptperformTarget:BPTMediatorBPTarget_CarModeler action:@"xuanchegalleryAggregate" params:param shouldCacheTarget:NO];
}

之后在车型模块创建target类BPTarget_CarModel,实现上面的actionxuanchegalleryAggregate。因为BPTarget_CarModel处于车型模块,所以可以处理所有车型模块相关业务

- (void)xuanchegalleryAggregate:(nullable NSDictionary *)param{
   [BPCJumpRouteManger chooseJumpCondeMage:BPCPhotoBrowserDetail dic:param other:nil];
}
二、调用方

调用方BPQSearchAllViewController引入BPTMediator

#import "BPTMediator+BPChoseSelegate.h"

点击图集时执行:openURL

[[BPTMediator sharedInstance] bptRouteOpenUrl:@"bitauto://yicheApp/xuanche/galleryAggregate"
                                          query:@{@"modelId":albumModel.serialId?:@"",
                                                  @"groupId":[BPQTool photoTypeWithPicType:@(phontoType)],
                                                  @"photoId":photoId?:@""}];

4.参考

上一篇 下一篇

猜你喜欢

热点阅读