Add Lottie-based global loading overlay across key flows.
Introduce GlobalLoadingCenter with reference counting, wire it through RootView and major auth/order/profile screens, and add the loading animation asset plus unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -13,6 +13,7 @@ struct StatisticsView: View {
|
||||
@Environment(PermissionContext.self) private var permissionContext
|
||||
@Environment(StatisticsAPI.self) private var statisticsAPI
|
||||
@Environment(ToastCenter.self) private var toastCenter
|
||||
@Environment(\.globalLoading) private var globalLoading
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
|
||||
@State private var viewModel = StatisticsViewModel()
|
||||
@ -165,8 +166,8 @@ struct StatisticsView: View {
|
||||
|
||||
Divider()
|
||||
|
||||
if viewModel.loading {
|
||||
ProgressView()
|
||||
if viewModel.loading && viewModel.dailyItems.isEmpty {
|
||||
Color.clear
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(minHeight: 280)
|
||||
} else if viewModel.dailyItems.isEmpty {
|
||||
@ -287,7 +288,9 @@ struct StatisticsView: View {
|
||||
|
||||
private func selectPeriod(_ period: StatisticsPeriod) async {
|
||||
do {
|
||||
try await viewModel.selectPeriod(period, api: statisticsAPI, scenicId: currentScenicId, roleId: currentRoleId)
|
||||
try await globalLoading.withLoading(message: "加载中...") {
|
||||
try await viewModel.selectPeriod(period, api: statisticsAPI, scenicId: currentScenicId, roleId: currentRoleId)
|
||||
}
|
||||
} catch {
|
||||
toastCenter.show(error.localizedDescription)
|
||||
}
|
||||
@ -295,7 +298,9 @@ struct StatisticsView: View {
|
||||
|
||||
private func reload(showLoading: Bool = true) async {
|
||||
do {
|
||||
try await viewModel.reload(api: statisticsAPI, scenicId: currentScenicId, roleId: currentRoleId, showLoading: showLoading)
|
||||
try await globalLoading.withOptionalLoading(showLoading && currentScenicId != nil && viewModel.dailyItems.isEmpty, message: "加载中...") {
|
||||
try await viewModel.reload(api: statisticsAPI, scenicId: currentScenicId, roleId: currentRoleId, showLoading: showLoading)
|
||||
}
|
||||
} catch {
|
||||
toastCenter.show(error.localizedDescription)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user