ContentView.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. @State private var userInfo: UserInfo = .init()
  13. var body: some View {
  14. TabView {
  15. NavigationView {
  16. NavigationLink(destination: examListView(count: $examCount)) {
  17. Text("共 \(examCount) 场考试")
  18. }
  19. .navigationBarTitle("74 桌")
  20. }
  21. .tabItem { Image(systemName: "chart.bar.fill")
  22. Text("成绩分析")
  23. }
  24. NavigationView {
  25. List {
  26. NavigationLink(destination: messageView(count: $messageCount)) {
  27. Text("消息")
  28. .badge(messageCount)
  29. }
  30. // for i in 0 ..< 5 {
  31. // if userInfo.tableData.count > i {
  32. // Text("\(userInfo.tableData[i].data[0].courseName)")
  33. // }
  34. // ForEach(0 ..< userInfo.tableData.filter { $0.day == i }.count, id: \.self) { i in
  35. // Text("\(userInfo.tableData[i].day)\(userInfo.tableData[i].lesson)\(userInfo.tableData[i].data[0].courseName.replacing("高中", with: "").replacing("实践类", with: ""))")
  36. // }
  37. // }
  38. }
  39. .navigationBarTitle("数字校园")
  40. }
  41. .tabItem { Image(systemName: "graduationcap")
  42. Text("数字校园")
  43. }
  44. NavigationView {
  45. if isLoggedIn != 0 {
  46. accountView(isLoggedIn: $isLoggedIn, userInfo: $userInfo)
  47. .navigationBarTitle("账号")
  48. } else {
  49. loginView(isLoggedIn: $isLoggedIn, userInfo: $userInfo)
  50. .navigationBarTitle("登录")
  51. }
  52. }
  53. .tabItem { Image(systemName: "person")
  54. Text("账号")
  55. }
  56. }
  57. }
  58. }
  59. extension View {
  60. func hideKeyboard() {
  61. UIApplication.shared.sendAction(
  62. #selector(UIResponder.resignFirstResponder),
  63. to: nil,
  64. from: nil,
  65. for: nil
  66. )
  67. }
  68. }
  69. struct ContentView_Previews: PreviewProvider {
  70. static var previews: some View {
  71. ContentView()
  72. }
  73. }