MainTaskSecondViewController.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. //
  2. // MainTaskSecondViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2017/3/12.
  6. // Copyright © 2017年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import AlamofireImage
  11. import AlamofireObjectMapper
  12. import SwiftyJSON
  13. import ObjectMapper
  14. import EZSwiftExtensions
  15. import swiftScan
  16. import CocoaLumberjack
  17. import MBProgressHUD
  18. import WebKit
  19. class MainTaskSecondViewController: UIViewController {
  20. fileprivate static let PAGE_SIZE = 20
  21. @IBOutlet weak var tableViewTopConstraint: NSLayoutConstraint!
  22. @IBOutlet weak var tableView: UITableView!
  23. //相关变量
  24. //1段分类
  25. fileprivate var seguementControl:SegmentedControl!
  26. //存储热点图片新闻数组
  27. private var taskImageshowEntitys:[TaskImageshowEntity] = [] {
  28. didSet {
  29. if taskImageshowEntitys.count > 0 {
  30. self.tableView.tableHeaderView = self.initTableHeaderView()
  31. let imageShowView = self.tableView.tableHeaderView as! ImageSlidesShowView
  32. imageShowView.imageshowEntitys = taskImageshowEntitys
  33. // self.tableView.reloadData()
  34. }else {
  35. self.tableView.tableHeaderView = self.initTableHeaderImageView()
  36. }
  37. }
  38. }
  39. fileprivate var newPublishPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  40. fileprivate var newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  41. //所有首页应用
  42. private var homeApps:[O2App] = []
  43. //所有待办数据
  44. fileprivate var todoTasks:[TodoTask] = []
  45. //所有最新公告数据
  46. fileprivate var newPublishInfos:[CMS_PublishInfo] = []
  47. //顶部导航
  48. private lazy var navView: MyView = {
  49. let nav = MyView(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDTH, height: safeAreaTopHeight))
  50. nav.backgroundColor = UIColor.clear
  51. return nav
  52. }()
  53. //分段视图
  54. lazy var segmentView: UIView = {
  55. let view = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 40))
  56. view.backgroundColor = UIColor.white
  57. view.addSubview(self.seguementControl)
  58. return view
  59. }()
  60. override func viewWillAppear(_ animated: Bool) {
  61. super.viewWillAppear(animated)
  62. loadHomeApps()
  63. loadPlayerList()
  64. loadNewPublish(newPublishPageModel)
  65. //self.initBarManager()
  66. self.navigationController?.navigationBar.isHidden = true
  67. self.tableView.delegate = self
  68. }
  69. override func viewWillDisappear(_ animated: Bool) {
  70. super.viewWillDisappear(animated)
  71. self.tableView.delegate = nil
  72. self.navigationController?.navigationBar.isHidden = false
  73. //ZoneNavigationBarManager.reStoreToSystemNavigationBar()
  74. }
  75. override func viewDidLoad() {
  76. super.viewDidLoad()
  77. //self.title = "首页"
  78. self.automaticallyAdjustsScrollViewInsets = false
  79. self.navView.tableViews.append(self.tableView)
  80. //添加扫描按钮事件
  81. self.navView.scanBtn?.addTarget(self, action: #selector(startScanAction(_:)), for: .touchUpInside)
  82. //添加发起按钮事件
  83. self.navView.addBtn?.addTarget(self, action: #selector(startFlowAction(_:)), for: .touchUpInside)
  84. self.view.addSubview(self.navView)
  85. self.seguementControl = initSegumentControl()
  86. self.tableView.dataSource = self
  87. self.tableView.tableHeaderView = self.initTableHeaderImageView()
  88. if #available(iOS 11.0, *) {
  89. let topConstant = CGFloat(0 - IOS11_TOP_STATUSBAR_HEIGHT)
  90. self.tableViewTopConstraint.constant = topConstant
  91. }
  92. }
  93. //初始化热点新闻显示
  94. private func initTableHeaderView() -> UIView {
  95. let height = SCREEN_WIDTH / 2
  96. let frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: height)
  97. let imageShowView = ImageSlidesShowView(frame: frame)
  98. imageShowView.delegate = self
  99. return imageShowView
  100. }
  101. //默认新闻热点使用图片 如果服务器有数据 就用ImageSlidesShowView
  102. private func initTableHeaderImageView() -> UIView {
  103. let height = SCREEN_WIDTH / 2
  104. let frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: height)
  105. let imageShowView = UIImageView(image: UIImage(named: "pic_lunbo_1"))
  106. imageShowView.frame = frame
  107. imageShowView.contentMode = .scaleAspectFill
  108. return imageShowView
  109. }
  110. //初始化
  111. private func initBarManager(){
  112. ZoneNavigationBarManager.managerWithController(self)
  113. ZoneNavigationBarManager.setBarColor(UIColor.clear)
  114. ZoneNavigationBarManager.setTintColor(UIColor.white)
  115. // ZoneNavigationBarManager.setBarColor(UIColor(colorLiteralRed: 1, green: 1, blue: 1, alpha: 0))
  116. // ZoneNavigationBarManager.setTintColor(UIColor.white)
  117. // ZoneNavigationBarManager.setStatusBarStyle(.lightContent)
  118. // ZoneNavigationBarManager.setZeroAlphaOffset(-64)
  119. // ZoneNavigationBarManager.setFullAlphaOffset(200)
  120. // ZoneNavigationBarManager.setFullAlphaTintColor(UIColor.red)
  121. //ZoneNavigationBarManager.setContinus(false)
  122. }
  123. //初始化分类显示
  124. private func initSegumentControl() -> SegmentedControl{
  125. let kLivelyBlueColor = UIColor(red: 251 / 255, green: 71 / 255, blue: 71/255, alpha: 1)
  126. //返回一个分类头部
  127. let titleStrings = ["信息中心", "办公中心"]
  128. let titles: [NSAttributedString] = {
  129. let attributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.black]
  130. var titles = [NSAttributedString]()
  131. for titleString in titleStrings {
  132. let title = NSAttributedString(string: titleString, attributes: attributes)
  133. titles.append(title)
  134. }
  135. return titles
  136. }()
  137. let selectedTitles: [NSAttributedString] = {
  138. let attributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: kLivelyBlueColor]
  139. var selectedTitles = [NSAttributedString]()
  140. for titleString in titleStrings {
  141. let selectedTitle = NSAttributedString(string: titleString, attributes: attributes)
  142. selectedTitles.append(selectedTitle)
  143. }
  144. return selectedTitles
  145. }()
  146. let segmentedControl = SegmentedControl.initWithTitles(titles, selectedTitles: selectedTitles)
  147. segmentedControl.delegate = self
  148. segmentedControl.backgroundColor = UIColor.white
  149. segmentedControl.autoresizingMask = [.flexibleRightMargin, .flexibleWidth]
  150. segmentedControl.selectionIndicatorStyle = .bottom
  151. segmentedControl.selectionIndicatorColor = kLivelyBlueColor
  152. segmentedControl.selectionIndicatorHeight = 0.5
  153. segmentedControl.segmentWidth = (UIScreen.main.bounds.width - 100) / 2
  154. //segmentedControl.frame.origin.y = 64
  155. segmentedControl.frame = CGRect(x:50,y:0,width: UIScreen.main.bounds.width, height: 40)
  156. //segmentedControl.frame.size = CGSize(width: UIScreen.main.bounds.width, height: 40)
  157. return segmentedControl
  158. }
  159. //开始扫描
  160. @objc private func startScanAction(_ sender:AnyObject?) {
  161. if let scanVC = ScanHelper.initScanViewController() {
  162. self.pushVC(scanVC)
  163. }else {
  164. gotoApplicationSettings(alertMessage: "是否跳转到手机设置页面开启相机权限?")
  165. }
  166. }
  167. //开始显示新建页面
  168. @objc private func startFlowAction(_ sender:AnyObject?){
  169. //self.navigationController?.navigationBar.isHidden = false
  170. self.performSegue(withIdentifier: "showAppCategorySegue", sender: nil)
  171. }
  172. //读取数据待办数据
  173. fileprivate func loadMainTodo(_ pageModel:CommonPageModel,_ isFirst:Bool = true){
  174. //pageModel.pageSize = MainTaskSecondViewController.PAGE_SIZE
  175. ProgressHUD.show("加载中...", interaction: false)
  176. //ZoneHUD.showNormalHUD((self.navigationController?.view!)!)
  177. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(TaskContext.taskContextKey, query: TaskContext.todoTaskListQuery, parameter: pageModel.toDictionary() as [String : AnyObject]?)
  178. if isFirst {
  179. self.todoTasks.removeAll(keepingCapacity: true)
  180. }
  181. Alamofire.request(url!).responseArray(queue: nil, keyPath: "data", context: nil, completionHandler: { (response:DataResponse<[TodoTask]>) in
  182. DDLogDebug(response.debugDescription)
  183. switch response.result {
  184. case .success(let tTasks):
  185. DispatchQueue.main.async {
  186. self.todoTasks.append(contentsOf: tTasks)
  187. //let count:Int = JSON(val)["count"].int ?? 0
  188. self.newTaskPageModel.setPageTotal(tTasks.count)
  189. //ZoneHUD.dismissNormalHUD()
  190. ProgressHUD.dismiss()
  191. DispatchQueue.main.async {
  192. self.tableView.beginUpdates()
  193. self.tableView.reloadSections(IndexSet.init(integer: 1), with: .automatic)
  194. self.tableView.endUpdates()
  195. }
  196. }
  197. //ProgressHUD.showSuccess("读取待办完成")
  198. case .failure(let err):
  199. DispatchQueue.main.async {
  200. ProgressHUD.showSuccess("加载待办失败")
  201. //ZoneHUD.showErrorHUD(errorText: "待办列表出错", 0.5)
  202. DDLogError(err.localizedDescription)
  203. }
  204. }
  205. })
  206. }
  207. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  208. if segue.identifier == "showMailSegue" {
  209. MailViewController.app = sender as? O2App
  210. }
  211. }
  212. //读取首页应用
  213. private func loadHomeApps() {
  214. let apps = OOAppsInfoDB.shareInstance.queryMainData()
  215. homeApps.removeAll()
  216. if apps.isEmpty {
  217. homeApps.append(contentsOf: O2AppUtil.defaultMainApps)
  218. }else {
  219. homeApps.append(contentsOf: apps)
  220. }
  221. tableView.beginUpdates()
  222. tableView.reloadSections(IndexSet.init(integer: 0), with: .automatic)
  223. tableView.endUpdates()
  224. }
  225. //读取最新公告
  226. fileprivate func loadNewPublish(_ pageModel:CommonPageModel,_ isFirst:Bool = true){
  227. //ZoneHUD.showNormalHUD((self.navigationController?.view!)!)
  228. ProgressHUD.show("加载中...", interaction: false)
  229. let npURL = AppDelegate.o2Collect.generateURLWithAppContextKey(CMSContext.cmsContextKey, query: CMSContext.cmsCategoryDetailQuery, parameter: pageModel.toDictionary() as[String:AnyObject]?)
  230. if isFirst {
  231. self.newPublishInfos.removeAll()
  232. }
  233. Alamofire.request(npURL!, method: .put, parameters:[String:Any](), encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  234. switch response.result {
  235. case .success(let val):
  236. let json = JSON(val)["data"]
  237. let type = JSON(val)["type"]
  238. if type == "success" {
  239. let pInfos = Mapper<CMS_PublishInfo>().mapArray(JSONString: json.description)
  240. if let uPInfos = pInfos {
  241. self.newPublishInfos.append(contentsOf: uPInfos)
  242. let count:Int = JSON(val)["count"].int ?? 0
  243. self.newPublishPageModel.setPageTotal(count)
  244. }
  245. DispatchQueue.main.async {
  246. //ZoneHUD.dismissNormalHUD()
  247. ProgressHUD.dismiss()
  248. self.tableView.beginUpdates()
  249. self.tableView.reloadSections(IndexSet.init(integer: 1), with: .automatic)
  250. self.tableView.endUpdates()
  251. }
  252. }else{
  253. DispatchQueue.main.async {
  254. //ZoneHUD.showErrorHUD(errorText: "新闻列表出错", 0.5)
  255. ProgressHUD.showError("新闻列表出错")
  256. DDLogError(json.description)
  257. }
  258. }
  259. //print(json)
  260. case .failure(let err):
  261. DispatchQueue.main.async {
  262. ProgressHUD.showError("新闻列表出错")
  263. //ZoneHUD.showErrorHUD(errorText: "新闻列表出错", 0.5)
  264. DDLogError(err.localizedDescription)
  265. }
  266. }
  267. }
  268. }
  269. //热点图片新闻
  270. private func loadPlayerList(){
  271. self.taskImageshowEntitys.removeAll(keepingCapacity: true)
  272. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(HotpicContext.hotpicContextKey, query: HotpicContext.hotpicAllListQuery, parameter: ["##page##":"0" as AnyObject,"##count##":"8" as AnyObject])
  273. Alamofire.request(url!, method: .put, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  274. switch response.result {
  275. case .success(let val):
  276. let type = JSON(val)["type"]
  277. if type == "success" {
  278. let data = JSON(val)["data"]
  279. let entrys = Mapper<TaskImageshowEntity>().mapArray(JSONString: data.description)
  280. DispatchQueue.main.async {
  281. self.taskImageshowEntitys.append(contentsOf: entrys!)
  282. }
  283. }else{
  284. }
  285. case .failure(let err):
  286. DDLogError(err.localizedDescription)
  287. }
  288. }
  289. }
  290. // MARK: - 回调刷新
  291. @IBAction func unWindRefreshSegueForMainTask(_ segue:UIStoryboardSegue){
  292. DDLogDebug("backRefreshMainTask")
  293. // newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  294. // self.loadMainTodo(newTaskPageModel)
  295. }
  296. @IBAction func unBackAppsForMain(_ segue:UIStoryboardSegue){
  297. DDLogDebug("返回应用列表")
  298. if segue.source.isKind(of: TaskCreateViewController.self) {
  299. newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  300. self.loadMainTodo(newTaskPageModel)
  301. // let sourceVC = segue.source as! TaskCreateViewController
  302. // if let task = sourceVC.task {
  303. // self.forwardTodoTaskDetail(task)
  304. // }
  305. }
  306. }
  307. override func didReceiveMemoryWarning() {
  308. super.didReceiveMemoryWarning()
  309. // Dispose of any resources that can be recreated.
  310. }
  311. }
  312. extension MainTaskSecondViewController:UITableViewDataSource,UITableViewDelegate{
  313. //分两个Section
  314. func numberOfSections(in tableView: UITableView) -> Int {
  315. return 2
  316. }
  317. //Section 0 返回1,Section 1返回读了的数据列表
  318. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  319. switch section {
  320. case 0:
  321. return 1
  322. case 1:
  323. if self.seguementControl.selectedIndex == 0 {
  324. return self.newPublishInfos.count
  325. }else if self.seguementControl.selectedIndex == 1 {
  326. return self.todoTasks.count
  327. }else{
  328. return 0
  329. }
  330. default:
  331. return 0
  332. }
  333. }
  334. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  335. if indexPath.section == 0 {
  336. //第0段返回应用列表
  337. let cell = tableView.dequeueReusableCell(withIdentifier: "NewMainAppTableViewCell", for: indexPath) as! (NewMainAppTableViewCell & Configurable)
  338. cell.apps.removeAll()
  339. cell.apps.append(contentsOf: homeApps)
  340. //设置代理
  341. cell.delegate = self
  342. return cell
  343. }else if indexPath.section == 1{
  344. //第1段返回数据列表
  345. let cell = tableView.dequeueReusableCell(withIdentifier: "NewMainItemTableViewCell", for: indexPath) as! NewMainItemTableViewCell
  346. if self.seguementControl.selectedIndex == 0 {
  347. if !self.newPublishInfos.isEmpty {
  348. let obj = self.newPublishInfos[indexPath.row]
  349. cell.model = obj
  350. }
  351. }else if self.seguementControl.selectedIndex == 1 {
  352. if !self.todoTasks.isEmpty {
  353. let obj = self.todoTasks[indexPath.row]
  354. cell.model = obj
  355. }
  356. }
  357. return cell
  358. }else{
  359. return UITableViewCell()
  360. }
  361. }
  362. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  363. if section == 1 {
  364. return 40.0
  365. }else{
  366. return 0
  367. }
  368. }
  369. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  370. if section == 0 {
  371. return 10.0
  372. }else{
  373. return 0.0
  374. }
  375. }
  376. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  377. if section == 0 {
  378. let view = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 10.0))
  379. view.backgroundColor = UIColor(red: 246.0/255.0, green: 246.0/255.0, blue: 246.0/255.0, alpha: 1.0)
  380. return view
  381. }else{
  382. return nil
  383. }
  384. }
  385. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  386. if section == 1{
  387. return segmentView
  388. }else{
  389. return nil
  390. }
  391. }
  392. //行高
  393. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  394. switch indexPath.section {
  395. case 0:
  396. return 100
  397. case 1:
  398. return 60
  399. default:
  400. return 50
  401. }
  402. }
  403. //信息点击和新闻点击执行
  404. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  405. if (indexPath as NSIndexPath).section == 1 {
  406. //self.navigationController?.navigationBar.isHidden = false
  407. if seguementControl.selectedIndex == 0 {
  408. let publishInfo = self.newPublishInfos[indexPath.row]
  409. let taskInfo = TaskImageshowEntity(JSON: (publishInfo.toJSON()))
  410. taskInfo?.infoId = publishInfo.id
  411. self.processApplicationForCMS(entity: taskInfo!)
  412. }else if seguementControl.selectedIndex == 1{
  413. let todoTask = self.todoTasks[(indexPath as NSIndexPath).row]
  414. //DDLogDebug("\(todoTask.title!)")
  415. self.forwardTodoTaskDetail(todoTask)
  416. }
  417. }
  418. }
  419. private func forwardTodoTaskDetail(_ todoTask:TodoTask){
  420. let taskStoryboard = UIStoryboard(name: "task", bundle: Bundle.main)
  421. let todoTaskDetailVC = taskStoryboard.instantiateViewController(withIdentifier: "todoTaskDetailVC") as! TodoTaskDetailViewController
  422. todoTaskDetailVC.todoTask = todoTask
  423. todoTaskDetailVC.backFlag = 1
  424. self.navigationController?.pushViewController(todoTaskDetailVC, animated: true)
  425. }
  426. }
  427. //分类显示点击代理
  428. extension MainTaskSecondViewController: SegmentedControlDelegate {
  429. func segmentedControl(_ segmentedControl: SegmentedControl, didSelectIndex selectedIndex: Int) {
  430. print("Did select index \(selectedIndex)")
  431. switch segmentedControl.style {
  432. case .text:
  433. print("The title is “\(segmentedControl.titles[selectedIndex].string)”\n")
  434. case .image:
  435. print("The image is “\(segmentedControl.images[selectedIndex])”\n")
  436. }
  437. switch selectedIndex {
  438. case 0:
  439. newPublishPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  440. loadNewPublish(newPublishPageModel)
  441. break
  442. case 1:
  443. newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  444. loadMainTodo(newTaskPageModel)
  445. break
  446. default:
  447. break
  448. }
  449. }
  450. }
  451. //应用点击代理
  452. extension MainTaskSecondViewController:NewMainAppTableViewCellDelegate{
  453. func emptyTapClick() {
  454. tabBarController?.cyl_tabBarController.cyl_popSelectTabBarChildViewController(at: 3)
  455. //tabBarController?.selectedIndex = 3
  456. }
  457. func NewMainAppTableViewCellWithApp(_ app: O2App) {
  458. AppConfigSettings.shared.appBackType = 1
  459. if let segueIdentifier = app.segueIdentifier,segueIdentifier != "" {
  460. if app.storyBoard! == "webview" {
  461. DDLogDebug("open webview for : "+app.title!+" url: "+app.vcName!)
  462. self.performSegue(withIdentifier: segueIdentifier, sender: app)
  463. }else {
  464. self.performSegue(withIdentifier: segueIdentifier, sender: nil)
  465. }
  466. } else {
  467. if app.storyBoard! == "webview" {
  468. DDLogDebug("open webview for : "+app.title!+" url: "+app.vcName!)
  469. let webConfiguration = WKWebViewConfiguration()
  470. let myURL = URL(string: app.vcName!)
  471. let webView = WKWebView(frame: self.view.bounds, configuration: webConfiguration)
  472. let myRequest = URLRequest(url: myURL!)
  473. webView.load(myRequest)
  474. self.view.addSubview(webView)
  475. } else {
  476. // 语音助手还没做
  477. if app.appId == "o2ai" {
  478. DDLogInfo("语音助手还没做,,,,,,,,,,,,,,,,")
  479. self.showError(title: "语音助手正在开发中......")
  480. return
  481. }
  482. let story = O2AppUtil.apps.first { (appInfo) -> Bool in
  483. return app.appId == appInfo.appId
  484. }
  485. var storyBoardName = app.storyBoard
  486. if story != nil {
  487. storyBoardName = story?.storyBoard
  488. }
  489. DDLogDebug("storyboard: \(storyBoardName!) , app:\(app.appId!)")
  490. let storyBoard = UIStoryboard(name: storyBoardName!, bundle: nil)
  491. //let storyBoard = UIStoryboard(name: app.storyBoard!, bundle: nil)
  492. var destVC:UIViewController!
  493. if let vcname = app.vcName,vcname.isEmpty == false {
  494. destVC = storyBoard.instantiateViewController(withIdentifier: app.vcName!)
  495. }else{
  496. destVC = storyBoard.instantiateInitialViewController()
  497. }
  498. if app.vcName == "todoTask" {
  499. if "taskcompleted" == app.appId {
  500. AppConfigSettings.shared.taskIndex = 2
  501. }else if "read" == app.appId {
  502. AppConfigSettings.shared.taskIndex = 1
  503. }else if "readcompleted" == app.appId {
  504. AppConfigSettings.shared.taskIndex = 3
  505. }else {
  506. AppConfigSettings.shared.taskIndex = 0
  507. }
  508. }
  509. if destVC.isKind(of: ZLNavigationController.self) {
  510. self.show(destVC, sender: nil)
  511. }else{
  512. self.navigationController?.pushViewController(destVC, animated: true)
  513. }
  514. }
  515. }
  516. }
  517. }
  518. //热点新闻代理实现
  519. extension MainTaskSecondViewController:ImageSlidesShowViewDelegate{
  520. func ImageSlidesShowClick(taskImageshowEntity: TaskImageshowEntity) {
  521. if taskImageshowEntity.application == "BBS" {
  522. processApplicationForBBS(entity: taskImageshowEntity)
  523. }else if taskImageshowEntity.application == "CMS" {
  524. processApplicationForCMS(entity: taskImageshowEntity)
  525. }
  526. }
  527. func processApplicationForBBS(entity:TaskImageshowEntity){
  528. let subjectURL = AppDelegate.o2Collect.generateURLWithAppContextKey(BBSContext.bbsContextKey, query: BBSContext.subjectByIdQuery, parameter: ["##id##":entity.infoId! as AnyObject])
  529. Alamofire.request(subjectURL!, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  530. switch response.result {
  531. case .success(let val):
  532. let type = JSON(val)["type"]
  533. if type == "success" {
  534. DDLogDebug(JSON(val).description)
  535. let currentSubject = JSON(val)["data"]["currentSubject"]
  536. let subjectData = Mapper<BBSSubjectData>().map(JSONString: currentSubject.description)
  537. DispatchQueue.main.async {
  538. let bbsStoryboard = UIStoryboard(name: "bbs", bundle: Bundle.main)
  539. let destVC = bbsStoryboard.instantiateViewController(withIdentifier: "BBSSubjectDetailVC") as! BBSSubjectDetailViewController
  540. destVC.subject = subjectData
  541. destVC.title = entity.title
  542. //self.navigationController?.navigationBar.isHidden = false
  543. self.pushVC(destVC)
  544. }
  545. }else{
  546. DDLogError(JSON(val).description)
  547. }
  548. case .failure(let err):
  549. DDLogDebug(err as! String)
  550. }
  551. }
  552. }
  553. func processApplicationForCMS(entity:TaskImageshowEntity){
  554. let bbsStoryboard = UIStoryboard(name: "information", bundle: Bundle.main)
  555. let destVC = bbsStoryboard.instantiateViewController(withIdentifier: "CMSSubjectDetailVC") as! CMSItemDetailViewController
  556. destVC.documentId = entity.infoId
  557. destVC.title = entity.title
  558. //self.navigationController?.navigationBar.isHidden = false
  559. self.pushVC(destVC)
  560. }
  561. }