O2MainViewModel.swift 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // O2MainViewModel.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/7/28.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import Promises
  9. import CocoaLumberjack
  10. class O2MainViewModel: NSObject {
  11. override init() {
  12. super.init()
  13. }
  14. private let orgPermissionApi = OOMoyaProvider<OrganizationPermissionAPI>()
  15. private let contactExpressAPI = OOMoyaProvider<OOContactExpressAPI>()
  16. }
  17. extension O2MainViewModel {
  18. func loadOrgContactPermission() {
  19. let view = O2AuthSDK.shared.customStyle()?.contactPermissionView ?? O2.CUSTOM_STYLE_CONTACT_PERMISSION_DEFAULT
  20. DDLogDebug("查询权限的view : \(view)")
  21. self.orgPermissionApi.request(.getPermissionViewInfo(view), completion: { result in
  22. let response = OOResult<BaseModelClass<OrganizationPermissionData>>(result)
  23. if response.isResultSuccess() {
  24. if let data = response.model?.data {
  25. DDLogDebug("查询成功")
  26. OrganizationPermissionManager.shared.initData(data: data)
  27. // 查询person转身份
  28. self.transferPerson2Identity(perList: OrganizationPermissionManager.shared.hideMobilePersons).then { (list) in
  29. if list.count > 0 {
  30. for item in list {
  31. OrganizationPermissionManager.shared.hideMobilePersons.append(item)
  32. }
  33. }
  34. }
  35. self.transferPerson2Identity(perList: OrganizationPermissionManager.shared.limitAll).then { (list) in
  36. if list.count > 0 {
  37. for item in list {
  38. OrganizationPermissionManager.shared.limitAll.append(item)
  39. }
  40. }
  41. }
  42. self.transferPerson2Identity(perList: OrganizationPermissionManager.shared.limitOuter).then { (list) in
  43. if list.count > 0 {
  44. for item in list {
  45. OrganizationPermissionManager.shared.limitOuter.append(item)
  46. }
  47. }
  48. }
  49. self.transferPerson2Identity(perList: OrganizationPermissionManager.shared.excludePersons).then { (list) in
  50. if list.count > 0 {
  51. for item in list {
  52. OrganizationPermissionManager.shared.excludePersons.append(item)
  53. }
  54. }
  55. }
  56. }
  57. } else {
  58. DDLogError(response.error?.localizedDescription ?? "查询通讯录权限错误!")
  59. }
  60. })
  61. }
  62. /// 讲人员DN转化成身份DN
  63. func transferPerson2Identity(perList: [String]) -> Promise<[String]> {
  64. return Promise {fulfill, reject in
  65. self.contactExpressAPI.request(.personIdentityByPersonList(perList), completion: { result in
  66. let response = OOResult<BaseModelClass<PersonIdentityListData>>(result)
  67. if response.isResultSuccess() {
  68. if let data = response.model?.data {
  69. fulfill(data.identityList ?? [])
  70. } else {
  71. reject(O2APIError.o2ResponseError("数据为空"))
  72. }
  73. }else {
  74. reject(response.error!)
  75. }
  76. })
  77. }
  78. }
  79. }