Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加了两处错误处理 #47

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DarockBili Watch App/InMain/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ struct MainView: View {
}
})
}
} else if isFailedToLoad {
Button {
LoadNewVideos()
} label: {
Label("加载失败,点击重试", systemImage: "wifi.exclamationmark")
}
} else {
ProgressView()
}
Expand Down
19 changes: 19 additions & 0 deletions DarockBili Watch App/InMain/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct SearchView: View {
Text("似乎在搜索时遇到了一些问题,以下是详细信息")
Text(debugResponse)
}
progressView()
}
}
.onAppear {
Expand Down Expand Up @@ -170,16 +171,34 @@ struct SearchView: View {
videos.append(["Pic": "https:" + video.1["pic"].string!, "Title": video.1["title"].string!.replacingOccurrences(of: "<em class=\"keyword\">", with: "").replacingOccurrences(of: "</em>", with: ""), "View": String(video.1["play"].int!), "Danmaku": String(video.1["danmaku"].int!), "UP": video.1["author"].string!, "BV": video.1["bvid"].string!])
}
debugResponse = respJson.debugDescription
} else {
debugResponse = "请检查您的网络连接状态"
}
}
}
}
} else {
debugResponse = "请检查您的网络连接状态"
}
}
isLoaded = true
}
}
}
@ViewBuilder
func progressView() -> some View {
let showError:Bool = {
if debugResponse.isEmpty {//这样是加载中或加载成功
return users.isEmpty && videos.isEmpty//两个都没有的话那肯定是加载中了,否则就是加载成功了
} else {//加载失败,有错误信息,不需要ProgressView
return false
}
}()
if showError {
ProgressView()
.padding(.top)
}
}
}

struct SearchView_Previews: PreviewProvider {
Expand Down
11 changes: 11 additions & 0 deletions DarockBili Watch App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,17 @@
},
"出现问题!" : {

},
"加载失败,点击重试" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Loading failed, tap to retry."
}
}
}
},
"加载更多" : {
"localizations" : {
Expand Down
WindowsMEMZ marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.