Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ThreeManager785 authored Feb 8, 2024
1 parent a0200c0 commit ff19b0b
Showing 1 changed file with 198 additions and 25 deletions.
223 changes: 198 additions & 25 deletions DarockBili Watch App/PersonalCenter/PersonAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,114 @@ struct PersonAccountView: View {
@AppStorage("SESSDATA") var sessdata = ""
@AppStorage("bili_jct") var biliJct = ""
@AppStorage("IsShowNetworkFixing") var isShowNetworkFixing = true
@State var userList1: [Any] = []
@State var userList2: [Any] = []
@State var userList3: [Any] = []
@State var userList4: [Any] = []
@State var isLoginPresented = false
@State var username = ""
@State var userSign = ""
@State var userFaceUrl = ""
@State var isLogoutAlertPresented = false
@State var isUserDetailSelfPresented = false
@State var isNetworkFixPresented = false
@State var isUserSwitchPresented = false
@State var isNewUserPresenting = false
var body: some View {
List {
//VStack {
if sessdata == "" {
Button(action: {
isLoginPresented = true
}, label: {
Text("User.tap-to-login")
Label("User.tap-to-login", systemImage: "qrcode.viewfinder")
})
.sheet(isPresented: $isLoginPresented, content: {LoginView()})
Button(action: {isUserSwitchPresented = true}, label: {
HStack {
HStack {
Image(systemName: "person.2.badge.key.fill")
.foregroundColor(.accentColor)
Text("User.switch")
}
.font(.system(size: 16))
Spacer()
}
})
.sheet(isPresented: $isUserSwitchPresented, content: {
List {
if #available(watchOS 10.0, *) {} else {
Button(action: {
isNewUserPresenting = true
}, label: {
Label("User.switch.add", systemImage: "plus")
})
}

if userList1.isEmpty {
Text("User.switch.none")
.bold()
.foregroundStyle(.secondary)
} else {
Section(content: {
ForEach(0..<userList1.count, id: \.self) { user in
Button(action: {
dedeUserID = userList1[user] as! String
dedeUserID__ckMd5 = userList2[user] as! String
sessdata = userList3[user] as! String
biliJct = userList4[user] as! String
}, label: {
Text(userList1[user] as! String)
})
}
.onDelete(perform: { user in
userList1.remove(atOffsets: user)
userList2.remove(atOffsets: user)
userList3.remove(atOffsets: user)
userList4.remove(atOffsets: user)
UserDefaults.standard.set(userList1, forKey: "userList1")
UserDefaults.standard.set(userList2, forKey: "userList2")
UserDefaults.standard.set(userList3, forKey: "userList3")
UserDefaults.standard.set(userList4, forKey: "userList4")
})
.onMove(perform: { users, user in
userList1.move(fromOffsets: users, toOffset: user)
userList2.move(fromOffsets: users, toOffset: user)
userList3.move(fromOffsets: users, toOffset: user)
userList4.move(fromOffsets: users, toOffset: user)
UserDefaults.standard.set(userList1, forKey: "userList1")
UserDefaults.standard.set(userList2, forKey: "userList2")
UserDefaults.standard.set(userList3, forKey: "userList3")
UserDefaults.standard.set(userList4, forKey: "userList4")
})
}, footer: {
Text("User.switch.description")
Text("User.switch.description.1")
})
}
}
.toolbar {
if #available(watchOS 10.0, *) {
ToolbarItem(placement: .bottomBar) {
HStack {
Spacer()
Button(action: {
isNewUserPresenting = true
}, label: {
Image(systemName: "plus")
})
}
}
}
}
})
.onAppear {
userList1 = UserDefaults.standard.array(forKey: "userList1") ?? []
userList2 = UserDefaults.standard.array(forKey: "userList2") ?? []
userList3 = UserDefaults.standard.array(forKey: "userList3") ?? []
userList4 = UserDefaults.standard.array(forKey: "userList4") ?? []
}
.sheet(isPresented: $isNewUserPresenting, content: {LoginView()})
} else {
VStack {
NavigationLink("", isActive: $isUserDetailSelfPresented, destination: {UserDetailView(uid: dedeUserID)})
Expand Down Expand Up @@ -152,6 +243,85 @@ struct PersonAccountView: View {
.onTapGesture {
isUserDetailSelfPresented = true
}
}
Button(action: {isUserSwitchPresented = true}, label: {
HStack {
HStack {
Image(systemName: "person.2.badge.key.fill")
.foregroundColor(.accentColor)
Text("User.switch")
}
.font(.system(size: 16))
Spacer()
}
})
.sheet(isPresented: $isNewUserPresenting, content: {LoginView()})
.sheet(isPresented: $isUserSwitchPresented, content: {
List {
if #available(watchOS 10.0, *) {} else {
Button(action: {
isNewUserPresenting = true
}, label: {
Label("User.switch.add", systemImage: "plus")
})
}

Section(content: {
ForEach(0..<userList1.count, id: \.self) {user in
Button(action: {
dedeUserID = userList1[user] as! String
dedeUserID__ckMd5 = userList2[user] as! String
sessdata = userList3[user] as! String
biliJct = userList4[user] as! String
}, label: {
Text(userList1[user] as! String)
})
}
.onDelete(perform: { user in
userList1.remove(atOffsets: user)
userList2.remove(atOffsets: user)
userList3.remove(atOffsets: user)
userList4.remove(atOffsets: user)
UserDefaults.standard.set(userList1, forKey: "userList1")
UserDefaults.standard.set(userList2, forKey: "userList2")
UserDefaults.standard.set(userList3, forKey: "userList3")
UserDefaults.standard.set(userList4, forKey: "userList4")
})
.onMove(perform: { users, user in
userList1.move(fromOffsets: users, toOffset: user)
userList2.move(fromOffsets: users, toOffset: user)
userList3.move(fromOffsets: users, toOffset: user)
userList4.move(fromOffsets: users, toOffset: user)
UserDefaults.standard.set(userList1, forKey: "userList1")
UserDefaults.standard.set(userList2, forKey: "userList2")
UserDefaults.standard.set(userList3, forKey: "userList3")
UserDefaults.standard.set(userList4, forKey: "userList4")
})
}, footer: {
Text("User.switch.description")
Text("User.switch.description.1")
})
}
.toolbar {
if #available(watchOS 10.0, *) {
ToolbarItem(placement: .bottomBar) {
HStack {
Spacer()
Button(action: {
isNewUserPresenting = true
}, label: {
Image(systemName: "plus")
})
}
}
}
}
})
.onAppear {
userList1 = UserDefaults.standard.array(forKey: "userList1") ?? []
userList2 = UserDefaults.standard.array(forKey: "userList2") ?? []
userList3 = UserDefaults.standard.array(forKey: "userList3") ?? []
userList4 = UserDefaults.standard.array(forKey: "userList4") ?? []
}
Group {
Section {
Expand Down Expand Up @@ -237,36 +407,39 @@ struct PersonAccountView: View {
.navigationTitle("About-me")
.navigationBarTitleDisplayMode(.large)
.onAppear {
if username == "" {
getBuvid(url: "https://api.bilibili.com/x/space/wbi/acc/info".urlEncoded()) { buvid3, buvid4, _uuid, resp in
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata); innersign=0; buvid3=\(buvid3); b_nut=1704873471; i-wanna-go-back=-1; b_ut=7; b_lsid=9910433CB_18CF260AB89; _uuid=\(_uuid); enable_web_push=DISABLE; header_theme_version=undefined; home_feed_column=4; browser_resolution=3440-1440; buvid4=\(buvid4);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
biliWbiSign(paramEncoded: "mid=\(dedeUserID)".base64Encoded()) { signed in
if let signed {
debugPrint(signed)
autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in
if isSuccess {
debugPrint(respJson)
if !CheckBApiError(from: respJson) { return }
username = respJson["data"]["name"].string ?? ""
userSign = respJson["data"]["sign"].string ?? ""
userFaceUrl = respJson["data"]["face"].string ?? "E"
} else if isShowNetworkFixing {
isNetworkFixPresented = true
}
}
}
}
}
}
getAccountInfos()
}
.sheet(isPresented: $isNetworkFixPresented, content: {NetworkFixView()})
}
//}
}
}
func getAccountInfos() {
if username == "" {
getBuvid(url: "https://api.bilibili.com/x/space/wbi/acc/info".urlEncoded()) { buvid3, buvid4, _uuid, resp in
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata); innersign=0; buvid3=\(buvid3); b_nut=1704873471; i-wanna-go-back=-1; b_ut=7; b_lsid=9910433CB_18CF260AB89; _uuid=\(_uuid); enable_web_push=DISABLE; header_theme_version=undefined; home_feed_column=4; browser_resolution=3440-1440; buvid4=\(buvid4);",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
]
biliWbiSign(paramEncoded: "mid=\(dedeUserID)".base64Encoded()) { signed in
if let signed {
debugPrint(signed)
autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/acc/info?\(signed)", headers: headers) { respJson, isSuccess in
if isSuccess {
debugPrint(respJson)
if !CheckBApiError(from: respJson) { return }
username = respJson["data"]["name"].string ?? ""
userSign = respJson["data"]["sign"].string ?? ""
userFaceUrl = respJson["data"]["face"].string ?? "E"
} else if isShowNetworkFixing {
isNetworkFixPresented = true
}
}
}
}
}
}
}
}
}

Expand Down

0 comments on commit ff19b0b

Please sign in to comment.