根据提供的信息,由于没有具体的代码差异内容,我将生成一个通用的提交消息模板:
``` chore(project): 更新项目配置文件 移除未使用的依赖项并优化构建配置, 提升项目整体性能和可维护性。 ```
This commit is contained in:
@@ -32,6 +32,12 @@ struct ArchiveListView: View {
|
||||
|
||||
@State private var filter: TimelineKind? = nil
|
||||
@State private var endingSymptom: Symptom?
|
||||
|
||||
/// 默认无参;从首页「我的报告档案」进入时传 `.report` 预选分类 chip。
|
||||
/// 仅在视图创建时生效(RootView 切 tab 会重建 ArchiveListView)。
|
||||
init(initialFilter: TimelineKind? = nil) {
|
||||
_filter = State(initialValue: initialFilter)
|
||||
}
|
||||
@State private var selectedEntry: TimelineEntry?
|
||||
@State private var selectedGroup: IndicatorGroup?
|
||||
@State private var route: Route?
|
||||
|
||||
@@ -6,6 +6,10 @@ import SwiftData
|
||||
/// 让 Qwen3 从医生问诊角度提 3-4 个追问,用户可一键将「补充模板」追加到输入框。
|
||||
/// 支持多轮——每轮把已问过的 q 传给 LLM 要求别重复;已采纳的 row 灰色 + ✓ 标记。
|
||||
struct DiaryQuickSheet: View {
|
||||
/// 语音「写日记」直达:隐藏顶部 2×2 入口选择,进入即聚焦正文直接写。
|
||||
/// 默认 false —— 从「新建」菜单进入时仍保留四选入口。
|
||||
var directWrite: Bool = false
|
||||
|
||||
@Environment(\.modelContext) private var ctx
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@@ -32,11 +36,10 @@ struct DiaryQuickSheet: View {
|
||||
/// 累积已覆盖的问诊维度(question.dim),回传下一轮 prompt 用于按维度去重。
|
||||
@State private var coveredDims: Set<String> = []
|
||||
@State private var suggestTask: Task<Void, Never>?
|
||||
/// 当前正在「就地填空」的 question id;nil = 没有展开的填空面板。
|
||||
@State private var fillingId: UUID?
|
||||
/// 当前填空面板各占位槽的输入值,长度 = 该模板占位数。
|
||||
@State private var fillValues: [String] = []
|
||||
/// 上一轮「再问一轮」没问出任何新维度(全被去重)时为 true,提示用户已覆盖主要维度。
|
||||
/// 关心条里被用户「跳过」的 question id。跳过的不从 questions 里删(其维度已计入
|
||||
/// coveredDims,下一轮不会再问),只是不再排进关心条队列。
|
||||
@State private var skippedQuestionIDs: Set<UUID> = []
|
||||
/// 上一轮「再想想」没问出任何新维度(全被去重)时为 true,提示用户主要维度已问全。
|
||||
@State private var exhaustedNote = false
|
||||
/// sheet detent。默认 large,确保建议面板有足够展示空间。
|
||||
/// 仍保留 medium,用户可手动下拉收回为半屏(纯写文本时更轻量)。
|
||||
@@ -75,6 +78,40 @@ struct DiaryQuickSheet: View {
|
||||
private var canRequestSuggest: Bool { hasContent && !isLoading && voicePhase == .idle }
|
||||
private var canSubmit: Bool { hasContent }
|
||||
|
||||
// MARK: - 关心条(care bar)状态
|
||||
|
||||
/// 收敛后的「关心」状态:把 phase + 队列 + 语音占用,归并成一个枚举。
|
||||
/// 键盘正上方的关心条与正文里的回落卡共用同一份状态,保证两处显示一致。
|
||||
private enum CareState {
|
||||
case hidden // 没内容 / 语音占用,不打扰
|
||||
case prompt // 有内容、还没生成,邀请用户让康康想想
|
||||
case thinking // 正在本地推理
|
||||
case asking(DiaryAssistService.Question) // 当前轮到要问的一句
|
||||
case caughtUp(exhausted: Bool) // 队列已清空;exhausted=这轮没问出新东西
|
||||
case failed(String)
|
||||
}
|
||||
|
||||
/// 还没被采纳 / 跳过的问题队列。关心条一次只露出队首一句(其余按维度排队等着)。
|
||||
private var pendingQuestions: [DiaryAssistService.Question] {
|
||||
questions.filter { !$0.adopted && !skippedQuestionIDs.contains($0.id) }
|
||||
}
|
||||
private var currentCareQuestion: DiaryAssistService.Question? { pendingQuestions.first }
|
||||
|
||||
private var careState: CareState {
|
||||
if voicePhase != .idle { return .hidden }
|
||||
switch phase {
|
||||
case .loading:
|
||||
return .thinking
|
||||
case .failed(let err):
|
||||
return .failed(err.localizedDescription)
|
||||
case .idle:
|
||||
return hasContent ? .prompt : .hidden
|
||||
case .ready:
|
||||
if let q = currentCareQuestion { return .asking(q) }
|
||||
return hasContent ? .caughtUp(exhausted: exhaustedNote) : .hidden
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
Capsule()
|
||||
@@ -88,7 +125,7 @@ struct DiaryQuickSheet: View {
|
||||
Text("健康记录")
|
||||
.font(.tjH2())
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Text("记录身体状态 · 可让 AI 多轮辅助查漏补缺")
|
||||
Text("记录身体状态 · 康康在一旁帮你想还能记点啥")
|
||||
.font(.tjScaled( 11))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
@@ -100,32 +137,13 @@ struct DiaryQuickSheet: View {
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 10)
|
||||
|
||||
// 入口四选(2×2):写日记(本页)/ 用药(MedicationLogSheet,记剂量+时间)/
|
||||
// 拍药盒(识别入药品库)/ 记症状(SymptomStartSheet)。
|
||||
LazyVGrid(columns: [GridItem(.flexible(), spacing: 10),
|
||||
GridItem(.flexible(), spacing: 10)], spacing: 10) {
|
||||
modeCard(icon: "pencil", title: String(appLoc: "写日记"),
|
||||
subtitle: String(appLoc: "文字或语音"), active: true) {
|
||||
contentFocused = true
|
||||
}
|
||||
modeCard(icon: "pills.fill", title: String(appLoc: "用药"),
|
||||
subtitle: String(appLoc: "记剂量与时间"), active: false) {
|
||||
showMedicationLog = true
|
||||
}
|
||||
modeCard(icon: "camera.viewfinder", title: String(appLoc: "拍药盒"),
|
||||
subtitle: String(appLoc: "识别入药品库"), active: false) {
|
||||
showMedicationScan = true
|
||||
}
|
||||
modeCard(icon: "waveform.path.ecg", title: String(appLoc: "记症状"),
|
||||
subtitle: String(appLoc: "持续追踪"), active: false) {
|
||||
showSymptomStart = true
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 14)
|
||||
// 模式入口(写日记 / 用药 / 拍药盒 / 记症状)只在「还没动笔」时露出:
|
||||
// 一旦聚焦正文或开始打字就收起,把写日记界面让出来,保持清爽
|
||||
//(对齐用药/症状那种打开即专一表单的观感)。
|
||||
modeSelector
|
||||
.animation(.snappy(duration: 0.22), value: showModeSelector)
|
||||
|
||||
ScrollViewReader { proxy in
|
||||
ScrollView(showsIndicators: false) {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
@@ -166,6 +184,12 @@ struct DiaryQuickSheet: View {
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.strokeBorder(Tj.Palette.line, lineWidth: 1)
|
||||
)
|
||||
// ①「关心条」主舞台:贴键盘正上方,随写随冒、一次只问一句。
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .keyboard) {
|
||||
careBarRow(compact: true)
|
||||
}
|
||||
}
|
||||
|
||||
if voicePhase != .idle {
|
||||
DiaryVoicePanel(
|
||||
@@ -218,25 +242,11 @@ struct DiaryQuickSheet: View {
|
||||
.datePickerStyle(.compact)
|
||||
.labelsHidden()
|
||||
}
|
||||
// 底部锚点,新一轮 question 进来后自动滚到这里
|
||||
Color.clear.frame(height: 1).id("assist-bottom")
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 6)
|
||||
}
|
||||
.scrollDismissesKeyboard(.interactively)
|
||||
.onChange(of: questions.count) { old, new in
|
||||
guard new > old else { return }
|
||||
// 滚到新一轮的 round divider(让用户先看到「第 N 轮」的标签,
|
||||
// 再依次看到这一轮的 questions)
|
||||
let roundId = "round-\(questions[old].round)"
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
|
||||
withAnimation(.easeOut(duration: 0.25)) {
|
||||
proxy.scrollTo(roundId, anchor: .top)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HStack(spacing: 12) {
|
||||
Button("取消") { dismiss() }
|
||||
@@ -276,6 +286,14 @@ struct DiaryQuickSheet: View {
|
||||
// 嵌套 sheet:用药记录表单自带保存/取消;保存后回到日记(不强行关闭)。
|
||||
MedicationLogSheet()
|
||||
}
|
||||
.onAppear {
|
||||
// 语音「写日记」直达:进入即聚焦正文,光标直接落在输入框,免去再点一下。
|
||||
// 轻微延迟等 sheet 呈现动画落定,否则首帧聚焦偶发不弹键盘。
|
||||
guard directWrite else { return }
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.45) {
|
||||
contentFocused = true
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
suggestTask?.cancel()
|
||||
voiceFlowTask?.cancel()
|
||||
@@ -294,304 +312,160 @@ struct DiaryQuickSheet: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AI 辅助区
|
||||
// MARK: - 关心条(care bar)视图
|
||||
|
||||
/// 正文里的「回落卡」:键盘收起时(关心条随键盘一起消失)在这里接住同一份 careState,
|
||||
/// 并承载 AI 免责声明。键盘弹起时整块让位给键盘正上方的关心条,避免两处重复。
|
||||
@ViewBuilder
|
||||
private var assistSection: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
// section header
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "sparkles")
|
||||
.font(.tjScaled( 11, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
sectionLabel(String(appLoc: "AI 辅助 · 医生角度查漏补缺"))
|
||||
Spacer()
|
||||
if hasQuestions {
|
||||
Text("\(questions.count) 个建议")
|
||||
.font(.tjScaled( 10, design: .monospaced))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
if lastRate > 0 {
|
||||
Text(String(format: "%.1f tok/s", lastRate))
|
||||
.font(.tjScaled( 10, design: .monospaced))
|
||||
.foregroundStyle(Tj.Palette.leaf)
|
||||
if !contentFocused {
|
||||
if case .hidden = careState {
|
||||
EmptyView()
|
||||
} else {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "sparkles")
|
||||
.font(.tjScaled( 11, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
sectionLabel(String(appLoc: "康康帮你记"))
|
||||
Spacer(minLength: 0)
|
||||
if lastRate > 0 {
|
||||
Text(String(format: "%.1f tok/s", lastRate))
|
||||
.font(.tjScaled( 10, design: .monospaced))
|
||||
.foregroundStyle(Tj.Palette.leaf)
|
||||
}
|
||||
}
|
||||
careBarRow(compact: false)
|
||||
.padding(12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.fill(Tj.Palette.paper)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.strokeBorder(Tj.Palette.lineSoft, lineWidth: 1)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 累积的 questions 列表(多轮,带轮次分隔)
|
||||
if hasQuestions {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(Array(questions.enumerated()), id: \.element.id) { idx, q in
|
||||
if idx == 0 || questions[idx - 1].round != q.round {
|
||||
roundDivider(round: q.round,
|
||||
count: questions.filter { $0.round == q.round }.count)
|
||||
.id("round-\(q.round)")
|
||||
}
|
||||
questionRow(index: roundLocalIndex(at: idx), question: q)
|
||||
}
|
||||
}
|
||||
// 用过一次 AI 后,免责声明常驻(键盘弹起时关心条在上方,这条留在正文里兜合规)。
|
||||
if !questions.isEmpty {
|
||||
AIDisclaimerFooter()
|
||||
}
|
||||
|
||||
if exhaustedNote {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "checkmark.seal.fill")
|
||||
.font(.tjScaled( 11))
|
||||
.foregroundStyle(Tj.Palette.leaf)
|
||||
Text("已覆盖主要问诊维度;补充原文后可再追问")
|
||||
.font(.tjScaled( 11))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
|
||||
// 底部主操作按钮(状态机驱动)
|
||||
phaseFooter
|
||||
}
|
||||
}
|
||||
|
||||
/// 关心条的统一渲染。`compact = true` 给键盘正上方那条(单行紧凑);
|
||||
/// `compact = false` 给正文回落卡(问题可换两行、留白更松)。两处共用同一 careState 与动作。
|
||||
@ViewBuilder
|
||||
private var phaseFooter: some View {
|
||||
switch phase {
|
||||
case .idle:
|
||||
assistPrimaryButton(
|
||||
icon: "sparkles",
|
||||
label: canRequestSuggest
|
||||
? String(appLoc: "让 AI 帮我想想还能记什么")
|
||||
: String(appLoc: "先写几个字,AI 来帮忙补充"),
|
||||
enabled: canRequestSuggest,
|
||||
prominent: true,
|
||||
action: requestSuggestions
|
||||
)
|
||||
private func careBarRow(compact: Bool) -> some View {
|
||||
switch careState {
|
||||
case .hidden:
|
||||
EmptyView()
|
||||
|
||||
case .loading:
|
||||
assistLoadingIndicator
|
||||
case .prompt:
|
||||
Button(action: requestSuggestions) {
|
||||
careCapsule(icon: "sparkles",
|
||||
text: String(appLoc: "让康康帮你把这条记得更全"),
|
||||
tint: Tj.Palette.brick, style: .soft, compact: compact)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(!canRequestSuggest)
|
||||
|
||||
case .ready:
|
||||
assistPrimaryButton(
|
||||
icon: "arrow.clockwise",
|
||||
label: canRequestSuggest
|
||||
? String(appLoc: "再问一轮 · 让 AI 从新角度追问")
|
||||
: String(appLoc: "更新一下原文,再让 AI 继续追问"),
|
||||
enabled: canRequestSuggest,
|
||||
action: requestSuggestions
|
||||
)
|
||||
|
||||
case .failed(let err):
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "exclamationmark.triangle.fill")
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
Text(err.localizedDescription)
|
||||
.font(.tjScaled( 12))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Spacer()
|
||||
case .thinking:
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "sparkles")
|
||||
.font(.tjScaled( compact ? 12 : 13, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
.symbolEffect(.pulse, options: .repeating)
|
||||
Text(lastRate > 0
|
||||
? String(format: String(appLoc: "康康在想想 · %.1f tok/s"), lastRate)
|
||||
: String(appLoc: "康康在想想…"))
|
||||
.font(.tjScaled( 13, weight: .medium))
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
Spacer(minLength: 0)
|
||||
Button(action: cancelSuggestions) {
|
||||
Text("停")
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
Button { requestSuggestions() } label: {
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
case .asking(let q):
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: "text.bubble.fill")
|
||||
.font(.tjScaled( compact ? 12 : 13, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
Text(q.q)
|
||||
.font(.tjScaled( compact ? 13 : 14, weight: .medium))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
.lineLimit(compact ? 1 : 2)
|
||||
.fixedSize(horizontal: false, vertical: !compact)
|
||||
Spacer(minLength: 6)
|
||||
Button { skipCurrent(q) } label: {
|
||||
Text("跳过")
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
Button { recordCurrent(q) } label: {
|
||||
careCapsule(icon: "plus", text: String(appLoc: "记一下"),
|
||||
tint: Tj.Palette.ink, style: .filled, compact: compact)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
case .caughtUp(let exhausted):
|
||||
Button(action: requestSuggestions) {
|
||||
careCapsule(
|
||||
icon: exhausted ? "checkmark.seal.fill" : "sparkles",
|
||||
text: exhausted
|
||||
? String(appLoc: "主要的都帮你问到啦 · 再想想?")
|
||||
: String(appLoc: "还想到几个想问你 · 再来一轮"),
|
||||
tint: exhausted ? Tj.Palette.leaf : Tj.Palette.brick,
|
||||
style: .soft, compact: compact)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(!canRequestSuggest)
|
||||
|
||||
case .failed(let msg):
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: "exclamationmark.triangle.fill")
|
||||
.font(.tjScaled( 12))
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
Text(msg)
|
||||
.font(.tjScaled( 12))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
.lineLimit(1)
|
||||
Spacer(minLength: 0)
|
||||
Button(action: requestSuggestions) {
|
||||
Text("重试")
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.ink)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
.padding(10)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.fill(Tj.Palette.brickSoft.opacity(0.5))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// 辅助主按钮。`prominent` 为真走实心强调样式(填充 brick + 白字 + 轻投影,一眼可点),
|
||||
/// 否则走低调描边样式(用于 .ready 的「再问一轮」)。
|
||||
private func assistPrimaryButton(icon: String,
|
||||
label: String,
|
||||
enabled: Bool,
|
||||
prominent: Bool = false,
|
||||
action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: icon)
|
||||
Text(label)
|
||||
}
|
||||
.font(.tjScaled( prominent ? 14 : 13, weight: .semibold))
|
||||
.foregroundStyle(prominent
|
||||
? (enabled ? Tj.Palette.paper : Tj.Palette.text3)
|
||||
: (enabled ? Tj.Palette.ink : Tj.Palette.text3))
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, prominent ? 14 : 11)
|
||||
.background(assistButtonBackground(enabled: enabled, prominent: prominent))
|
||||
// 纯描边背景、内部透明:补 contentShape 让整框可点(否则只有图标+文字本体能点)。
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(!enabled)
|
||||
}
|
||||
private enum CareCapsuleStyle { case filled, soft }
|
||||
|
||||
@ViewBuilder
|
||||
private func assistButtonBackground(enabled: Bool, prominent: Bool) -> some View {
|
||||
let shape = RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
if prominent {
|
||||
shape
|
||||
.fill(enabled ? Tj.Palette.brick : Tj.Palette.brickSoft)
|
||||
.shadow(color: enabled ? Tj.Palette.brick.opacity(0.30) : .clear,
|
||||
radius: 8, x: 0, y: 3)
|
||||
} else {
|
||||
shape
|
||||
.strokeBorder(
|
||||
enabled ? Tj.Palette.ink : Tj.Palette.line,
|
||||
style: StrokeStyle(lineWidth: 1, dash: enabled ? [] : [3, 3])
|
||||
)
|
||||
/// 关心条里的胶囊。filled = 实心(主动作「记一下」);soft = 浅色底(邀请类)。
|
||||
private func careCapsule(icon: String, text: String, tint: Color,
|
||||
style: CareCapsuleStyle, compact: Bool) -> some View {
|
||||
HStack(spacing: 5) {
|
||||
Image(systemName: icon)
|
||||
.font(.tjScaled( compact ? 11 : 12, weight: .semibold))
|
||||
Text(text)
|
||||
.font(.tjScaled( compact ? 12 : 13, weight: .semibold))
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
/// .loading 等待态:安静的 paper 卡片,底部一条细窄的不确定进度条来回滑动(Linear/Vercel 式极简)。
|
||||
/// 不用高亮扫光、不填强调色,避免刺眼;只靠细线 + sparkles 轻脉冲传达「在算」。
|
||||
private var assistLoadingIndicator: some View {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: "sparkles")
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
.symbolEffect(.pulse, options: .repeating)
|
||||
Text(lastRate > 0
|
||||
? String(format: String(appLoc: "AI 生成中 · %.1f tok/s"), lastRate)
|
||||
: String(appLoc: "AI 生成中 · 本地推理"))
|
||||
.font(.tjScaled( 13, weight: .medium))
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
Spacer(minLength: 0)
|
||||
Button("取消") { cancelSuggestions() }
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
.padding(.vertical, 11)
|
||||
.foregroundStyle(style == .filled ? Tj.Palette.paper : tint)
|
||||
.padding(.horizontal, 12)
|
||||
.frame(maxWidth: .infinity)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.fill(Tj.Palette.paper)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.strokeBorder(Tj.Palette.lineSoft, lineWidth: 1)
|
||||
)
|
||||
.overlay(alignment: .bottom) {
|
||||
AIFlowBar().padding(.horizontal, 1)
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous))
|
||||
}
|
||||
|
||||
/// 给定整张 questions list 里 idx 位置的 question,返回它在自己 round 内的序号(1-based)。
|
||||
private func roundLocalIndex(at idx: Int) -> Int {
|
||||
let target = questions[idx].round
|
||||
var count = 0
|
||||
for i in 0...idx where questions[i].round == target {
|
||||
count += 1
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
/// 第 N 轮的分隔条 —— 让用户清楚下一轮 LLM 看到的是更新过的最新文本。
|
||||
private func roundDivider(round: Int, count: Int) -> some View {
|
||||
HStack(spacing: 8) {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: round == 1 ? "1.circle.fill" : "arrow.triangle.2.circlepath")
|
||||
.font(.tjScaled( 11, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.brick)
|
||||
Text(round == 1
|
||||
? String(appLoc: "第 1 轮 · \(count) 条")
|
||||
: String(appLoc: "第 \(round) 轮 · 基于你刚才更新的文本 · \(count) 条"))
|
||||
.font(.tjScaled( 11, weight: .semibold))
|
||||
.tracking(0.3)
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
}
|
||||
Rectangle()
|
||||
.fill(Tj.Palette.line)
|
||||
.frame(height: 1)
|
||||
.mask(
|
||||
HStack(spacing: 3) {
|
||||
ForEach(0..<60, id: \.self) { _ in
|
||||
Rectangle().frame(width: 3, height: 1)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
.padding(.top, round == 1 ? 0 : 6)
|
||||
}
|
||||
|
||||
private func questionRow(index: Int, question: DiaryAssistService.Question) -> some View {
|
||||
let adopted = question.adopted
|
||||
let filling = fillingId == question.id
|
||||
return VStack(alignment: .leading, spacing: 6) {
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
Text("\(index).")
|
||||
.font(.tjScaled( 13, weight: .semibold, design: .monospaced))
|
||||
.foregroundStyle(adopted ? Tj.Palette.text3 : Tj.Palette.brick)
|
||||
Text(question.q)
|
||||
.font(.tjScaled( 13, weight: .medium))
|
||||
.foregroundStyle(adopted ? Tj.Palette.text3 : Tj.Palette.text)
|
||||
.strikethrough(adopted, color: Tj.Palette.text3)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
Spacer(minLength: 4)
|
||||
|
||||
if adopted {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: "checkmark")
|
||||
.font(.tjScaled( 10, weight: .bold))
|
||||
Text("已采纳")
|
||||
.font(.tjScaled( 11, weight: .semibold))
|
||||
}
|
||||
.foregroundStyle(Tj.Palette.leaf)
|
||||
.padding(.horizontal, 8)
|
||||
.padding(.vertical, 5)
|
||||
.background(Capsule().fill(Tj.Palette.leafSoft))
|
||||
} else if !filling {
|
||||
Button { adopt(question) } label: {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: "plus.circle.fill")
|
||||
.font(.tjScaled( 12))
|
||||
Text("采纳")
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
}
|
||||
.foregroundStyle(Tj.Palette.paper)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 5)
|
||||
.background(Capsule().fill(Tj.Palette.ink))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
if filling {
|
||||
QuestionFillPanel(
|
||||
template: question.fill,
|
||||
values: $fillValues,
|
||||
onCommit: { assembled in commitAdoption(question, text: assembled) },
|
||||
onCancel: { closeFill() }
|
||||
)
|
||||
} else if !question.fill.isEmpty && !adopted {
|
||||
HStack(alignment: .top, spacing: 4) {
|
||||
Text("将追加:")
|
||||
.font(.tjScaled( 11))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Text(question.fill)
|
||||
.font(.tjScaled( 11))
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
.padding(.leading, 22)
|
||||
}
|
||||
}
|
||||
.padding(10)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.fill(adopted ? Tj.Palette.sand2 : Tj.Palette.paper)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.strokeBorder(Tj.Palette.lineSoft, lineWidth: 1)
|
||||
)
|
||||
.padding(.vertical, 7)
|
||||
.background(Capsule().fill(style == .filled ? tint : tint.opacity(0.12)))
|
||||
.contentShape(Capsule())
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
@@ -603,6 +477,41 @@ struct DiaryQuickSheet: View {
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
}
|
||||
|
||||
/// 顶部模式入口仅在「未直达写日记 + 正文未聚焦 + 未输入任何内容」时展示。
|
||||
/// 用户一旦点进正文 / 开始写,就收起入口,留出清爽的写作面。
|
||||
private var showModeSelector: Bool {
|
||||
!directWrite && !contentFocused && !hasContent
|
||||
}
|
||||
|
||||
/// 模式入口(2×2):写日记(本页)/ 用药(记剂量+时间)/ 拍药盒(识别入药品库)/ 记症状。
|
||||
@ViewBuilder
|
||||
private var modeSelector: some View {
|
||||
if showModeSelector {
|
||||
LazyVGrid(columns: [GridItem(.flexible(), spacing: 10),
|
||||
GridItem(.flexible(), spacing: 10)], spacing: 10) {
|
||||
modeCard(icon: "pencil", title: String(appLoc: "写日记"),
|
||||
subtitle: String(appLoc: "文字或语音"), active: true) {
|
||||
contentFocused = true
|
||||
}
|
||||
modeCard(icon: "pills.fill", title: String(appLoc: "用药"),
|
||||
subtitle: String(appLoc: "记剂量与时间"), active: false) {
|
||||
showMedicationLog = true
|
||||
}
|
||||
modeCard(icon: "camera.viewfinder", title: String(appLoc: "拍药盒"),
|
||||
subtitle: String(appLoc: "识别入药品库"), active: false) {
|
||||
showMedicationScan = true
|
||||
}
|
||||
modeCard(icon: "waveform.path.ecg", title: String(appLoc: "记症状"),
|
||||
subtitle: String(appLoc: "持续追踪"), active: false) {
|
||||
showSymptomStart = true
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 14)
|
||||
.transition(.opacity.combined(with: .move(edge: .top)))
|
||||
}
|
||||
}
|
||||
|
||||
/// 顶部入口三选一卡片(写日记 / 拍药盒 / 记症状)。active 表示当前所在模式。
|
||||
/// 竖排紧凑布局:三卡并排在 iPhone 宽度下横排放不下完整文案。
|
||||
private func modeCard(icon: String, title: String, subtitle: String,
|
||||
@@ -734,18 +643,12 @@ struct DiaryQuickSheet: View {
|
||||
|
||||
/// 触发一轮 AI 辅助。把已覆盖的问诊维度(coveredDims)传给 LLM,
|
||||
/// 要求本轮避开这些维度,从结构上压住跨轮换皮重复。
|
||||
/// 关心条形态下**不收键盘**:让生成中的「康康在想想」就停在键盘正上方,
|
||||
/// 出结果后直接在原位换成第一句追问,书写节奏不被打断。
|
||||
private func requestSuggestions() {
|
||||
suggestTask?.cancel()
|
||||
let snapshotContent = content.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let covered = Array(coveredDims)
|
||||
// 1. 主动收起键盘 —— 否则建议面板被键盘吃掉一半
|
||||
contentFocused = false
|
||||
// 2. 确保 sheet 在 large(用户可能下拉到 medium 又触发 AI)
|
||||
if detent != .large {
|
||||
withAnimation(.snappy(duration: 0.25)) {
|
||||
detent = .large
|
||||
}
|
||||
}
|
||||
exhaustedNote = false
|
||||
phase = .loading
|
||||
suggestTask = Task { @MainActor in
|
||||
@@ -819,38 +722,25 @@ struct DiaryQuickSheet: View {
|
||||
phase = hasQuestions ? .ready : .idle
|
||||
}
|
||||
|
||||
/// 采纳:模板含 `[占位]` 时展开就地填空面板;无占位则直接把整句追加(并标记 adopted)。
|
||||
/// 已采纳的 q 不会从列表里消失;其维度已在生成时计入 coveredDims,下一轮 prompt 会避开。
|
||||
private func adopt(_ question: DiaryAssistService.Question) {
|
||||
guard !question.fill.isEmpty, DiaryFillTemplate.slotCount(question.fill) > 0 else {
|
||||
// 无占位:直接采纳整句(空 fill 时退回到追加问题本身)。
|
||||
commitAdoption(question, text: question.fill.isEmpty ? question.q : question.fill)
|
||||
return
|
||||
}
|
||||
withAnimation(.snappy(duration: 0.18)) {
|
||||
fillingId = question.id
|
||||
fillValues = Array(repeating: "", count: DiaryFillTemplate.slotCount(question.fill))
|
||||
}
|
||||
}
|
||||
|
||||
/// 关闭填空面板(取消)。
|
||||
private func closeFill() {
|
||||
withAnimation(.snappy(duration: 0.18)) {
|
||||
fillingId = nil
|
||||
fillValues = []
|
||||
}
|
||||
}
|
||||
|
||||
/// 提交采纳:把(填好的)整句追加到正文,标记 adopted,收起面板。
|
||||
private func commitAdoption(_ question: DiaryAssistService.Question, text: String) {
|
||||
/// 「记一下」:把这条问题对应的补充句落进正文,标记已采纳,关心条自动滑到下一句。
|
||||
/// 用 `assemble(values: [])` 取「去方括号、占位回退为原词」的干净句子——
|
||||
/// 即便用户不再细填,也不会把 `[时间]` 这种机器括号留进日记。
|
||||
private func recordCurrent(_ question: DiaryAssistService.Question) {
|
||||
let stub = question.fill.isEmpty
|
||||
? question.q
|
||||
: DiaryFillTemplate.assemble(question.fill, values: [])
|
||||
appendToContent(stub)
|
||||
if let idx = questions.firstIndex(where: { $0.id == question.id }) {
|
||||
withAnimation(.snappy(duration: 0.18)) {
|
||||
questions[idx].adopted = true
|
||||
}
|
||||
questions[idx].adopted = true
|
||||
}
|
||||
appendToContent(text)
|
||||
fillingId = nil
|
||||
fillValues = []
|
||||
// 落字后把键盘留住:用户顺势接着写,关心条已切到下一句。
|
||||
contentFocused = true
|
||||
}
|
||||
|
||||
/// 「跳过」:这句先不记,关心条滑到下一句。该维度已在生成时计入 coveredDims,
|
||||
/// 下一轮 prompt 不会再问它,所以跳过的不必从 questions 里删。
|
||||
private func skipCurrent(_ question: DiaryAssistService.Question) {
|
||||
skippedQuestionIDs.insert(question.id)
|
||||
}
|
||||
|
||||
/// 把一段补充文本追加到正文末尾(自动补换行,空文本忽略)。
|
||||
|
||||
@@ -20,6 +20,11 @@ struct MedicationLogSheet: View {
|
||||
@State private var dosage = ""
|
||||
@State private var takenAt: Date = .now
|
||||
|
||||
/// 从药品库某个药直接拉起时预选它(药品库详情页「记录一次服用」)。默认 nil = 自由选择。
|
||||
init(preselected: Medication? = nil) {
|
||||
_selectedMed = State(initialValue: preselected)
|
||||
}
|
||||
|
||||
private var resolvedName: String {
|
||||
(selectedMed?.name ?? manualName).trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct HomeView: View {
|
||||
var onTapArchive: () -> Void = {}
|
||||
/// 跳记录页;传 filter 时预选对应分类 chip(报告档案卡传 `.report`,统计磁贴按类别预选)。
|
||||
var onTapArchive: (TimelineKind?) -> Void = { _ in }
|
||||
|
||||
@Query(sort: \Indicator.capturedAt, order: .reverse)
|
||||
private var indicators: [Indicator]
|
||||
@@ -16,21 +17,27 @@ struct HomeView: View {
|
||||
@Query(sort: \Symptom.startedAt, order: .reverse)
|
||||
private var symptoms: [Symptom]
|
||||
|
||||
/// 点「最近记录」某行 → 打开只读详情 sheet(与档案库 C1 同款交互)。
|
||||
@State private var selectedEntry: TimelineEntry?
|
||||
/// 点指标行 → 打开同类聚合详情(历次翻页 + 趋势,与档案库 C1 同款)。
|
||||
@Query private var profiles: [UserProfile]
|
||||
@Query private var customMetrics: [CustomMonitorMetric]
|
||||
|
||||
/// 点迷你趋势卡 → 打开同类聚合详情(历次翻页 + 趋势,与档案库 C1 同款)。
|
||||
@State private var selectedGroup: IndicatorGroup?
|
||||
|
||||
private var profile: UserProfile? { profiles.first }
|
||||
|
||||
/// 主页只挑前 3 条最有代表性的趋势:长期监测优先,其次化验指标。数据不足时整段隐藏。
|
||||
@MainActor
|
||||
private var recentEntries: [TimelineEntry] {
|
||||
let all =
|
||||
TimelineEntry.aggregatedIndicators(indicators) +
|
||||
reports.map(TimelineEntry.from(report:)) +
|
||||
diaries.map(TimelineEntry.from(diary:)) +
|
||||
symptoms.map(TimelineEntry.from(symptom:))
|
||||
return all.sorted { $0.date > $1.date }.prefix(6).map { $0 }
|
||||
private var featuredBuckets: [SeriesBucket] {
|
||||
let all = SeriesBucket.build(from: indicators,
|
||||
profile: profile,
|
||||
customMetrics: customMetrics)
|
||||
let monitor = all.filter { $0.kind == .monitor }
|
||||
let lab = all.filter { $0.kind == .lab }
|
||||
return Array((monitor + lab).prefix(3))
|
||||
}
|
||||
|
||||
private var ongoingSymptomCount: Int { symptoms.filter { $0.endedAt == nil }.count }
|
||||
|
||||
var body: some View {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
@@ -39,49 +46,65 @@ struct HomeView: View {
|
||||
.padding(.bottom, 18)
|
||||
|
||||
HomeCalendarCard()
|
||||
.padding(.bottom, 18)
|
||||
|
||||
overviewSection
|
||||
.padding(.bottom, 18)
|
||||
|
||||
let buckets = featuredBuckets
|
||||
if !buckets.isEmpty {
|
||||
trendsSection(buckets)
|
||||
.padding(.bottom, 18)
|
||||
}
|
||||
|
||||
TodayRemindersCard()
|
||||
|
||||
OngoingSymptomsCard()
|
||||
.padding(.bottom, 18)
|
||||
|
||||
recentSection
|
||||
.padding(.bottom, 22)
|
||||
|
||||
archiveSection
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
.background(Tj.Palette.sand.ignoresSafeArea())
|
||||
.sheet(item: $selectedEntry) { entry in
|
||||
if let d = TimelineDetail.resolve(
|
||||
for: entry,
|
||||
indicators: indicators, reports: reports,
|
||||
diaries: diaries, symptoms: symptoms
|
||||
) {
|
||||
TimelineEntryDetailView(detail: d)
|
||||
}
|
||||
}
|
||||
.sheet(item: $selectedGroup) { group in
|
||||
IndicatorSeriesDetailView(group: group)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - 问候
|
||||
|
||||
private var greeting: some View {
|
||||
HStack(alignment: .top) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
let t = TimeOfDay.current
|
||||
return HStack(alignment: .center, spacing: 14) {
|
||||
// 时段徽章:暖色圆底 + 对应图标(晨/午/夜),随时段自动切换。
|
||||
ZStack {
|
||||
Circle().fill(Tj.Palette.sand2)
|
||||
Image(systemName: t.icon)
|
||||
.font(.tjScaled( 22))
|
||||
.foregroundStyle(Tj.Palette.amber)
|
||||
}
|
||||
.frame(width: 52, height: 52)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(todayLine)
|
||||
.font(.tjScaled( 12))
|
||||
.font(.tjScaled( 11))
|
||||
.tracking(1)
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Text(greetingWord)
|
||||
.font(.tjTitle())
|
||||
// 衬线问候,编辑感更强。
|
||||
Text(t.word)
|
||||
.font(.tjScaled( 28, weight: .semibold, design: .serif))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Text(t.subtitle)
|
||||
.font(.tjScaled( 12))
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
}
|
||||
Spacer()
|
||||
|
||||
Spacer(minLength: 8)
|
||||
|
||||
TjLockChip()
|
||||
.padding(.top, 4)
|
||||
.padding(.top, 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,84 +115,137 @@ struct HomeView: View {
|
||||
return "\(day) · \(weekday)"
|
||||
}
|
||||
|
||||
private var greetingWord: String {
|
||||
switch Calendar.current.component(.hour, from: Date()) {
|
||||
case 5..<12: return String(appLoc: "早安")
|
||||
case 12..<18: return String(appLoc: "下午好")
|
||||
default: return String(appLoc: "晚上好")
|
||||
/// 一天三段:驱动问候语、副标题、徽章图标,保证三者一致。
|
||||
private enum TimeOfDay {
|
||||
case morning, afternoon, evening
|
||||
|
||||
static var current: TimeOfDay {
|
||||
switch Calendar.current.component(.hour, from: Date()) {
|
||||
case 5..<12: return .morning
|
||||
case 12..<18: return .afternoon
|
||||
default: return .evening
|
||||
}
|
||||
}
|
||||
|
||||
var word: String {
|
||||
switch self {
|
||||
case .morning: return String(appLoc: "早安")
|
||||
case .afternoon: return String(appLoc: "下午好")
|
||||
case .evening: return String(appLoc: "晚上好")
|
||||
}
|
||||
}
|
||||
|
||||
var subtitle: String {
|
||||
switch self {
|
||||
case .morning: return String(appLoc: "新的一天,慢慢来")
|
||||
case .afternoon: return String(appLoc: "记得起身活动一下")
|
||||
case .evening: return String(appLoc: "夜深了,记得早点休息")
|
||||
}
|
||||
}
|
||||
|
||||
var icon: String {
|
||||
switch self {
|
||||
case .morning: return "sun.max.fill"
|
||||
case .afternoon: return "sun.haze.fill"
|
||||
case .evening: return "moon.stars.fill"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var recentSection: some View {
|
||||
// 聚合(含血压配对 O(m²))在一次 body 内只算一次,再派生分组,避免 .isEmpty 与分组各算一遍。
|
||||
let entries = recentEntries
|
||||
let groups = TimelineGrouping.group(entries)
|
||||
return VStack(alignment: .leading, spacing: 10) {
|
||||
HStack(alignment: .lastTextBaseline) {
|
||||
Text("最近记录").font(.tjH2()).foregroundStyle(Tj.Palette.text)
|
||||
Spacer()
|
||||
Button(action: onTapArchive) {
|
||||
Text("全部 ›")
|
||||
.font(.tjScaled( 12))
|
||||
// MARK: - 数据概览磁贴(2×2,大数字 + 图标,点进对应分类)
|
||||
|
||||
private var overviewSection: some View {
|
||||
LazyVGrid(columns: [GridItem(.flexible(), spacing: 12),
|
||||
GridItem(.flexible(), spacing: 12)], spacing: 12) {
|
||||
statTile(icon: "doc.fill", value: reports.count,
|
||||
label: String(appLoc: "报告"), tint: Tj.Palette.ink) {
|
||||
onTapArchive(.report)
|
||||
}
|
||||
statTile(icon: "drop.fill", value: indicators.count,
|
||||
label: String(appLoc: "指标"), tint: Tj.Palette.brick) {
|
||||
onTapArchive(.indicator)
|
||||
}
|
||||
statTile(icon: "pencil", value: diaries.count,
|
||||
label: String(appLoc: "日记"), tint: Tj.Palette.leaf) {
|
||||
onTapArchive(.diary)
|
||||
}
|
||||
statTile(icon: "waveform.path.ecg", value: symptoms.count,
|
||||
label: ongoingSymptomCount > 0
|
||||
? String(appLoc: "症状 · \(ongoingSymptomCount) 进行中")
|
||||
: String(appLoc: "症状"),
|
||||
tint: Tj.Palette.amber) {
|
||||
onTapArchive(.symptom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func statTile(icon: String, value: Int, label: String,
|
||||
tint: Color, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
Circle().fill(tint.opacity(0.15))
|
||||
Image(systemName: icon)
|
||||
.font(.tjScaled( 16, weight: .semibold))
|
||||
.foregroundStyle(tint)
|
||||
}
|
||||
.frame(width: 40, height: 40)
|
||||
|
||||
VStack(alignment: .leading, spacing: 1) {
|
||||
Text("\(value)")
|
||||
.font(.tjScaled( 22, weight: .bold, design: .rounded))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Text(label)
|
||||
.font(.tjScaled( 11))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.85)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(12)
|
||||
.frame(maxWidth: .infinity)
|
||||
.tjCard()
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
if entries.isEmpty {
|
||||
emptyRecent
|
||||
} else {
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
ForEach(groups, id: \.section) { group in
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(group.section.label)
|
||||
.font(.tjScaled( 11, weight: .semibold))
|
||||
.tracking(0.5)
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
VStack(spacing: 10) {
|
||||
ForEach(group.items) { entry in
|
||||
Button {
|
||||
// 指标 → 同类聚合详情(历次 + 趋势);其余 → 只读详情。与档案库 C1 一致。
|
||||
guard let d = TimelineDetail.resolve(
|
||||
for: entry,
|
||||
indicators: indicators, reports: reports,
|
||||
diaries: diaries, symptoms: symptoms
|
||||
) else { return }
|
||||
switch d {
|
||||
case .indicator(let i): selectedGroup = IndicatorGroup.of(i)
|
||||
case .bloodPressure(let sys, _): selectedGroup = IndicatorGroup.of(sys)
|
||||
default: selectedEntry = entry
|
||||
}
|
||||
} label: {
|
||||
TimelineRow(entry: entry)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
// MARK: - 健康趋势(迷你折线图,复用趋势页 TrendRow)
|
||||
|
||||
private func trendsSection(_ buckets: [SeriesBucket]) -> some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("健康趋势")
|
||||
.font(.tjH2())
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
|
||||
VStack(spacing: 12) {
|
||||
ForEach(buckets) { bucket in
|
||||
Button {
|
||||
selectedGroup = group(for: bucket)
|
||||
} label: {
|
||||
TrendRow(bucket: bucket)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var emptyRecent: some View {
|
||||
HStack {
|
||||
Text("还没有任何记录,点底部 + 号开始第一条")
|
||||
.font(.tjScaled( 13))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.vertical, 14)
|
||||
.padding(.horizontal, 16)
|
||||
.tjCard(bordered: true)
|
||||
/// SeriesBucket → 聚合详情的 IndicatorGroup(与趋势页分组语义一致)。
|
||||
private func group(for bucket: SeriesBucket) -> IndicatorGroup {
|
||||
if bucket.id == "bp" { return .bloodPressure }
|
||||
if bucket.id.hasPrefix("lab:") { return .lab(key: String(bucket.id.dropFirst(4))) }
|
||||
return .series(key: bucket.id)
|
||||
}
|
||||
|
||||
// MARK: - 影像档案入口
|
||||
|
||||
private var archiveSection: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("影像档案").font(.tjH2()).foregroundStyle(Tj.Palette.text)
|
||||
|
||||
Button(action: onTapArchive) {
|
||||
Button { onTapArchive(.report) } label: {
|
||||
HStack(spacing: 14) {
|
||||
TjPlaceholder(label: String(appLoc: "档案 · \(reports.count)"))
|
||||
.frame(width: 56, height: 56)
|
||||
|
||||
@@ -95,8 +95,7 @@ struct TodayRemindersCard: View {
|
||||
RoundedRectangle(cornerRadius: Tj.Radius.sm, style: .continuous)
|
||||
.fill(Tj.Palette.paper)
|
||||
)
|
||||
.shadow(color: Color(red: 0.196, green: 0.157, blue: 0.098).opacity(0.04),
|
||||
radius: 2, x: 0, y: 1)
|
||||
.shadow(color: Tj.Palette.shadow.opacity(0.05), radius: 2, x: 0, y: 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,18 @@ import SwiftUI
|
||||
/// 切换只改持久化选择;下一次 AI 调用(prepare/generate)按新引擎加载。
|
||||
struct InferenceSettingsView: View {
|
||||
@AppStorage("kk.inferenceEngine") private var engineRaw = EnginePreference.auto.rawValue
|
||||
@State private var modelService = ModelDownloadService.shared
|
||||
|
||||
private var selected: EnginePreference {
|
||||
EnginePreference(rawValue: engineRaw) ?? .auto
|
||||
}
|
||||
|
||||
/// 性能自检需要模型就绪(MNN 主或 MLX 兜底任一)。
|
||||
private var modelReady: Bool {
|
||||
modelService.states[.mnnLLM]?.phase == .ready
|
||||
|| modelService.states[.llm]?.phase == .ready
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: 12) {
|
||||
@@ -26,12 +33,74 @@ struct InferenceSettingsView: View {
|
||||
}
|
||||
|
||||
sme2Card
|
||||
selfTestSection
|
||||
noteCard
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 20)
|
||||
}
|
||||
.background(Tj.Palette.sand.ignoresSafeArea())
|
||||
.onAppear { modelService.refreshStates() }
|
||||
}
|
||||
|
||||
/// 性能自检入口:用当前选中的引擎跑固定 prompt,实测并按后端归档对比。
|
||||
/// 模型未就绪时显示「前往下载」提示而非死链。
|
||||
@ViewBuilder
|
||||
private var selfTestSection: some View {
|
||||
if modelReady {
|
||||
NavigationLink {
|
||||
ModelSelfTestView()
|
||||
} label: {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
Circle().fill(Tj.Palette.sand2)
|
||||
Image(systemName: "gauge.with.needle")
|
||||
.font(.tjScaled(18))
|
||||
.foregroundStyle(Tj.Palette.ink)
|
||||
}
|
||||
.frame(width: 44, height: 44)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("性能自检")
|
||||
.font(.tjScaled(15, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Text("用上方选中的引擎跑固定 prompt,实测 prefill / 生成 tok/s")
|
||||
.font(.tjScaled(12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
.lineLimit(2)
|
||||
}
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.tjScaled(13, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
.padding(14)
|
||||
.tjCard()
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
} else {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
Circle().fill(Tj.Palette.sand2)
|
||||
Image(systemName: "gauge.with.needle")
|
||||
.font(.tjScaled(18))
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
}
|
||||
.frame(width: 44, height: 44)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("性能自检")
|
||||
.font(.tjScaled(15, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Text("模型未就绪,前往「模型管理」下载后可用")
|
||||
.font(.tjScaled(12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
.lineLimit(2)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding(14)
|
||||
.tjCard()
|
||||
.opacity(0.55)
|
||||
}
|
||||
}
|
||||
|
||||
private func engineRow(_ engine: EnginePreference) -> some View {
|
||||
|
||||
@@ -28,19 +28,6 @@ struct ModelManagementView: View {
|
||||
actionButtons
|
||||
.padding(.top, 4)
|
||||
|
||||
if service.states[.mnnLLM]?.phase == .ready || service.states[.llm]?.phase == .ready {
|
||||
NavigationLink {
|
||||
ModelSelfTestView()
|
||||
} label: {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "gauge.with.needle")
|
||||
Text("性能自检")
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.buttonStyle(TjGhostButton())
|
||||
}
|
||||
|
||||
if let importError {
|
||||
Text(importError)
|
||||
.font(.tjScaled( 12))
|
||||
|
||||
@@ -175,6 +175,8 @@ private struct MedicationEditSheet: View {
|
||||
@State private var hydrated = false
|
||||
/// 点缩略图全屏查看的起始页;nil = 未打开查看器。
|
||||
@State private var viewerStart: PhotoIndex?
|
||||
/// 「记录一次服用」:嵌套拉起 MedicationLogSheet,预选当前药。
|
||||
@State private var showLog = false
|
||||
|
||||
private var isEditing: Bool { existing != nil }
|
||||
private var canSave: Bool {
|
||||
@@ -184,6 +186,29 @@ private struct MedicationEditSheet: View {
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
if isEditing {
|
||||
Section {
|
||||
Button { showLog = true } label: {
|
||||
HStack(spacing: 10) {
|
||||
Image(systemName: "pills.circle.fill")
|
||||
.font(.tjScaled( 18))
|
||||
.foregroundStyle(Tj.Palette.ink)
|
||||
Text("记录一次服用")
|
||||
.font(.tjScaled( 15, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.tjScaled( 12, weight: .medium))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
} footer: {
|
||||
Text("记某次吃药的剂量和时间,会进「记录 · 用药」时间线。不提供剂量建议。")
|
||||
}
|
||||
}
|
||||
|
||||
if let m = existing, !m.assets.isEmpty {
|
||||
Section {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
@@ -252,6 +277,9 @@ private struct MedicationEditSheet: View {
|
||||
MedicationPhotoViewer(assets: m.assets, startIndex: start.index)
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showLog) {
|
||||
MedicationLogSheet(preselected: existing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ struct SingleShotCameraView: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("拍一张含目标指标的照片 · 拍完再框选")
|
||||
Text("轻点画面对焦 · 拍完再框选")
|
||||
.font(.tjScaled( 13, weight: .medium))
|
||||
.foregroundStyle(.white)
|
||||
.padding(.horizontal, 12)
|
||||
@@ -187,6 +187,10 @@ final class RegionPreviewUIView: UIView, AVCapturePhotoCaptureDelegate {
|
||||
private var previewLayer: AVCaptureVideoPreviewLayer?
|
||||
private var setupDone = false
|
||||
private var captureCompletion: ((UIImage?) -> Void)?
|
||||
/// 持有当前输入设备,供点击对焦时重新 lockForConfiguration。
|
||||
private var device: AVCaptureDevice?
|
||||
/// 点击对焦时短暂显示的黄框;弱引用,移除后自动置空。
|
||||
private weak var focusIndicator: UIView?
|
||||
|
||||
override func didMoveToWindow() {
|
||||
super.didMoveToWindow()
|
||||
@@ -205,6 +209,20 @@ final class RegionPreviewUIView: UIView, AVCapturePhotoCaptureDelegate {
|
||||
return
|
||||
}
|
||||
session.addInput(input)
|
||||
self.device = device
|
||||
|
||||
// 近距对焦:贴着拍化验单/小标签时持续自动对焦,并把搜索范围偏向近处,
|
||||
// 避免反复拉风箱。所有机型生效;不支持的项静默跳过。
|
||||
if (try? device.lockForConfiguration()) != nil {
|
||||
if device.isFocusModeSupported(.continuousAutoFocus) {
|
||||
device.focusMode = .continuousAutoFocus
|
||||
}
|
||||
if device.isAutoFocusRangeRestrictionSupported {
|
||||
device.autoFocusRangeRestriction = .near
|
||||
}
|
||||
device.unlockForConfiguration()
|
||||
}
|
||||
|
||||
if session.canAddOutput(output) { session.addOutput(output) }
|
||||
session.commitConfiguration()
|
||||
|
||||
@@ -215,6 +233,10 @@ final class RegionPreviewUIView: UIView, AVCapturePhotoCaptureDelegate {
|
||||
self.previewLayer = preview
|
||||
applyPortrait(preview.connection)
|
||||
|
||||
// 点击对焦:贴着拍小标签时连续自动对焦偶尔锁不准,允许用户点屏指定对焦点。
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(handleFocusTap(_:)))
|
||||
addGestureRecognizer(tap)
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
|
||||
self?.session.startRunning()
|
||||
}
|
||||
@@ -233,6 +255,61 @@ final class RegionPreviewUIView: UIView, AVCapturePhotoCaptureDelegate {
|
||||
previewLayer?.frame = bounds
|
||||
}
|
||||
|
||||
// MARK: - 点击对焦
|
||||
|
||||
@objc private func handleFocusTap(_ gr: UITapGestureRecognizer) {
|
||||
guard let previewLayer, device != nil else { return }
|
||||
let point = gr.location(in: self)
|
||||
// 屏幕点 → 设备归一化对焦坐标(随 videoGravity/旋转正确换算)。
|
||||
let devicePoint = previewLayer.captureDevicePointConverted(fromLayerPoint: point)
|
||||
focus(at: devicePoint)
|
||||
showFocusIndicator(at: point)
|
||||
}
|
||||
|
||||
/// 把对焦/测光点锁到指定设备坐标,单次自动对焦;不支持的项静默跳过。
|
||||
private func focus(at devicePoint: CGPoint) {
|
||||
guard let device, (try? device.lockForConfiguration()) != nil else { return }
|
||||
if device.isFocusPointOfInterestSupported {
|
||||
device.focusPointOfInterest = devicePoint
|
||||
}
|
||||
if device.isFocusModeSupported(.autoFocus) {
|
||||
device.focusMode = .autoFocus // 单次对焦,锁到该点
|
||||
}
|
||||
if device.isExposurePointOfInterestSupported {
|
||||
device.exposurePointOfInterest = devicePoint
|
||||
}
|
||||
if device.isExposureModeSupported(.autoExpose) {
|
||||
device.exposureMode = .autoExpose
|
||||
}
|
||||
device.unlockForConfiguration()
|
||||
}
|
||||
|
||||
/// 在点击位置短暂显示一个黄色对焦框作为反馈。
|
||||
private func showFocusIndicator(at point: CGPoint) {
|
||||
focusIndicator?.removeFromSuperview()
|
||||
let box = UIView(frame: CGRect(x: 0, y: 0, width: 76, height: 76))
|
||||
box.center = point
|
||||
box.backgroundColor = .clear
|
||||
box.layer.borderColor = UIColor.systemYellow.cgColor
|
||||
box.layer.borderWidth = 1.5
|
||||
box.layer.cornerRadius = 6
|
||||
box.isUserInteractionEnabled = false
|
||||
box.alpha = 0
|
||||
box.transform = CGAffineTransform(scaleX: 1.35, y: 1.35)
|
||||
addSubview(box)
|
||||
focusIndicator = box
|
||||
UIView.animate(withDuration: 0.2, animations: {
|
||||
box.alpha = 1
|
||||
box.transform = .identity
|
||||
}, completion: { _ in
|
||||
UIView.animate(withDuration: 0.3, delay: 0.7, options: []) {
|
||||
box.alpha = 0
|
||||
} completion: { _ in
|
||||
box.removeFromSuperview()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func capture(completion: @escaping (UIImage?) -> Void) {
|
||||
guard session.isRunning else { completion(nil); return }
|
||||
captureCompletion = completion
|
||||
|
||||
@@ -250,9 +250,15 @@ struct VoiceCommandSheet: View {
|
||||
private func finishRecording() {
|
||||
guard phase == .recording else { return }
|
||||
ticker?.cancel()
|
||||
// 已经在屏幕上的实时字幕:stop() 偶发因最终结果竞争/取消返回空,
|
||||
// 这时别把用户已经看到的内容丢掉,回退到实时字幕。
|
||||
let live = transcript
|
||||
phase = .classifying
|
||||
Task {
|
||||
let text = await dictation.stop()
|
||||
let finalText = await dictation.stop()
|
||||
let text = finalText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||
? live
|
||||
: finalText
|
||||
transcript = text
|
||||
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else {
|
||||
|
||||
@@ -93,8 +93,7 @@ struct OngoingSymptomsCard: View {
|
||||
)
|
||||
}
|
||||
)
|
||||
.shadow(color: Color(red: 0.196, green: 0.157, blue: 0.098).opacity(0.04),
|
||||
radius: 2, x: 0, y: 1)
|
||||
.shadow(color: Tj.Palette.shadow.opacity(0.05), radius: 2, x: 0, y: 1)
|
||||
}
|
||||
|
||||
private func severityDot(_ value: Int) -> some View {
|
||||
|
||||
@@ -133,7 +133,7 @@ extension SeriesBucket {
|
||||
id: "lab:\(latest.name)",
|
||||
seriesKey: "lab:\(latest.name)",
|
||||
label: nil,
|
||||
color: Tj.Palette.ink,
|
||||
color: Tj.Palette.teal,
|
||||
points: points,
|
||||
referenceRange: parseRange(latest.range)
|
||||
)
|
||||
@@ -172,7 +172,7 @@ extension SeriesBucket {
|
||||
id: key,
|
||||
seriesKey: key,
|
||||
label: nil,
|
||||
color: Tj.Palette.ink,
|
||||
color: Tj.Palette.teal,
|
||||
points: sorted.compactMap { point(from: $0) },
|
||||
referenceRange: range
|
||||
)
|
||||
@@ -200,7 +200,7 @@ extension SeriesBucket {
|
||||
id: "bp.systolic",
|
||||
seriesKey: "bp.systolic",
|
||||
label: String(appLoc: "收缩"),
|
||||
color: Tj.Palette.brick,
|
||||
color: Tj.Palette.teal,
|
||||
points: sysItems.compactMap { point(from: $0) },
|
||||
referenceRange: m.effectiveRange(for: sysField, profile: profile)
|
||||
)
|
||||
|
||||
@@ -111,6 +111,24 @@ struct SeriesChartCard: View {
|
||||
}
|
||||
}
|
||||
|
||||
// 单条线时,线下垫一层渐变面积,增加体量、柔化观感
|
||||
//(多条线如血压不加,避免两片面积互相盖住)。
|
||||
if bucket.lines.count == 1, let line = bucket.lines.first {
|
||||
ForEach(line.points) { p in
|
||||
// 显式把基线钉在值域下界:单值 AreaMark 的隐式基线(0/域外)会把渐变
|
||||
// 拉到可视区外、几乎不淡出,看着像一块实色底色一路铺到图表底。
|
||||
AreaMark(
|
||||
x: .value("时间", p.date),
|
||||
yStart: .value("基线", (valueDomain ?? 0...1).lowerBound),
|
||||
yEnd: .value(line.label ?? bucket.title, p.value)
|
||||
)
|
||||
.foregroundStyle(LinearGradient(
|
||||
colors: [line.color.opacity(0.16), line.color.opacity(0)],
|
||||
startPoint: .top, endPoint: .bottom))
|
||||
.interpolationMethod(.monotone)
|
||||
}
|
||||
}
|
||||
|
||||
// 折线 + 点
|
||||
ForEach(bucket.lines) { line in
|
||||
ForEach(line.points) { p in
|
||||
@@ -119,8 +137,10 @@ struct SeriesChartCard: View {
|
||||
y: .value(line.label ?? bucket.title, p.value)
|
||||
)
|
||||
.foregroundStyle(line.color)
|
||||
.interpolationMethod(.catmullRom)
|
||||
.lineStyle(StrokeStyle(lineWidth: 2))
|
||||
// monotone:平滑但不在数据尖峰处过冲鼓包,比 catmullRom 更贴合真实读数。
|
||||
.interpolationMethod(.monotone)
|
||||
// 圆角端点 + 连接,去掉折线的生硬尖角。
|
||||
.lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
|
||||
}
|
||||
.symbol {
|
||||
Circle()
|
||||
|
||||
@@ -179,6 +179,23 @@ struct TrendDetailView: View {
|
||||
.foregroundStyle(line.color.opacity(0.08))
|
||||
}
|
||||
}
|
||||
// 单条线时,线下垫一层渐变面积,增加体量、柔化观感
|
||||
//(多条线如血压不加,避免两片面积互相盖住)。
|
||||
if filteredLines.count == 1, let line = filteredLines.first {
|
||||
ForEach(line.points) { p in
|
||||
// 显式把基线钉在值域下界:用单值 AreaMark 会以隐式基线(0/域外)兜底,
|
||||
// 渐变被拉到可视区外几乎不淡出,看着像一块实色底色一路铺到图表底。
|
||||
AreaMark(
|
||||
x: .value("时间", p.date),
|
||||
yStart: .value("基线", (valueDomain ?? 0...1).lowerBound),
|
||||
yEnd: .value(line.label ?? bucket.title, p.value)
|
||||
)
|
||||
.foregroundStyle(LinearGradient(
|
||||
colors: [line.color.opacity(0.16), line.color.opacity(0)],
|
||||
startPoint: .top, endPoint: .bottom))
|
||||
.interpolationMethod(.monotone)
|
||||
}
|
||||
}
|
||||
ForEach(filteredLines) { line in
|
||||
ForEach(line.points) { p in
|
||||
LineMark(
|
||||
@@ -187,8 +204,10 @@ struct TrendDetailView: View {
|
||||
series: .value("series", line.id)
|
||||
)
|
||||
.foregroundStyle(line.color)
|
||||
.interpolationMethod(.catmullRom)
|
||||
.lineStyle(StrokeStyle(lineWidth: 2))
|
||||
// monotone:平滑但不在尖峰处过冲鼓包,更贴合真实读数。
|
||||
.interpolationMethod(.monotone)
|
||||
// 圆角端点 + 连接,去掉折线的生硬尖角。
|
||||
.lineStyle(StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
|
||||
PointMark(
|
||||
x: .value("时间", p.date),
|
||||
y: .value(line.label ?? bucket.title, p.value)
|
||||
@@ -421,6 +440,24 @@ private struct TrendInsightCard: View {
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text2)
|
||||
Spacer()
|
||||
// 手动重新解读:任何时候都能点(解读中除外)。解决偶发不自动触发,
|
||||
// 也允许已生成后再跑一次拿最新解读。
|
||||
if !running {
|
||||
Button { Task { await load(force: true) } } label: {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
.font(.tjScaled( 11, weight: .semibold))
|
||||
Text(text == nil ? String(appLoc: "解读") : String(appLoc: "重新解读"))
|
||||
.font(.tjScaled( 12, weight: .semibold))
|
||||
}
|
||||
.foregroundStyle(Tj.Palette.ink)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 5)
|
||||
.background(Capsule().fill(Tj.Palette.sand2))
|
||||
.contentShape(Capsule())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
if let text {
|
||||
Text(text)
|
||||
@@ -435,15 +472,14 @@ private struct TrendInsightCard: View {
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
AIFlowBar()
|
||||
} else if let failedMessage {
|
||||
HStack {
|
||||
Text(failedMessage)
|
||||
.font(.tjScaled( 12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Spacer()
|
||||
Button("重试") { Task { await load(force: true) } }
|
||||
.font(.tjScaled( 12, weight: .medium))
|
||||
.foregroundStyle(Tj.Palette.ink)
|
||||
}
|
||||
Text(failedMessage)
|
||||
.font(.tjScaled( 12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
} else {
|
||||
// 空闲态(偶发没自动触发):给明确引导,点右上即可生成。
|
||||
Text("点右上「解读」生成本地趋势解读")
|
||||
.font(.tjScaled( 12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
}
|
||||
.padding(14)
|
||||
|
||||
@@ -54,6 +54,19 @@ struct TrendRow: View {
|
||||
|
||||
private var sparkline: some View {
|
||||
Chart {
|
||||
// 单条线时,线下垫一层渐变面积,迷你图也更有体量、不发生硬。
|
||||
if bucket.lines.count == 1, let line = bucket.lines.first {
|
||||
ForEach(line.points) { p in
|
||||
AreaMark(
|
||||
x: .value("t", p.date),
|
||||
y: .value(line.label ?? bucket.title, p.value)
|
||||
)
|
||||
.foregroundStyle(LinearGradient(
|
||||
colors: [line.color.opacity(0.18), line.color.opacity(0)],
|
||||
startPoint: .top, endPoint: .bottom))
|
||||
.interpolationMethod(.monotone)
|
||||
}
|
||||
}
|
||||
ForEach(bucket.lines) { line in
|
||||
ForEach(line.points) { p in
|
||||
LineMark(
|
||||
@@ -62,8 +75,9 @@ struct TrendRow: View {
|
||||
series: .value("s", line.id)
|
||||
)
|
||||
.foregroundStyle(line.color)
|
||||
.interpolationMethod(.catmullRom)
|
||||
.lineStyle(StrokeStyle(lineWidth: 1.6))
|
||||
// monotone + 圆角端点:迷你曲线更柔,无尖角无过冲。
|
||||
.interpolationMethod(.monotone)
|
||||
.lineStyle(StrokeStyle(lineWidth: 1.6, lineCap: .round, lineJoin: .round))
|
||||
}
|
||||
}
|
||||
// 最新点高亮
|
||||
|
||||
Reference in New Issue
Block a user