增加过渡页面
This commit is contained in:
parent
bda86f1c8a
commit
2175a8c74e
21
dimensionhub/Assets.xcassets/lost_network.imageset/Contents.json
vendored
Normal file
21
dimensionhub/Assets.xcassets/lost_network.imageset/Contents.json
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
BIN
dimensionhub/Assets.xcassets/lost_network.imageset/lost.jpg
vendored
Normal file
BIN
dimensionhub/Assets.xcassets/lost_network.imageset/lost.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user