feat: 按钮显示上传中
This commit is contained in:
parent
776824b51d
commit
5b9413699f
@ -26,6 +26,8 @@ struct MediaUploadView: View {
|
||||
@State private var uploadComplete = false
|
||||
/// 上传完成的文件ID列表
|
||||
@State private var uploadedFileIds: [[String: String]] = []
|
||||
/// Continue 提交过程中(调用接口)加载状态
|
||||
@State private var isSubmitting: Bool = false
|
||||
|
||||
// MARK: - 视图主体
|
||||
|
||||
@ -145,18 +147,32 @@ struct MediaUploadView: View {
|
||||
|
||||
/// 继续按钮
|
||||
private var continueButton: some View {
|
||||
Button(action: handleContinue) {
|
||||
Text("Continue")
|
||||
.font(.headline)
|
||||
.foregroundColor(uploadManager.selectedMedia.isEmpty ? Color.themeTextMessage : Color.themeTextMessageMain)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 56)
|
||||
.background(uploadManager.selectedMedia.isEmpty ? Color.white : Color.themePrimary)
|
||||
.cornerRadius(28)
|
||||
.padding(.horizontal, 24)
|
||||
let uploading = isUploading()
|
||||
let hasSelection = !uploadManager.selectedMedia.isEmpty
|
||||
let canProceed = uploadManager.isAllUploaded
|
||||
let isLoading = uploading || isSubmitting
|
||||
return Button(action: handleContinue) {
|
||||
HStack(spacing: 8) {
|
||||
if isLoading {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle())
|
||||
}
|
||||
Text(uploading ? "Uploading..." : (isSubmitting ? "Processing..." : "Continue"))
|
||||
.font(.headline)
|
||||
}
|
||||
.foregroundColor(hasSelection ? Color.themeTextMessageMain : Color.themeTextMessage)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 56)
|
||||
.background(
|
||||
hasSelection
|
||||
? (isSubmitting ? Color.gray.opacity(0.3) : Color.themePrimary)
|
||||
: Color.white
|
||||
)
|
||||
.cornerRadius(28)
|
||||
.padding(.horizontal, 24)
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
.disabled(uploadManager.selectedMedia.isEmpty)
|
||||
.disabled(!canProceed || isSubmitting)
|
||||
}
|
||||
|
||||
/// 媒体选择器视图
|
||||
@ -315,6 +331,9 @@ struct MediaUploadView: View {
|
||||
|
||||
/// 处理继续按钮点击
|
||||
private func handleContinue() {
|
||||
// 避免重复点击触发
|
||||
guard !isSubmitting else { return }
|
||||
|
||||
// 获取所有已上传文件的结果
|
||||
let uploadResults = uploadManager.uploadResults
|
||||
guard !uploadResults.isEmpty else {
|
||||
@ -332,6 +351,8 @@ struct MediaUploadView: View {
|
||||
|
||||
// 提交素材,并利用返回的素材id数组,创建第二个盲盒
|
||||
Task {
|
||||
isSubmitting = true
|
||||
defer { isSubmitting = false }
|
||||
do {
|
||||
let materialIds = try await MaterialUpload.shared.addMaterials(files: files)
|
||||
print("🚀 素材ID: \(materialIds ?? [])")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user