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:
@ -15,6 +15,7 @@ struct RealNameAuthView: View {
|
||||
@Environment(ProfileAPI.self) private var profileAPI
|
||||
@Environment(OSSUploadService.self) private var ossUploadService
|
||||
@Environment(ToastCenter.self) private var toastCenter
|
||||
@Environment(\.globalLoading) private var globalLoading
|
||||
@State private var viewModel = RealNameAuthViewModel()
|
||||
@State private var pickedFrontItem: PhotosPickerItem?
|
||||
@State private var pickedBackItem: PhotosPickerItem?
|
||||
@ -37,14 +38,6 @@ struct RealNameAuthView: View {
|
||||
.task {
|
||||
await loadInfo()
|
||||
}
|
||||
.overlay {
|
||||
if viewModel.loading && viewModel.info == nil {
|
||||
ProgressView()
|
||||
.controlSize(.large)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(Color.white.opacity(0.35))
|
||||
}
|
||||
}
|
||||
.onChange(of: pickedFrontItem) { _, item in
|
||||
Task { await prepareIdentityImage(from: item, side: .front) }
|
||||
}
|
||||
@ -380,7 +373,9 @@ struct RealNameAuthView: View {
|
||||
/// 拉取实名认证信息。
|
||||
private func loadInfo() async {
|
||||
do {
|
||||
try await viewModel.load(api: profileAPI)
|
||||
try await globalLoading.withOptionalLoading(viewModel.info == nil, message: "加载中...") {
|
||||
try await viewModel.load(api: profileAPI)
|
||||
}
|
||||
} catch is CancellationError {
|
||||
return
|
||||
} catch {
|
||||
@ -400,11 +395,13 @@ struct RealNameAuthView: View {
|
||||
/// 提交实名资料。
|
||||
private func submit() async {
|
||||
do {
|
||||
try await viewModel.submit(
|
||||
api: profileAPI,
|
||||
uploader: ossUploadService,
|
||||
scenicId: accountContext.currentScenic?.id ?? 0
|
||||
)
|
||||
try await globalLoading.withLoading(message: "提交中...") {
|
||||
try await viewModel.submit(
|
||||
api: profileAPI,
|
||||
uploader: ossUploadService,
|
||||
scenicId: accountContext.currentScenic?.id ?? 0
|
||||
)
|
||||
}
|
||||
} catch {
|
||||
viewModel.statusMessage = error.localizedDescription
|
||||
toastCenter.show(error.localizedDescription)
|
||||
|
||||
Reference in New Issue
Block a user