You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
416 lines
15 KiB
416 lines
15 KiB
// |
|
// ProtectionViewController.m |
|
// LekangGuard |
|
// |
|
// Created by ecell on 2023/8/23. |
|
// |
|
|
|
#import "ProtectionViewController.h" |
|
#import "MoreMenuTitleView.h" |
|
#import "FunctionView.h" |
|
#import "DeviceSetView.h" |
|
#import "DeviceMsgHeaderView.h" |
|
|
|
@interface ProtectionViewController () |
|
|
|
@property (nonatomic ,strong) UIScrollView *menuScroll; |
|
|
|
@property (nonatomic ,strong) NSMutableArray *menuArr; |
|
|
|
@property (nonatomic ,strong) NSMutableArray *menuImgArr; |
|
|
|
@property (nonatomic ,weak) DeviceMsgHeaderView *devMsgView; |
|
|
|
@property (nonatomic ,weak) FunctionView *fastView; |
|
|
|
@property (nonatomic ,weak) FunctionView *funView; |
|
|
|
@property (nonatomic ,weak) DeviceSetView *setView; |
|
|
|
/// 解绑按钮 |
|
@property (nonatomic ,weak) UIButton *unbundleBtn; |
|
|
|
|
|
|
|
|
|
@end |
|
|
|
|
|
@implementation ProtectionViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.view.backgroundColor = KKBackgroundGrey; |
|
|
|
self.zx_navLeftBtn.titleLabel.font = FontBoldADA_(18); |
|
[self.zx_navLeftBtn setTitleColor:KKWhiteColorColor forState:0]; |
|
|
|
[self zx_setRightBtnWithImg:ImageName_(@"icon_switch_devices") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
[self isDevShowMenu]; |
|
}]; |
|
|
|
[self setMenu]; |
|
[self.view addSubview:self.menuScroll]; |
|
[self.menuScroll mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight); |
|
make.bottom.equalTo(self.view.mas_bottom); |
|
}]; |
|
[self SubOneView]; |
|
} |
|
|
|
- (void)SubOneView |
|
{ |
|
DeviceMsgHeaderView *devMsgView = [[DeviceMsgHeaderView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, 148)]; |
|
self.devMsgView = devMsgView; |
|
[self.menuScroll addSubview:devMsgView]; |
|
[devMsgView setModel]; |
|
|
|
MoreMenuTitleView *titleView1 = [[MoreMenuTitleView alloc] initWithFrame:CGRectMake(0, devMsgView.bottom+10, SCREEN_WIDTH, 30)]; |
|
titleView1.titleStr = GJText(@"快捷功能"); |
|
[self.menuScroll addSubview:titleView1]; |
|
|
|
FunctionView *fastView = [[FunctionView alloc] initWithFrame:CGRectMake(0, titleView1.bottom+5, SCREEN_WIDTH, (SCREEN_WIDTH-20)/4.5)]; |
|
self.fastView = fastView; |
|
fastView.imgArr = @[@"icon_member",@"icon_phonebook",@"icon_alarm",@"icon_class_disable"]; |
|
fastView.titleArr = @[@"成员管理",@"电话本",@"设备闹钟",@"上课禁用"]; |
|
[self.menuScroll addSubview:fastView]; |
|
|
|
|
|
MoreMenuTitleView *titleView = [[MoreMenuTitleView alloc] initWithFrame:CGRectMake(0, fastView.bottom+10, SCREEN_WIDTH, 30)]; |
|
titleView.titleStr = GJText(@"基础功能"); |
|
[self.menuScroll addSubview:titleView]; |
|
|
|
FunctionView *funView = [[FunctionView alloc] initWithFrame:CGRectMake(0, titleView.bottom+5, SCREEN_WIDTH, [self getViewsHeight])]; |
|
self.funView = funView; |
|
funView.imgArr = self.menuImgArr; |
|
funView.titleArr = self.menuArr; |
|
[self.menuScroll addSubview:funView]; |
|
|
|
[self subTwoView:funView]; |
|
} |
|
|
|
- (void)subTwoView:(UIView *)views |
|
{ |
|
MoreMenuTitleView *titleView = [[MoreMenuTitleView alloc] initWithFrame:CGRectMake(0, views.bottom+10, SCREEN_WIDTH, 30)]; |
|
titleView.titleStr = GJText(@"设备设置"); |
|
[self.menuScroll addSubview:titleView]; |
|
|
|
|
|
DeviceSetView *setView = [[DeviceSetView alloc] initWithFrame:CGRectMake(0, titleView.bottom+5, SCREEN_WIDTH, [APIManager sharedManager].deviceModel.dial ? Adapted(220) : Adapted(165))]; |
|
self.setView = setView; |
|
[self.menuScroll addSubview:setView]; |
|
setView.isOpenState = ^{ |
|
[super updataNotificat]; |
|
}; |
|
[setView DevicePosition]; |
|
|
|
/// 远程关机 |
|
UIButton *shutdownBtn = [UICommon ui_buttonSimple:CGRectMake(10, setView.bottom+Adapted(60), SCREEN_WIDTH-20, Adapted(44)) font:FontADA_(15) normalColor:KKWhiteColorColor normalText:GJText(@"远程关机") click:^(id x) { |
|
|
|
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"远程关机") subtitle:GJText(@"\n远程关机后将无法通话与定位,是否确认关机?") AlertViewType:AlertViewTypeSystemAlert config:nil]; |
|
[alertV addAlertItem:^EasyAlertItem *{ |
|
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil]; |
|
}]; |
|
[alertV addAlertItem:^EasyAlertItem *{ |
|
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) { |
|
[self DeviceShutDown]; |
|
}]; |
|
}]; |
|
[alertV showAlertView]; |
|
|
|
}]; |
|
shutdownBtn.backgroundColor = KKMainColor; |
|
shutdownBtn.layer.cornerRadius = Adapted(22); |
|
shutdownBtn.layer.masksToBounds = YES; |
|
[self.menuScroll addSubview:shutdownBtn]; |
|
|
|
NSString *msg = GJText(@"\n解除绑定后,将无法对设备进行监护,设备将重启,其他绑定该设备的用户,将自动解绑"); |
|
if(APIManager.sharedManager.deviceModel.identity == 2) |
|
msg = GJText(@"\n您是设备的管理员,如果您进行解绑,其他绑定该设备的用户,将自动解绑,确认解除绑定吗?"); |
|
|
|
/// 解除与设备的绑定 |
|
UIButton *unbundleBtn = [UICommon ui_buttonSimple:CGRectMake(10, shutdownBtn.bottom+20, SCREEN_WIDTH-20, Adapted(44)) font:FontADA_(15) normalColor:KKMainColor normalText:GJText(@"解除与设备的绑定") click:^(id x) { |
|
|
|
EasyAlertView *alertV = [EasyAlertView alertViewWithTitle:GJText(@"设备解绑") subtitle:GJText(msg) AlertViewType:AlertViewTypeSystemAlert config:nil]; |
|
[alertV addAlertItem:^EasyAlertItem *{ |
|
return [EasyAlertItem itemWithTitle:GJText(@"取消") type:AlertItemTypeSystemCancel callback:nil]; |
|
}]; |
|
[alertV addAlertItem:^EasyAlertItem *{ |
|
return [EasyAlertItem itemWithTitle:GJText(@"确定") type:AlertItemTypeSystemDefault callback:^(EasyAlertView *showview, long index) { |
|
[self DeviceUnbind]; |
|
}]; |
|
}]; |
|
[alertV showAlertView]; |
|
}]; |
|
unbundleBtn.backgroundColor = KKClearColor; |
|
unbundleBtn.layer.cornerRadius = Adapted(22); |
|
unbundleBtn.layer.borderWidth = 1; |
|
unbundleBtn.layer.borderColor = KKMainColor.CGColor; |
|
unbundleBtn.layer.masksToBounds = YES; |
|
self.unbundleBtn = unbundleBtn; |
|
[self.menuScroll addSubview:unbundleBtn]; |
|
|
|
[self.menuScroll setContentSize:CGSizeMake(SCREEN_WIDTH, unbundleBtn.bottom+iPhoneX_TabbarSafeBottomMargin)]; |
|
|
|
} |
|
|
|
- (UIScrollView *)menuScroll |
|
{ |
|
if (!_menuScroll) |
|
{ |
|
_menuScroll = [UIScrollView new]; |
|
_menuScroll.backgroundColor = KKClearColor; |
|
} |
|
return _menuScroll; |
|
} |
|
|
|
/// 菜单设置 |
|
- (void)setMenu |
|
{ |
|
self.menuArr = [NSMutableArray new]; |
|
self.menuImgArr = [NSMutableArray new]; |
|
|
|
|
|
// if ([APIManager sharedManager].deviceModel.identity == 2) |
|
// [self.menuArr addObject:GJText(@"管理员")]; |
|
// else |
|
|
|
// [self.menuArr addObject:GJText(@"打电话")]; |
|
// [self.menuImgArr addObject:@"icon_call_up"]; |
|
// |
|
// [self.menuArr addObject:GJText(@"电话本")]; |
|
// [self.menuImgArr addObject:@"icon_phonebook"]; |
|
|
|
|
|
// if([APIManager sharedManager].deviceModel.videoModelName != 0) |
|
// { |
|
// [self.menuArr addObject:GJText(@"视频通话")]; |
|
// [self.menuImgArr addObject:@"icon_more_video_call"]; |
|
// } |
|
// if ([APIManager sharedManager].deviceModel.watchAlarmClock ) |
|
// { |
|
// [self.menuArr addObject:GJText(@"设备闹钟")]; |
|
// [self.menuImgArr addObject:@"icon_alarm"]; |
|
// } |
|
// if ([APIManager sharedManager].deviceModel.classDisable ) |
|
// { |
|
// [self.menuArr addObject:GJText(@"上课禁用")]; |
|
// [self.menuImgArr addObject:@"icon_class_disable"]; |
|
// } |
|
if([APIManager sharedManager].deviceModel.chatFun) |
|
{ |
|
[self.menuArr addObject:GJText(@"微聊")]; |
|
[self.menuImgArr addObject:@"icon_wechat"]; |
|
} |
|
if([APIManager sharedManager].deviceModel.lookupFun) |
|
{ |
|
[self.menuArr addObject:GJText(@"查找设备")]; |
|
[self.menuImgArr addObject:@"icon_find_devices"]; |
|
} |
|
if ([APIManager sharedManager].deviceModel.sosPhone) |
|
{ |
|
[self.menuArr addObject:GJText(@"SOS号码")]; |
|
[self.menuImgArr addObject:@"icon_sos"]; |
|
} |
|
// if([APIManager sharedManager].deviceModel.watchWiff) |
|
// { |
|
// [self.menuArr addObject:GJText(@"设备WIFI")]; |
|
// [self.menuImgArr addObject:@"icon_watch_wifi"]; |
|
// } |
|
|
|
if([APIManager sharedManager].deviceModel.timingSwitch) |
|
{ |
|
[self.menuArr addObject:GJText(@"定时开关机")]; |
|
[self.menuImgArr addObject:@"icon_on_off"]; |
|
} |
|
|
|
|
|
if([APIManager sharedManager].deviceModel.stepRecorder) |
|
{ |
|
[self.menuArr addObject:GJText(@"计步")]; |
|
[self.menuImgArr addObject:@"icon_step"]; |
|
} |
|
// 学生卡 |
|
//if([APIManager sharedManager].deviceModel.familyPhone) |
|
{ |
|
[self.menuArr addObject:GJText(@"亲情号")]; |
|
[self.menuImgArr addObject:@"icon_family"]; |
|
} |
|
|
|
// // 学生资料 |
|
// if([APIManager sharedManager].deviceModel.deviceType == 2) |
|
// { |
|
// [self.menuArr addObject:GJText(@"学生资料")]; |
|
// [self.menuImgArr addObject:@"icon_more_watch_data"]; |
|
// } |
|
|
|
// if ([APIManager sharedManager].deviceModel.whiteList) |
|
// { |
|
// [self.menuArr addObject:GJText(@"通讯录")]; |
|
// [self.menuImgArr addObject:@"icon_home_phone_book"]; |
|
// } |
|
|
|
|
|
[self.menuArr addObject:GJText(@"设备资料")]; |
|
[self.menuImgArr addObject:@"icon_watch_data"]; |
|
} |
|
|
|
|
|
|
|
#pragma mark 设备远程关机 |
|
/// 设备远程关机 |
|
- (void)DeviceShutDown |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; |
|
[[[APIManager sharedManager] APGET:DeviceShutDown_URL parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[super updataNotificat]; |
|
[UICommon MessageSuccessText:@"远程关机成功"]; |
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
|
|
#pragma mark 解除与设备绑定 |
|
/// 解除与设备绑定 |
|
- (void)DeviceUnbind |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; |
|
[parameters setValue:APIManager.sharedManager.loginModel.openid forKey:@"userId"]; |
|
[[[APIManager sharedManager] APPOST:DeviceUnbind_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[APIManager.sharedManager cleardeviceInfo]; |
|
[UICommon MessageSuccessText:@"解绑成功"]; |
|
[[NSNotificationCenter defaultCenter] postNotificationName:UPDATA_DeviceList object:nil]; |
|
AfterDispatch(0.5, ^{ |
|
[self.navigationController popViewControllerAnimated:YES]; |
|
}); |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
#pragma mark 查询当前设备用户微聊未读消息数 |
|
/// 查询当前设备用户微聊未读消息数 |
|
- (void)GetUnreadTotal |
|
{ |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.groupid forKey:@"groupId"]; |
|
[[[APIManager sharedManager] APGET:UnreadTotal_URL parameters:parameters resultClass:nil] subscribeNext:^(NSString *x) { |
|
[UICommon HidenLoading]; |
|
NSInteger chatCoutn = x.integerValue; |
|
self.funView.chatCoutn = chatCoutn; |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
- (void)updateAllMessage |
|
{ |
|
AfterDispatch(1, ^{ |
|
[self.setView DevicePosition]; |
|
}); |
|
} |
|
|
|
/// 切换设备弹出框 |
|
- (void)isDevShowMenu |
|
{ |
|
WeakSelf |
|
[DeviceSwitchover.sharedManager showMenuViewWithAdd:NO ]; |
|
[DeviceSwitchover.sharedManager setSwitchDevice:^(NSInteger index) { |
|
DeviceModel *model = APIManager.sharedManager.deviceList[index]; |
|
APIManager.sharedManager.deviceModel = model; |
|
[APIManager.sharedManager.cache setObject:model forKey:sDeviceKey]; |
|
[weakSelf realTimeUpadteMsg]; |
|
}]; |
|
} |
|
- (void)viewWillAppear:(BOOL)animated |
|
{ |
|
[super viewWillAppear:animated]; |
|
[self realTimeUpadteMsg]; |
|
[self GetUnreadTotal]; |
|
[self GetMunberTotal]; |
|
} |
|
|
|
|
|
/// 切换设备或者其他页面切换设备刷新界面 |
|
- (void)realTimeUpadteMsg |
|
{ |
|
[self.zx_navLeftBtn setTitle:APIManager.sharedManager.deviceModel.name forState:0]; |
|
WeakSelf |
|
[weakSelf setMenu]; |
|
[weakSelf.devMsgView setModel]; |
|
weakSelf.funView.size = CGSizeMake(SCREEN_WIDTH, [self getViewsHeight]); |
|
weakSelf.funView.imgArr = weakSelf.menuImgArr; |
|
weakSelf.funView.titleArr = weakSelf.menuArr; |
|
weakSelf.setView.size = CGSizeMake(SCREEN_WIDTH, [APIManager sharedManager].deviceModel.dial ? Adapted(220) : Adapted(165)); |
|
[weakSelf.setView subHeaderView]; |
|
[weakSelf.menuScroll setContentSize:CGSizeMake(SCREEN_WIDTH, weakSelf.unbundleBtn.bottom+iPhoneX_TabbarSafeBottomMargin)]; |
|
} |
|
|
|
|
|
- (CGFloat)getViewsHeight |
|
{ |
|
CGFloat hh = (SCREEN_WIDTH-20)/4.5; |
|
NSInteger count = self.menuArr.count; |
|
if (count < 5) return hh; |
|
if (count < 9) return hh*2; |
|
if (count < 13) return hh*3; |
|
if (count < 17) return hh*4; |
|
if (count < 21) return hh*5; |
|
if (count > 20) return hh*6; |
|
return hh; |
|
} |
|
|
|
|
|
#pragma mark 查询成员管理未读消息数 |
|
/// 查询成员管理未读消息数 |
|
- (void)GetMunberTotal |
|
{ |
|
kWeakSelf(self) |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[[[APIManager sharedManager] APGET:UnReadTotal_URL parameters:parameters resultClass:nil] subscribeNext:^(NSArray *arr) { |
|
[UICommon HidenLoading]; |
|
if (ARRAYHASVALUE(arr)) |
|
{ |
|
[arr enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) { |
|
NSInteger total = [obj[@"total"] integerValue]; |
|
NSInteger type = [obj[@"type"] integerValue]; |
|
if (type == 2) |
|
{ |
|
weakself.fastView.munberCoutn = total; |
|
} |
|
}]; |
|
} |
|
|
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
/* |
|
#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
|
|
|