模拟功能

This commit is contained in:
History
2026-01-22 09:35:35 +08:00
parent 57643da94d
commit a7d78ef4d8
6 changed files with 554 additions and 0 deletions
@@ -0,0 +1,16 @@
//
// SimulationModel.h
// EscortProject
//
// Created by Apple on 2024/8/15.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface SimulationModel : NSObject
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,12 @@
//
// SimulationModel.m
// EscortProject
//
// Created by Apple on 2024/8/15.
//
#import "SimulationModel.h"
@implementation SimulationModel
@end
@@ -0,0 +1,20 @@
//
// SimulationTableViewCell.h
// EscortProject
//
// Created by Apple on 2024/8/15.
//
#import <UIKit/UIKit.h>
#import "SimulationModel.h"
#import "XJMineCenterUserModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface SimulationTableViewCell : UITableViewCell
@property (nonatomic, strong) XJMineCenterUserModel * model;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,96 @@
//
// SimulationTableViewCell.m
// EscortProject
//
// Created by Apple on 2024/8/15.
//
#import "SimulationTableViewCell.h"
@interface SimulationTableViewCell ()
@property (nonatomic, strong) UILabel * usernameLable;
@property (nonatomic, strong) UILabel * realnameLabel;
@property (nonatomic, strong) UILabel * phoneLabel;
@property (nonatomic, strong) UILabel * workNoLabel;
@end
@implementation SimulationTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self createUI];
}
return self;
}
- (void)createUI {
self.usernameLable = [self createLabel:0];
[self.contentView addSubview:self.usernameLable];
self.realnameLabel = [self createLabel:self.usernameLable.right];
[self.contentView addSubview:self.realnameLabel];
self.phoneLabel = [self createLabel: self.realnameLabel.right];
[self.contentView addSubview:self.phoneLabel];
self.workNoLabel = [self createLabel: self.phoneLabel.right];
[self.contentView addSubview:self.workNoLabel];
}
- (UILabel *)createLabel:(CGFloat)x {
CGFloat labW = kScreenWidth/4;
UILabel * lab = [[UILabel alloc] initWithFrame:CGRectMake( x, 0, labW, kRealValue(44))];
lab.numberOfLines = 0;
lab.textAlignment = NSTextAlignmentCenter;
lab.font = MEDIUMFONT(13);
lab.textColor = CFontColor1;
return lab;
}
- (void)setModel:(XJMineCenterUserModel *)model {
_model = model;
self.realnameLabel.text = _model.realname;
self.workNoLabel.text = _model.workNo;
self.phoneLabel.text = _model.phone;
self.usernameLable.text = _model.username;
}
@end
@@ -0,0 +1,16 @@
//
// SimulationViewController.h
// EscortProject
//
// Created by Apple on 2024/8/15.
//
#import "XJBaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface SimulationViewController : XJBaseViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,394 @@
//
// SimulationViewController.m
// EscortProject
//
// Created by Apple on 2024/8/15.
//
#import "SimulationViewController.h"
#import "SimulationTableViewCell.h"
#import "XJMineCenterUserModel.h"
#import "HQSearchView.h"
@interface SimulationViewController ()<UITableViewDelegate,UITableViewDataSource,V2TIMSDKListener,V2TIMSDKListener>
@property (nonatomic, strong) UITableView * homeTable;
@property (nonatomic, strong) NSMutableArray * dataArray;
@property (nonatomic, assign) NSInteger pageNo;
@property (nonatomic, strong) XJMineCenterUserModel * userModel ;
@property (nonatomic, strong) NSString * currentRelname;
@property (nonatomic, assign) bool isStarted;
@property (nonatomic, copy) NSString * realName;
@end
@implementation SimulationViewController
- (NSMutableArray *)dataArray {
if (!_dataArray) {
_dataArray = [[NSMutableArray alloc] init];
}
return _dataArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.isHidenNaviBar = false;
self.navigationItem.title = @"模拟用户";
self.pageNo = 1;
[self createUI];
[self getData];
[self getSimUserInfo];
}
- (void)createUI
{
self.homeTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth , kScreenHeight - kTopHeight - 60) style:UITableViewStylePlain];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 11) {
self.homeTable.estimatedRowHeight = 0;
self.homeTable.estimatedSectionFooterHeight = 0;
self.homeTable.estimatedSectionHeaderHeight = 0;
if (@available(iOS 15.0, *)) {
self.homeTable.sectionHeaderTopPadding = 0;
} else {
// Fallback on earlier versions
}
self.homeTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
self.homeTable.delegate = self;
self.homeTable.dataSource = self;
self.homeTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.homeTable.showsVerticalScrollIndicator = NO;
self.homeTable.sectionHeaderHeight = 0;
self.homeTable.sectionFooterHeight = 0;
self.homeTable.contentInset = UIEdgeInsetsZero;
self.homeTable.contentOffset = CGPointZero;
[self.view addSubview:self.homeTable];
__weak __typeof(self) weakSelf = self;
self.homeTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
weakSelf.pageNo = 1;
[weakSelf getData];
}];
self.homeTable.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
weakSelf.pageNo ++;
[weakSelf getData];
}];
self.isStarted = false;
UIButton * surebtn = [[UIButton alloc] initWithFrame:CGRectMake(0, self.homeTable.bottom, kScreenWidth, 60)];
[surebtn setTitle:@"开始模拟" forState:UIControlStateNormal];
[surebtn setBackgroundColor:UIColorHex(#21BEBE)];
surebtn.titleLabel.font = SYSTEMFONT(15);
[surebtn addTarget:self action:@selector(sureSelected) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:surebtn];
}
- (void)getData {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:@(self.pageNo) forKey:@"pageNo"];
if (!ValidStr(self.realName) ) {
[parmDic setObject:self.realName forKey:@"realname"];
}
[parmDic setObject:@"20" forKey:@"pageSize"];
[parmDic setObject:@"1" forKey:@"personType"];
XJPNetAPI * simApi = [[XJPNetAPI alloc] init:self tag:@"SIMLIST" NeedToken:nil];
[simApi getSimulationUserList:parmDic];
}
#pragma mark -网络请求处理
- (void)Failed:(NSString*)message tag:(NSString*)tag
{
[self showMBProgressHUDOnlyWithString:message];
[self hiddenAllMBProgressHUD];
[self.homeTable.mj_header endRefreshing];
[self.homeTable.mj_footer endRefreshing];
}
- (void)Sucess:(id)response tag:(NSString*)tag
{
[self.homeTable.mj_header endRefreshing];
[self.homeTable.mj_footer endRefreshing];
if ([tag isEqualToString:@"SIMLIST"]) {
NSDictionary * responseDic = response;
NSArray * records;
if ([responseDic.allKeys containsObject:@"records"])
{
records = [responseDic objectForKey:@"records"];
}
if (self.pageNo == 1) {
[self.dataArray removeAllObjects];
}
for (NSDictionary * dic in records) {
XJMineCenterUserModel * userModel = [XJMineCenterUserModel modelWithDictionary:dic];
[self.dataArray addObject:userModel];
}
[self.homeTable reloadData];
}
if ([tag isEqualToString:@"StarteAPI"]) {
//获取用户信息
self.isStarted = true;
[self getSimUserInfo];
}
if ([tag isEqualToString:@"infoAPI"]) {
NSDictionary * dic = response;
if (ValidDict(dic)) {
XJMineCenterUserModel * userModel = [XJMineCenterUserModel modelWithDictionary:dic];
self.currentRelname =[NSString stringWithFormat:@"当前模拟用户:%@", userModel.realname];
HQUserInfo * user = [[HQUserInfo alloc] init];
user.userInfo = dic;
user.token = [[NSUserDefaults standardUserDefaults] objectForKey:@"SIMTOKEN"];
[HQCommonUtils keyedArchiverWithData:user key:LoginUserInfo];
[self.homeTable reloadData];
}
if (self.isStarted == true) {
[self.navigationController popViewControllerAnimated:true];
}
}
if ([tag isEqualToString:@"RecoveryAPI"]) {
[HQCommonUtils keyedArchiverWithData:nil key:LoginUserInfo];
[ESCTUIManager outLoginTUISDK];
self.isStarted = false;
[self getSimUserInfo];
}
if ([tag isEqualToString:@"IMAPI"]) {
NSDictionary * pamrDic = response;
IMUserInfoModel * model = [IMUserInfoModel modelWithDictionary:pamrDic];
IMUserInfoModel * iminfoModel = [[IMUserInfoModel alloc] init];
iminfoModel.IMInfo = pamrDic;
[HQCommonUtils keyedArchiverWithData:iminfoModel key:IMLoginUserInfo];
// 1. 从即时通信 IM 控制台获取应用 SDKAppID。
// 2. 初始化 config 对象
V2TIMSDKConfig *config = [[V2TIMSDKConfig alloc] init];
// 3. 指定 log 输出级别。
config.logLevel = V2TIM_LOG_INFO;
// 4. 添加 V2TIMSDKListener 的事件监听器,self 是 id<V2TIMSDKListener> 的实现类,如果您不需要监听 IM SDK 的事件,这个步骤可以忽略。
[[V2TIMManager sharedInstance] addIMSDKListener:self];
// 5. 初始化 IM SDK,调用这个接口后,可以立即调用登录接口。
[[V2TIMManager sharedInstance] initSDK:[model.sdkAppId intValue] config:config];
[ESCTUIManager loginInitTUISDKAppidWith:[model.sdkAppId intValue] UserID:model.userId userSig:model.userSig];
}
}
#pragma mark - DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArray.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * cellID = @"cellID";
SimulationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[SimulationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.model = self.dataArray[indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return kRealValue(44);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// MineCenterUserModel * userModel = self.dataArray[indexPath.row];
self.userModel = self.dataArray[indexPath.row];
}
- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return kRealValue(150);
}
- (CGFloat )tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView * sectionHeardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kRealValue(150))];
sectionHeardView.backgroundColor = KWhiteColor;
UILabel * conntelabel = [[UILabel alloc] initWithFrame:CGRectMake( kRealValue(20), kRealValue(0), 200, kRealValue(50))];
conntelabel.numberOfLines = 0;
conntelabel.textAlignment = NSTextAlignmentLeft;
conntelabel.font = MEDIUMFONT(13);
conntelabel.textColor = CFontColor1;
conntelabel.text = self.currentRelname;
[sectionHeardView addSubview:conntelabel];
UIButton * quitSimBtn = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 70 - 15, 10, 70, 30)];
quitSimBtn.layer.cornerRadius = 8;
quitSimBtn.layer.masksToBounds = true;
[quitSimBtn setTitle:@"退出模拟" forState:UIControlStateNormal];
quitSimBtn.titleLabel.font = SYSTEMFONT(13);
[quitSimBtn setBackgroundColor:UIColorHex(#21BEBE)];
[quitSimBtn addTarget:self action:@selector(quitSimOnclick) forControlEvents:UIControlEventTouchUpInside];
[sectionHeardView addSubview:quitSimBtn];
HQSearchView * seacrhView = [[HQSearchView alloc] initWithFrame:CGRectMake(0, conntelabel.bottom, kScreenWidth, kRealValue(40))];
seacrhView.backgroundColor = KWhiteColor;
seacrhView.searchPlacehold = @"请输入用户姓名搜索";
seacrhView.searchBlock = ^(NSString * _Nonnull fieldtext) {
if (ValidStr(fieldtext)) {
[self showMBProgressHUDOnlyWithString:@"请输入关键字"];
return;
}
[self searchReult:fieldtext];
};
[sectionHeardView addSubview:seacrhView];
CGFloat labW = kScreenWidth/4;
NSArray * array = @[@"登录账户",@"用户姓名",@"电话",@"工号"];
for (int i = 0 ; i < array.count ; i ++) {
UILabel * lab = [[UILabel alloc] initWithFrame:CGRectMake( i * labW, seacrhView.bottom, labW, kRealValue(50))];
lab.numberOfLines = 0;
lab.text = array[i];
lab.textAlignment = NSTextAlignmentCenter;
lab.font = MEDIUMFONT(13);
lab.textColor = CFontColor1;
lab.backgroundColor = CViewBgColor;
lab.layer.borderColor = KClearColor.CGColor;
[sectionHeardView addSubview:lab];
}
return sectionHeardView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] init];
}
#pragma mark:开始模拟
- (void)sureSelected {
NSMutableDictionary * parmDic = [[NSMutableDictionary alloc] init];
[parmDic setObject:self.userModel.userId_id forKey:@"userId"];
XJPNetAPI * StartedApi = [[XJPNetAPI alloc] init:self tag:@"StarteAPI" NeedToken:nil];
[StartedApi postStartedSimulationUser:parmDic];
}
- (void)searchReult:(NSString *)keyword {
self.pageNo = 1;
self.realName = keyword;
[self getData];
}
- (void)getSimUserInfo {
XJPNetAPI * StartedApi = [[XJPNetAPI alloc] init:self tag:@"infoAPI" NeedToken:nil];
[StartedApi postSimulationUser:nil];
}
- (void)loginImAccount {
XJPNetAPI * proctocolApi = [[XJPNetAPI alloc] init:self tag:@"IMAPI" NeedToken:nil];
[proctocolApi GetIMLoginAccount:nil];
}
- (void)quitSimOnclick {
XJPNetAPI * proctocolApi = [[XJPNetAPI alloc] init:self tag:@"RecoveryAPI" NeedToken:nil];
[proctocolApi postRecoverySimulationUser:nil];
}
@end