diff --git a/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard b/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard index 478c52a..084ab52 100644 --- a/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard +++ b/YouerLiveVideo/YouerLiveVideo/Base.lproj/Main.storyboard @@ -50,11 +50,11 @@ - + - + @@ -547,40 +547,40 @@ - + - - + + - + - + - - + + - + - + - + @@ -609,11 +609,14 @@ - - - + + + + + + @@ -626,16 +629,19 @@ + - + + + - + diff --git a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/MoreTVStationViewController.swift b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/MoreTVStationViewController.swift index 5dc9ba2..4df689d 100644 --- a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/MoreTVStationViewController.swift +++ b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/MoreTVStationViewController.swift @@ -9,13 +9,89 @@ import UIKit class MoreTVStationViewController: UIViewController { - + + @IBOutlet weak var collectionView: UICollectionView! + + var topTenTVStation:[TVStationInfor] = [] + var xxcellentSchool:[TVStationInfor] = [] + var excellentTVStationProgram:[TVStationSubject] = [] + var type:Int = 0 //0:十佳电视台,1:优秀电视台,2:优秀校园节目 + var pageIndex:Int = 2 override func viewDidLoad() { super.viewDidLoad() + if type != 0{ + addCellAndRefresh() + } // Do any additional setup after loading the view. } + func addCellAndRefresh(){ + collectionView.mj_header=MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(MoreTVStationViewController.loadNewData)) + + collectionView.mj_footer=MJRefreshAutoNormalFooter(refreshingTarget: self, refreshingAction: #selector(MoreTVStationViewController.loadMoreData)) + } + + // MARK: - 下拉刷新 + func loadNewData(){ + pageIndex=1 + getTVStation() { (finish) in + self.collectionView.mj_header.endRefreshing() + } + } + // MARK: - 上拉加载更多 + func loadMoreData(){ + getTVStation() { (finish) in + self.collectionView.mj_footer.endRefreshing() + } + } + + func getTVStation(finish: @escaping (Bool)->()){ + if type == 1{ + AppDelegate.instance().httpServer.postExcellentSchool(parameters: ["pageIndex":pageIndex as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + if json.contentData().dictionaryValue["resultData"] != nil{ + if self.pageIndex==1{ + self.xxcellentSchool.removeAll() + } + for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{ + self.xxcellentSchool.append(TVStationInfor(json: item)) + } + if json.contentData().dictionaryValue["resultData"]!.arrayValue.count > 0{ + self.pageIndex=self.pageIndex+1 + } + finish(true) + self.collectionView.reloadData() + } + }, failHandler: { (error) in + finish(false) + + }) + } + }else if type == 2{ + AppDelegate.instance().httpServer.postExcellentProgram(parameters: ["pageIndex":pageIndex as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + if json.contentData().dictionaryValue["resultData"] != nil{ + if self.pageIndex==1{ + self.excellentTVStationProgram.removeAll() + } + for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{ + self.excellentTVStationProgram.append(TVStationSubject(json: item)) + } + if json.contentData().dictionaryValue["resultData"]!.arrayValue.count > 0{ + self.pageIndex=self.pageIndex+1 + } + finish(true) + self.collectionView.reloadData() + } + }, failHandler: { (error) in + finish(false) + }) + } + } + } + + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. @@ -37,15 +113,39 @@ class MoreTVStationViewController: UIViewController { extension MoreTVStationViewController:UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource{ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - + if type == 2{ + let vc = Story.instantiateViewControllerWithIdentifier("TVStationInforViewControllerVC", storyName: "TVStation") as! TVStationInforViewController + vc.excellentTVStationProgram = excellentTVStationProgram[indexPath.row] + self.navigationController?.pushViewController(vc, animated: true) + } + } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MoreTVStationViewCollectionCell + if type == 0{ + cell.tvPicture.sd_setImage(with: URL(string: topTenTVStation[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon")) + cell.tvStationName.text = topTenTVStation[indexPath.row].f_SchoolName + }else if type == 1{ + cell.tvPicture.sd_setImage(with: URL(string: xxcellentSchool[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon")) + cell.tvStationName.text = xxcellentSchool[indexPath.row].f_SchoolName + }else if type == 2{ + cell.tvPicture.sd_setImage(with: URL(string: excellentTVStationProgram[indexPath.row].f_Img), placeholderImage: UIImage(named:"icon")) + cell.tvStationName.text = excellentTVStationProgram[indexPath.row].f_Title + } return cell } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 5 + switch type { + case 0: + return topTenTVStation.count + case 1: + return xxcellentSchool.count + case 2: + return excellentTVStationProgram.count + default: + return 0 + } } } diff --git a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStation.storyboard b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStation.storyboard index 20b9dde..21ba817 100644 --- a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStation.storyboard +++ b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStation.storyboard @@ -1,10 +1,10 @@ - + - + @@ -21,10 +21,9 @@ - + - - + @@ -40,11 +39,11 @@ - + @@ -71,7 +70,16 @@ + + + + + + + + + @@ -282,7 +290,7 @@ - + @@ -389,6 +397,15 @@ + + + + + + + + + + @@ -427,14 +450,22 @@ + + + + + + + + diff --git a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationInforViewController.swift b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationInforViewController.swift index fbcc256..7178d8c 100644 --- a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationInforViewController.swift +++ b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationInforViewController.swift @@ -9,9 +9,19 @@ import UIKit class TVStationInforViewController: UIViewController { - + var excellentTVStationProgram:TVStationSubject! + + @IBOutlet weak var tvImage: UIImageView! + @IBOutlet weak var creatTime: UILabel! + @IBOutlet weak var tvName: UILabel! + @IBOutlet weak var discreption: UITextView! override func viewDidLoad() { super.viewDidLoad() + tvImage.sd_setImage(with: URL(string: excellentTVStationProgram.f_Img), placeholderImage: UIImage(named:"icon")) + tvName.text = excellentTVStationProgram.f_Title + creatTime.text = setDateToString(date:dateFromISO8601(dateString: excellentTVStationProgram.f_CreatorTime)) + discreption.text = excellentTVStationProgram.f_Detail + // Do any additional setup after loading the view. } @@ -20,6 +30,9 @@ class TVStationInforViewController: UIViewController { // Dispose of any resources that can be recreated. } + @IBAction func enterTVStationBtnClick(_ sender: Any) { + + } /* // MARK: - Navigation diff --git a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationViewController.swift b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationViewController.swift index f48771d..e15b5bb 100644 --- a/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationViewController.swift +++ b/YouerLiveVideo/YouerLiveVideo/controllers/TVStation/TVStationViewController.swift @@ -10,7 +10,11 @@ import UIKit class TVStationViewController: UIViewController { var dataSet:[AnyObject] = [] - + var topTenTVStation:[TVStationInfor] = [] + var xxcellentSchool:[TVStationInfor] = [] + var excellentTVStationProgram:[TVStationSubject] = [] + @IBOutlet weak var tableView: UITableView! + var TVStationType:[String] = ["十佳电视台","优秀电视台","优秀校园节目"] override func viewDidLoad() { super.viewDidLoad() self.configTheme() @@ -24,7 +28,41 @@ class TVStationViewController: UIViewController { } func getDataList(){ - + AppDelegate.instance().httpServer.getTopTenSchool(parameters: nil) { (str, error) in + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + for item in json.contentData().arrayValue{ + self.topTenTVStation.append(TVStationInfor(json: item)) + } + (self.tableView.cellForRow(at: IndexPath(item: 0, section: 0)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData() + }, failHandler: { (error) in + + }) + } + AppDelegate.instance().httpServer.postExcellentSchool(parameters: ["pageIndex":1 as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + if json.contentData().dictionaryValue["resultData"] != nil{ + for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{ + self.xxcellentSchool.append(TVStationInfor(json: item)) + } + (self.tableView.cellForRow(at: IndexPath(item: 0, section: 1)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData() + } + }, failHandler: { (error) in + + }) + } + AppDelegate.instance().httpServer.postExcellentProgram(parameters: ["pageIndex":1 as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in + httpJsonResule(jsonString: str, error: error, successHandler: { (json) in + if json.contentData().dictionaryValue["resultData"] != nil{ + for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{ + self.excellentTVStationProgram.append(TVStationSubject(json: item)) + } + (self.tableView.cellForRow(at: IndexPath(item: 0, section: 2)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData() + } + }, failHandler: { (error) in + + }) + } + } override func didReceiveMemoryWarning() { @@ -34,6 +72,18 @@ class TVStationViewController: UIViewController { func moreBtnClick(sender:UIButton){ let vc = Story.instantiateViewControllerWithIdentifier("MoreTVStationViewControllerVC", storyName: "TVStation") as! MoreTVStationViewController + switch sender.tag { + case 0: + vc.topTenTVStation = topTenTVStation + case 1: + vc.xxcellentSchool = xxcellentSchool + case 2: + vc.excellentTVStationProgram = excellentTVStationProgram + default: + break + } + vc.type = sender.tag + vc.title = TVStationType[sender.tag] self.navigationController?.pushViewController(vc, animated: true) } /* @@ -54,15 +104,16 @@ extension TVStationViewController:UITableViewDelegate,UITableViewDataSource{ } func numberOfSections(in tableView: UITableView) -> Int { - return 10 + return TVStationType.count } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let view = UIView(frame: CGRect(x: 0, y: 0, width: getScreenWidth(), height: 44)) + view.backgroundColor = tableView.backgroundColor let imageView = UIImageView(frame: CGRect(x: 8, y: 8, width: 28, height: 28)) imageView.image = UIImage(named: "icon") let label = UILabel(frame: CGRect(x: imageView.frame.maxX+8, y: 11, width: 100, height: 21)) - label.text = "世家电视台" + label.text = TVStationType[section] label.textAlignment = .left label.sizeToFit() let btn = UIButton(frame: CGRect(x: getScreenWidth() - 8 - 30, y: 7, width: 30, height: 30)) @@ -85,6 +136,7 @@ extension TVStationViewController:UITableViewDelegate,UITableViewDataSource{ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TVStationViewControllerTableViewCell + cell.collectionView.tag = indexPath.section+1 return cell } } @@ -92,28 +144,160 @@ extension TVStationViewController:UITableViewDelegate,UITableViewDataSource{ extension TVStationViewController:UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource{ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - let vc = Story.instantiateViewControllerWithIdentifier("TVStationInforViewControllerVC", storyName: "TVStation") as! TVStationInforViewController - self.navigationController?.pushViewController(vc, animated: true) + if collectionView.tag == 3{ + let vc = Story.instantiateViewControllerWithIdentifier("TVStationInforViewControllerVC", storyName: "TVStation") as! TVStationInforViewController + vc.excellentTVStationProgram = excellentTVStationProgram[indexPath.row] + self.navigationController?.pushViewController(vc, animated: true) + } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! TVStationViewControllerCollectionCell + if collectionView.tag == 1{ + cell.image.sd_setImage(with: URL(string: topTenTVStation[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon")) + cell.tvStationName.text = topTenTVStation[indexPath.row].f_SchoolName + }else if collectionView.tag == 2{ + cell.image.sd_setImage(with: URL(string: xxcellentSchool[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon")) + cell.tvStationName.text = xxcellentSchool[indexPath.row].f_SchoolName + }else if collectionView.tag == 3{ + cell.image.sd_setImage(with: URL(string: excellentTVStationProgram[indexPath.row].f_Img), placeholderImage: UIImage(named:"icon")) + cell.tvStationName.text = excellentTVStationProgram[indexPath.row].f_Title + } return cell } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 5 + switch collectionView.tag { + case 1: + return topTenTVStation.count + case 2: + return xxcellentSchool.count + case 3: + return excellentTVStationProgram.count + default: + return 0 + } } } class TVStationViewControllerTableViewCell:UITableViewCell{ + @IBOutlet weak var collectionView: UICollectionView! } class TVStationViewControllerCollectionCell:UICollectionViewCell{ - + var index:Int! @IBOutlet weak var image: UIImageView! @IBOutlet weak var tvStationName: UILabel! } + +class TVStationInfor { + var f_Id:String! //标识字段,Guid标识 , + var f_DeleteMark:Bool = false //删除标识,1-已删除 , + var f_CreatorTime:String!//创建时间 , + var f_CreatorUserId:String!//创建人员ID , + var f_LastModifyTime:String! //最近一次编辑时间 , + var f_LastModifyUserId:String! //最近一次编辑人员 , + var f_DeleteTime:String! //删除时间 , + var f_DeleteUserId:String! //删除人员 , + var f_SchoolName:String! //学校名称 , + var f_SchoolTypeId:String!// 学校类型 , + var f_Logo:String! //校徽 , + var f_IsTopTen:Bool = false //是否十佳校园电视台 , + var f_IsExcellent:Bool = false //是否优秀校园电视台 , + var f_Url:String!// 机构地址 + + init(json:JSON){ + f_Id = json["f_Id"].stringValue + f_DeleteMark = json["f_DeleteMark"].boolValue + f_CreatorTime = json["f_CreatorTime"].stringValue + f_CreatorUserId = json["f_CreatorUserId"].stringValue + f_LastModifyTime = json["f_LastModifyTime"].stringValue + f_LastModifyUserId = json["f_LastModifyUserId"].stringValue + f_DeleteTime = json["f_DeleteTime"].stringValue + f_DeleteUserId = json["f_DeleteUserId"].stringValue + f_SchoolName = json["f_SchoolName"].stringValue + f_SchoolTypeId = json["f_SchoolTypeId"].stringValue + f_Logo = json["f_Logo"].stringValue + f_IsTopTen = json["f_IsTopTen"].boolValue + f_IsExcellent = json["f_IsExcellent"].boolValue + f_Url = json["f_Url"].stringValue + } +} + +class TVStationSubject { + var f_Url:String!// 机构地址 + + var f_WaveTitle:String! + var f_ChapterName:String! + var f_TopicName:String! + var f_TestName:String! + var f_Id:String!// 标识字段,Guid标识 , + var f_DeleteMark:Bool = false // 删除标识,1-已删除 , + var f_CreatorTime:String!// 创建时间 , + var f_CreatorUserId:String!// 创建人员ID , + var f_LastModifyTime:String!// 最近一次编辑时间 , + var f_LastModifyUserId:String!//最近一次编辑人员 , + var f_DeleteTime:String!//删除时间 , + var f_DeleteUserId:String!// 删除人员 , + var f_Img :String!//课件图标/微课封面 , + var f_Title:String!//课件名称 , + var f_CreatorName:String!// 上传人员昵称 , + var f_Pv:Int!// 浏览量 , + var f_DownloadSum:Int!// 下载量 , + var f_LoveSum:Int!// 点赞量 , + var f_Price:Int!// 价格 , + var f_WaveId:String!// 所属教材ID , + var f_ChapterId:String!// 所属章节 , + var f_TopicId:String!//所属知识点 , + var f_TestId:String!//所属考点 , + var f_SchoolId:String!// 上传老师的学校ID , + var f_IsExamine:Int!// 审核状态:0-未审核,1-审核通过,2-审核不通过 , + var f_ExamineUserId :String!//审核人ID , + var f_ExamineName:String!//审核人姓名 , + var f_ExamineDatetime :String!// 审核日期 , + var f_ResourceType:Int!// 资源类型 0-微课 1-资源 2-电视台 , + var f_ResourceUrl:String!// 资源地址 , + var f_IsOpen:Bool = false // 是否公开 , + var f_Detail :String!// 资源简介 , + var f_TelevisionId :String!//电视台目录 + init(json:JSON){ + f_Url = json["f_Url"].stringValue + f_WaveTitle = json["f_WaveTitle"].stringValue + f_ChapterName = json["f_ChapterName"].stringValue + f_TopicName = json["f_TopicName"].stringValue + f_TestName = json["f_TestName"].stringValue + f_Id = json["f_Id"].stringValue + f_DeleteMark = json["f_DeleteMark"].boolValue + f_CreatorTime = json["f_CreatorTime"].stringValue + f_CreatorUserId = json["f_CreatorUserId"].stringValue + f_LastModifyTime = json["f_LastModifyTime"].stringValue + f_LastModifyUserId = json["f_LastModifyUserId"].stringValue + f_DeleteTime = json["f_DeleteTime"].stringValue + f_DeleteUserId = json["f_DeleteUserId"].stringValue + f_Img = json["f_Img"].stringValue + f_Title = json["f_Title"].stringValue + f_CreatorName = json["f_CreatorName"].stringValue + f_Pv = json["f_Pv"].intValue + f_DownloadSum = json["f_DownloadSum"].intValue + f_LoveSum = json["f_LoveSum"].intValue + f_Price = json["f_Price"].intValue + f_WaveId = json["f_WaveId"].stringValue + f_ChapterId = json["f_ChapterId"].stringValue + f_TopicId = json["f_TopicId"].stringValue + f_TestId = json["f_TestId"].stringValue + f_SchoolId = json["f_SchoolId"].stringValue + f_IsExamine = json["f_IsExamine"].intValue + f_ExamineUserId = json["f_ExamineUserId"].stringValue + f_ExamineName = json["f_ExamineName"].stringValue + f_ExamineDatetime = json["f_ExamineDatetime"].stringValue + f_ResourceType = json["f_ResourceType"].intValue + f_ResourceUrl = json["f_ResourceUrl"].stringValue + f_IsOpen = json["f_IsOpen"].boolValue + f_Detail = json["f_Detail"].stringValue + f_TelevisionId = json["f_TelevisionId"].stringValue + + } +} diff --git a/YouerLiveVideo/YouerLiveVideo/util/utiles.swift b/YouerLiveVideo/YouerLiveVideo/util/utiles.swift index 9b48ca5..9783108 100644 --- a/YouerLiveVideo/YouerLiveVideo/util/utiles.swift +++ b/YouerLiveVideo/YouerLiveVideo/util/utiles.swift @@ -346,6 +346,39 @@ func resignTextFiledFirstResponder(){ firstView?.resignFirstResponder() } } + +///ISO8601相关 +private var iso8601Formatter:DateFormatter? +func dateFromISO8601(dateString:String)->Date{ + var dateFormatter:DateFormatter! + if let tmp=iso8601Formatter{ + dateFormatter=tmp + }else{ + iso8601Formatter = DateFormatter() + iso8601Formatter!.locale = Locale(identifier: "en_US_POSIX") + //iso8601Formatter!.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ" + //iso8601Formatter!.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SS" + dateFormatter=iso8601Formatter! + } + //不知道为什么服务器传回的时间有不同格式 + let arr = ["yyyy-MM-dd'T'HH:mm:ss.SSS","yyyy-MM-dd'T'HH:mm:ss","yyyy-MM-dd HH:mm:ss","yyyy-MM-dd HH:mm:ss.SSS","yyyy-MM-dd HH:mm:ss.SSS'Z'","yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"] + for item in arr { + iso8601Formatter!.dateFormat = item + let ret=dateFormatter.date(from: dateString) + if let date=ret{ + return date + } + } + + return Date(timeIntervalSince1970: 0) +} + +func setDateToString(date:Date)->String{ + let timeFormatter = DateFormatter() + timeFormatter.dateFormat = "yyyy-MM-dd" + return timeFormatter.string(from: date) +} + //时间处理 func currentTime()->String{ let format = creatDateFormate(dateFormat: "yyyy-MM-dd HH:mm:ss") -- libgit2 0.21.0