MeView.swift 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // MeView.swift
  3. // naiyoup
  4. //
  5. // Created by C Auto on 2021/7/14.
  6. //
  7. import SwiftUI
  8. import SwiftyUserDefaults
  9. struct ProfileRow: View {
  10. var title = "账号:"
  11. @Binding var subTitle : String
  12. @Binding var reTitle : String
  13. var body: some View {
  14. VStack(spacing:0){
  15. HStack {
  16. Text(title)
  17. .foregroundColor(Color.black)
  18. if (subTitle != ""){
  19. Text(subTitle)
  20. .foregroundColor(Color.black)
  21. }
  22. if (reTitle != ""){
  23. Spacer()
  24. Text(reTitle)
  25. .foregroundColor(Color.black)
  26. }
  27. Spacer()
  28. Image(systemName: "chevron.right")
  29. .foregroundColor(Color.black)
  30. }
  31. .padding(.leading,20)
  32. .padding(.trailing,20)
  33. .frame(width:UIScreen.main.bounds.width - 20, height: 70)
  34. .background(Color.white)
  35. Rectangle()
  36. .foregroundColor(Color.white.opacity(0.15))
  37. .frame(width:UIScreen.main.bounds.width - 20, height: 2)
  38. }
  39. }
  40. }
  41. struct MeView: View {
  42. @ObservedObject var meViewModel = MeViewModel.me
  43. @ObservedObject var userModel = LoginViewModel.user
  44. @State var user = ""
  45. @State var exTime = "2017/10/12"
  46. @State var emtyp = ""
  47. @State var rettitleac = "刷新"
  48. @State var isPop : Bool = false
  49. @State var czPop : Bool = false
  50. init() {
  51. //UINavigationBar.appearance().backgroundImage(for: <#T##UIBarPosition#>, barMetrics: <#T##UIBarMetrics#>)
  52. UIApplication.statusBarBackgroundColor = UIColor.init(named: "BackgroundColor")
  53. UINavigationBar.appearance().backgroundColor = UIColor.init(named: "BackgroundColor")
  54. UINavigationBar.appearance().tintColor = UIColor.white
  55. UINavigationBar.appearance().barTintColor = UIColor.white
  56. UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
  57. UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.white]
  58. }
  59. var body: some View {
  60. ZStack {
  61. if self.meViewModel.loading == true
  62. {
  63. ActivityIndicator(isAnimating: self.meViewModel.loading)
  64. .configure { $0.color = .blue}
  65. .padding()
  66. } else if self.meViewModel.isAlt == true {
  67. VStack{
  68. Text("\(self.meViewModel.errmsg)")
  69. .foregroundColor(Color.black)
  70. Text("点击重试")
  71. .foregroundColor(Color.black)
  72. .onTapGesture {
  73. self.meViewModel.GetProfile()
  74. }
  75. }
  76. } else {
  77. Rectangle()
  78. .fill(Color.gray.opacity(0.6))
  79. .edgesIgnoringSafeArea(.all)
  80. VStack{
  81. ScrollView{
  82. VStack(spacing:0){
  83. ProfileRow(title: "账号:",subTitle: $meViewModel.username, reTitle: $emtyp)
  84. if meViewModel.userModel?.zfshow == 1 {
  85. ProfileRow(title: "到期时间:",subTitle: $meViewModel.expired_at,reTitle: $emtyp)
  86. ProfileRow(title: "剩余流量:",subTitle: $meViewModel.unusedTraffic,reTitle: $rettitleac)
  87. .onTapGesture {
  88. //self.rettitleac = "正在刷新.."
  89. self.meViewModel.GetProfile()
  90. }
  91. ProfileRow(title: "充值续费",subTitle: $emtyp, reTitle: $emtyp)
  92. .onTapGesture {
  93. let urlString = "https://user.vipone.xyz/logina?email=" + meViewModel.username + "&password=" + meViewModel.password
  94. if let url = URL (string: urlString) {
  95. //根据iOS系统版本,分别处理
  96. if #available(iOS 10, *) {
  97. UIApplication .shared.open(url, options: [:],
  98. completionHandler: {
  99. (success) in
  100. })
  101. } else {
  102. UIApplication .shared.openURL(url)
  103. }
  104. }
  105. }
  106. }
  107. // NavigationLink(
  108. // destination: LazyView(NWebView(url: "https://user.vipone.xyz/logina?email=" + meViewModel.username + "&password=" + meViewModel.password, showing: self.$czPop)),
  109. // isActive: self.$czPop,
  110. // label: {
  111. //
  112. // ProfileRow(title: "充值续费",subTitle: $emtyp, reTitle: $emtyp)
  113. //
  114. // })
  115. NavigationLink(
  116. destination: LazyView(NWebView(url: "https://user.vipone.xyz/logintoticket?email=" + meViewModel.username + "&password=" + meViewModel.password, showing: self.$isPop)),
  117. isActive: self.$isPop,
  118. label: {
  119. ProfileRow(title: "在线客服",subTitle: $emtyp, reTitle: $emtyp)
  120. })
  121. if meViewModel.userModel?.zfshow == 1 {
  122. ProfileRow(title: "推广地址",subTitle: $emtyp, reTitle: $emtyp)
  123. .onTapGesture {
  124. let urlString = "https://user.vipone.xyz/logintoreferral?email=" + meViewModel.username + "&password=" + meViewModel.password
  125. if let url = URL (string: urlString) {
  126. //根据iOS系统版本,分别处理
  127. if #available(iOS 10, *) {
  128. UIApplication .shared.open(url, options: [:],
  129. completionHandler: {
  130. (success) in
  131. })
  132. } else {
  133. UIApplication .shared.openURL(url)
  134. }
  135. }
  136. }
  137. }
  138. ProfileRow(title: "退出账号",subTitle: $emtyp, reTitle: $emtyp)
  139. .onTapGesture {
  140. userModel.setLoginFlag(flag: false)
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. .onAppear {
  148. let controller = UIApplication.shared.windows[0].rootViewController as? MyHontingController
  149. controller?.statusBarStyle = .lightContent
  150. meViewModel.GetUserName()
  151. meViewModel.GetPassword()
  152. self.meViewModel.GetProfile()
  153. }
  154. //.navigationBarTitle(Text("TEST")).navigationBarHidden(false)
  155. .navigationBarTitle(Text("个人中心"), displayMode: .inline)
  156. // .navigationBarTitle("")
  157. // .navigationBarHidden(true)
  158. }
  159. }
  160. struct MeView_Previews: PreviewProvider {
  161. static var previews: some View {
  162. MeView()
  163. }
  164. }