Преглед на файлове

nnnnnnnnnnnnnnnnnnnnnnnnnbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

schtonn преди 1 година
родител
ревизия
44c97df253
променени са 2 файла, в които са добавени 40 реда и са изтрити 34 реда
  1. 18 3
      sdsz74/ContentView.swift
  2. 22 31
      sdsz74/account.swift

+ 18 - 3
sdsz74/ContentView.swift

@@ -26,9 +26,24 @@ struct ContentView: View {
             }
             NavigationView {
                 List {
-                    NavigationLink(destination: messageView(count: $messageCount)) {
-                        Text("消息")
-                            .badge(messageCount)
+                    Section {
+                        NavigationLink(destination: messageView(count: $messageCount)) {
+                            Text("消息")
+                                .badge(messageCount)
+                        }
+                    }
+                    Section {
+                        ForEach(0 ..< userInfo.tableData.count, id: \.self) { i in
+                            HStack {
+                                ForEach(0 ..< userInfo.tableData[i].count, id: \.self) { j in
+                                    if userInfo.tableData[i][j].data.count != 0 {
+                                        Text("\(userInfo.tableData[i][j].data[0].courseName.replacing("高中", with: "").replacing("实践类", with: "").replacing("语文阅读", with: "阅读"))")
+                                    } else {
+                                        Text("  ").frame(minWidth: 10)
+                                    }
+                                }
+                            }
+                        }
                     }
 //                    for i in 0 ..< 5 {
 //                        if userInfo.tableData.count > i {

+ 22 - 31
sdsz74/account.swift

@@ -49,7 +49,7 @@ struct UserInfo: Decodable {
     var xydLink: String
     var serviceLink: String
     var studyLink: String
-    var tableData: [PurpleDatum]
+    var tableData: [[PurpleDatum]]
     init() {
         name = "-"
         oid = "-"
@@ -163,7 +163,7 @@ struct Welcome: Codable {
 
 struct Block: Codable {
     let ownObjID, type: String
-    let name: Name
+    let name: String
     let data: [BlockDatum]
     let weekMetas: JSONNull?
 
@@ -192,13 +192,13 @@ struct PurpleDatum: Codable {
 
 struct FluffyDatum: Codable {
     let timetableID: JSONNull?
-    let className: Name
-    let classID: ClassID
+    let className: String
+    let classID: String
     let courseName: String
     let courseID, courseType: Int
     let placeID: JSONNull?
-    let placeName: PlaceName
-    let placeSn: PlaceSn
+    let placeName: String
+    let placeSn: String
     let teacher: [Teacher]
     let room: JSONNull?
     let start, end: String
@@ -216,30 +216,6 @@ struct FluffyDatum: Codable {
     }
 }
 
-enum ClassID: String, Codable {
-    case ac342897 = "AC_342897"
-    case tac8109 = "TAC_8109"
-    case tac8123 = "TAC_8123"
-}
-
-enum Name: String, Codable {
-    case 高一数学P1班 = "高一数学[P]1班"
-    case 高一物理A5班 = "高一物理[A]5班"
-    case 高中2025届11班
-}
-
-enum PlaceName: String, Codable {
-    case 信毅楼408 = "信毅楼4-08"
-    case 信毅楼412 = "信毅楼4-12"
-    case 本班教室
-}
-
-enum PlaceSn: String, Codable {
-    case bxXy408 = " BX-XY-408  "
-    case bxXy410 = " BX-XY-410  "
-    case empty = ""
-}
-
 // MARK: - Teacher
 
 struct Teacher: Codable {
@@ -360,7 +336,22 @@ func getUserInfo(userInfoIn: UserInfo, action: @escaping (_: UserInfo) -> Void)
                     let table = try! JSONSerialization.jsonObject(with: data!) as? [String: Any]
                     let decoder = JSONDecoder()
                     let kkd = try decoder.decode(Welcome.self, from: data!)
-                    userInfo.tableData = kkd.blocks.first?.data.first?.data ?? []
+                    let pp = kkd.blocks.first?.data.first?.data ?? []
+                    var ret: [[PurpleDatum]] = [], mx: Int = 0
+                    for i in 0 ..< pp.count {
+                        print(pp[i])
+                        mx = max(mx, pp[i].lesson)
+                    }
+                    for i in 0 ... mx {
+                        ret.append([])
+                        for j in 0 ... 5 {
+                            ret[i].append(PurpleDatum(day: 0, lesson: 0, data: []))
+                        }
+                    }
+                    for i in 0 ..< pp.count {
+                        ret[pp[i].lesson][pp[i].day] = pp[i]
+                    }
+                    userInfo.tableData = ret
                 } catch {
                     print(error)
                 }