Browse Source

name & id

schtonn 1 year ago
parent
commit
112c04d43b
1 changed files with 14 additions and 6 deletions
  1. 14 6
      sdsz74/account.swift

+ 14 - 6
sdsz74/account.swift

@@ -144,10 +144,16 @@ func doLogin(user: String, password: String, action: @escaping (_: Int) -> Void)
 
 struct DecodableType: Decodable { let url: String }
 
-func getUserInfo(userInfo: inout UserInfo) {
-    userInfo.name = "向量"
+func getUserInfo(action: @escaping (_: UserInfo) -> Void) {
     FetchHandler().fetchAny(url: "bxn-portal/portal/osforstudent/index") { res in
-        print(res)
+        var userInfo: UserInfo = .init(name: "", o: "")
+        if let name = res.firstMatch(of: /userFullName" value="(.*?)"/) {
+            userInfo.name = "\(name.1)"
+        }
+        if let name = res.firstMatch(of: /userId" value="(.*?)"/) {
+            userInfo.o = "\(name.1)"
+        }
+        action(userInfo)
     }
 }
 
@@ -192,7 +198,9 @@ struct loginView: View {
                                 btnText = "登录失败"
                                 btnColor = .red
                             } else {
-                                getUserInfo(userInfo: &userInfo)
+                                getUserInfo { res in
+                                    userInfo = res
+                                }
                             }
                         }
                     }) {
@@ -227,9 +235,9 @@ struct accountView: View {
                         Text(userInfo.name)
                     }
                     HStack {
-                        Text("所属班级")
+                        Text("内部 ID")
                         Spacer()
-                        Text(userInfo.name)
+                        Text(userInfo.o)
                     }
                 }
                 Section {