ContentView.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // ContentView.swift
  3. // sdsz74
  4. //
  5. // Created by yunli on 2023/5/18.
  6. //
  7. import SwiftUI
  8. struct ContentView: View {
  9. @State private var examCount = 0
  10. @State private var messageCount = 0
  11. @State private var isLoggedIn = 0
  12. var body: some View {
  13. TabView{
  14. NavigationView {
  15. NavigationLink(destination: examListView(count:$examCount)) {
  16. Text("共 \(examCount) 场考试")
  17. }
  18. .navigationBarTitle("74 桌")
  19. }
  20. .tabItem({Image(systemName: "chart.bar.fill")
  21. Text("成绩分析")})
  22. NavigationView {
  23. List{
  24. NavigationLink(destination: messageView(count:$messageCount)) {
  25. Text("消息")
  26. .badge(messageCount)
  27. }
  28. }
  29. .navigationBarTitle("数字校园")
  30. }
  31. .tabItem({Image(systemName: "graduationcap")
  32. Text("数字校园")})
  33. NavigationView{
  34. if isLoggedIn != 0{
  35. accountView(isLoggedIn: $isLoggedIn)
  36. .navigationBarTitle("账号")
  37. }
  38. else{
  39. loginView(isLoggedIn:$isLoggedIn)
  40. .navigationBarTitle("登录")
  41. }
  42. }
  43. .tabItem({Image(systemName: "person")
  44. Text("账号")})
  45. }
  46. }
  47. }
  48. extension View {
  49. func hideKeyboard() {
  50. UIApplication.shared.sendAction(
  51. #selector(UIResponder.resignFirstResponder),
  52. to: nil,
  53. from: nil,
  54. for: nil
  55. )
  56. }
  57. }
  58. func doLogin(status:inout Int)->Void{
  59. status=1
  60. }
  61. struct loginView:View{
  62. @State var username: String = ""
  63. @State var password: String = ""
  64. @FocusState private var isFocused:Bool
  65. @Binding var isLoggedIn: Int
  66. var body: some View {
  67. VStack{
  68. Form {
  69. Section{
  70. TextField(text: $username, prompt: Text("数字校园号")) {
  71. Text("Username")
  72. }.focused($isFocused)
  73. SecureField(text: $password, prompt: Text("密码")) {
  74. Text("Password")
  75. }.focused($isFocused)
  76. }.onTapGesture {
  77. isFocused=false
  78. }
  79. Section{
  80. HStack{
  81. Spacer()
  82. Button(action:{doLogin(status: &isLoggedIn)}){
  83. VStack{
  84. Text("登录")
  85. }
  86. }.font(.title3)
  87. Spacer()
  88. }
  89. }
  90. }
  91. Spacer()
  92. }
  93. }
  94. }
  95. struct accountView:View{
  96. @State var username: String = ""
  97. @State var password: String = ""
  98. @FocusState private var isFocused:Bool
  99. @Binding var isLoggedIn: Int
  100. var body: some View {
  101. VStack{
  102. Form {
  103. Section(header:Text("hi")){
  104. Text("一些")
  105. Text("一些")
  106. Text("东西")
  107. }
  108. Section{
  109. Button(action:{isLoggedIn=0}){
  110. VStack{
  111. Text("退出").foregroundColor(.red)
  112. }
  113. }
  114. }
  115. }
  116. Spacer()
  117. }
  118. }
  119. }
  120. struct ContentView_Previews: PreviewProvider {
  121. static var previews: some View {
  122. ContentView()
  123. }
  124. }