schtonn 1 year ago
parent
commit
41a8eed0aa

+ 4 - 0
74.xcodeproj/project.pbxproj

@@ -19,6 +19,7 @@
 		AB92C7912A16646D00FCA57D /* sdsz74Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB92C7902A16646D00FCA57D /* sdsz74Tests.swift */; };
 		AB92C79B2A16646D00FCA57D /* sdsz74UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB92C79A2A16646D00FCA57D /* sdsz74UITests.swift */; };
 		AB92C79D2A16646D00FCA57D /* sdsz74UITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB92C79C2A16646D00FCA57D /* sdsz74UITestsLaunchTests.swift */; };
+		ABE0F96C2A1A27F4007D8A2E /* school.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABE0F96B2A1A27F4007D8A2E /* school.swift */; };
 		E241BD4A98EE21008263BFE3 /* Pods_74Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 067465520EEAD75741204C54 /* Pods_74Tests.framework */; };
 /* End PBXBuildFile section */
 
@@ -58,6 +59,7 @@
 		AB92C7962A16646D00FCA57D /* 74UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = 74UITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		AB92C79A2A16646D00FCA57D /* sdsz74UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = sdsz74UITests.swift; sourceTree = "<group>"; };
 		AB92C79C2A16646D00FCA57D /* sdsz74UITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = sdsz74UITestsLaunchTests.swift; sourceTree = "<group>"; };
+		ABE0F96B2A1A27F4007D8A2E /* school.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = school.swift; sourceTree = "<group>"; };
 		C7A6C43D304F70BD35321CEA /* Pods-74-74UITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-74-74UITests.release.xcconfig"; path = "Target Support Files/Pods-74-74UITests/Pods-74-74UITests.release.xcconfig"; sourceTree = "<group>"; };
 		CCF5F8EE3AB051EEEAC0DE61 /* Pods-74.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-74.release.xcconfig"; path = "Target Support Files/Pods-74/Pods-74.release.xcconfig"; sourceTree = "<group>"; };
 		CE8895F8599CB94A570D8797 /* Pods-74.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-74.debug.xcconfig"; path = "Target Support Files/Pods-74/Pods-74.debug.xcconfig"; sourceTree = "<group>"; };
@@ -136,6 +138,7 @@
 				AB92C7822A16646D00FCA57D /* Assets.xcassets */,
 				AB92C7842A16646D00FCA57D /* sdsz74.entitlements */,
 				AB92C7852A16646D00FCA57D /* Preview Content */,
+				ABE0F96B2A1A27F4007D8A2E /* school.swift */,
 			);
 			path = sdsz74;
 			sourceTree = "<group>";
@@ -421,6 +424,7 @@
 				AB5424512A1853E200BFC98E /* account.swift in Sources */,
 				AB54244D2A184B1500BFC98E /* exam.swift in Sources */,
 				AB92C77F2A16646C00FCA57D /* sdsz74App.swift in Sources */,
