IHActivityService.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // IHActivityService.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/24.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. class IHActivityService: NSObject {
  10. static let share = IHActivityService()
  11. lazy var loglist: [LogData] = {
  12. let loglist = [LogData]()
  13. return loglist
  14. }()
  15. deinit {
  16. NotificationCenter.default.removeObserver(self)
  17. }
  18. func getLoglist(_ page : Int,requestSuccess:((Bool,String?)->Void)?,requestFail:@escaping (()->Void)) {
  19. let username = AppShare.username
  20. let token = AppShare.token
  21. let os = AppShare.os
  22. let version = AppShare.version
  23. let client_key = AppShare.client_key
  24. let userId = AppShare.mLoginData?.id
  25. let count = 10
  26. g_operation_log_listHttpRequest(username, client_key: client_key, os: os, version: version, token: token, userId: userId!, page: page, count: count, success: { (json) -> (Void) in
  27. if page == 1{
  28. self.loglist.removeAll()
  29. }
  30. let mLoginInfo = Log_Info.fromJSON(json)
  31. let result = mLoginInfo?.result
  32. if result?.code == .Success{
  33. requestSuccess!(true,nil)
  34. }else{
  35. let msg = result?.msg
  36. requestSuccess!(false,msg)
  37. return
  38. }
  39. guard let _loglist = result?.list else{return}
  40. if page == 1 {
  41. self.loglist = _loglist
  42. }else{
  43. let total = (result?.total)!
  44. if self.loglist.count < total {
  45. self.loglist += _loglist
  46. }
  47. }
  48. NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHActivityHistoryViewGetlogList), object: self.loglist)
  49. }) { () -> (Void) in
  50. }
  51. }
  52. }