// // MeView.swift // naiyoup // // Created by C Auto on 2021/7/14. // import SwiftUI import SwiftyUserDefaults struct ProfileRow: View { var title = "账号:" @Binding var subTitle : String @Binding var reTitle : String var body: some View { VStack(spacing:0){ HStack { Text(title) .foregroundColor(Color.black) if (subTitle != ""){ Text(subTitle) .foregroundColor(Color.black) } if (reTitle != ""){ Spacer() Text(reTitle) .foregroundColor(Color.black) } Spacer() Image(systemName: "chevron.right") .foregroundColor(Color.black) } .padding(.leading,20) .padding(.trailing,20) .frame(width:UIScreen.main.bounds.width - 20, height: 70) .background(Color.white) Rectangle() .foregroundColor(Color.white.opacity(0.15)) .frame(width:UIScreen.main.bounds.width - 20, height: 2) } } } struct MeView: View { @ObservedObject var meViewModel = MeViewModel.me @ObservedObject var userModel = LoginViewModel.user @State var user = "" @State var exTime = "2017/10/12" @State var emtyp = "" @State var rettitleac = "刷新" @State var isPop : Bool = false @State var czPop : Bool = false init() { //UINavigationBar.appearance().backgroundImage(for: <#T##UIBarPosition#>, barMetrics: <#T##UIBarMetrics#>) UIApplication.statusBarBackgroundColor = UIColor.init(named: "BackgroundColor") UINavigationBar.appearance().backgroundColor = UIColor.init(named: "BackgroundColor") UINavigationBar.appearance().tintColor = UIColor.white UINavigationBar.appearance().barTintColor = UIColor.white UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white] UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.white] } var body: some View { ZStack { if self.meViewModel.loading == true { ActivityIndicator(isAnimating: self.meViewModel.loading) .configure { $0.color = .blue} .padding() } else if self.meViewModel.isAlt == true { VStack{ Text("\(self.meViewModel.errmsg)") .foregroundColor(Color.black) Text("点击重试") .foregroundColor(Color.black) .onTapGesture { self.meViewModel.GetProfile() } } } else { Rectangle() .fill(Color.gray.opacity(0.6)) .edgesIgnoringSafeArea(.all) VStack{ ScrollView{ VStack(spacing:0){ ProfileRow(title: "账号:",subTitle: $meViewModel.username, reTitle: $emtyp) if meViewModel.userModel?.zfshow == 1 { ProfileRow(title: "到期时间:",subTitle: $meViewModel.expired_at,reTitle: $emtyp) ProfileRow(title: "剩余流量:",subTitle: $meViewModel.unusedTraffic,reTitle: $rettitleac) .onTapGesture { //self.rettitleac = "正在刷新.." self.meViewModel.GetProfile() } ProfileRow(title: "充值续费",subTitle: $emtyp, reTitle: $emtyp) .onTapGesture { let urlString = "https://user.vipone.xyz/logina?email=" + meViewModel.username + "&password=" + meViewModel.password if let url = URL (string: urlString) { //根据iOS系统版本,分别处理 if #available(iOS 10, *) { UIApplication .shared.open(url, options: [:], completionHandler: { (success) in }) } else { UIApplication .shared.openURL(url) } } } } // NavigationLink( // destination: LazyView(NWebView(url: "https://user.vipone.xyz/logina?email=" + meViewModel.username + "&password=" + meViewModel.password, showing: self.$czPop)), // isActive: self.$czPop, // label: { // // ProfileRow(title: "充值续费",subTitle: $emtyp, reTitle: $emtyp) // // }) NavigationLink( destination: LazyView(NWebView(url: "https://user.vipone.xyz/logintoticket?email=" + meViewModel.username + "&password=" + meViewModel.password, showing: self.$isPop)), isActive: self.$isPop, label: { ProfileRow(title: "在线客服",subTitle: $emtyp, reTitle: $emtyp) }) if meViewModel.userModel?.zfshow == 1 { ProfileRow(title: "推广地址",subTitle: $emtyp, reTitle: $emtyp) .onTapGesture { let urlString = "https://user.vipone.xyz/logintoreferral?email=" + meViewModel.username + "&password=" + meViewModel.password if let url = URL (string: urlString) { //根据iOS系统版本,分别处理 if #available(iOS 10, *) { UIApplication .shared.open(url, options: [:], completionHandler: { (success) in }) } else { UIApplication .shared.openURL(url) } } } } ProfileRow(title: "退出账号",subTitle: $emtyp, reTitle: $emtyp) .onTapGesture { userModel.setLoginFlag(flag: false) } } } } } } .onAppear { let controller = UIApplication.shared.windows[0].rootViewController as? MyHontingController controller?.statusBarStyle = .lightContent meViewModel.GetUserName() meViewModel.GetPassword() self.meViewModel.GetProfile() } //.navigationBarTitle(Text("TEST")).navigationBarHidden(false) .navigationBarTitle(Text("个人中心"), displayMode: .inline) // .navigationBarTitle("") // .navigationBarHidden(true) } } struct MeView_Previews: PreviewProvider { static var previews: some View { MeView() } }