按用户的"800 行红线、单一职责"约束拆分。零行为变化,只是物理文件结构。 - SettingsView.swift 87 (root: 枚举 + 导航模型 + 主分发) - SettingsComponents.swift 218 (SettingsPage / GlassSection / GlassPanel / MetricTile / Notification 名 / polishModeHint / isFilled) - Sidebar.swift 270 (FixedSidebar + 状态卡 + stats + WindowCanvasBackground) - Tabs/HomeTab.swift 161 - Tabs/HistoryTab.swift 50 - Tabs/DictionaryTab.swift 349 (含 Chip + ChipFlow + EditorSheet) - Tabs/StyleTab.swift 123 (含 StyleCard) - Tabs/HelpTab.swift 100 - Tabs/SettingsHubTab.swift 184 - Tabs/LegacyTabs.swift 172 (Overview/Hotkey/Modes/Privacy 旧版孤儿,原样搬) private 改成默认 internal 让跨文件可见,封装边界仍止于 OpenLessApp 模块内部。 项目最长文件从 1697 行 → 566 行 (DictationCoordinator),全部在 800 红线下。
51 lines
1.9 KiB
Swift
51 lines
1.9 KiB
Swift
import SwiftUI
|
|
import OpenLessCore
|
|
import OpenLessPersistence
|
|
|
|
struct HistoryTab: View {
|
|
@State private var sessions: [DictationSession] = []
|
|
private let store = HistoryStore()
|
|
|
|
var body: some View {
|
|
SettingsPage(
|
|
title: "历史",
|
|
subtitle: "最近的识别结果只保存在本机。"
|
|
) {
|
|
PrimaryActionRow {
|
|
Button("刷新") { reload() }
|
|
Button("清空") { store.clear(); reload() }
|
|
}
|
|
|
|
if sessions.isEmpty {
|
|
ContentUnavailableView("还没有历史记录", systemImage: "clock", description: Text("完成一次语音输入后会显示在这里。"))
|
|
.frame(maxWidth: .infinity, minHeight: 260)
|
|
} else {
|
|
GlassSection(title: "最近记录", symbol: "clock") {
|
|
ForEach(Array(sessions.enumerated()), id: \.element.id) { index, session in
|
|
if index > 0 { DividerLine() }
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
HStack {
|
|
Text(session.createdAt, style: .time)
|
|
Text(session.mode.displayName)
|
|
.foregroundStyle(.secondary)
|
|
Spacer()
|
|
Text(session.insertStatus.rawValue)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
Text(session.finalText)
|
|
.lineLimit(3)
|
|
}
|
|
.padding(.vertical, 9)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.onAppear { reload() }
|
|
}
|
|
|
|
private func reload() {
|
|
sessions = store.recent(limit: 100)
|
|
}
|
|
}
|