ContentView.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. Section {
  27. NavigationLink(destination: messageView(count: $messageCount)) {
  28. Text("消息")
  29. .badge(messageCount)
  30. }
  31. }
  32. Section {
  33. ForEach(0 ..< userInfo.tableData.count, id: \.self) { i in
  34. HStack {
  35. ForEach(0 ..< userInfo.tableData[i].count, id: \.self) { j in
  36. if userInfo.tableData[i][j].data.count != 0 {
  37. Text("\(userInfo.tableData[i][j].data[0].courseName.replacing("高中", with: "").replacing("实践类", with: "").replacing("语文阅读", with: "阅读"))")
  38. } else {
  39. Text("  ").frame(minWidth: 10)
  40. }
  41. }
  42. }
  43. }
  44. }
  45. // for i in 0 ..< 5 {
  46. // if userInfo.tableData.count > i {
  47. // Text("\(userInfo.tableData[i].data[0].courseName)")
  48. // }
  49. // ForEach(0 ..< userInfo.tableData.filter { $0.day == i }.count, id: \.self) { i in
  50. // Text("\(userInfo.tableData[i].day)\(userInfo.tableData[i].lesson)\(userInfo.tableData[i].data[0].courseName.replacing("高中", with: "").replacing("实践类", with: ""))")
  51. // }
  52. // }
  53. }
  54. .navigationBarTitle("数字校园")
  55. }
  56. .tabItem { Image(systemName: "graduationcap")
  57. Text("数字校园")
  58. }
  59. NavigationView {
  60. if isLoggedIn != 0 {
  61. accountView(isLoggedIn: $isLoggedIn, userInfo: $userInfo)
  62. .navigationBarTitle("账号")
  63. } else {
  64. loginView(isLoggedIn: $isLoggedIn, userInfo: $userInfo)
  65. .navigationBarTitle("登录")
  66. }
  67. }
  68. .tabItem { Image(systemName: "person")
  69. Text("账号")
  70. }
  71. }
  72. }
  73. }
  74. extension View {
  75. func hideKeyboard() {
  76. UIApplication.shared.sendAction(
  77. #selector(UIResponder.resignFirstResponder),
  78. to: nil,
  79. from: nil,
  80. for: nil
  81. )
  82. }
  83. }
  84. struct ContentView_Previews: PreviewProvider {
  85. static var previews: some View {
  86. ContentView()
  87. }
  88. }