From f90f90ee416275103683e29b6bf979ed0483e5bd Mon Sep 17 00:00:00 2001 From: wangdl Date: Wed, 27 May 2026 21:28:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(ios):=20=E5=88=9B=E5=BB=BA=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=BA=93=E9=A1=B5=E9=9D=A2=20-=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E8=BF=94=E5=9B=9E=20+=20=E6=88=90?= =?UTF-8?q?=E5=8A=9F/=E5=A4=B1=E8=B4=A5=E5=8F=8D=E9=A6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 @Environment(\.dismiss) 创建成功后自动返回列表 - 新增 isCreating 加载态,按钮显示 ProgressView 并禁用 - 空名称时按钮灰色不可点击 - 成功 toast "知识库已创建" + 自动 dismiss - 失败 toast "创建失败,请重试" Co-Authored-By: Claude Opus 4.7 --- .../Features/Library/LibrarySubpages.swift | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift b/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift index 5c1859b..bd63eb7 100644 --- a/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift +++ b/AIStudyApp/AIStudyApp/Features/Library/LibrarySubpages.swift @@ -1,15 +1,38 @@ import SwiftUI struct CreateLibraryPage: View { - @State private var name = ""; @State private var desc = "" + @Environment(\.dismiss) private var dismiss + @State private var name = ""; @State private var desc = ""; @State private var isCreating = false var body: some View { ZStack { Color.zxBg0.ignoresSafeArea(); VStack(spacing: 0) { ScrollView { VStack(spacing: 20) { VStack(alignment: .leading, spacing: 8) { Text("知识库名称").font(.system(size: 12, weight: .semibold)).foregroundColor(Color.zxF035); TextField("例如:机器学习", text: $name).font(.system(size: 15)).tint(Color.zxPurple).padding(.horizontal, 16).frame(height: 52).background(Color.zxFill004).clipShape(RoundedRectangle(cornerRadius: 14)).overlay(RoundedRectangle(cornerRadius: 14).stroke(Color.zxBorder008, lineWidth: 1)) } VStack(alignment: .leading, spacing: 8) { Text("描述(可选)").font(.system(size: 12, weight: .semibold)).foregroundColor(Color.zxF035); TextField("简单描述这个知识库的内容", text: $desc).font(.system(size: 15)).tint(Color.zxPurple).padding(.horizontal, 16).frame(height: 52).background(Color.zxFill004).clipShape(RoundedRectangle(cornerRadius: 14)).overlay(RoundedRectangle(cornerRadius: 14).stroke(Color.zxBorder008, lineWidth: 1)) } Button { - Task { _ = try? await KnowledgeBaseService.shared.create(title: name, description: desc.isEmpty ? nil : desc) } - } label: { Text("创建").font(.system(size: 14, weight: .bold)).foregroundColor(.white).frame(maxWidth: .infinity).frame(height: 52).background(ZXGradient.ctaPurple).clipShape(RoundedRectangle(cornerRadius: 16)) } + guard !name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return } + isCreating = true + Task { + let kb = try? await KnowledgeBaseService.shared.create(title: name, description: desc.isEmpty ? nil : desc) + await MainActor.run { + isCreating = false + if kb != nil { + ZXToastManager.shared.success("知识库已创建") + dismiss() + } else { + ZXToastManager.shared.error("创建失败,请重试") + } + } + } + } label: { + HStack(spacing: 8) { + if isCreating { ProgressView().tint(.white) } + Text("创建").font(.system(size: 14, weight: .bold)) + } + .foregroundColor(.white).frame(maxWidth: .infinity).frame(height: 52) + .background(name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? Color.zxHairlineStrong : ZXGradient.ctaPurple) + .clipShape(RoundedRectangle(cornerRadius: 16)) + } + .disabled(isCreating || name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) }.padding(.horizontal, 20).padding(.top, 20) }.scrollIndicators(.hidden) } }.navigationBarTitleDisplayMode(.inline).toolbarBackground(.hidden, for: .navigationBar)} }