'update'
This commit is contained in:
55
ipad_app/Sources/Views/BookDetailView.swift
Normal file
55
ipad_app/Sources/Views/BookDetailView.swift
Normal file
@@ -0,0 +1,55 @@
|
||||
#if os(iOS)
|
||||
import SwiftUI
|
||||
|
||||
@available(macOS 10.15, iOS 13.0, *)
|
||||
struct BookDetailView: View {
|
||||
let book: BookMeta
|
||||
let index: BundleIndex
|
||||
let bundleDir: URL
|
||||
|
||||
var annotations: [AnnotationRow] { index.annotationsMap[book.id] ?? [] }
|
||||
var review: String? { index.bookIntro[book.title] }
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
HStack(alignment:.top, spacing:16) {
|
||||
CoverImageView(book: book, bundleDir: bundleDir).frame(width:120,height:170)
|
||||
VStack(alignment:.leading, spacing:8) {
|
||||
Text(book.title).font(.title2).bold()
|
||||
Text(book.author).foregroundColor(.secondary)
|
||||
if let y = book.readtime_year { Text("全年阅读 \(y/60) 小时").font(.callout) }
|
||||
if book.is_finished_this_year == true { Text("今年已读完 ✅").font(.caption).foregroundColor(.green) }
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
if let review = review, !review.isEmpty {
|
||||
VStack(alignment:.leading, spacing:8) {
|
||||
Text("书籍简评").font(.headline)
|
||||
Text(review).font(.body)
|
||||
}
|
||||
}
|
||||
if !annotations.isEmpty {
|
||||
VStack(alignment:.leading, spacing:8) {
|
||||
Text("批注 (\(annotations.count))").font(.headline)
|
||||
ForEach(annotations) { ann in
|
||||
VStack(alignment:.leading, spacing:4) {
|
||||
if let sel = ann.selected { Text(sel).font(.body) }
|
||||
if let note = ann.note, !note.isEmpty { Text("✎ " + note).font(.footnote).foregroundColor(.secondary) }
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text("无批注").foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.navigationTitle("详情")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
57
ipad_app/Sources/Views/BookListView.swift
Normal file
57
ipad_app/Sources/Views/BookListView.swift
Normal file
@@ -0,0 +1,57 @@
|
||||
#if os(iOS)
|
||||
import SwiftUI
|
||||
|
||||
struct BookListView: View {
|
||||
@ObservedObject var importer: BundleImporter
|
||||
@ObservedObject var vm: LibraryViewModel
|
||||
@State private var selected: BookMeta? = nil
|
||||
|
||||
private func bundleDir(of id: String) -> URL? { // 取最新导入目录
|
||||
guard let root = try? FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("ImportedBundle") else { return nil }
|
||||
let subs = (try? FileManager.default.contentsOfDirectory(at: root, includingPropertiesForKeys: nil)) ?? []
|
||||
return subs.sorted { $0.lastPathComponent > $1.lastPathComponent }.first
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
HStack {
|
||||
TextField("搜索书名/作者", text: $vm.searchText)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
Button("导入") { importer.presentPicker() }
|
||||
if let msg = importer.progressMessage { Text(msg).font(.footnote).foregroundColor(.secondary) }
|
||||
}.padding(.horizontal).padding(.top,8)
|
||||
Divider()
|
||||
if vm.filteredBooks.isEmpty {
|
||||
EmptyStateView(message: "无数据,点击导入按钮加载 ZIP", actionTitle: "导入") { importer.presentPicker() }
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
List(vm.filteredBooks) { book in
|
||||
Button {
|
||||
selected = book
|
||||
} label: {
|
||||
HStack(alignment:.top, spacing:12) {
|
||||
if let dir = bundleDir(of: book.id) {
|
||||
CoverImageView(book: book, bundleDir: dir).frame(width:70,height:100)
|
||||
}
|
||||
VStack(alignment:.leading, spacing:4) {
|
||||
Text(book.title).font(.headline)
|
||||
Text(book.author).font(.subheadline).foregroundColor(.secondary)
|
||||
if let rt = book.readtime_year { Text("全年阅读: \(rt/60) 小时").font(.caption).foregroundColor(.secondary) }
|
||||
if book.is_finished_this_year == true { Text("今年已读完 ✅").font(.caption2).foregroundColor(.green) }
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $selected) { b in
|
||||
if let idx = importer.bundleIndex, let dir = bundleDir(of: b.id) {
|
||||
BookDetailView(book: b, index: idx, bundleDir: dir)
|
||||
} else {
|
||||
Text("数据缺失")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
52
ipad_app/Sources/Views/Components/BubbleMetricsView.swift
Normal file
52
ipad_app/Sources/Views/Components/BubbleMetricsView.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
#if os(iOS)
|
||||
import SwiftUI
|
||||
|
||||
@available(macOS 10.15, iOS 13.0, *)
|
||||
struct BubbleMetric: Identifiable {
|
||||
let id = UUID()
|
||||
let label: String
|
||||
let display: String
|
||||
let valueMinutes: Double // 用于相对半径
|
||||
let color: Color
|
||||
}
|
||||
|
||||
@available(macOS 10.15, iOS 13.0, *)
|
||||
struct BubbleMetricsView: View {
|
||||
let metrics: [BubbleMetric]
|
||||
|
||||
private func radius(for v: Double, maxV: Double) -> CGFloat {
|
||||
guard maxV > 0 else { return 20 }
|
||||
let norm = sqrt(v / maxV)
|
||||
return 30 + norm * 70
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geo in
|
||||
let maxV = metrics.map { $0.valueMinutes }.max() ?? 1
|
||||
ZStack {
|
||||
ForEach(Array(metrics.enumerated()), id: \.[1].id) { idx, m in
|
||||
// 简单环形布局
|
||||
let angle = Double(idx) / Double(metrics.count) * Double.pi * 2
|
||||
let R = min(geo.size.width, geo.size.height) / 2 - 80
|
||||
let x = geo.size.width/2 + CGFloat(cos(angle)) * R
|
||||
let y = geo.size.height/2 + CGFloat(sin(angle)) * R
|
||||
let r = radius(for: m.valueMinutes, maxV: maxV)
|
||||
Circle()
|
||||
.fill(m.color.opacity(0.75))
|
||||
.frame(width: r, height: r)
|
||||
.overlay(
|
||||
VStack(spacing:4){
|
||||
Text(m.display).font(.system(size: min(18, r*0.28))).bold().foregroundColor(.white)
|
||||
Text(m.label).font(.system(size: min(14, r*0.22))).foregroundColor(.white)
|
||||
}.padding(4)
|
||||
)
|
||||
.position(x: x, y: y)
|
||||
.shadow(radius: 4, y: 2)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
.frame(height: 340)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
19
ipad_app/Sources/Views/Components/EmptyStateView.swift
Normal file
19
ipad_app/Sources/Views/Components/EmptyStateView.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
#if os(iOS)
|
||||
import SwiftUI
|
||||
|
||||
struct EmptyStateView: View {
|
||||
let message: String
|
||||
let actionTitle: String
|
||||
let action: () -> Void
|
||||
var body: some View {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "tray")
|
||||
.font(.system(size: 48))
|
||||
.foregroundColor(.secondary)
|
||||
Text(message).foregroundColor(.secondary)
|
||||
Button(actionTitle, action: action)
|
||||
}
|
||||
.padding(40)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
50
ipad_app/Sources/Views/StatsView.swift
Normal file
50
ipad_app/Sources/Views/StatsView.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
#if os(iOS)
|
||||
import SwiftUI
|
||||
import Charts
|
||||
|
||||
struct StatsView: View {
|
||||
let index: BundleIndex
|
||||
|
||||
struct DayVal: Identifiable { let id = UUID(); let label: String; let value: Int }
|
||||
struct MonthVal: Identifiable { let id = UUID(); let label: String; let value: Int }
|
||||
struct YearVal: Identifiable { let id = UUID(); let label: String; let hours: Double }
|
||||
|
||||
var weekSeries: [DayVal] {
|
||||
let arr = (index.stats.global.week_total_minutes, index.stats.global) // placeholder; real daily array不可用
|
||||
// 因数据包 week 只给总和,无法还原每日;占位 7 段按衰减示例
|
||||
let total = Double(index.stats.global.week_total_minutes)
|
||||
return (0..<7).map { i in
|
||||
let frac = (7.0-Double(i))*1.0/28.0 + 0.05
|
||||
return DayVal(label: ["今","昨","2","3","4","5","6"][i], value: Int(total * frac / 2.0))
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment:.leading, spacing: 24) {
|
||||
Text("阅读统计").font(.title2).bold().padding(.top)
|
||||
// 气泡指标
|
||||
let g = index.stats.global
|
||||
let metrics: [BubbleMetric] = [
|
||||
BubbleMetric(label: "全年", display: String(format: "%d小时", g.year_total_minutes/60), valueMinutes: Double(g.year_total_minutes), color: .blue),
|
||||
BubbleMetric(label: "月均", display: String(format: "%d分钟", g.month_avg_minutes), valueMinutes: Double(g.month_avg_minutes), color: .purple),
|
||||
BubbleMetric(label: "近7天", display: String(format: "%d分钟", g.week_total_minutes), valueMinutes: Double(g.week_total_minutes), color: .pink),
|
||||
BubbleMetric(label: "日均", display: String(format: "%d分钟", g.day_avg_minutes), valueMinutes: Double(g.day_avg_minutes), color: .yellow),
|
||||
BubbleMetric(label: "已读", display: String(format: "%d本", g.finished_books_count), valueMinutes: Double(g.finished_books_count*60), color: .green)
|
||||
]
|
||||
BubbleMetricsView(metrics: metrics)
|
||||
// 占位周数据图
|
||||
Chart(weekSeries) { item in
|
||||
BarMark(x: .value("Day", item.label), y: .value("Min", item.value))
|
||||
}.frame(height: 180)
|
||||
Text("说明: 因数据包未携带逐日数组,这里周图为占位模拟。可扩展导出添加 daily 数组。")
|
||||
.font(.footnote).foregroundColor(.secondary)
|
||||
// 年度平均小时散点(使用 readtime_year)
|
||||
let yearHours = Double(g.year_total_minutes)/60.0
|
||||
HStack { Text("全年总时长约 \(String(format: "%.1f", yearHours)) 小时").font(.headline); Spacer() }
|
||||
}
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user