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