增加过渡页面

This commit is contained in:
anlicheng 2025-02-25 23:28:01 +08:00
parent bda86f1c8a
commit 2175a8c74e
4 changed files with 218 additions and 117 deletions

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "lost.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -48,7 +48,7 @@ final class DateNavModel {
} else {
let response = await API.getDateIndex(userId: userId, as: [DateModel].self)
switch response {
case .error(let code, let message):
case .error(_, _):
return []
case .result(let models):
await DataCache.shared.setDateModelCache(models)

View File

@ -8,6 +8,7 @@
import SwiftUI
import SwiftData
import Observation
import Network
@Observable
final class IndexModel {
@ -194,6 +195,88 @@ final class IndexModel {
}
struct IndexView: View {
// , app
enum NetworkStatus {
case satisfied
case unsatisfied
}
@State private var networkStatus: NetworkStatus = .satisfied
private static let queue = DispatchQueue(label: "NetworkMonitorQueue")
var body: some View {
ZStack {
switch self.networkStatus {
case .unsatisfied:
IndexExceptionView {
self.checkNetworkStatus()
}
case .satisfied:
IndexMainView()
}
}
.onAppear {
self.checkNetworkStatus()
}
}
private func checkNetworkStatus() {
let monitor = NWPathMonitor()
monitor.pathUpdateHandler = { path in
DispatchQueue.main.async {
switch path.status {
case .satisfied:
self.networkStatus = .satisfied
default:
self.networkStatus = .unsatisfied
}
}
}
monitor.start(queue: Self.queue)
}
}
extension IndexView {
struct IndexExceptionView: View {
let onRetry: () -> Void
var body: some View {
HStack {
Spacer()
VStack(alignment: .center, spacing: 20) {
Spacer()
Image("lost_network")
Text("网络状态待提升,点击重试")
.font(.system(size: 13))
.foregroundColor(Color(hex: "#333333"))
Rectangle()
.frame(width: 100, height: 25)
.foregroundColor(Color(hex: "#F2F2F2"))
.overlay {
Text("重新加载")
.font(.system(size: 13))
.foregroundColor(Color(hex: "#999999"))
.fontWeight(.regular)
}
.onTapGesture {
onRetry()
}
Spacer()
}
Spacer()
}
.background(Color(hex: "#F6F6F6"), ignoresSafeAreaEdges: .all)
}
}
//
struct IndexMainView: View {
@Environment(\.modelContext) private var modelContext
@AppStorage("userId") private var userId: String = Utils.defaultUserId()
@ -320,8 +403,6 @@ struct IndexView: View {
}
}
extension IndexView {
//
struct DramaCellView: View {
let dramaItem: IndexModel.DramaItem
@ -379,7 +460,6 @@ extension IndexView {
}
}
//
struct DramaGroupView: View {
let group: IndexModel.UpdateDramaGroup