feat(AI): 统一多模态模型架构,整合文本和视觉推理路径 - 将文本生成和VL(图→文)功能合并到单一的Qwen3.5-4B多模态MNN模型 - 移除独立的Qwen3-VL-4B模型依赖,MLX VL改为使用.llm的多模态模型 - 更新ModelKind枚举,新增userFacing集合用于面向用户展示 - MNN后端现在同时支持文本和视觉任务,模拟器回退到MLX refactor(models): 模型管理和界面调整以适应新的多模态架构 - 更新模型管理界面,只显示统一的Qwen3.5-4B(MNN)模型给用户 - 修改就绪状态检查逻辑,使用ModelKind.userFacing替代allCases - 更新模型文件清单,从Qwen3.5-2B升级到Qwen3.5-4B-4bit - 调整模型管理页面UI,突出MNN+SME2端侧加速功能 feat(camera): 添加拍照识别引擎切换功能 - 实现双路径拍照识别:Apple Vision OCR + 文本模型 和 Qwen3-VL直接识别 - 添加预处理逻辑,优化Qwen3-VL对窄长区域图片的识别效果 - 在模型管理页面添加拍照识别引擎选择组件 - 提供用户界面选项,在两种识别方式间切换 style(ui): 优化输入框样式和颜色主题一致性 - 为指标快速表单添加浅色主题偏好 - 统一所有文本输入框的颜色样式(theme) - 创建EntryInputField组件,替换原有的单行输入+按钮模式 - 实现聊天框风格的条目输入,支持多行自适应和圆形发送按钮 fix(build): 修正Xcode项目配置中的重复框架搜索路径 - 清理project.pbxproj中重复的FRAMEWORK_SEARCH_PATHS配置 - 重新排列Swift桥接头文件配置确保正确引用 - 修复因路径配置重复导致的编译警告问题 test: 增加区域图片预处理和模型清单测试覆盖 - 添加RegionImageCropper.prepareForQwenVL的单元测试 - 验证宽而矮图片的放大和填充逻辑 - 更新ModelManifestTests中的字节数预期值以匹配新模型 - 修正OCRService中VNRecognizedTextObservation类型的处理 ```
288 lines
10 KiB
Swift
288 lines
10 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct MeView: View {
|
|
@Environment(\.modelContext) private var ctx
|
|
@Query private var profiles: [UserProfile]
|
|
@Query private var customMetrics: [CustomMonitorMetric]
|
|
|
|
@State private var downloadService = ModelDownloadService.shared
|
|
@State private var appLock = AppLock.shared
|
|
@State private var lang = LanguageManager.shared
|
|
@State private var fontScale = FontScaleManager.shared
|
|
// key 必须与 AppLock.enabledKey 一致。
|
|
@AppStorage("faceIDLockEnabled") private var lockEnabled = false
|
|
|
|
private var profile: UserProfile? { profiles.first }
|
|
|
|
/// 真实读取 Bundle 版本号,与「关于」页保持一致。
|
|
private var appVersionText: String {
|
|
let short = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.1"
|
|
return "v\(short)"
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
ScrollView {
|
|
VStack(spacing: 12) {
|
|
HStack {
|
|
Text("我的")
|
|
.font(.tjTitle())
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Spacer()
|
|
}
|
|
.padding(.top, 4)
|
|
.padding(.bottom, 6)
|
|
|
|
profileCard
|
|
customMetricsCard
|
|
modelManagementCard
|
|
inferenceEngineCard
|
|
languageCard
|
|
fontScaleCard
|
|
faceIDCard
|
|
NavigationLink {
|
|
AboutView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "关于"),
|
|
detail: appVersionText,
|
|
icon: "info.circle")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 20)
|
|
}
|
|
.background(Tj.Palette.sand.ignoresSafeArea())
|
|
// 标题改用内容文字渲染(与 主页/记录/趋势 一致),不走 .navigationTitle:
|
|
// 大标题导航栏在真机状态栏区域会露出系统白底,破坏全 App 的沙色背景。
|
|
.onAppear {
|
|
if profiles.isEmpty {
|
|
_ = UserProfileStore.loadOrCreate(in: ctx)
|
|
}
|
|
downloadService.refreshStates()
|
|
appLock.refreshAvailability()
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Cards
|
|
|
|
private var profileCard: some View {
|
|
NavigationLink {
|
|
ProfileEditView()
|
|
} label: {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle()
|
|
.fill(Tj.Palette.amber.opacity(0.25))
|
|
Image(systemName: "person.crop.circle.fill")
|
|
.font(.tjScaled( 22))
|
|
.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(profileLine)
|
|
.font(.tjScaled( 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
.lineLimit(1)
|
|
}
|
|
Spacer()
|
|
Image(systemName: "chevron.right")
|
|
.font(.tjScaled( 13, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
.padding(14)
|
|
.tjCard()
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private var customMetricsCard: some View {
|
|
NavigationLink {
|
|
CustomMetricsListView()
|
|
} label: {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle()
|
|
.fill(customMetrics.isEmpty ? Tj.Palette.sand2 : Tj.Palette.leafSoft)
|
|
Image(systemName: "slider.horizontal.3")
|
|
.font(.tjScaled( 18))
|
|
.foregroundStyle(customMetrics.isEmpty ? Tj.Palette.text2 : Tj.Palette.ink)
|
|
}
|
|
.frame(width: 44, height: 44)
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("自定义指标")
|
|
.font(.tjScaled( 15, weight: .semibold))
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Text(customMetricsLine)
|
|
.font(.tjScaled( 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
.lineLimit(1)
|
|
}
|
|
Spacer()
|
|
Image(systemName: "chevron.right")
|
|
.font(.tjScaled( 13, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
.padding(14)
|
|
.tjCard()
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private var customMetricsLine: String {
|
|
if customMetrics.isEmpty { return String(appLoc: "添加你自己的长期监测项") }
|
|
return String(appLoc: "\(customMetrics.count) 项")
|
|
}
|
|
|
|
private var modelManagementCard: some View {
|
|
NavigationLink {
|
|
ModelManagementView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "模型管理"), detail: modelDetail, icon: "cpu")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private var modelDetail: String {
|
|
let states = downloadService.states
|
|
if ModelKind.userFacing.allSatisfy({ states[$0]?.phase == .ready }) { return String(appLoc: "已就绪") }
|
|
if downloadService.isAnyDownloading { return String(appLoc: "下载中…") }
|
|
let readyCount = ModelKind.userFacing.filter { states[$0]?.phase == .ready }.count
|
|
return readyCount == 0 ? String(appLoc: "未下载") : String(appLoc: "\(readyCount)/\(ModelKind.userFacing.count) 就绪")
|
|
}
|
|
|
|
private var inferenceEngineCard: some View {
|
|
NavigationLink {
|
|
InferenceSettingsView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "推理引擎"), detail: engineDetail, icon: "cpu.fill")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private var engineDetail: String {
|
|
switch InferenceEngine.current {
|
|
case .mnn: return InferenceEngine.cpuSupportsSME2 ? "MNN · SME2" : "MNN · CPU"
|
|
case .mlx: return "MLX · GPU"
|
|
}
|
|
}
|
|
|
|
private var languageCard: some View {
|
|
NavigationLink {
|
|
LanguageSettingsView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "语言"),
|
|
detail: lang.current.displayName,
|
|
icon: "character.bubble")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private var fontScaleCard: some View {
|
|
NavigationLink {
|
|
FontSettingsView()
|
|
} label: {
|
|
settingsCard(title: String(appLoc: "字体大小"),
|
|
detail: fontScale.scale.label,
|
|
icon: "textformat.size")
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
// MARK: - Face ID 启动锁(可交互 Toggle 卡)
|
|
|
|
private var faceIDCard: some View {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle().fill(lockEnabled ? Tj.Palette.amber.opacity(0.25) : Tj.Palette.sand2)
|
|
Image(systemName: "faceid")
|
|
.font(.tjScaled( 18))
|
|
.foregroundStyle(lockEnabled ? Tj.Palette.ink : Tj.Palette.text2)
|
|
}
|
|
.frame(width: 44, height: 44)
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text("Face ID 启动锁")
|
|
.font(.tjScaled( 15, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Text(faceIDLine)
|
|
.font(.tjScaled( 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
Spacer()
|
|
Toggle("", isOn: faceIDBinding)
|
|
.labelsHidden()
|
|
.disabled(!appLock.biometryAvailable)
|
|
}
|
|
.padding(14)
|
|
.tjCard()
|
|
}
|
|
|
|
private var faceIDLine: String {
|
|
if !appLock.biometryAvailable { return String(appLoc: "本设备未设置 Face ID 或密码") }
|
|
return lockEnabled ? String(appLoc: "已开启 · \(appLock.biometryLabel)") : String(appLoc: "关闭")
|
|
}
|
|
|
|
/// 打开 → 先认证一次,成功才置 enabled(失败则开关弹回);关闭 → 直接关。
|
|
private var faceIDBinding: Binding<Bool> {
|
|
Binding(
|
|
get: { lockEnabled },
|
|
set: { newValue in
|
|
if newValue {
|
|
Task { await appLock.enableWithAuth() }
|
|
} else {
|
|
appLock.disable()
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
private func settingsCard(title: String, detail: String, icon: String) -> some View {
|
|
HStack(spacing: 12) {
|
|
ZStack {
|
|
Circle().fill(Tj.Palette.sand2)
|
|
Image(systemName: icon)
|
|
.font(.tjScaled( 18))
|
|
.foregroundStyle(Tj.Palette.text2)
|
|
}
|
|
.frame(width: 44, height: 44)
|
|
|
|
Text(title)
|
|
.font(.tjScaled( 15, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text)
|
|
Spacer()
|
|
Text(detail)
|
|
.font(.tjScaled( 12))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
Image(systemName: "chevron.right")
|
|
.font(.tjScaled( 13, weight: .medium))
|
|
.foregroundStyle(Tj.Palette.text3)
|
|
}
|
|
.padding(14)
|
|
.tjCard()
|
|
}
|
|
|
|
private var profileLine: String {
|
|
guard let p = profile, p.hasAnyBasics else {
|
|
return String(appLoc: "点这里完善你的资料")
|
|
}
|
|
return p.summaryLine
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
MeView()
|
|
.modelContainer(for: [
|
|
UserProfile.self, Indicator.self, Report.self, DiaryEntry.self,
|
|
Asset.self, ChatTurn.self, Symptom.self, MetricReminder.self,
|
|
CustomMonitorMetric.self,
|
|
], inMemory: true)
|
|
}
|