From a8fe2388cc39fd1e940888eedb474913bc1d9533 Mon Sep 17 00:00:00 2001 From: Cao yang Date: Fri, 20 Apr 2018 15:30:31 +0800 Subject: [PATCH] 封装定位,优化代码 --- ParentAssistant/ParentAssistant.xcodeproj/project.pbxproj | 8 ++++++++ ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate | Bin 300544 -> 0 bytes ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist | 16 ---------------- ParentAssistant/ParentAssistant/AppDelegate.swift | 11 +++++++++-- ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- ParentAssistant/ParentAssistant/Classes/controllers/Grow/Program/ProgramViewController.swift | 60 +++++++++++++++++++++++++++++++++--------------------------- ParentAssistant/ParentAssistant/Classes/controllers/Information/ChannelViewController.swift | 4 ++-- ParentAssistant/ParentAssistant/Classes/controllers/Information/InformationViewController.swift | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- ParentAssistant/ParentAssistant/Classes/controllers/evaluation/EvaluationViewController.swift | 12 ++++++------ ParentAssistant/ParentAssistant/Classes/controllers/userCenter/BaseCityChooseSchoolViewController.swift | 8 ++++---- ParentAssistant/ParentAssistant/Classes/util/LocationManger.swift | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ParentAssistant/ParentAssistant/Classes/util/Macro.swift | 5 +++++ ParentAssistant/ParentAssistant/Classes/util/account.swift | 28 +++++++++++++++------------- ParentAssistant/ParentAssistant/Classes/util/view/AlertShowView.swift | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/Contents.json | 21 +++++++++++++++++++++ ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/grow_empty_Image@2x.png | Bin 0 -> 14428 bytes 16 files changed, 394 insertions(+), 87 deletions(-) create mode 100644 ParentAssistant/ParentAssistant/Classes/util/LocationManger.swift create mode 100644 ParentAssistant/ParentAssistant/Classes/util/view/AlertShowView.swift create mode 100644 ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/Contents.json create mode 100644 ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/grow_empty_Image@2x.png diff --git a/ParentAssistant/ParentAssistant.xcodeproj/project.pbxproj b/ParentAssistant/ParentAssistant.xcodeproj/project.pbxproj index 78e1737..331729e 100644 --- a/ParentAssistant/ParentAssistant.xcodeproj/project.pbxproj +++ b/ParentAssistant/ParentAssistant.xcodeproj/project.pbxproj @@ -59,6 +59,8 @@ AD5681CB208044860034A948 /* GrowCheckUpTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AD5681C9208044860034A948 /* GrowCheckUpTableViewCell.xib */; }; AD5681CE2080449A0034A948 /* GrowCheckDownTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5681CC2080449A0034A948 /* GrowCheckDownTableViewCell.swift */; }; AD5681CF2080449A0034A948 /* GrowCheckDownTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AD5681CD2080449A0034A948 /* GrowCheckDownTableViewCell.xib */; }; + AD639F0520897CBC0028BE73 /* AlertShowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD639F0420897CBC0028BE73 /* AlertShowView.swift */; }; + AD639F072089C3950028BE73 /* LocationManger.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD639F062089C3950028BE73 /* LocationManger.swift */; }; AD64A2C0207F289400B25E80 /* ProgramVacateTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD64A2BE207F289400B25E80 /* ProgramVacateTableViewCell.swift */; }; AD64A2C1207F289400B25E80 /* ProgramVacateTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AD64A2BF207F289400B25E80 /* ProgramVacateTableViewCell.xib */; }; AD64A2C3207F28CF00B25E80 /* ProgramVacateBodyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD64A2C2207F28CF00B25E80 /* ProgramVacateBodyTableViewCell.swift */; }; @@ -237,6 +239,8 @@ AD5681C9208044860034A948 /* GrowCheckUpTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GrowCheckUpTableViewCell.xib; sourceTree = ""; }; AD5681CC2080449A0034A948 /* GrowCheckDownTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GrowCheckDownTableViewCell.swift; sourceTree = ""; }; AD5681CD2080449A0034A948 /* GrowCheckDownTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GrowCheckDownTableViewCell.xib; sourceTree = ""; }; + AD639F0420897CBC0028BE73 /* AlertShowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertShowView.swift; sourceTree = ""; }; + AD639F062089C3950028BE73 /* LocationManger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManger.swift; sourceTree = ""; }; AD64A2BE207F289400B25E80 /* ProgramVacateTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramVacateTableViewCell.swift; sourceTree = ""; }; AD64A2BF207F289400B25E80 /* ProgramVacateTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ProgramVacateTableViewCell.xib; sourceTree = ""; }; AD64A2C2207F28CF00B25E80 /* ProgramVacateBodyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramVacateBodyTableViewCell.swift; sourceTree = ""; }; @@ -513,6 +517,7 @@ ADE33B302062202300BEA6E6 /* Macro.swift */, BF5D1669204E675C00274489 /* account.swift */, BF5D166B204E6A0300274489 /* network.swift */, + AD639F062089C3950028BE73 /* LocationManger.swift */, BFA7446B208193D300845D30 /* MessageManager.swift */, 599365282052553900C8B371 /* pinyin.c */, 599365292052553900C8B371 /* pinyin.h */, @@ -883,6 +888,7 @@ children = ( BFF9B7F12057A28900F39B3E /* TableEmptyView.swift */, BFF9B7F32057A29D00F39B3E /* TableEmptyView.xib */, + AD639F0420897CBC0028BE73 /* AlertShowView.swift */, ); path = view; sourceTree = ""; @@ -1107,6 +1113,7 @@ 5993652A2052553900C8B371 /* pinyin.c in Sources */, AD122AB6208433BA00C7D0AD /* ProgramVacateDetailViewController.swift in Sources */, BFF9B7EF20577CD300F39B3E /* MyChildrenTableViewCell.swift in Sources */, + AD639F072089C3950028BE73 /* LocationManger.swift in Sources */, 590944E22057DA73004478B5 /* utils.swift in Sources */, BFEAAAC9205257460072FAAF /* NSDate+GFCalendar.m in Sources */, BF5D166A204E675C00274489 /* account.swift in Sources */, @@ -1156,6 +1163,7 @@ ADF159612069E00000A9485D /* CalendarView.swift in Sources */, AD122ACA2084498F00C7D0AD /* ProgramVacateAddView.swift in Sources */, BF406CD82057B529000A6681 /* MessageTableViewCell.swift in Sources */, + AD639F0520897CBC0028BE73 /* AlertShowView.swift in Sources */, 599364EC204E62E700C8B371 /* EvaluationViewController.swift in Sources */, AD122ABB20843AD700C7D0AD /* ProgramVacateDetailCell.swift in Sources */, 599364F0204E62E700C8B371 /* ReportViewController.swift in Sources */, diff --git a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate index 2d31bd0..1a89df8 100644 Binary files a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate and b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 1a0ebde..e2573a5 100644 --- a/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/caoyang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -13,21 +13,5 @@ stopOnStyle = "0"> - - - - diff --git a/ParentAssistant/ParentAssistant/AppDelegate.swift b/ParentAssistant/ParentAssistant/AppDelegate.swift index 855a31c..04f3957 100644 --- a/ParentAssistant/ParentAssistant/AppDelegate.swift +++ b/ParentAssistant/ParentAssistant/AppDelegate.swift @@ -37,12 +37,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } }) } + + //定位 + LocationManger.shared.locationSelf() + setShareSDKSetting() let tabbarVC = Story.instantiateViewControllerWithIdentifier("TabBarController", storyName: "Main") as! TabBarController self.window?.rootViewController = tabbarVC self.window?.makeKeyAndVisible() // 加载广告 requestAD(vc: tabbarVC) + + + return true } //设置云信的appkey @@ -68,7 +75,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { if Setting.getString("isFirst") == "\(AppDelegate.version())" {//是否是第一次下载 position = 1 let adView = ZLaunchAd.create() - //position 广告位置0-首次广告位1-开屏广告位2-资讯首页3-频道首页4-频道内容5-文章内容页 AccountManager.shared.address + //position 广告位置0-首次广告位1-开屏广告位2-资讯首页3-频道首页4-频道内容5-文章内容页 localAddress HTTPServer.shared.getAds(["position":position as AnyObject], completionHandler: { (str, error) in httpJsonResule(jsonString: str, error: error, successHandler: { (json) in if json["status"] == 1 && error == nil{ @@ -93,7 +100,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { vc.view.addSubview(view) position = 0 let _ = Setting.save("\(AppDelegate.version())", forKey: "isFirst") - //position 广告位置0-首次广告位1-开屏广告位2-资讯首页3-频道首页4-频道内容5-文章内容页 AccountManager.shared.address + //position 广告位置0-首次广告位1-开屏广告位2-资讯首页3-频道首页4-频道内容5-文章内容页 localAddress HTTPServer.shared.getAds(["position":position as AnyObject], completionHandler: { (str, error) in view.removeFromSuperview() httpJsonResule(jsonString: str, error: error, successHandler: { (json) in diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift index b7ae515..11e508f 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/GrowViewController.swift @@ -10,7 +10,6 @@ import UIKit class GrowViewController: UIViewController,UIScrollViewDelegate { - //MARK: - 标题数据 //标题 lazy var titleView = {() -> UIView in let title = UIScrollView() @@ -18,7 +17,6 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { title.backgroundColor = Theme.topBarColor() return title }() - //MARK: - 内容数据 //内容 lazy var contentScrollView = {()->UIScrollView in let scrollView = UIScrollView.init(frame: self.view.bounds) @@ -41,6 +39,19 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { return lineLay }() + /// 空数据页面 + lazy var emptyView = {()-> UIView in + let view = UIView.init(frame: self.view.bounds) + view.backgroundColor = UIColor.white + let imageView = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: 0.5*screenWidth, height: 0.5*screenWidth)) + imageView.center = CGPoint.init(x: screenWidth/2, y: screenHeight*0.4) + imageView.image = UIImage.init(named: "grow_empty_Image") + imageView.contentMode = UIViewContentMode.scaleAspectFit + + view.addSubview(imageView) + return view + }() + var titleLeftLab = UILabel() //是否显示右侧按钮 @@ -68,22 +79,31 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { override func viewWillAppear(_ animated: Bool) { - - let model = AccountManager.shared.getUserInfo() - print(model.name) + configUserStatus() + } + + //MARK: - 判断登录状态 + func configUserStatus(){ var title = String() if AccountManager.shared.isOnline() { - if AccountManager.shared.rawUserInfo!.contentData()["studentClass"].arrayValue.count == 0 { + let array = AccountManager.shared.getChildClassInfo() + + self.contentScrollView.isHidden = false + self.emptyView.removeFromSuperview() + + if array.isEmpty { title = "未绑定" }else{ - title = AccountManager.shared.rawUserInfo!.contentData()["studentClass"][0]["studentName"].stringValue + title = array[0].studentName } }else{ title = "未登录" + self.view.addSubview(self.emptyView) + self.contentScrollView.isHidden = true } self.titleLeftLab.text = title } - + //MARK: 导航栏视图UI func drawHeadView () { //左按钮 let leftView = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 60, height: 44)) @@ -100,7 +120,7 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { imageView.contentMode = .scaleAspectFit leftView.addSubview(imageView) - // leftView.addTarget(self, action: #selector(showView), for: UIControlEvents.touchDown) + leftView.addTarget(self, action: #selector(switchChildrenAction), for: UIControlEvents.touchDown) let leftBtn = UIBarButtonItem.init(customView: leftView) self.navigationItem.leftBarButtonItem = leftBtn @@ -123,7 +143,46 @@ class GrowViewController: UIViewController,UIScrollViewDelegate { } + //MARK: 切换孩子按钮 + @objc func switchChildrenAction(){ + + if AccountManager.shared.isOnline() { + let arr = AccountManager.shared.getChildClassInfo() + if arr.count > 0 { + let view = AlertShowView.init(frame: CGRect.init(x: 10, y: Int((navigationBarHeight!+statusBarHeight)+5), width: Int(screenHeight*0.2), height: 50*arr.count)) + view.setUpDataResource(arr:arr) + view.showView() + view.AlertBlock = { object in + if object is StudentClassInfoModel { + let model = object as! StudentClassInfoModel + self.titleLeftLab.text = model.studentName + } + } + }else{ + let alertView = UIAlertController.init(title: "提示", message: "您尚未绑定孩子信息,是否前往绑定?", preferredStyle: UIAlertControllerStyle.alert) + let action = UIAlertAction.init(title: "确定", style: UIAlertActionStyle.default) { (action) in + let vc = Story.instantiateViewControllerWithIdentifier("MyChildrenViewController", storyName: "My") as! MyChildrenViewController + self.navigationController?.pushViewController(vc, animated: true) + } + let cancle = UIAlertAction.init(title: "取消", style: UIAlertActionStyle.cancel, handler: nil) + alertView.addAction(action) + alertView.addAction(cancle) + self.present(alertView, animated: true, completion: nil) + } + }else{ + let alertView = UIAlertController.init(title: "提示", message: "您尚未登录,是否前往登录?", preferredStyle: UIAlertControllerStyle.alert) + let action = UIAlertAction.init(title: "确定", style: UIAlertActionStyle.default) { (action) in + let vc = Story.instantiateViewControllerWithIdentifier("LoginViewController", storyName: "My") as! LoginViewController + self.navigationController?.pushViewController(vc, animated: true) + } + let cancle = UIAlertAction.init(title: "取消", style: UIAlertActionStyle.cancel, handler: nil) + alertView.addAction(action) + alertView.addAction(cancle) + self.present(alertView, animated: true, completion: nil) + } + } + //MARK: - 设置控制器子视图 private func setChildViewContent(){ //添加子控制器 diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Program/ProgramViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Program/ProgramViewController.swift index 3263c85..acfa3f0 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Program/ProgramViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Grow/Program/ProgramViewController.swift @@ -18,33 +18,8 @@ class ProgramViewController: UIViewController,UITableViewDelegate,UITableViewDat table.tableFooterView = UIView.init() return table }() - //Data - var tableData = Array() - var titleImage = Array() - - override func viewDidLoad() { - super.viewDidLoad() - self.view.backgroundColor = backGroundColor - - var isCheck = true - if AccountManager.shared.isOnline() { - if AccountManager.shared.rawUserInfo!.contentData()["studentClass"].arrayValue.count == 0 { - isCheck = false - }else{ - isCheck = true - } - } - if isCheck { - self.view.addSubview(self.tableView) - }else{ - drawEmptyView() - } - self.tableData = ["考勤","补卡","请假"] - self.titleImage = ["program_check","program_card","program_leave"] - // Do any additional setup after loading the view. - } - func drawEmptyView () { + lazy var empty = {()->UIView in let emptyView = UIView.init(frame: self.view.bounds) emptyView.backgroundColor = backGroundColor @@ -70,11 +45,42 @@ class ProgramViewController: UIViewController,UITableViewDelegate,UITableViewDat emptyView.addSubview(label2) emptyView.addSubview(label3) - self.view.addSubview(emptyView) + return emptyView + }() + + //Data + var tableData = Array() + var titleImage = Array() + + + override func viewWillAppear(_ animated: Bool) { + let array = AccountManager.shared.getChildClassInfo() + if array.isEmpty { + self.view.addSubview(self.empty) + self.tableView.isHidden = true + }else{ + self.empty.removeFromSuperview() + self.tableView.isHidden = false + } } + + + override func viewDidLoad() { + super.viewDidLoad() + self.view.backgroundColor = backGroundColor + + self.view.addSubview(self.tableView) + + self.tableData = ["考勤","补卡","请假"] + self.titleImage = ["program_check","program_card","program_leave"] + // Do any additional setup after loading the view. + } + @objc func gotoChildView () { print("去个人中心页面-我的孩子!") + let vc = Story.instantiateViewControllerWithIdentifier("MyChildrenViewController", storyName: "My") as! MyChildrenViewController + self.navigationController?.pushViewController(vc, animated: true) } diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Information/ChannelViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Information/ChannelViewController.swift index 916918c..d368974 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Information/ChannelViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Information/ChannelViewController.swift @@ -44,7 +44,7 @@ class ChannelViewController: UIViewController,UISearchBarDelegate { }) } topADsQueue.async { - HTTPServer.shared.getChannelInfo([ "areaName": AccountManager.shared.address as AnyObject,"channel": self.channelId as AnyObject,"toFirstPage": 0 as AnyObject,"pageIndex": 1 as AnyObject,"pageSize": 20 as AnyObject], completionHandler: { (str, error) in + HTTPServer.shared.getChannelInfo([ "areaName": localAddress as AnyObject,"channel": self.channelId as AnyObject,"toFirstPage": 0 as AnyObject,"pageIndex": 1 as AnyObject,"pageSize": 20 as AnyObject], completionHandler: { (str, error) in httpJsonResule(jsonString: str, error: error, successHandler: { (json) in if json["status"] == 1 && error == nil{ self.data = ChannelDemol(j: json.contentData()) @@ -61,7 +61,7 @@ class ChannelViewController: UIViewController,UISearchBarDelegate { if key == nil{ return } - HTTPServer.shared.getInformationTopic(["keyword":key as AnyObject, "areaName": AccountManager.shared.address as AnyObject,"channel": self.channelId as AnyObject,"toFirstPage": 0 as AnyObject,"pageIndex": 1 as AnyObject,"pageSize": 20 as AnyObject], completionHandler: { (str, error) in + HTTPServer.shared.getInformationTopic(["keyword":key as AnyObject, "areaName": localAddress as AnyObject,"channel": self.channelId as AnyObject,"toFirstPage": 0 as AnyObject,"pageIndex": 1 as AnyObject,"pageSize": 20 as AnyObject], completionHandler: { (str, error) in httpJsonResule(jsonString: str, error: error, successHandler: { (json) in if json["status"] == 1 && error == nil{ self.data.channelContent.removeAll() diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/Information/InformationViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/Information/InformationViewController.swift index e917d9e..82d3997 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/Information/InformationViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/Information/InformationViewController.swift @@ -38,6 +38,45 @@ class InformationViewController: UIViewController,UISearchBarDelegate { self.navigationController?.navigationBar.tintColor=UIColor.white } + private func getDataFromNet(){ + + let group = DispatchGroup() + var position:Int = 2 + if !self.isFirstviewController { + position = 3 + } + group.enter() + HTTPServer.shared.getAds(["position":position as AnyObject,"areaName":localAddress as AnyObject], completionHandler: { (str, error) in//getPercentEncodingString(str: localAddress) + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + if json["status"] == 1 && error == nil{ + self.topADs.removeAll() + for item in json.contentData().arrayValue{ + self.topADs.append(ADSModel(j: item)) + } + } + }, failHandler: { (error) in + + }) + group.leave() + }) + group.enter() + let dic = self.getListDic() + HTTPServer.shared.getChannelInfo(dic, completionHandler: { (str, error) in + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + if json["status"] == 1 && error == nil{ + self.data = ChannelDemol(j: json.contentData()) + } + }, failHandler: { (error) in + + }) + group.leave() + }) + group.notify(queue: DispatchQueue.main) { + self.collectView.reloadData() + } + } + + func getData(){ let topADsQueue = DispatchQueue(label: "topADs") topADsQueue.async { @@ -46,7 +85,7 @@ class InformationViewController: UIViewController,UISearchBarDelegate { if !self.isFirstviewController { position = 3 } - HTTPServer.shared.getAds(["position":position as AnyObject,"areaName":AccountManager.shared.address as AnyObject], completionHandler: { (str, error) in//getPercentEncodingString(str: AccountManager.shared.address) + HTTPServer.shared.getAds(["position":position as AnyObject,"areaName":localAddress as AnyObject], completionHandler: { (str, error) in//getPercentEncodingString(str: localAddress) httpJsonResule(jsonString: str, error: error, successHandler: { (json) in if json["status"] == 1 && error == nil{ self.topADs.removeAll() @@ -99,7 +138,7 @@ class InformationViewController: UIViewController,UISearchBarDelegate { //获得请求参数 func getListDic()->[String:AnyObject]{ - var dic = [ "areaName": AccountManager.shared.address as AnyObject,"pageIndex": 1 as AnyObject,"pageSize": 20 as AnyObject] + var dic = [ "areaName": localAddress as AnyObject,"pageIndex": 1 as AnyObject,"pageSize": 20 as AnyObject] var toFirstPage:Int = 1 var ch:Int = 0 if !isFirstviewController{ @@ -115,7 +154,7 @@ class InformationViewController: UIViewController,UISearchBarDelegate { func addLeftBarBtn(){ let leftbtn = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 40)) leftLabel = UILabel(frame: CGRect(x: 0, y: 10, width: 60, height: 20)) - leftLabel.text = AccountManager.shared.address + leftLabel.text = localAddress leftLabel.textColor = UIColor.white leftLabel.sizeToFit() let image = UIImageView(frame: CGRect(x: leftLabel.frame.maxX+4, y: 15, width: 16, height: 9)) @@ -143,9 +182,11 @@ class InformationViewController: UIViewController,UISearchBarDelegate { //完成选择城市 func selectCity(city: String) { - AccountManager.shared.address = city + localAddress = city addLeftBarBtn() - getData() +// getData() + getDataFromNet() + } func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { @@ -174,7 +215,8 @@ class InformationViewController: UIViewController,UISearchBarDelegate { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - getData() +// getData() + getDataFromNet() if isFirstviewController{ addLeftBarBtn() }else{ @@ -193,7 +235,7 @@ class InformationViewController: UIViewController,UISearchBarDelegate { if data.channelContent[index].url != "" { vcs.webURL = data.channelContent[index].url }else{ - vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(data.channelContent[index].id)"+"&areaname="+AccountManager.shared.address).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(data.channelContent[index].id)"+"&areaname="+localAddress).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! } self.navigationController?.present(vcs.wrapWithNavigationController(), animated: true, completion: nil) } @@ -297,7 +339,7 @@ extension InformationViewController:UICollectionViewDataSource,UICollectionViewD if data.channelContent[indexPath.row].url != "" { vcs.webURL = data.channelContent[indexPath.row].url }else{ - vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(data.channelContent[indexPath.row].id)"+"&areaname="+AccountManager.shared.address).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(data.channelContent[indexPath.row].id)"+"&areaname="+localAddress).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! } self.navigationController?.present(vcs.wrapWithNavigationController(), animated: true, completion: nil) diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/evaluation/EvaluationViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/evaluation/EvaluationViewController.swift index a061c52..80b9aae 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/evaluation/EvaluationViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/evaluation/EvaluationViewController.swift @@ -40,7 +40,7 @@ class EvaluationViewController: UIViewController,CLLocationManagerDelegate,Selec } func getData(){ - HTTPServer.shared.getActivityTool(["areaName":AccountManager.shared.address as AnyObject]) { (str, error) in + HTTPServer.shared.getActivityTool(["areaName":localAddress as AnyObject]) { (str, error) in httpJsonResule(jsonString: str, error: error, successHandler: { (json) in if json["status"]==1{ self.activityArr.removeAll() @@ -120,7 +120,7 @@ class EvaluationViewController: UIViewController,CLLocationManagerDelegate,Selec self.navigationController?.navigationBar.setBackgroundImage(backImage, for: UIBarMetrics.default) let leftbtn = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 40)) leftLabel = UILabel(frame: CGRect(x: 0, y: 10, width: 60, height: 20)) - leftLabel.text = AccountManager.shared.address + leftLabel.text = localAddress leftLabel.textColor = UIColor.white leftLabel.sizeToFit() let image = UIImageView(frame: CGRect(x: leftLabel.frame.maxX+4, y: 15, width: 16, height: 9)) @@ -164,7 +164,7 @@ class EvaluationViewController: UIViewController,CLLocationManagerDelegate,Selec if city == nil{ city = placeMark!.administrativeArea } - AccountManager.shared.address = city! + localAddress = city! self.getData() self.addLeftBarBtn() }else if error == nil && arr == nil{ @@ -194,7 +194,7 @@ class EvaluationViewController: UIViewController,CLLocationManagerDelegate,Selec } func selectCity(city: String) { - AccountManager.shared.address = city + localAddress = city self.getData() addLeftBarBtn() } @@ -234,7 +234,7 @@ class EvaluationViewController: UIViewController,CLLocationManagerDelegate,Selec if activityArr[sender.tag-3000].toolUrl != "" { vcs.webURL = activityArr[sender.tag-3000].toolUrl }else{ - vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(activityArr[sender.tag-3000].toolId)"+"&areaname="+AccountManager.shared.address).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(activityArr[sender.tag-3000].toolId)"+"&areaname="+localAddress).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! } self.navigationController?.present(vcs.wrapWithNavigationController(), animated: true, completion: nil) } @@ -276,7 +276,7 @@ extension EvaluationViewController:UICollectionViewDataSource,UICollectionViewDe if toolArr[indexPath.row].toolUrl != "" { vcs.webURL = toolArr[indexPath.row].toolUrl }else{ - vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(toolArr[indexPath.row].toolId)"+"&areaname="+AccountManager.shared.address).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! + vcs.webURL = (HOSTWAP+"/InformationDetail.aspx?id="+"\(toolArr[indexPath.row].toolId)"+"&areaname="+localAddress).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! } self.navigationController?.present(vcs.wrapWithNavigationController(), animated: true, completion: nil) } diff --git a/ParentAssistant/ParentAssistant/Classes/controllers/userCenter/BaseCityChooseSchoolViewController.swift b/ParentAssistant/ParentAssistant/Classes/controllers/userCenter/BaseCityChooseSchoolViewController.swift index fddcda2..1235508 100644 --- a/ParentAssistant/ParentAssistant/Classes/controllers/userCenter/BaseCityChooseSchoolViewController.swift +++ b/ParentAssistant/ParentAssistant/Classes/controllers/userCenter/BaseCityChooseSchoolViewController.swift @@ -19,14 +19,14 @@ class BaseCityChooseSchoolViewController: UIViewController,UISearchBarDelegate { override func viewDidLoad() { super.viewDidLoad() - citySelectbtn.text = AccountManager.shared.address + citySelectbtn.text = localAddress getData() // Do any additional setup after loading the view. } //根据关键字获取学校 func getData(_ keyword:String=""){ - var dic:[String:AnyObject] = ["areaName":AccountManager.shared.address as AnyObject,"keyword":keyword as AnyObject] + var dic:[String:AnyObject] = ["areaName":localAddress as AnyObject,"keyword":keyword as AnyObject] if keyword == ""{ dic.removeValue(forKey: "keyword") } @@ -155,7 +155,7 @@ class BaseCityChooseSchoolViewController: UIViewController,UISearchBarDelegate { } func selectCity(city: String) { - AccountManager.shared.address = city + localAddress = city citySelectbtn.text = city self.getData() @@ -163,7 +163,7 @@ class BaseCityChooseSchoolViewController: UIViewController,UISearchBarDelegate { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - citySelectbtn.text = AccountManager.shared.address + citySelectbtn.text = localAddress } /* // MARK: - Navigation diff --git a/ParentAssistant/ParentAssistant/Classes/util/LocationManger.swift b/ParentAssistant/ParentAssistant/Classes/util/LocationManger.swift new file mode 100644 index 0000000..bdb2fa4 --- /dev/null +++ b/ParentAssistant/ParentAssistant/Classes/util/LocationManger.swift @@ -0,0 +1,54 @@ +// +// LocationManger.swift +// ParentAssistant +// +// Created by Cao yang on 2018/4/20. +// Copyright © 2018年 HANGZHOUTEAM. All rights reserved. +// + +import UIKit +import CoreLocation + +class LocationManger: NSObject,CLLocationManagerDelegate { + + static let shared = LocationManger() + required override init() {} + + var locationManger = CLLocationManager() + + func locationSelf(){ + if TARGET_IPHONE_SIMULATOR==0{//判断是模拟器还是真机 + if CLLocationManager.locationServicesEnabled() && (CLLocationManager.authorizationStatus() == .authorizedWhenInUse || CLLocationManager.authorizationStatus() == .notDetermined){ + locationManger = CLLocationManager() + locationManger.distanceFilter = 100 + locationManger.desiredAccuracy = 10 + locationManger.requestWhenInUseAuthorization() + locationManger.delegate = self + locationManger.allowsBackgroundLocationUpdates = false + locationManger.startUpdatingLocation() + }else{ + appDelegate.window!.makeToast("请在设置中打开定位功能") + } + } + } + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + let curr = locations.last! + let geocoder = CLGeocoder() + geocoder.reverseGeocodeLocation(curr) { (arr, error) in + if arr != nil{ + let placeMark = arr!.first + var city = placeMark!.subLocality + if city == nil{ + city = placeMark!.administrativeArea + } + localAddress = city! + + }else if error == nil && arr == nil{ + + }else if error == nil{ + + } + } + manager.stopUpdatingLocation() + } +} diff --git a/ParentAssistant/ParentAssistant/Classes/util/Macro.swift b/ParentAssistant/ParentAssistant/Classes/util/Macro.swift index 91bdb79..869154c 100644 --- a/ParentAssistant/ParentAssistant/Classes/util/Macro.swift +++ b/ParentAssistant/ParentAssistant/Classes/util/Macro.swift @@ -18,6 +18,11 @@ let screenWidth = UIScreen.main.bounds.size.width let screenHeight = UIScreen.main.bounds.size.height let backGroundColor = UIColor.init(red: 239/255, green: 239/255, blue: 244/255, alpha: 1) let navigationColor = UIColorWithRGB(R: 109, G: 155, B: 255) + +var localAddress = "未知" + + + //MARK: -------------------------- 接口地址 ---------------------------- let appsecret="sincere:3a530f39f99411b454e667d69693c127" var ReleaseHOST:String!="http://campus.myjxt.com"//正式网址 diff --git a/ParentAssistant/ParentAssistant/Classes/util/account.swift b/ParentAssistant/ParentAssistant/Classes/util/account.swift index b8bbc4c..6d4ad49 100644 --- a/ParentAssistant/ParentAssistant/Classes/util/account.swift +++ b/ParentAssistant/ParentAssistant/Classes/util/account.swift @@ -12,7 +12,7 @@ class AccountManager: NSObject { var userid:String="" var token:String? var refreshToken:String="" - var address:String = "未知" +// var address:String = "未知" //单例 @@ -32,10 +32,11 @@ class AccountManager: NSObject { func getUserInfo() -> UserInfoModel { var model = UserInfoModel() - let dic = Setting.getUserInfo()?.dictionary - let data = dic!["data"]?.dictionary - if let value = data { - model = UserInfoModel.deserialize(from: value)! + if let dic = Setting.getUserInfo()?.dictionary { + let data = dic["data"]?.dictionary + if let value = data { + model = UserInfoModel.deserialize(from: value)! + } } return model } @@ -45,14 +46,15 @@ class AccountManager: NSObject { /// - Returns: 返回 StudentClassInfoModel func getChildClassInfo()-> Array { var array = Array() - let dic = Setting.getUserInfo()?.dictionary - let data = dic!["data"]?.dictionary - let studentArr = data!["studentClass"]?.arrayValue - for i in 0..() + + + lazy var tableView = { ()-> UITableView in + + let table = UITableView.init(frame: self.bounds) + table.delegate = self + table.dataSource = self + table.layer.cornerRadius = 5 + table.clipsToBounds = true + table.separatorStyle = .none + table.backgroundColor = backGroundColor + table.register(UITableViewCell.self, forCellReuseIdentifier: "showAlertCell") + return table + }() + private var dataArr = Array() + private var keysWindow = UIWindow() + private var navigateButton = UIButton() + private var backButton = UIButton() + + var rect = CGRect() + var AlertBlock : AlertBackBlock? + + override init(frame: CGRect) { + super.init(frame: frame) + if !frame.isEmpty { + self.rect = frame + self.addSubview(self.tableView) + } + } + func showView() { + let window = UIApplication.shared.keyWindow + let btn = UIButton.init(frame: CGRect.init(x: 0, y: navigationBarHeight!+statusBarHeight, width: screenWidth, height: screenHeight)) + btn.backgroundColor = UIColor.black + btn.alpha = 0.4 + btn.addTarget(self, action: #selector(closeView), for: UIControlEvents.touchDown) + + let upBtn = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth, height: navigationBarHeight!+statusBarHeight)) + upBtn.backgroundColor = UIColor.clear + upBtn.addTarget(self, action: #selector(closeView), for: UIControlEvents.touchDown) + + + + self.keysWindow = window! + self.backButton = btn + self.navigateButton = upBtn + + self.keysWindow.addSubview(self.backButton) + self.keysWindow.addSubview(self.navigateButton) + self.keysWindow.addSubview(self) + showAnimation() + } + + @objc private func closeView(){ + + self.backButton.removeFromSuperview() + self.navigateButton.removeFromSuperview() + self.removeFromSuperview() + self.keysWindow = UIWindow.init() + } + + private func showAnimation(){ + + self.alpha = 0 + self.backButton.alpha = 0 + UIView.animate(withDuration: 0.3) { + self.alpha = 1 + self.backButton.alpha = 0.4 + } + } + + func setUpDataResource (arr:Array) { + if arr.count > 0 { + self.dataArr = arr + } + self.tableView.reloadData() + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.dataArr.count + } + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 50 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + let cell = tableView.dequeueReusableCell(withIdentifier: "showAlertCell") + let dic = self.dataArr[indexPath.row] + + if dic is StudentClassInfoModel { + let dict = dic as! StudentClassInfoModel + cell?.textLabel?.text = dict.studentName + } + return cell! + } + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let selectData = self.dataArr[indexPath.row] + self.AlertBlock!(selectData) + closeView() + } + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + +} diff --git a/ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/Contents.json b/ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/Contents.json new file mode 100644 index 0000000..ff65a26 --- /dev/null +++ b/ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "grow_empty_Image@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/grow_empty_Image@2x.png b/ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/grow_empty_Image@2x.png new file mode 100644 index 0000000..0964f04 Binary files /dev/null and b/ParentAssistant/ParentAssistant/Supporting Files/Assets.xcassets/report/grow_empty_Image.imageset/grow_empty_Image@2x.png differ -- libgit2 0.21.0