+				ABE0F96C2A1A27F4007D8A2E /* school.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 6 - 0
74.xcworkspace/xcuserdata/yunli.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Bucket
+   uuid = "F6E4D214-5312-43F0-8615-85B4EE5BD91F"
+   type = "0"
+   version = "2.0">
+</Bucket>

+ 10 - 3
sdsz74/ContentView.swift

@@ -30,6 +30,14 @@ struct ContentView: View {
                         Text("消息")
                             .badge(messageCount)
                     }
+//                    for i in 0 ..< 5 {
+//                        if userInfo.tableData.count > i {
+//                            Text("\(userInfo.tableData[i].data[0].courseName)")
+//                        }
+//                            ForEach(0 ..< userInfo.tableData.filter { $0.day == i }.count, id: \.self) { i in
+//                                Text("\(userInfo.tableData[i].day)\(userInfo.tableData[i].lesson)\(userInfo.tableData[i].data[0].courseName.replacing("高中", with: "").replacing("实践类", with: ""))")
+//                            }
+//                    }
                 }
                 .navigationBarTitle("数字校园")
             }
@@ -63,9 +71,8 @@ extension View {
     }
 }
 
-
- struct ContentView_Previews: PreviewProvider {
+struct ContentView_Previews: PreviewProvider {
     static var previews: some View {
         ContentView()
     }
- }
+}

+ 168 - 5
sdsz74/account.swift

@@ -42,13 +42,14 @@ struct Login: Encodable {
     let cook: String
 }
 
-struct UserInfo: Encodable {
+struct UserInfo: Decodable {
     var name: String
     var oid: String
     var id: String
     var xydLink: String
     var serviceLink: String
     var studyLink: String
+    var tableData: [PurpleDatum]
     init() {
         name = "-"
         oid = "-"
@@ -56,6 +57,7 @@ struct UserInfo: Encodable {
         xydLink = "-"
         serviceLink = "-"
         studyLink = "-"
+        tableData = []
     }
 }
 
@@ -143,13 +145,166 @@ func doLogin(user: String, password: String, action: @escaping (_: Int) -> Void)
     }
 }
 
-struct DecodableType: Decodable { let url: String }
+// This file was generated from JSON Schema using quicktype, do not modify it directly.
+// To parse the JSON, add this file to your project and do:
+//
+//   let welcome = try? JSONDecoder().decode(Welcome.self, from: jsonData)
+
+import Foundation
+
+// MARK: - Welcome
+
+struct Welcome: Codable {
+    let workRests: [WorkREST]
+    let blocks: [Block]
+}
+
+// MARK: - Block
+
+struct Block: Codable {
+    let ownObjID, type: String
+    let name: Name
+    let data: [BlockDatum]
+    let weekMetas: JSONNull?
+
+    enum CodingKeys: String, CodingKey {
+        case ownObjID = "ownObjId"
+        case type, name, data, weekMetas
+    }
+}
+
+// MARK: - BlockDatum
+
+struct BlockDatum: Codable {
+    let week: Int
+    let weekMeta: WeekMeta
+    let data: [PurpleDatum]
+}
+
+// MARK: - PurpleDatum
+
+struct PurpleDatum: Codable {
+    let day, lesson: Int
+    let data: [FluffyDatum]
+}
+
+// MARK: - FluffyDatum
+
+struct FluffyDatum: Codable {
+    let timetableID: JSONNull?
+    let className: Name
+    let classID: ClassID
+    let courseName: String
+    let courseID, courseType: Int
+    let placeID: JSONNull?
+    let placeName: PlaceName
+    let placeSn: PlaceSn
+    let teacher: [Teacher]
+    let room: JSONNull?
+    let start, end: String
+    let timeScope: Int
+
+    enum CodingKeys: String, CodingKey {
+        case timetableID = "timetableId"
+        case className
+        case classID = "classId"
+        case courseName
+        case courseID = "courseId"
+        case courseType
+        case placeID = "placeId"
+        case placeName, placeSn, teacher, room, start, end, timeScope
+    }
+}
+
+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 {
+    let userID: Int
+    let userName: JSONNull?
+    let fullName: String
+    let userNo: JSONNull?
+
+    enum CodingKeys: String, CodingKey {
+        case userID = "userId"
+        case userName, fullName, userNo
+    }
+}
+
+// MARK: - WeekMeta
+
+struct WeekMeta: Codable {
+    let morningRead: Bool
+    let night, afternoon, morning, teachingDay: Int
+    let time: [Time]
+}
+
+// MARK: - Time
+
+struct Time: Codable {
+    let seq: Int
+    let start, end: String
+}
+
+// MARK: - WorkREST
+
+struct WorkREST: Codable {
+    let beginTime, endTime, time, lessonName: String
+}
+
+// MARK: - Encode/decode helpers
+
+class JSONNull: Codable, Hashable {
+    public static func == (_: JSONNull, _: JSONNull) -> Bool {
+        return true
+    }
+
+    func hash(into _: inout Hasher) {}
+
+    public init() {}
+
+    public required init(from decoder: Decoder) throws {
+        let container = try decoder.singleValueContainer()
+        if !container.decodeNil() {
+            throw DecodingError.typeMismatch(JSONNull.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for JSONNull"))
+        }
+    }
+
+    public func encode(to encoder: Encoder) throws {
+        var container = encoder.singleValueContainer()
+        try container.encodeNil()
+    }
+}
 
 var Count: Int = 0
 
 func addCompleted(userInfo: UserInfo, action: @escaping (_: UserInfo) -> Void) {
     Count += 1
     if Count == 3 {
+        print(userInfo.tableData)
         action(userInfo)
     }
 }
@@ -159,7 +314,7 @@ extension String {
         do {
             let RE = try NSRegularExpression(pattern: regex, options: options)
             let modified = RE.stringByReplacingMatches(in: self, range: NSRange(location: 0, length: count), withTemplate: with)
-            return self
+            return modified
         } catch {
             return "ERR"
         }
@@ -169,7 +324,7 @@ extension String {
         do {
             let RE = try NSRegularExpression(pattern: regex)
             let modified = RE.stringByReplacingMatches(in: self, range: NSRange(location: 0, length: count), withTemplate: with)
-            return self
+            return modified
         } catch {
             return "ERR"
         }
@@ -200,7 +355,15 @@ func getUserInfo(userInfoIn: UserInfo, action: @escaping (_: UserInfo) -> Void)
         ]
         AF.request("https://debug.sdsz.icu/getWeek", method: .post, parameters: tableParam, encoder: JSONParameterEncoder.default, headers: header).responseString { res in
             FetchHandler().fetchAny(url: "bxn-timetable/timetable/monitor/homepage/data/student?studentId=\(userInfo.oid)&dateScope=\(res.value ?? "")&_=0") { res in
-                print(res)
+                do {
+                    let data = res.data(using: String.Encoding.utf8)
+                    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 ?? []
+                } catch {
+                    print(error)
+                }
                 addCompleted(userInfo: userInfo, action: action)
             }
         }

+ 9 - 0
sdsz74/school.swift

@@ -0,0 +1,9 @@
+//
+//  school.swift
+//  74
+//
+//  Created by yunli on 2023/5/21.
+//
+
+import SwiftUI
+