浏览代码

完成添加房间获取设备列表的主体结构及接口调试,剩余列表 UI 未完成。

Kevin 1 年之前
父节点
当前提交
cac344f5f9

+ 4 - 2
Temperature/AppConfig/RDSConfig.h

@@ -24,8 +24,10 @@
 #define kBaseUrlHeadImg_test      @"http://yongxu.yehaoji.cn:18199" // 头像地址
 
 // 生产环境
-#define kBaseUrlHost        @"https://app.yongxulvjian.com/api/v1"
-#define kBaseUrlHeadImg     @"https://app.yongxulvjian.com"
+//#define kBaseUrlHost        @"https://app.yongxulvjian.com/api/v1"
+//#define kBaseUrlHeadImg     @"https://app.yongxulvjian.com"
+#define kBaseUrlHost        @"http://114.115.251.196:8299/api/v1"
+#define kBaseUrlHeadImg     @"http://yongxu.yehaoji.cn:18199"
 
 
 

+ 21 - 6
Temperature/ControlModule/Home/Controller/RDSSelectDeviceMainVC.m

@@ -25,12 +25,24 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
-    [self configSubviews];
     
-    [self.deviceTypeModel fetchDeviceTypeList];
+    [self p_getDeviceTypes];
 }
 
-- (void)configSubviews {
+#pragma mark - Load Data
+- (void)p_getDeviceTypes {
+    [RDSHudShower showWithStatus:@"加载中..."];
+    [self.deviceTypeModel rds_fetchDeviceTypeListFinished:^(NSError * _Nullable error) {
+        [RDSHudShower dismissHUD];
+        if (error) {
+            [RDSHudShower showBottomToast:error.localizedDescription];
+        } else {
+            [self p_configSubviews];
+        }
+    }];
+}
+
+- (void)p_configSubviews {
     self.navigationItem.title = @"选择设备";
     
     self.pagerBar = [[TYTabPagerBar alloc] init];
@@ -81,12 +93,12 @@
 
 #pragma mark - TYTabPagerBarDataSource
 - (NSInteger)numberOfItemsInPagerTabBar {
-    return self.pagerBarTitleArray.count;
+    return self.deviceTypeModel.deviceTypeList.count;
 }
 
 - (UICollectionViewCell<TYTabPagerBarCellProtocol> *)pagerTabBar:(TYTabPagerBar *)pagerTabBar cellForItemAtIndex:(NSInteger)index {
     UICollectionViewCell<TYTabPagerBarCellProtocol> *cell = [pagerTabBar dequeueReusableCellWithReuseIdentifier:[TYTabPagerBarCell cellIdentifier] forIndex:index];
-    NSString *title = self.pagerBarTitleArray[index];
+    NSString *title = [self.deviceTypeModel getDeviceNameWithIndex:index];
     cell.titleLabel.text = title;
     return cell;
 }
@@ -106,7 +118,10 @@
 }
 
 - (UIViewController *)pagerController:(TYPagerController *)pagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
-    return [[RDSSelectDeviceSubVC alloc] init];
+    RDSSelectDeviceSubVC *selectDeviceSubVC = [[RDSSelectDeviceSubVC alloc] init];
+    RDSDeviceTypeModel *deviceTypeModel = self.deviceTypeModel.deviceTypeList[index];
+    [selectDeviceSubVC reloadDataWithDataSource:deviceTypeModel.children];
+    return selectDeviceSubVC;
 }
 
 #pragma mark - TYPagerControllerDelegate

+ 1 - 1
Temperature/ControlModule/Home/Controller/RDSSelectDeviceSubVC.h

@@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface RDSSelectDeviceSubVC : RDSBaseViewController
 
-@property (nonatomic, strong) NSArray *dataSource;
+- (void)reloadDataWithDataSource:(NSArray *)dataSource;
 
 @end
 

+ 10 - 0
Temperature/ControlModule/Home/Controller/RDSSelectDeviceSubVC.m

@@ -10,6 +10,7 @@
 @interface RDSSelectDeviceSubVC () <UITableViewDelegate, UITableViewDataSource>
 
 @property (nonatomic, strong) UITableView *tableView;
+@property (nonatomic, strong) NSArray *dataSource;
 
 @end
 
@@ -33,6 +34,15 @@
     }];
 }
 
+- (void)reloadDataWithDataSource:(NSArray *)dataSource {
+    if (!dataSource) {
+        self.dataSource = [NSMutableArray array];
+        return;
+    }
+    self.dataSource = [dataSource copy];
+    [self.tableView reloadData];
+}
+
 #pragma mark - UITableViewDataSource
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return self.dataSource.count;

+ 5 - 3
Temperature/ControlModule/Home/Model/RDSDeviceTypeModel.h

@@ -16,11 +16,13 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, copy) NSString *code;
 @property (nonatomic, copy) NSString *parent_id;
 @property (nonatomic, copy) NSString *icon;
-@property (nonatomic, strong) NSArray *children;
+@property (nonatomic, strong) NSArray<RDSDeviceTypeModel *> *children;
 
-@property (nonatomic, strong) NSMutableArray<RDSDeviceTypeModel *> *deviceTypeList;
+@property (nonatomic, strong, readonly) NSMutableArray<RDSDeviceTypeModel *> *deviceTypeList;
 
-- (void)fetchDeviceTypeList;
+- (NSString * _Nullable)getDeviceNameWithIndex:(NSInteger)index;
+
+- (void)rds_fetchDeviceTypeListFinished:(void(^)(NSError * _Nullable error))finished;
 
 @end
 

+ 18 - 2
Temperature/ControlModule/Home/Model/RDSDeviceTypeModel.m

@@ -9,11 +9,27 @@
 
 @implementation RDSDeviceTypeModel
 
-- (void)fetchDeviceTypeList {
+- (NSString * _Nullable)getDeviceNameWithIndex:(NSInteger)index {
+    if (index < self.deviceTypeList.count) {
+        RDSDeviceTypeModel *deviceTypeModel = self.deviceTypeList[index];
+        return deviceTypeModel.name;
+    }
+    return nil;
+}
+
+- (void)rds_fetchDeviceTypeListFinished:(void (^)(NSError * _Nullable))finished {
     [RDSDemoApiHelper rds_getDeviceTypeListSuccess:^(id responseObject) {
         NSLog(@"responseObject is %@", responseObject);
+        if ([responseObject[@"code"] integerValue] == 0) {
+            NSDictionary *data = responseObject[@"data"];
+            self->_deviceTypeList = [RDSDeviceTypeModel mj_objectArrayWithKeyValuesArray:data];
+            BLOCK_SAFE_RUN(finished, nil)
+        } else {
+            NSError *error = [NSError errorWithDomain:responseObject[@"message"] code:[responseObject[@"code"] intValue] userInfo:nil];
+            BLOCK_SAFE_RUN(finished, error)
+        }
     } failure:^(NSError *error) {
-        
+        BLOCK_SAFE_RUN(finished, error)
     }];
 }