fix(ios): M1 审查修复 3 个 Bug
- AIChatPage 会话列表按钮补充 .sheet 展示历史对话 - AIChatViewModel 新增 loadSession() 加载对话历史 - NotificationListView 日期解析兼容多种 ISO 格式 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
26610c1baa
commit
c7b8360ff6
@ -77,6 +77,34 @@ struct AIChatPage: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sheet(isPresented: $showSessions) {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
RoundedRectangle(cornerRadius: 3).fill(Color.zxF03).frame(width: 36, height: 5).padding(.top, 12).padding(.bottom, 16)
|
||||||
|
Text("对话列表").font(.system(size: 16, weight: .semibold)).foregroundColor(Color.zxF0).padding(.bottom, 16)
|
||||||
|
if sessions.isEmpty {
|
||||||
|
Text("暂无历史对话").font(.system(size: 14)).foregroundColor(Color.zxF04).padding(.top, 40)
|
||||||
|
} else {
|
||||||
|
ScrollView {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
ForEach(sessions) { s in
|
||||||
|
Button {
|
||||||
|
showSessions = false
|
||||||
|
Task { await vm.loadSession(s.id) }
|
||||||
|
} label: {
|
||||||
|
HStack {
|
||||||
|
Text(s.title ?? "对话").font(.system(size: 14)).foregroundColor(Color.zxF0)
|
||||||
|
Spacer()
|
||||||
|
Text(s.updatedAt?.prefix(10).description ?? "").font(.system(size: 11)).foregroundColor(Color.zxF04)
|
||||||
|
}.padding(.horizontal, 20).padding(.vertical, 14)
|
||||||
|
}.foregroundColor(.primary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity).background(Color.zxBg0)
|
||||||
|
.presentationDetents([.medium, .large])
|
||||||
|
}
|
||||||
.task { await vm.load() }
|
.task { await vm.load() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,7 +85,17 @@ final class AIChatViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setKnowledgeBase(_ id: String) {
|
func setKnowledgeBase(_ id: String) { knowledgeBaseId = id }
|
||||||
knowledgeBaseId = id
|
|
||||||
|
func loadSession(_ id: String) async {
|
||||||
|
sessionId = id
|
||||||
|
isCreatingSession = true
|
||||||
|
do {
|
||||||
|
let msgs: [ChatMessage] = try await RagChatService.shared.getMessages(sessionId: id)
|
||||||
|
messages = msgs.map { m in
|
||||||
|
AIMessage(role: m.role == "user" ? .user : .ai, content: m.content, citations: m.citations)
|
||||||
|
}
|
||||||
|
} catch { sessionError = "加载对话失败" }
|
||||||
|
isCreatingSession = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,12 +83,17 @@ struct NotificationListView: View {
|
|||||||
|
|
||||||
private func isToday(_ dateStr: String?) -> Bool {
|
private func isToday(_ dateStr: String?) -> Bool {
|
||||||
guard let d = dateStr else { return false }
|
guard let d = dateStr else { return false }
|
||||||
let today = ISO8601DateFormatter().string(from: Date())
|
let f = DateFormatter(); f.dateFormat = "yyyy-MM-dd"
|
||||||
return d.prefix(10) == today.prefix(10)
|
let today = f.string(from: Date())
|
||||||
|
return d.prefix(10) == today
|
||||||
}
|
}
|
||||||
|
|
||||||
private func isThisWeek(_ dateStr: String?) -> Bool {
|
private func isThisWeek(_ dateStr: String?) -> Bool {
|
||||||
guard let d = dateStr, let date = ISO8601DateFormatter().date(from: String(d.prefix(19)) + "Z") else { return false }
|
guard let d = dateStr else { return false }
|
||||||
|
// Backend returns ISO 8601 or MySQL datetime
|
||||||
|
let clean = d.prefix(19).replacingOccurrences(of: "T", with: " ")
|
||||||
|
let f = DateFormatter(); f.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
||||||
|
guard let date = f.date(from: String(clean)) else { return false }
|
||||||
return Date().timeIntervalSince(date) < 7 * 86400
|
return Date().timeIntervalSince(date) < 7 * 86400
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user