PortalViewModel.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // PortalViewModel.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/12/20.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import Promises
  9. import CocoaLumberjack
  10. import Moya
  11. import Combine
  12. class PortalViewModel {
  13. private let portalAPI = OOMoyaProvider<PortalAPI>()
  14. /// 查询我能看到的门户列表
  15. /// 和移动端门户列表进行排除
  16. func listMobile(localList: [O2App])-> Promise<[O2App]> {
  17. return Promise { fulfill, reject in
  18. self.portalAPI.request(.listMobile, completion: {result in
  19. let response = OOResult<BaseModelClass<[O2PortalInfo]>>(result)
  20. if response.isResultSuccess() {
  21. if let list = response.model?.data {
  22. var newLocal:[O2App] = []
  23. for local in localList {
  24. var isIn = false
  25. for portal in list {
  26. if portal.id != nil && portal.id == local.appId {
  27. isIn = true
  28. }
  29. }
  30. if isIn {
  31. newLocal.append(local)
  32. }
  33. }
  34. fulfill(newLocal)
  35. } else {
  36. fulfill(localList)
  37. }
  38. }else {
  39. fulfill(localList)
  40. }
  41. })
  42. }
  43. }
  44. }