feat: 重做智能录入并支持位置留空
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
7efb80022a
commit
bf17c02d00
|
|
@ -117,7 +117,7 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 13;
|
CURRENT_PROJECT_VERSION = 14;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com";
|
ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com";
|
||||||
|
|
@ -138,7 +138,7 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 13;
|
CURRENT_PROJECT_VERSION = 14;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com";
|
ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com";
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ struct ItemEditor: View {
|
||||||
private enum Field { case name, aliases, price, notes }
|
private enum Field { case name, aliases, price, notes }
|
||||||
|
|
||||||
private var canSave: Bool {
|
private var canSave: Bool {
|
||||||
!name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && locationID != nil && validPrice &&
|
!name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && validPrice &&
|
||||||
!busy && !loadingPhoto
|
!busy && !loadingPhoto
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,8 +67,8 @@ struct ItemEditor: View {
|
||||||
}
|
}
|
||||||
.disabled(busy || savedItem != nil)
|
.disabled(busy || savedItem != nil)
|
||||||
if existing == nil {
|
if existing == nil {
|
||||||
Section("放在哪") {
|
Section("存放位置(可选)") {
|
||||||
LocationPicker(store: store, selection: $locationID)
|
LocationPicker(store: store, selection: $locationID, allowsClearing: true)
|
||||||
if !loadingLocations && store.locations.isEmpty {
|
if !loadingLocations && store.locations.isEmpty {
|
||||||
Button("新建位置") { focus = nil; showingAddLocation = true }
|
Button("新建位置") { focus = nil; showingAddLocation = true }
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +164,7 @@ struct ItemEditor: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func save() async {
|
private func save() async {
|
||||||
guard canSave, let locationID else { return }
|
guard canSave else { return }
|
||||||
busy = true
|
busy = true
|
||||||
error = nil
|
error = nil
|
||||||
defer { busy = false }
|
defer { busy = false }
|
||||||
|
|
@ -195,18 +195,24 @@ struct MoveEditor: View {
|
||||||
@State private var error: String?
|
@State private var error: String?
|
||||||
@State private var busy = false
|
@State private var busy = false
|
||||||
|
|
||||||
|
init(store: InventoryStore, item: Item) {
|
||||||
|
self.store = store
|
||||||
|
self.item = item
|
||||||
|
_locationID = State(initialValue: item.locationId)
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
Form {
|
Form {
|
||||||
Section("原位置") { Text(item.locationPath) }
|
Section("原位置") { Text(item.locationLabel) }
|
||||||
Section("新位置") { LocationPicker(store: store, selection: $locationID) }
|
Section("新位置") { LocationPicker(store: store, selection: $locationID, allowsClearing: true) }
|
||||||
if let error { Text(error).foregroundStyle(.red) }
|
if let error { Text(error).foregroundStyle(.red) }
|
||||||
}
|
}
|
||||||
.navigationTitle("移位")
|
.navigationTitle("移位")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .cancellationAction) { Button("取消") { dismiss() }.disabled(busy) }
|
ToolbarItem(placement: .cancellationAction) { Button("取消") { dismiss() }.disabled(busy) }
|
||||||
ToolbarItem(placement: .confirmationAction) {
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
Button("确认移位") { Task { await save() } }.disabled(locationID == nil || locationID == item.locationId || busy)
|
Button("确认移位") { Task { await save() } }.disabled(locationID == item.locationId || busy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -218,8 +224,19 @@ struct MoveEditor: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func save() async {
|
private func save() async {
|
||||||
guard let locationID else { return }
|
guard locationID != item.locationId, !busy else { return }
|
||||||
struct Move: Encodable { let locationId: UUID; let version: Int }
|
struct Move: Encodable {
|
||||||
|
let locationId: UUID?
|
||||||
|
let version: Int
|
||||||
|
|
||||||
|
enum CodingKeys: CodingKey { case locationId, version }
|
||||||
|
|
||||||
|
func encode(to encoder: Encoder) throws {
|
||||||
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(locationId, forKey: .locationId)
|
||||||
|
try container.encode(version, forKey: .version)
|
||||||
|
}
|
||||||
|
}
|
||||||
busy = true
|
busy = true
|
||||||
defer { busy = false }
|
defer { busy = false }
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct HoldRecordingControl: UIViewRepresentable {
|
||||||
|
let label: String
|
||||||
|
let enabled: Bool
|
||||||
|
let onPress: () -> Void
|
||||||
|
let onRelease: () -> Void
|
||||||
|
let onAccessibilityActivate: () -> Void
|
||||||
|
|
||||||
|
func makeUIView(context: Context) -> Control { Control() }
|
||||||
|
|
||||||
|
func updateUIView(_ view: Control, context: Context) {
|
||||||
|
view.accessibilityLabel = label
|
||||||
|
view.accessibilityHint = "使用旁白时,轻点两下开始,再轻点两下结束。"
|
||||||
|
view.isEnabled = enabled
|
||||||
|
view.onPress = onPress
|
||||||
|
view.onRelease = onRelease
|
||||||
|
view.onAccessibilityActivate = onAccessibilityActivate
|
||||||
|
}
|
||||||
|
|
||||||
|
final class Control: UIControl {
|
||||||
|
var onPress: (() -> Void)?
|
||||||
|
var onRelease: (() -> Void)?
|
||||||
|
var onAccessibilityActivate: (() -> Void)?
|
||||||
|
|
||||||
|
init() {
|
||||||
|
super.init(frame: .zero)
|
||||||
|
isAccessibilityElement = true
|
||||||
|
accessibilityTraits = .button
|
||||||
|
isMultipleTouchEnabled = false
|
||||||
|
addTarget(self, action: #selector(pressed), for: .touchDown)
|
||||||
|
addTarget(self, action: #selector(released), for: [.touchUpInside, .touchUpOutside, .touchCancel])
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) { nil }
|
||||||
|
|
||||||
|
@objc private func pressed() { if isEnabled { onPress?() } }
|
||||||
|
@objc private func released() { onRelease?() }
|
||||||
|
|
||||||
|
override func accessibilityActivate() -> Bool {
|
||||||
|
guard isEnabled, let onAccessibilityActivate else { return false }
|
||||||
|
onAccessibilityActivate()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum IntakeLocationMatcher {
|
||||||
|
static func match(_ hint: String?, locations: [Place], defaultID: UUID?) -> UUID? {
|
||||||
|
let current = locations.first { $0.id == defaultID }
|
||||||
|
guard let hint, !hint.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return current?.id }
|
||||||
|
let literal = key(hint)
|
||||||
|
guard !literal.isEmpty else { return nil }
|
||||||
|
let withoutPrefix = stripPrefix(literal)
|
||||||
|
let terms = [literal, withoutPrefix, stripSuffix(withoutPrefix)].filter { !$0.isEmpty }
|
||||||
|
|
||||||
|
for term in terms {
|
||||||
|
let paths = locations.filter { key($0.path) == term }
|
||||||
|
if !paths.isEmpty { return unique(paths, within: current) }
|
||||||
|
}
|
||||||
|
for term in terms {
|
||||||
|
let names = locations.filter { key($0.name) == term }
|
||||||
|
if !names.isEmpty { return unique(names, within: current) }
|
||||||
|
}
|
||||||
|
for term in terms {
|
||||||
|
let trailingPaths = locations.filter { place in
|
||||||
|
let components = place.path.components(separatedBy: " / ")
|
||||||
|
return components.indices.dropFirst().contains { key(components[$0...].joined()) == term }
|
||||||
|
}
|
||||||
|
if !trailingPaths.isEmpty { return unique(trailingPaths, within: current) }
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func unique(_ matching: [Place], within current: Place?) -> UUID? {
|
||||||
|
if matching.count == 1 { return matching.first?.id }
|
||||||
|
guard let current else { return nil }
|
||||||
|
let local = matching.filter { $0.id == current.id || $0.path.hasPrefix(current.path + " / ") }
|
||||||
|
return local.count == 1 ? local.first?.id : nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func key(_ value: String) -> String {
|
||||||
|
value.folding(options: [.caseInsensitive, .widthInsensitive], locale: Locale(identifier: "zh-CN"))
|
||||||
|
.filter { !$0.isWhitespace && !$0.isPunctuation }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func stripPrefix(_ value: String) -> String {
|
||||||
|
guard let prefix = ["放在", "放到", "收进", "在", "到"].first(where: { value.hasPrefix($0) }) else { return value }
|
||||||
|
return String(value.dropFirst(prefix.count))
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func stripSuffix(_ value: String) -> String {
|
||||||
|
guard let suffix = ["里面了", "里边了", "里了", "内了", "里面", "里边", "里", "内", "了"]
|
||||||
|
.first(where: { value.hasSuffix($0) }) else { return value }
|
||||||
|
return String(value.dropLast(suffix.count))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ struct IntakeView: View {
|
||||||
let store: InventoryStore
|
let store: InventoryStore
|
||||||
var initialLocation: Place? = nil
|
var initialLocation: Place? = nil
|
||||||
@Environment(\.scenePhase) private var scenePhase
|
@Environment(\.scenePhase) private var scenePhase
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
@AppStorage("atlas.voice.recording-mode") private var recordingMode: RecordingMode = .tap
|
@AppStorage("atlas.voice.recording-mode") private var recordingMode: RecordingMode = .tap
|
||||||
@GestureState private var holdingMicrophone = false
|
|
||||||
@FocusState private var typing: Bool
|
@FocusState private var typing: Bool
|
||||||
@State private var voice = VoiceCapture()
|
@State private var voice = VoiceCapture()
|
||||||
@State private var text = ""
|
@State private var text = ""
|
||||||
|
|
@ -43,221 +43,279 @@ struct IntakeView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if store.canWrite {
|
ScrollViewReader { scroll in
|
||||||
Form {
|
ScrollView {
|
||||||
if let initialLocation {
|
VStack(alignment: .leading, spacing: 14) {
|
||||||
Section {
|
if let initialLocation {
|
||||||
Label(initialLocation.path, systemImage: "location")
|
Label(initialLocation.path, systemImage: "mappin")
|
||||||
.font(.subheadline)
|
.font(.subheadline).foregroundStyle(.secondary)
|
||||||
.foregroundStyle(.secondary)
|
.accessibilityLabel("默认位置," + initialLocation.path)
|
||||||
.accessibilityLabel("录入位置," + initialLocation.path)
|
|
||||||
}
|
}
|
||||||
|
smartCard
|
||||||
|
manualEntry
|
||||||
|
if voice.phase == .idle && operation == nil {
|
||||||
|
inputCard
|
||||||
|
if let draft { reviewCard(draft).id(draft.id) }
|
||||||
|
}
|
||||||
|
if let operation { operationCard(operation) }
|
||||||
|
if let error { Text(error).font(.callout).foregroundStyle(.red) }
|
||||||
}
|
}
|
||||||
Section {
|
.frame(maxWidth: 560)
|
||||||
Button { showingAdd = true } label: { Label("手动添加物品", systemImage: "plus") }
|
.padding(16)
|
||||||
.disabled(voice.phase != .idle)
|
.frame(maxWidth: .infinity)
|
||||||
}
|
|
||||||
Section("录音录入") {
|
|
||||||
voiceButton
|
|
||||||
if voice.phase == .recording || voice.phase == .finishing {
|
|
||||||
recordingProgress
|
|
||||||
}
|
|
||||||
if !voice.transcript.isEmpty {
|
|
||||||
Text(voice.transcript).foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
if let error = voice.error { Text(error).font(.footnote).foregroundStyle(.secondary) }
|
|
||||||
DisclosureGroup("录音设置") {
|
|
||||||
Picker("录音方式", selection: $recordingMode) {
|
|
||||||
Text("点按开始,再点结束").tag(RecordingMode.tap)
|
|
||||||
Text("按住录音,松手结束").tag(RecordingMode.hold)
|
|
||||||
}.disabled(voice.phase != .idle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if voice.phase == .idle {
|
|
||||||
Section("录入文字") {
|
|
||||||
TextEditor(text: $text)
|
|
||||||
.frame(minHeight: 88)
|
|
||||||
.focused($typing)
|
|
||||||
.accessibilityLabel("录入文字")
|
|
||||||
.disabled(busy || operation != nil)
|
|
||||||
.overlay(alignment: .topLeading) {
|
|
||||||
if text.isEmpty {
|
|
||||||
Text("录音转写会显示在这里,也可以直接输入。")
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
.padding(.horizontal, 5)
|
|
||||||
.padding(.vertical, 8)
|
|
||||||
.allowsHitTesting(false)
|
|
||||||
.accessibilityHidden(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if text.utf16.count > 4000 {
|
|
||||||
Text("录入文字达到长度上限,请分开整理。").font(.footnote).foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
if !text.isEmpty && draft == nil {
|
|
||||||
Button("生成物品草稿") { typing = false; Task { await parse() } }
|
|
||||||
.disabled(!canParse)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if voice.phase == .idle, let draft {
|
|
||||||
Section("核对物品和位置") {
|
|
||||||
if draft.candidates.isEmpty {
|
|
||||||
Text(draft.status == "MODEL_UNAVAILABLE"
|
|
||||||
? "AI 暂不可用。你可以再试一次,或手动添加物品。"
|
|
||||||
: "还没整理出物品。可以修改原话,或让 AI 整理较长的描述。")
|
|
||||||
.font(.footnote).foregroundStyle(.secondary)
|
|
||||||
Button("用 AI 整理") { typing = false; Task { await parse(source: "MODEL") } }
|
|
||||||
.disabled(!canParse)
|
|
||||||
}
|
|
||||||
ForEach(draft.candidates.indices, id: \.self) { index in
|
|
||||||
let candidate = draft.candidates[index]
|
|
||||||
if candidate.action == "SKIP" {
|
|
||||||
Text("\(candidate.name) · 跳过").foregroundStyle(.secondary)
|
|
||||||
} else {
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text("\(candidate.name) ×\(candidate.quantity ?? 1)")
|
|
||||||
if let hint = candidate.location, !hint.isEmpty {
|
|
||||||
Text("原话位置:\(hint)").font(.footnote).foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
LocationPicker(store: store,
|
|
||||||
selection: Binding(get: { selections[index] }, set: { selections[index] = $0 }),
|
|
||||||
title: "存放位置", allowsClearing: true)
|
|
||||||
}.disabled(operation != nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !draft.candidates.isEmpty {
|
|
||||||
Button("保存物品") { typing = false; Task { await submit(draft) } }
|
|
||||||
.disabled(busy || selections.isEmpty || operation != nil || voice.phase != .idle)
|
|
||||||
if selections.isEmpty {
|
|
||||||
Text("选好存放位置后就可以保存。").font(.footnote).foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let operation {
|
|
||||||
Section {
|
|
||||||
Text(statusText(operation.status))
|
|
||||||
if operation.status == "COMPLETED" {
|
|
||||||
Button("继续录入") { reset(clearText: true) }
|
|
||||||
} else if ["FAILED", "REJECTED"].contains(operation.status) {
|
|
||||||
Button("返回核对") { reset(clearText: false) }
|
|
||||||
} else if operation.status == "NEEDS_REVIEW" {
|
|
||||||
Button("重试交付") { Task { await retry(operation) } }.disabled(busy)
|
|
||||||
} else {
|
|
||||||
Button("刷新进度") { Task { await poll(operation) } }.disabled(busy)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if busy { ProgressView() }
|
|
||||||
if let error { Text(error).foregroundStyle(.red) }
|
|
||||||
}
|
}
|
||||||
.dismissibleKeyboard(active: typing) { typing = false }
|
.onChange(of: draft?.id) { _, id in
|
||||||
.navigationTitle("录入")
|
if let id { withAnimation { scroll.scrollTo(id, anchor: .top) } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.background(Color(uiColor: .systemGroupedBackground))
|
||||||
|
.scrollDismissesKeyboard(.interactively)
|
||||||
|
.dismissibleKeyboard(active: typing) { typing = false }
|
||||||
|
.navigationTitle("录入物品")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
|
Button("关闭") { dismiss() }.disabled(busy)
|
||||||
|
}
|
||||||
|
ToolbarItem(placement: .topBarTrailing) {
|
||||||
|
Button { showingHelp = true } label: { Label("录入说明", systemImage: "questionmark.circle") }
|
||||||
|
.disabled(voice.phase != .idle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.interactiveDismissDisabled(busy || voice.phase != .idle)
|
||||||
|
.sensoryFeedback(.start, trigger: voice.phase) { _, phase in phase == .recording }
|
||||||
|
.onDisappear { voice.cancel() }
|
||||||
|
.onChange(of: scenePhase) { _, phase in
|
||||||
|
if phase == .background { voice.cancel() }
|
||||||
|
}
|
||||||
|
.onChange(of: text) { _, updated in
|
||||||
|
if operation == nil && draft?.originalText != updated {
|
||||||
|
draft = nil
|
||||||
|
selections = [:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.sheet(isPresented: $showingHelp) { help }
|
||||||
|
.sheet(isPresented: $showingAdd) { ItemEditor(store: store, initialLocation: initialLocation?.id) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var smartCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack(alignment: .firstTextBaseline) {
|
||||||
|
Text("智能录入").font(.title3.weight(.semibold))
|
||||||
|
.accessibilityAddTraits(.isHeader)
|
||||||
|
Spacer()
|
||||||
|
Menu {
|
||||||
|
Picker("录音方式", selection: $recordingMode) {
|
||||||
|
Text("点按开始,再点结束").tag(RecordingMode.tap)
|
||||||
|
Text("按住录音,松手结束").tag(RecordingMode.hold)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Label(recordingMode == .hold ? "按住说" : "点按录音", systemImage: "chevron.up.chevron.down")
|
||||||
|
.font(.subheadline.weight(.medium))
|
||||||
|
}
|
||||||
|
.accessibilityLabel("录音方式")
|
||||||
|
.accessibilityValue(recordingMode == .hold ? "按住说" : "点按录音")
|
||||||
|
.disabled(voice.phase != .idle)
|
||||||
|
}
|
||||||
|
Text("说出要记的物品,例如「记录两根数据线」。")
|
||||||
|
.font(.subheadline).foregroundStyle(.secondary)
|
||||||
|
voiceButton
|
||||||
|
if voice.phase == .recording || voice.phase == .finishing {
|
||||||
|
ProgressView(value: Double(voice.elapsedSeconds), total: Double(VoiceCapture.maximumDuration)) {
|
||||||
|
Text("\(voice.elapsedSeconds) / \(VoiceCapture.maximumDuration) 秒")
|
||||||
|
.font(.caption.monospacedDigit())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !voice.transcript.isEmpty {
|
||||||
|
Text(voice.transcript).font(.callout)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
if let error = voice.error { Text(error).font(.footnote).foregroundStyle(.secondary) }
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.background(Color.atlasBlue.opacity(0.10), in: .rect(cornerRadius: 20))
|
||||||
|
}
|
||||||
|
|
||||||
|
private var manualEntry: some View {
|
||||||
|
Button { showingAdd = true } label: {
|
||||||
|
HStack(spacing: 13) {
|
||||||
|
Image(systemName: "square.and.pencil")
|
||||||
|
.font(.headline)
|
||||||
|
.foregroundStyle(Color.atlasBlue)
|
||||||
|
.frame(width: 36, height: 36)
|
||||||
|
.background(Color.atlasBlue.opacity(0.10), in: .rect(cornerRadius: 10))
|
||||||
|
.accessibilityHidden(true)
|
||||||
|
VStack(alignment: .leading, spacing: 3) {
|
||||||
|
Text("手动添加").font(.headline).foregroundStyle(.primary)
|
||||||
|
Text("填写名称、照片和备注").font(.subheadline).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: "chevron.right").font(.footnote.weight(.semibold))
|
||||||
|
.foregroundStyle(.tertiary).accessibilityHidden(true)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.padding(14)
|
||||||
|
.background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16))
|
||||||
|
.contentShape(.rect(cornerRadius: 16))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.accessibilityIdentifier("intake.manual")
|
||||||
|
.disabled(voice.phase != .idle || busy)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var inputCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 10) {
|
||||||
|
Text("物品描述").font(.headline).accessibilityAddTraits(.isHeader)
|
||||||
|
TextField("录音文字会显示在这里,也可以直接输入", text: $text, axis: .vertical)
|
||||||
|
.lineLimit(3...7)
|
||||||
|
.focused($typing)
|
||||||
|
.accessibilityLabel("物品描述")
|
||||||
|
.disabled(busy)
|
||||||
|
if text.utf16.count > 4000 {
|
||||||
|
Text("最多 4,000 字,可以分开整理。").font(.footnote).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
if !text.isEmpty && draft == nil {
|
||||||
|
Button("整理成物品草稿") { typing = false; Task { await parse() } }.disabled(!canParse)
|
||||||
|
}
|
||||||
|
if busy && draft == nil { ProgressView("正在整理") }
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func reviewCard(_ draft: Draft) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
Text("核对物品").font(.headline).accessibilityAddTraits(.isHeader)
|
||||||
|
if draft.candidates.isEmpty {
|
||||||
|
Text(draft.status == "MODEL_UNAVAILABLE"
|
||||||
|
? "AI 暂不可用,可以重试或手动添加。"
|
||||||
|
: "这段话还没整理出物品,可以修改原话或用 AI 整理。")
|
||||||
|
.font(.callout).foregroundStyle(.secondary)
|
||||||
|
Button("用 AI 整理") { typing = false; Task { await parse(source: "MODEL") } }
|
||||||
|
.disabled(!canParse)
|
||||||
|
}
|
||||||
|
ForEach(draft.candidates.indices, id: \.self) { index in
|
||||||
|
let candidate = draft.candidates[index]
|
||||||
|
if candidate.action == "SKIP" {
|
||||||
|
Text("\(candidate.name) · 跳过").font(.callout).foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("\(candidate.name) ×\(candidate.quantity ?? 1)").font(.subheadline.weight(.semibold))
|
||||||
|
if let hint = candidate.location, !hint.isEmpty, selections[index] == nil {
|
||||||
|
Text("原话位置 · " + hint).font(.footnote).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
LocationPicker(store: store,
|
||||||
|
selection: Binding(get: { selections[index] }, set: { selections[index] = $0 }),
|
||||||
|
title: "存放位置", allowsClearing: true)
|
||||||
|
}
|
||||||
|
.padding(12)
|
||||||
|
.background(Color(uiColor: .systemGroupedBackground), in: .rect(cornerRadius: 12))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if draft.candidates.contains(where: { $0.action != "SKIP" }) {
|
||||||
|
Button { typing = false; Task { await submit(draft) } } label: {
|
||||||
|
Text("保存物品").frame(maxWidth: .infinity).padding(.vertical, 4)
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.disabled(busy)
|
||||||
|
}
|
||||||
|
if busy { ProgressView(draft.candidates.isEmpty ? "正在整理" : "正在保存") }
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func operationCard(_ operation: Operation) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 10) {
|
||||||
|
Text(statusText(operation.status)).font(.headline)
|
||||||
|
if busy {
|
||||||
|
ProgressView()
|
||||||
|
} else if operation.status == "COMPLETED" {
|
||||||
|
Button("继续录入") { reset(clearText: true) }
|
||||||
|
} else if ["FAILED", "REJECTED"].contains(operation.status) {
|
||||||
|
Button("返回核对") { reset(clearText: false) }
|
||||||
|
} else if operation.status == "NEEDS_REVIEW" {
|
||||||
|
Button("重试交付") { Task { await retry(operation) } }
|
||||||
|
} else {
|
||||||
|
Button("刷新进度") { Task { await poll(operation) } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.padding(16)
|
||||||
|
.background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16))
|
||||||
|
}
|
||||||
|
|
||||||
|
private var help: some View {
|
||||||
|
NavigationStack {
|
||||||
|
List {
|
||||||
|
Section("智能录入") {
|
||||||
|
Text("1. 点按开始录音,或者选择按住录音。")
|
||||||
|
Text("2. 看到录音状态再说。一次最多 25 秒,可以停顿。")
|
||||||
|
Text("3. 说完松手或再次点按。可以修改转写,也可以直接打字。")
|
||||||
|
Text("4. 核对物品后保存。位置可以调整、清除或留空。")
|
||||||
|
}
|
||||||
|
Section("手动添加") {
|
||||||
|
Text("填写名称就能录入单件物品。需要时再加位置、照片或备注。")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationTitle("怎么录入")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .topBarTrailing) {
|
ToolbarItem(placement: .confirmationAction) { Button("完成") { showingHelp = false } }
|
||||||
Button { showingHelp = true } label: { Label("录入说明", systemImage: "questionmark.circle") }
|
|
||||||
.disabled(voice.phase != .idle)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onDisappear { voice.cancel() }
|
|
||||||
.onChange(of: scenePhase) { _, phase in
|
|
||||||
if phase == .background { voice.cancel() }
|
|
||||||
}
|
|
||||||
.onChange(of: text) { _, updated in
|
|
||||||
if operation == nil && draft?.originalText != updated {
|
|
||||||
draft = nil
|
|
||||||
selections = [:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.sheet(isPresented: $showingHelp) {
|
|
||||||
NavigationStack {
|
|
||||||
List {
|
|
||||||
Section("录音录入") {
|
|
||||||
Text("1. 点「开始录音」。也可以在设置里切换为按住说。")
|
|
||||||
Text("2. 说完点结束或松手。每次最多 25 秒,中间可以停顿。")
|
|
||||||
Text("3. 查看转写和草稿。可以修改文字,或点「用 AI 整理」。")
|
|
||||||
Text("4. 核对物品和存放位置,再点「保存物品」。")
|
|
||||||
}
|
|
||||||
Section("手动添加") {
|
|
||||||
Text("点「手动添加物品」,填写名称,选好存放位置再保存。")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.navigationTitle("怎么录入")
|
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
|
||||||
.toolbar {
|
|
||||||
ToolbarItem(placement: .confirmationAction) { Button("完成") { showingHelp = false } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.sheet(isPresented: $showingAdd) { ItemEditor(store: store, initialLocation: initialLocation?.id) }
|
|
||||||
} else {
|
|
||||||
ContentUnavailableView("当前空间只有查看权限", systemImage: "lock")
|
|
||||||
.navigationTitle("录入").navigationBarTitleDisplayMode(.inline)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var voiceEnabled: Bool { !busy && operation == nil && voice.phase != .finishing }
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var voiceButton: some View {
|
private var voiceButton: some View {
|
||||||
if recordingMode == .tap {
|
if recordingMode == .tap {
|
||||||
Button(action: toggleRecording) { recordingLabel }
|
Button(action: toggleRecording) { recordingLabel }
|
||||||
.disabled(busy || operation != nil || voice.phase == .finishing)
|
.buttonStyle(.plain)
|
||||||
|
.disabled(!voiceEnabled)
|
||||||
} else {
|
} else {
|
||||||
recordingLabel
|
recordingLabel
|
||||||
.foregroundStyle(Color.accentColor)
|
.accessibilityHidden(true)
|
||||||
.gesture(DragGesture(minimumDistance: 0).updating($holdingMicrophone) { _, active, _ in
|
.overlay {
|
||||||
active = true
|
HoldRecordingControl(label: recordingTitle, enabled: voiceEnabled,
|
||||||
})
|
onPress: beginRecording, onRelease: { voice.stop() },
|
||||||
.onChange(of: holdingMicrophone) { _, active in
|
onAccessibilityActivate: toggleRecording)
|
||||||
if active { beginRecording(whileHeld: true) } else { voice.stop() }
|
|
||||||
}
|
}
|
||||||
.accessibilityAddTraits(.isButton)
|
}
|
||||||
.accessibilityAction { toggleRecording() }
|
}
|
||||||
.accessibilityHint("使用旁白时,轻点两下开始,再轻点两下结束。")
|
|
||||||
.allowsHitTesting(!busy && operation == nil && voice.phase != .finishing)
|
private var recordingTitle: String {
|
||||||
|
switch voice.phase {
|
||||||
|
case .idle: recordingMode == .hold ? "按住说" : "开始录音"
|
||||||
|
case .preparing: "麦克风准备中"
|
||||||
|
case .recording: recordingMode == .hold ? "松手结束" : "结束录音"
|
||||||
|
case .finishing: "正在转写"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var recordingLabel: some View {
|
private var recordingLabel: some View {
|
||||||
Group {
|
Label(recordingTitle, systemImage: voice.phase == .recording ? "waveform" : "mic.fill")
|
||||||
switch voice.phase {
|
.font(.headline)
|
||||||
case .idle: Label(recordingMode == .hold ? "按住录音" : "开始录音", systemImage: "mic.fill")
|
.frame(maxWidth: .infinity, minHeight: 54)
|
||||||
case .preparing: Label("准备麦克风…", systemImage: "mic")
|
.foregroundStyle(.white)
|
||||||
case .recording: Label(recordingMode == .hold ? "松手结束" : "结束录音", systemImage: "stop.circle.fill")
|
.background(voice.phase == .recording ? Color.atlasNavy : Color.atlasBlue,
|
||||||
case .finishing: Label("正在转写…", systemImage: "waveform")
|
in: .rect(cornerRadius: 14))
|
||||||
}
|
.opacity(voiceEnabled ? 1 : 0.55)
|
||||||
}
|
.contentShape(Rectangle())
|
||||||
.frame(maxWidth: .infinity, minHeight: 32, alignment: .leading)
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
}
|
|
||||||
|
|
||||||
private var recordingProgress: some View {
|
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
|
||||||
HStack {
|
|
||||||
Label(voice.phase == .finishing ? "完成转写中" : "录音中", systemImage: "waveform")
|
|
||||||
Spacer()
|
|
||||||
Text("\(voice.elapsedSeconds) / \(VoiceCapture.maximumDuration) 秒").monospacedDigit()
|
|
||||||
}
|
|
||||||
.font(.footnote)
|
|
||||||
ProgressView(value: Double(voice.elapsedSeconds), total: Double(VoiceCapture.maximumDuration))
|
|
||||||
.accessibilityHidden(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func toggleRecording() {
|
private func toggleRecording() {
|
||||||
if voice.phase == .idle { beginRecording() } else { voice.stop() }
|
if voice.phase == .idle { beginRecording() } else { voice.stop() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private func beginRecording(whileHeld: Bool = false) {
|
private func beginRecording() {
|
||||||
guard !busy, operation == nil else { return }
|
guard voiceEnabled, voice.phase == .idle else { return }
|
||||||
typing = false
|
typing = false
|
||||||
Task {
|
voice.start(context: store.locations.map(\.name)) { phrase, complete in
|
||||||
if whileHeld && !holdingMicrophone { return }
|
let previous = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
await voice.start(context: store.locations.map(\.name)) { phrase, complete in
|
text = previous.isEmpty ? phrase : previous + "\n" + phrase
|
||||||
let previous = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
if complete { Task { await parse() } }
|
||||||
text = previous.isEmpty ? phrase : previous + "\n" + phrase
|
|
||||||
if complete { Task { await parse() } }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,35 +331,20 @@ struct IntakeView: View {
|
||||||
guard text == original else { return }
|
guard text == original else { return }
|
||||||
draft = result
|
draft = result
|
||||||
selections = Dictionary(uniqueKeysWithValues: result.candidates.enumerated().compactMap { index, candidate in
|
selections = Dictionary(uniqueKeysWithValues: result.candidates.enumerated().compactMap { index, candidate in
|
||||||
guard candidate.action != "SKIP", let place = suggestedPlace(candidate.location) else { return nil }
|
guard candidate.action != "SKIP",
|
||||||
return (index, place.id)
|
let place = IntakeLocationMatcher.match(candidate.location, locations: store.locations,
|
||||||
|
defaultID: initialLocation?.id) else { return nil }
|
||||||
|
return (index, place)
|
||||||
})
|
})
|
||||||
} catch { self.error = error.localizedDescription }
|
} catch { self.error = error.localizedDescription }
|
||||||
}
|
}
|
||||||
|
|
||||||
private func suggestedPlace(_ original: String?) -> Place? {
|
|
||||||
guard let original, !original.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
|
||||||
return store.locations.first { $0.id == initialLocation?.id }
|
|
||||||
}
|
|
||||||
func key(_ value: String) -> String {
|
|
||||||
value.folding(options: [.caseInsensitive, .widthInsensitive], locale: Locale(identifier: "zh-CN"))
|
|
||||||
.filter { !$0.isWhitespace && $0 != "/" }
|
|
||||||
}
|
|
||||||
let hint = key(original)
|
|
||||||
guard !hint.isEmpty else { return nil }
|
|
||||||
let spoken = hint.hasSuffix("了") ? String(hint.dropLast()) : hint
|
|
||||||
let exact = store.locations.filter { key($0.path) == hint }
|
|
||||||
let matches = exact.isEmpty ? store.locations.filter { key($0.path) == spoken } : exact
|
|
||||||
if !matches.isEmpty { return matches.count == 1 ? matches.first : nil }
|
|
||||||
let names = store.locations.filter { key($0.name) == hint || key($0.name) == spoken }
|
|
||||||
return names.count == 1 ? names.first : nil
|
|
||||||
}
|
|
||||||
|
|
||||||
private func submit(_ draft: Draft) async {
|
private func submit(_ draft: Draft) async {
|
||||||
guard draft.originalText == text, !busy, operation == nil, voice.phase == .idle else { return }
|
guard draft.originalText == text, !busy, operation == nil, voice.phase == .idle else { return }
|
||||||
let items = draft.candidates.enumerated().compactMap { index, candidate -> ItemInput? in
|
let items = draft.candidates.enumerated().compactMap { index, candidate -> ItemInput? in
|
||||||
guard let location = selections[index], candidate.action != "SKIP" else { return nil }
|
guard candidate.action != "SKIP" else { return nil }
|
||||||
return ItemInput(name: candidate.name, quantity: candidate.quantity ?? 1, notes: "", locationId: location, aliases: [])
|
return ItemInput(name: candidate.name, quantity: candidate.quantity ?? 1, notes: "",
|
||||||
|
locationId: selections[index], aliases: [])
|
||||||
}
|
}
|
||||||
guard !items.isEmpty else { return }
|
guard !items.isEmpty else { return }
|
||||||
busy = true
|
busy = true
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ struct Item: Decodable, Identifiable {
|
||||||
let name: String
|
let name: String
|
||||||
let quantity: Int
|
let quantity: Int
|
||||||
let notes: String
|
let notes: String
|
||||||
let locationId: UUID
|
let locationId: UUID?
|
||||||
let locationPath: String
|
let locationPath: String
|
||||||
let version: Int
|
let version: Int
|
||||||
let aliases: [String]
|
let aliases: [String]
|
||||||
|
|
@ -35,13 +35,15 @@ struct Item: Decodable, Identifiable {
|
||||||
var icon: String? = nil
|
var icon: String? = nil
|
||||||
var priceCents: Int64? = nil
|
var priceCents: Int64? = nil
|
||||||
var published: Bool? = nil
|
var published: Bool? = nil
|
||||||
|
|
||||||
|
var locationLabel: String { locationPath.isEmpty ? "未设置位置" : locationPath }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ItemInput: Encodable {
|
struct ItemInput: Encodable {
|
||||||
let name: String
|
let name: String
|
||||||
let quantity: Int
|
let quantity: Int
|
||||||
let notes: String
|
let notes: String
|
||||||
let locationId: UUID
|
let locationId: UUID?
|
||||||
let aliases: [String]
|
let aliases: [String]
|
||||||
var version: Int? = nil
|
var version: Int? = nil
|
||||||
var appearance: Appearance? = nil
|
var appearance: Appearance? = nil
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@ import SwiftUI
|
||||||
struct InventoryView: View {
|
struct InventoryView: View {
|
||||||
let store: InventoryStore
|
let store: InventoryStore
|
||||||
let switcher: SpaceMenu.Actions
|
let switcher: SpaceMenu.Actions
|
||||||
|
let onIntake: () -> Void
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
ItemListView(store: store)
|
ItemListView(store: store, onIntake: onIntake)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
if #available(iOS 26.0, *) {
|
if #available(iOS 26.0, *) {
|
||||||
ToolbarItem(placement: .topBarTrailing) {
|
ToolbarItem(placement: .topBarTrailing) {
|
||||||
|
|
@ -70,15 +71,17 @@ struct SpaceMenu: View {
|
||||||
|
|
||||||
struct ItemListView: View {
|
struct ItemListView: View {
|
||||||
let store: InventoryStore
|
let store: InventoryStore
|
||||||
var favoritesOnly = false
|
let favoritesOnly: Bool
|
||||||
|
let onIntake: (() -> Void)?
|
||||||
@Environment(\.colorScheme) private var colorScheme
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
@State private var results: ItemListResults
|
@State private var results: ItemListResults
|
||||||
@State private var query = ""
|
@State private var query = ""
|
||||||
@FocusState private var searching: Bool
|
@FocusState private var searching: Bool
|
||||||
|
|
||||||
init(store: InventoryStore, favoritesOnly: Bool = false) {
|
init(store: InventoryStore, favoritesOnly: Bool = false, onIntake: (() -> Void)? = nil) {
|
||||||
self.store = store
|
self.store = store
|
||||||
self.favoritesOnly = favoritesOnly
|
self.favoritesOnly = favoritesOnly
|
||||||
|
self.onIntake = onIntake
|
||||||
_results = State(initialValue: ItemListResults(firstPage: store.cachedItems(favorites: favoritesOnly)))
|
_results = State(initialValue: ItemListResults(firstPage: store.cachedItems(favorites: favoritesOnly)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +107,12 @@ struct ItemListView: View {
|
||||||
.padding(.horizontal, 16)
|
.padding(.horizontal, 16)
|
||||||
.padding(.vertical, 8)
|
.padding(.vertical, 8)
|
||||||
.background(Color.entryBackground(for: colorScheme))
|
.background(Color.entryBackground(for: colorScheme))
|
||||||
List { ItemsSection(store: store, results: results, query: query, favorites: favoritesOnly) }
|
List {
|
||||||
|
ItemsSection(store: store, results: results, query: query, favorites: favoritesOnly, onIntake: {
|
||||||
|
searching = false
|
||||||
|
onIntake?()
|
||||||
|
})
|
||||||
|
}
|
||||||
.listStyle(.plain).scrollDismissesKeyboard(.interactively)
|
.listStyle(.plain).scrollDismissesKeyboard(.interactively)
|
||||||
}
|
}
|
||||||
.navigationTitle(favoritesOnly ? "我的收藏" : "找物")
|
.navigationTitle(favoritesOnly ? "我的收藏" : "找物")
|
||||||
|
|
@ -212,7 +220,7 @@ struct ItemsSection: View {
|
||||||
var query = ""
|
var query = ""
|
||||||
var favorites = false
|
var favorites = false
|
||||||
var location: UUID? = nil
|
var location: UUID? = nil
|
||||||
@State private var showingAdd = false
|
var onIntake: (() -> Void)? = nil
|
||||||
|
|
||||||
private var input: String { query.trimmingCharacters(in: .whitespacesAndNewlines) }
|
private var input: String { query.trimmingCharacters(in: .whitespacesAndNewlines) }
|
||||||
|
|
||||||
|
|
@ -231,7 +239,7 @@ struct ItemsSection: View {
|
||||||
.frame(width: 46, height: 46).clipShape(.rect(cornerRadius: 8)).accessibilityHidden(true)
|
.frame(width: 46, height: 46).clipShape(.rect(cornerRadius: 8)).accessibilityHidden(true)
|
||||||
VStack(alignment: .leading, spacing: 3) {
|
VStack(alignment: .leading, spacing: 3) {
|
||||||
Text(item.name).font(.headline)
|
Text(item.name).font(.headline)
|
||||||
Text(item.locationPath).font(.subheadline).foregroundStyle(.secondary)
|
Text(item.locationLabel).font(.subheadline).foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
if item.quantity > 1 { Text("×\(item.quantity)").font(.caption).foregroundStyle(.secondary) }
|
if item.quantity > 1 { Text("×\(item.quantity)").font(.caption).foregroundStyle(.secondary) }
|
||||||
|
|
@ -250,11 +258,11 @@ struct ItemsSection: View {
|
||||||
Task { await results.load(store: store, query: query, favorites: favorites, location: location, refresh: true) }
|
Task { await results.load(store: store, query: query, favorites: favorites, location: location, refresh: true) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !favorites && store.canWrite && input.isEmpty && location == nil {
|
if let onIntake, !favorites, store.canWrite, input.isEmpty, location == nil,
|
||||||
Button { showingAdd = true } label: { Label("添加物品", systemImage: "plus") }
|
results.displayedQuery == input, results.rows.isEmpty, results.error == nil {
|
||||||
|
Button(action: onIntake) { Label("添加物品", systemImage: "plus") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showingAdd) { ItemEditor(store: store, initialLocation: location) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var emptyTitle: String {
|
private var emptyTitle: String {
|
||||||
|
|
@ -293,8 +301,8 @@ struct ItemDetailView: View {
|
||||||
if let item = detail?.item ?? summary {
|
if let item = detail?.item ?? summary {
|
||||||
List {
|
List {
|
||||||
Section("当前位置") {
|
Section("当前位置") {
|
||||||
Label(item.locationPath, systemImage: "location.fill").foregroundStyle(Color.atlasBlue)
|
Label(item.locationLabel, systemImage: "location.fill").foregroundStyle(Color.atlasBlue)
|
||||||
if store.canWrite && detail != nil { Button("移位") { showingMove = true } }
|
if store.canWrite && detail != nil { Button(item.locationId == nil ? "设置位置" : "移位") { showingMove = true } }
|
||||||
}
|
}
|
||||||
Section("物品信息") {
|
Section("物品信息") {
|
||||||
LabeledContent("数量", value: "\(item.quantity)")
|
LabeledContent("数量", value: "\(item.quantity)")
|
||||||
|
|
@ -313,7 +321,7 @@ struct ItemDetailView: View {
|
||||||
Section("关联物品") {
|
Section("关联物品") {
|
||||||
ForEach(detail.relations) { relation in
|
ForEach(detail.relations) { relation in
|
||||||
NavigationLink { ItemDetailView(store: store, itemID: relation.itemId) } label: {
|
NavigationLink { ItemDetailView(store: store, itemID: relation.itemId) } label: {
|
||||||
LabeledContent(relation.name, value: relation.locationPath)
|
LabeledContent(relation.name, value: relation.locationPath.isEmpty ? "未设置位置" : relation.locationPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -322,7 +330,7 @@ struct ItemDetailView: View {
|
||||||
Section("移位历史") {
|
Section("移位历史") {
|
||||||
ForEach(Array(detail.moves.enumerated()), id: \.offset) { _, move in
|
ForEach(Array(detail.moves.enumerated()), id: \.offset) { _, move in
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
Text("\(move.fromPath) → \(move.toPath)")
|
Text("\(move.fromPath.isEmpty ? "未设置位置" : move.fromPath) → \(move.toPath.isEmpty ? "未设置位置" : move.toPath)")
|
||||||
Text(move.movedAt.prefix(10)).font(.caption).foregroundStyle(.secondary)
|
Text(move.movedAt.prefix(10)).font(.caption).foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
@main
|
@main
|
||||||
struct ItemAtlasApp: App {
|
struct ItemAtlasApp: App {
|
||||||
|
|
@ -159,7 +160,37 @@ private struct SpacesView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct SpaceTabs: View {
|
private struct SpaceTabs: View {
|
||||||
|
private enum Page: Hashable {
|
||||||
|
case inventory, locations, community, profile
|
||||||
|
|
||||||
|
var title: String {
|
||||||
|
switch self {
|
||||||
|
case .inventory: "找物"
|
||||||
|
case .locations: "位置"
|
||||||
|
case .community: "社区"
|
||||||
|
case .profile: "我的"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var symbol: String {
|
||||||
|
switch self {
|
||||||
|
case .inventory: "magnifyingglass"
|
||||||
|
case .locations: "square.stack"
|
||||||
|
case .community: "bubble.left.and.bubble.right"
|
||||||
|
case .profile: "person.crop.circle"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct IntakeRequest: Identifiable {
|
||||||
|
let id = UUID()
|
||||||
|
let location: Place?
|
||||||
|
}
|
||||||
|
|
||||||
@State private var store: InventoryStore
|
@State private var store: InventoryStore
|
||||||
|
@State private var page = Page.inventory
|
||||||
|
@State private var intake: IntakeRequest?
|
||||||
|
@State private var keyboardVisible = false
|
||||||
let switcher: SpaceMenu.Actions
|
let switcher: SpaceMenu.Actions
|
||||||
let openSpaces: () -> Void
|
let openSpaces: () -> Void
|
||||||
|
|
||||||
|
|
@ -171,18 +202,92 @@ private struct SpaceTabs: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TabView {
|
TabView(selection: $page) {
|
||||||
InventoryView(store: store, switcher: switcher).tabItem { Label("找物", systemImage: "magnifyingglass") }
|
InventoryView(store: store, switcher: switcher, onIntake: { openIntake() })
|
||||||
LocationView(store: store).tabItem { Label("位置", systemImage: "square.stack") }
|
.toolbar(.hidden, for: .tabBar)
|
||||||
|
.tabItem { Label(Page.inventory.title, systemImage: Page.inventory.symbol) }
|
||||||
|
.tag(Page.inventory)
|
||||||
|
LocationView(store: store, onIntake: openIntake)
|
||||||
|
.toolbar(.hidden, for: .tabBar)
|
||||||
|
.tabItem { Label(Page.locations.title, systemImage: Page.locations.symbol) }
|
||||||
|
.tag(Page.locations)
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
CommunityFeedView(account: store.account, source: store)
|
CommunityFeedView(account: store.account, source: store)
|
||||||
}.tabItem { Label("社区", systemImage: "bubble.left.and.bubble.right") }
|
}
|
||||||
|
.toolbar(.hidden, for: .tabBar)
|
||||||
|
.tabItem { Label(Page.community.title, systemImage: Page.community.symbol) }
|
||||||
|
.tag(Page.community)
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
MyView(account: store.account, store: store, openSpaces: openSpaces)
|
MyView(account: store.account, store: store, openSpaces: openSpaces)
|
||||||
}.tabItem { Label("我的", systemImage: "person.crop.circle") }
|
}
|
||||||
|
.toolbar(.hidden, for: .tabBar)
|
||||||
|
.tabItem { Label(Page.profile.title, systemImage: Page.profile.symbol) }
|
||||||
|
.tag(Page.profile)
|
||||||
|
}
|
||||||
|
.toolbar(.hidden, for: .tabBar)
|
||||||
|
.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||||
|
if !keyboardVisible { navigationBar }
|
||||||
|
}
|
||||||
|
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)) { _ in
|
||||||
|
keyboardVisible = true
|
||||||
|
}
|
||||||
|
.onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)) { _ in
|
||||||
|
keyboardVisible = false
|
||||||
|
}
|
||||||
|
.sheet(item: $intake) { request in
|
||||||
|
NavigationStack { IntakeView(store: store, initialLocation: request.location) }
|
||||||
|
.presentationDragIndicator(.visible)
|
||||||
}
|
}
|
||||||
.task { await store.warm() }
|
.task { await store.warm() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var navigationBar: some View {
|
||||||
|
HStack(spacing: 0) {
|
||||||
|
tabButton(.inventory)
|
||||||
|
tabButton(.locations)
|
||||||
|
if store.canWrite {
|
||||||
|
Button { openIntake() } label: {
|
||||||
|
Image(systemName: "plus")
|
||||||
|
.font(.system(size: 24, weight: .semibold))
|
||||||
|
.foregroundStyle(.white)
|
||||||
|
.frame(width: 52, height: 52)
|
||||||
|
.background(Color.atlasBlue, in: Circle())
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.accessibilityLabel("录入物品")
|
||||||
|
.accessibilityIdentifier("intake.add")
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
}
|
||||||
|
tabButton(.community)
|
||||||
|
tabButton(.profile)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: 600)
|
||||||
|
.padding(.horizontal, 10)
|
||||||
|
.padding(.vertical, 6)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.background(.regularMaterial)
|
||||||
|
.overlay(alignment: .top) { Divider() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func tabButton(_ destination: Page) -> some View {
|
||||||
|
Button { page = destination } label: {
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
Image(systemName: destination.symbol).font(.system(size: 19, weight: .medium))
|
||||||
|
.accessibilityHidden(true)
|
||||||
|
Text(destination.title).font(.caption2.weight(page == destination ? .semibold : .medium))
|
||||||
|
}
|
||||||
|
.foregroundStyle(page == destination ? Color.atlasBlue : Color.secondary)
|
||||||
|
.frame(maxWidth: .infinity, minHeight: 48)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.accessibilityAddTraits(page == destination ? .isSelected : [])
|
||||||
|
}
|
||||||
|
|
||||||
|
private func openIntake(_ location: Place? = nil) {
|
||||||
|
guard store.canWrite else { return }
|
||||||
|
intake = IntakeRequest(location: location)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct SpaceEditor: View {
|
private struct SpaceEditor: View {
|
||||||
|
|
|
||||||
|
|
@ -9,23 +9,38 @@ struct LocationPicker: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let path = store.locations.first { $0.id == selection }?.path
|
let path = store.locations.first { $0.id == selection }?.path
|
||||||
Button { showingPicker = true } label: {
|
HStack(spacing: 6) {
|
||||||
HStack(spacing: 8) {
|
Button { showingPicker = true } label: {
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
HStack(spacing: 8) {
|
||||||
Text(title).foregroundStyle(.primary)
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
Text(path ?? "请选择").font(.subheadline).foregroundStyle(.secondary)
|
Text(title).foregroundStyle(.primary)
|
||||||
|
Text(path ?? (allowsClearing ? "未设置" : "请选择"))
|
||||||
|
.font(.subheadline).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: "chevron.right")
|
||||||
|
.font(.footnote.weight(.semibold))
|
||||||
|
.foregroundStyle(.tertiary)
|
||||||
|
.accessibilityHidden(true)
|
||||||
}
|
}
|
||||||
Spacer()
|
.frame(minHeight: 44)
|
||||||
Image(systemName: "chevron.right")
|
.contentShape(Rectangle())
|
||||||
.font(.footnote.weight(.semibold))
|
}
|
||||||
.foregroundStyle(.tertiary)
|
.buttonStyle(.plain)
|
||||||
.accessibilityHidden(true)
|
.accessibilityLabel(title)
|
||||||
|
.accessibilityValue(path ?? "未设置")
|
||||||
|
if allowsClearing, selection != nil {
|
||||||
|
Button { selection = nil } label: {
|
||||||
|
Image(systemName: "xmark.circle.fill")
|
||||||
|
.font(.body)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
.frame(width: 44, height: 44)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderless)
|
||||||
|
.accessibilityLabel("清除位置")
|
||||||
}
|
}
|
||||||
.contentShape(Rectangle())
|
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
|
||||||
.accessibilityLabel(title)
|
|
||||||
.accessibilityValue(path ?? "未选择")
|
|
||||||
.sheet(isPresented: $showingPicker) {
|
.sheet(isPresented: $showingPicker) {
|
||||||
LocationSelection(store: store, places: store.locations, selected: selection, allowsClearing: allowsClearing) { chosen in
|
LocationSelection(store: store, places: store.locations, selected: selection, allowsClearing: allowsClearing) { chosen in
|
||||||
selection = chosen
|
selection = chosen
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,17 @@ import SwiftUI
|
||||||
|
|
||||||
struct LocationView: View {
|
struct LocationView: View {
|
||||||
let store: InventoryStore
|
let store: InventoryStore
|
||||||
|
let onIntake: (Place?) -> Void
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack { LocationContents(store: store, initialLocation: nil) }
|
NavigationStack { LocationContents(store: store, initialLocation: nil, onIntake: onIntake) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct LocationContents: View {
|
private struct LocationContents: View {
|
||||||
let store: InventoryStore
|
let store: InventoryStore
|
||||||
let initialLocation: Place?
|
let initialLocation: Place?
|
||||||
|
let onIntake: (Place?) -> Void
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@State private var items: ItemListResults
|
@State private var items: ItemListResults
|
||||||
@State private var addingLocation = false
|
@State private var addingLocation = false
|
||||||
|
|
@ -19,9 +22,10 @@ private struct LocationContents: View {
|
||||||
@State private var error: String?
|
@State private var error: String?
|
||||||
@State private var busy = false
|
@State private var busy = false
|
||||||
|
|
||||||
init(store: InventoryStore, initialLocation: Place?) {
|
init(store: InventoryStore, initialLocation: Place?, onIntake: @escaping (Place?) -> Void) {
|
||||||
self.store = store
|
self.store = store
|
||||||
self.initialLocation = initialLocation
|
self.initialLocation = initialLocation
|
||||||
|
self.onIntake = onIntake
|
||||||
let preview = initialLocation.flatMap { store.cachedItems(favorites: false, location: $0.id) }
|
let preview = initialLocation.flatMap { store.cachedItems(favorites: false, location: $0.id) }
|
||||||
_items = State(initialValue: ItemListResults(firstPage: preview))
|
_items = State(initialValue: ItemListResults(firstPage: preview))
|
||||||
}
|
}
|
||||||
|
|
@ -64,17 +68,15 @@ private struct LocationContents: View {
|
||||||
.disabled(busy)
|
.disabled(busy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if store.canWrite {
|
if let location, store.canWrite {
|
||||||
Section {
|
Section {
|
||||||
NavigationLink {
|
Button { onIntake(location) } label: {
|
||||||
IntakeView(store: store, initialLocation: location)
|
|
||||||
} label: {
|
|
||||||
Label {
|
Label {
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
Text(location == nil ? "录入物品" : "在这里录入")
|
Text("在这里录入")
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
.foregroundStyle(.primary)
|
.foregroundStyle(.primary)
|
||||||
Text("语音录入或手动添加")
|
Text("智能录入或手动添加")
|
||||||
.font(.subheadline)
|
.font(.subheadline)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +100,7 @@ private struct LocationContents: View {
|
||||||
}
|
}
|
||||||
Section(LocationLevel(depth: (location?.levelDepth ?? 0) + 1).title) {
|
Section(LocationLevel(depth: (location?.levelDepth ?? 0) + 1).title) {
|
||||||
ForEach(store.locations.filter { $0.parentId == location?.id }) { child in
|
ForEach(store.locations.filter { $0.parentId == location?.id }) { child in
|
||||||
NavigationLink { LocationContents(store: store, initialLocation: child) } label: {
|
NavigationLink { LocationContents(store: store, initialLocation: child, onIntake: onIntake) } label: {
|
||||||
HStack(spacing: 11) {
|
HStack(spacing: 11) {
|
||||||
LocationMark(store: store, place: child)
|
LocationMark(store: store, place: child)
|
||||||
Text(child.name)
|
Text(child.name)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import Speech
|
||||||
@MainActor
|
@MainActor
|
||||||
@Observable
|
@Observable
|
||||||
final class VoiceCapture {
|
final class VoiceCapture {
|
||||||
enum Phase { case idle, preparing, recording, finishing }
|
enum Phase: Equatable { case idle, preparing, recording, finishing }
|
||||||
|
|
||||||
static let maximumDuration = 25
|
static let maximumDuration = 25
|
||||||
private static let locale = Locale(identifier: "zh-CN")
|
private static let locale = Locale(identifier: "zh-CN")
|
||||||
|
|
@ -16,6 +16,7 @@ final class VoiceCapture {
|
||||||
|
|
||||||
private let engine = AVAudioEngine()
|
private let engine = AVAudioEngine()
|
||||||
private var timer: Task<Void, Never>?
|
private var timer: Task<Void, Never>?
|
||||||
|
private var preparation: Task<Void, Never>?
|
||||||
private var sessionID: UUID?
|
private var sessionID: UUID?
|
||||||
private var tapInstalled = false
|
private var tapInstalled = false
|
||||||
private var audioActive = false
|
private var audioActive = false
|
||||||
|
|
@ -27,12 +28,21 @@ final class VoiceCapture {
|
||||||
private var preview = ""
|
private var preview = ""
|
||||||
private var legacy = LegacyTranscription()
|
private var legacy = LegacyTranscription()
|
||||||
|
|
||||||
func start(context: [String], completion: @escaping (String, Bool) -> Void) async {
|
func start(context: [String], completion: @escaping (String, Bool) -> Void) {
|
||||||
guard phase == .idle else { return }
|
guard phase == .idle else { return }
|
||||||
let id = UUID()
|
let id = UUID()
|
||||||
sessionID = id
|
sessionID = id
|
||||||
error = nil
|
error = nil
|
||||||
phase = .preparing
|
phase = .preparing
|
||||||
|
preparation = Task { [weak self] in
|
||||||
|
await self?.prepare(id: id, context: context, completion: completion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func prepare(id: UUID, context: [String], completion: @escaping (String, Bool) -> Void) async {
|
||||||
|
// Releasing a short press can cancel the pending start before it runs.
|
||||||
|
guard !Task.isCancelled, sessionID == id else { return }
|
||||||
|
defer { if sessionID == id { preparation = nil } }
|
||||||
let microphone = await AVAudioApplication.requestRecordPermission()
|
let microphone = await AVAudioApplication.requestRecordPermission()
|
||||||
guard sessionID == id else { return }
|
guard sessionID == id else { return }
|
||||||
guard microphone else {
|
guard microphone else {
|
||||||
|
|
@ -101,6 +111,7 @@ final class VoiceCapture {
|
||||||
func stop() {
|
func stop() {
|
||||||
if phase == .preparing {
|
if phase == .preparing {
|
||||||
cancel()
|
cancel()
|
||||||
|
error = "录音还未开始。等麦克风准备好后再说。"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard phase == .recording else { return }
|
guard phase == .recording else { return }
|
||||||
|
|
@ -116,6 +127,8 @@ final class VoiceCapture {
|
||||||
|
|
||||||
func cancel() {
|
func cancel() {
|
||||||
sessionID = nil
|
sessionID = nil
|
||||||
|
preparation?.cancel()
|
||||||
|
preparation = nil
|
||||||
stopMicrophone()
|
stopMicrophone()
|
||||||
cancelRecognition?()
|
cancelRecognition?()
|
||||||
cancelRecognition = nil
|
cancelRecognition = nil
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
找物、收藏、位置、手工录入和批量草稿使用项目 API。搜索和编辑表单可以手动收起键盘,表单也支持下滑收起。照片从系统照片选择器导入,支持平移、调整放大比例与方形剪裁,按最长边 1600 像素压缩为 JPEG。客户端最多接受 30 MiB 来源文件,上传上限为 5 MiB,每件最多六张。列表使用服务端生成的缩略图。
|
找物、收藏、位置、手工录入和批量草稿使用项目 API。搜索和编辑表单可以手动收起键盘,表单也支持下滑收起。照片从系统照片选择器导入,支持平移、调整放大比例与方形剪裁,按最长边 1600 像素压缩为 JPEG。客户端最多接受 30 MiB 来源文件,上传上限为 5 MiB,每件最多六张。列表使用服务端生成的缩略图。
|
||||||
|
|
||||||
录入页支持普通话本机分段转写。默认点按开始和结束,也可以选择按住说、松手结束。一次最多 25 秒。核对草稿后手动保存,需要模型时由用户选择。家庭邀请用对方的见物账号发出,接收者在空间列表接受。 [语音、搜索和家庭邀请](../../docs/architecture/mobile-capture-and-search.md)
|
底栏中央的加号进入录入页。智能录入支持普通话本机分段转写,也可以直接填写物品描述。手动和智能录入的位置均可留空。默认点按开始和结束,也可以选择按住说、松手结束。一次最多 25 秒。核对草稿后手动保存,需要模型时由用户选择。家庭邀请用对方的见物账号发出,接收者在空间列表接受。 [语音、搜索和家庭邀请](../../docs/architecture/mobile-capture-and-search.md)
|
||||||
|
|
||||||
## 构建
|
## 构建
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ final class IntakeDtos {
|
||||||
record Draft(UUID id, String originalText, List<Candidate> candidates, String status, int version, DraftSource source) {}
|
record Draft(UUID id, String originalText, List<Candidate> candidates, String status, int version, DraftSource source) {}
|
||||||
record Place(UUID id, String path) {}
|
record Place(UUID id, String path) {}
|
||||||
record ItemInput(@NotBlank @Size(max = 150) String name, @Min(1) @Max(9999) int quantity,
|
record ItemInput(@NotBlank @Size(max = 150) String name, @Min(1) @Max(9999) int quantity,
|
||||||
@Size(max = 1500) String notes, @NotNull UUID locationId,
|
@Size(max = 1500) String notes, UUID locationId,
|
||||||
@Size(max = 20) List<@NotBlank @Size(max = 80) String> aliases) {}
|
@Size(max = 20) List<@NotBlank @Size(max = 80) String> aliases) {}
|
||||||
record Confirm(@NotNull @Min(0) Integer version, @NotEmpty @Size(max = 30) List<@NotNull @Valid ItemInput> items,
|
record Confirm(@NotNull @Min(0) Integer version, @NotEmpty @Size(max = 30) List<@NotNull @Valid ItemInput> items,
|
||||||
Boolean automatic) {}
|
Boolean automatic) {}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import java.util.regex.Pattern;
|
||||||
final class VoiceDraft {
|
final class VoiceDraft {
|
||||||
private static final Pattern COMMAND = Pattern.compile(
|
private static final Pattern COMMAND = Pattern.compile(
|
||||||
"(?:我(?:刚刚|刚才|现在|刚)?\\s*)?(?:把|将)?\\s*(.+?)\\s*(?:放到|放在|放进|收进)\\s*(.+)");
|
"(?:我(?:刚刚|刚才|现在|刚)?\\s*)?(?:把|将)?\\s*(.+?)\\s*(?:放到|放在|放进|收进)\\s*(.+)");
|
||||||
|
private static final Pattern RECORD = Pattern.compile("^(?:记下|记个|记录|录入|添加|新增)\\s*(.+)$");
|
||||||
private static final Pattern UNCERTAIN = Pattern.compile(
|
private static final Pattern UNCERTAIN = Pattern.compile(
|
||||||
"[、,,;;。!?!?\\n]|不(?:要|用|必|会|能|想|放|把|是|确定)|没(?:有|把|将|放)|别(?:把|放|收)|可能|好像|应该|或者|如果|然后|还有|一起|打算|想把|准备|哪里|哪儿|吗");
|
"[、,,;;。!?!?\\n]|不(?:要|用|必|会|能|想|放|把|是|确定)|没(?:有|把|将|放)|别(?:把|放|收)|可能|好像|应该|或者|如果|然后|还有|一起|打算|想把|准备|哪里|哪儿|吗");
|
||||||
private static final Pattern QUANTITY = Pattern.compile(
|
private static final Pattern QUANTITY = Pattern.compile(
|
||||||
|
|
@ -28,11 +29,20 @@ final class VoiceDraft {
|
||||||
String text = Normalizer.normalize(original, Normalizer.Form.NFKC).strip().replaceFirst("[。.!!]+$", "");
|
String text = Normalizer.normalize(original, Normalizer.Form.NFKC).strip().replaceFirst("[。.!!]+$", "");
|
||||||
if (text.length() > 120 || UNCERTAIN.matcher(text).find()) return List.of();
|
if (text.length() > 120 || UNCERTAIN.matcher(text).find()) return List.of();
|
||||||
var command = COMMAND.matcher(text);
|
var command = COMMAND.matcher(text);
|
||||||
if (!command.matches()) return List.of();
|
var record = RECORD.matcher(text);
|
||||||
String name = command.group(1).strip().replaceFirst("^(?:那个|这个)", "").strip();
|
String name;
|
||||||
String location = command.group(2).strip();
|
String location = null;
|
||||||
if (name.isEmpty() || location.isEmpty() || name.contains("和") || name.contains("跟")
|
if (command.matches()) {
|
||||||
|| COMMAND.matcher(location).matches()) return List.of();
|
name = RECORD.matcher(command.group(1).strip()).replaceFirst("$1");
|
||||||
|
location = command.group(2).strip();
|
||||||
|
if (location.isEmpty() || COMMAND.matcher(location).matches()) return List.of();
|
||||||
|
} else if (record.matches()) {
|
||||||
|
name = record.group(1);
|
||||||
|
} else {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
name = name.strip().replaceFirst("^(?:那个|这个)", "").strip();
|
||||||
|
if (name.isEmpty() || name.contains("和") || name.contains("跟")) return List.of();
|
||||||
var quantity = QUANTITY.matcher(name);
|
var quantity = QUANTITY.matcher(name);
|
||||||
int count = 1;
|
int count = 1;
|
||||||
if (quantity.matches()) {
|
if (quantity.matches()) {
|
||||||
|
|
@ -53,7 +63,7 @@ final class VoiceDraft {
|
||||||
var candidate = draft.candidates().getFirst();
|
var candidate = draft.candidates().getFirst();
|
||||||
var item = input.items().getFirst();
|
var item = input.items().getFirst();
|
||||||
if (candidate.action() != Action.RECORD || !candidate.name().equals(item.name()) || candidate.quantity() == null
|
if (candidate.action() != Action.RECORD || !candidate.name().equals(item.name()) || candidate.quantity() == null
|
||||||
|| candidate.quantity() != item.quantity()) return Optional.empty();
|
|| candidate.quantity() != item.quantity() || candidate.location() == null) return Optional.empty();
|
||||||
String location = pathKey(candidate.location());
|
String location = pathKey(candidate.location());
|
||||||
var exact = places.stream().filter(p -> pathKey(p.path()).equals(location)).toList();
|
var exact = places.stream().filter(p -> pathKey(p.path()).equals(location)).toList();
|
||||||
if (exact.isEmpty() && location.endsWith("了")) {
|
if (exact.isEmpty() && location.endsWith("了")) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.tutudog.itematlas.inventory;
|
package com.tutudog.itematlas.inventory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.Max;
|
import jakarta.validation.constraints.Max;
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
|
|
@ -33,12 +34,12 @@ final class InventoryDtos {
|
||||||
ItemIcon icon, Long priceCents, boolean published) {}
|
ItemIcon icon, Long priceCents, boolean published) {}
|
||||||
record ItemInput(@NotBlank @Size(max = 150) String name,
|
record ItemInput(@NotBlank @Size(max = 150) String name,
|
||||||
@Min(1) @Max(9999) int quantity, @Size(max = 1500) String notes,
|
@Min(1) @Max(9999) int quantity, @Size(max = 1500) String notes,
|
||||||
@NotNull UUID locationId,
|
UUID locationId,
|
||||||
@Size(max = 20) List<@NotBlank @Size(max = 80) String> aliases, @Valid Appearance appearance) {}
|
@Size(max = 20) List<@NotBlank @Size(max = 80) String> aliases, @Valid Appearance appearance) {}
|
||||||
record ItemEdit(@NotNull @Min(0) Integer version, @NotBlank @Size(max = 150) String name,
|
record ItemEdit(@NotNull @Min(0) Integer version, @NotBlank @Size(max = 150) String name,
|
||||||
@Min(1) @Max(9999) int quantity, @Size(max = 1500) String notes,
|
@Min(1) @Max(9999) int quantity, @Size(max = 1500) String notes,
|
||||||
@Size(max = 20) List<@NotBlank @Size(max = 80) String> aliases, @Valid Appearance appearance) {}
|
@Size(max = 20) List<@NotBlank @Size(max = 80) String> aliases, @Valid Appearance appearance) {}
|
||||||
record MoveInput(@NotNull UUID locationId, @NotNull @Min(0) Integer version) {}
|
record MoveInput(@JsonProperty(required = true) UUID locationId, @NotNull @Min(0) Integer version) {}
|
||||||
record Move(String fromPath, String toPath, OffsetDateTime movedAt) {}
|
record Move(String fromPath, String toPath, OffsetDateTime movedAt) {}
|
||||||
enum RelationKind { ACCESSORY, SIMILAR, TOGETHER }
|
enum RelationKind { ACCESSORY, SIMILAR, TOGETHER }
|
||||||
record RelationInput(@NotNull UUID itemId, @NotNull RelationKind kind) {}
|
record RelationInput(@NotNull UUID itemId, @NotNull RelationKind kind) {}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import java.sql.Types;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
@ -59,14 +60,14 @@ class InventoryService {
|
||||||
)
|
)
|
||||||
""";
|
""";
|
||||||
private static final String SELECT_ITEMS = """
|
private static final String SELECT_ITEMS = """
|
||||||
SELECT i.*, p.path,
|
SELECT i.*, COALESCE(p.path, '') AS path,
|
||||||
EXISTS (SELECT FROM community_post post WHERE (post.household_id,post.item_id)=(i.household_id,i.id)) AS published,
|
EXISTS (SELECT FROM community_post post WHERE (post.household_id,post.item_id)=(i.household_id,i.id)) AS published,
|
||||||
ARRAY(SELECT a.alias FROM item_alias a
|
ARRAY(SELECT a.alias FROM item_alias a
|
||||||
WHERE a.household_id=i.household_id AND a.item_id=i.id ORDER BY a.alias) AS aliases,
|
WHERE a.household_id=i.household_id AND a.item_id=i.id ORDER BY a.alias) AS aliases,
|
||||||
(SELECT photo.id FROM item_photo photo
|
(SELECT photo.id FROM item_photo photo
|
||||||
WHERE (photo.household_id,photo.item_id)=(i.household_id,i.id)
|
WHERE (photo.household_id,photo.item_id)=(i.household_id,i.id)
|
||||||
ORDER BY photo.created_at,photo.id LIMIT 1) AS cover_photo_id
|
ORDER BY photo.created_at,photo.id LIMIT 1) AS cover_photo_id
|
||||||
FROM item i JOIN paths p ON p.household_id=i.household_id AND p.id=i.location_id
|
FROM item i LEFT JOIN paths p ON p.household_id=i.household_id AND p.id=i.location_id
|
||||||
%s
|
%s
|
||||||
WHERE i.household_id=:household AND i.archived_at IS NULL
|
WHERE i.household_id=:household AND i.archived_at IS NULL
|
||||||
""";
|
""";
|
||||||
|
|
@ -212,9 +213,9 @@ class InventoryService {
|
||||||
""").param("household", household).param("id", id).query((rs, row) -> new Move(
|
""").param("household", household).param("id", id).query((rs, row) -> new Move(
|
||||||
rs.getString(1), rs.getString(2), rs.getObject(3, OffsetDateTime.class))).list();
|
rs.getString(1), rs.getString(2), rs.getObject(3, OffsetDateTime.class))).list();
|
||||||
var relations = db.sql("""
|
var relations = db.sql("""
|
||||||
SELECT r.related_id,i.name,p.path,r.kind FROM item_relation r
|
SELECT r.related_id,i.name,COALESCE(p.path,''),r.kind FROM item_relation r
|
||||||
JOIN item i ON (i.household_id,i.id)=(r.household_id,r.related_id)
|
JOIN item i ON (i.household_id,i.id)=(r.household_id,r.related_id)
|
||||||
JOIN location_paths(:household) p ON (p.household_id,p.id)=(i.household_id,i.location_id)
|
LEFT JOIN location_paths(:household) p ON (p.household_id,p.id)=(i.household_id,i.location_id)
|
||||||
WHERE r.household_id=:household AND r.item_id=:id AND i.archived_at IS NULL ORDER BY i.name,i.id
|
WHERE r.household_id=:household AND r.item_id=:id AND i.archived_at IS NULL ORDER BY i.name,i.id
|
||||||
""").param("household", household).param("id", id).query((rs, row) -> new Relation(
|
""").param("household", household).param("id", id).query((rs, row) -> new Relation(
|
||||||
rs.getObject(1, UUID.class), rs.getString(2), rs.getString(3),
|
rs.getObject(1, UUID.class), rs.getString(2), rs.getString(3),
|
||||||
|
|
@ -238,7 +239,7 @@ class InventoryService {
|
||||||
.query(UUID.class).optional();
|
.query(UUID.class).optional();
|
||||||
if (previous.isPresent()) { return item(household, previous.get()); }
|
if (previous.isPresent()) { return item(household, previous.get()); }
|
||||||
}
|
}
|
||||||
location(household, input.locationId());
|
if (input.locationId() != null) { location(household, input.locationId()); }
|
||||||
return insertItem(household, input, requestKey == null ? null : actor, requestKey);
|
return insertItem(household, input, requestKey == null ? null : actor, requestKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,7 +251,7 @@ class InventoryService {
|
||||||
VALUES (:household,:id,:name,:quantity,:notes,:location,:icon,:price,:creator,:key)
|
VALUES (:household,:id,:name,:quantity,:notes,:location,:icon,:price,:creator,:key)
|
||||||
""").param("household", household).param("id", id).param("name", input.name().strip())
|
""").param("household", household).param("id", id).param("name", input.name().strip())
|
||||||
.param("quantity", input.quantity()).param("notes", text(input.notes()))
|
.param("quantity", input.quantity()).param("notes", text(input.notes()))
|
||||||
.param("location", input.locationId())
|
.param("location", input.locationId(), Types.OTHER)
|
||||||
.param("icon", appearance == null ? ItemIcon.BOX.name() : appearance.icon().name())
|
.param("icon", appearance == null ? ItemIcon.BOX.name() : appearance.icon().name())
|
||||||
.param("price", appearance == null ? null : appearance.priceCents(), Types.BIGINT)
|
.param("price", appearance == null ? null : appearance.priceCents(), Types.BIGINT)
|
||||||
.param("creator", creator, Types.VARCHAR).param("key", requestKey, Types.OTHER).update();
|
.param("creator", creator, Types.VARCHAR).param("key", requestKey, Types.OTHER).update();
|
||||||
|
|
@ -290,15 +291,16 @@ class InventoryService {
|
||||||
access.requireWrite(household, actor);
|
access.requireWrite(household, actor);
|
||||||
Item current = item(household, id);
|
Item current = item(household, id);
|
||||||
checkVersion(current, input.version());
|
checkVersion(current, input.version());
|
||||||
Location destination = location(household, input.locationId());
|
UUID target = input.locationId();
|
||||||
if (current.locationId().equals(destination.id())) { return current; }
|
if (Objects.equals(current.locationId(), target)) { return current; }
|
||||||
|
String nextPath = target == null ? "" : location(household, target).path();
|
||||||
db.sql("""
|
db.sql("""
|
||||||
UPDATE item SET location_id=:location,version=version+1 WHERE household_id=:household AND id=:id
|
UPDATE item SET location_id=:location,version=version+1 WHERE household_id=:household AND id=:id
|
||||||
""").param("household", household).param("id", id).param("location", destination.id()).update();
|
""").param("household", household).param("id", id).param("location", target, Types.OTHER).update();
|
||||||
db.sql("""
|
db.sql("""
|
||||||
INSERT INTO item_move(household_id,item_id,from_path,to_path) VALUES (:household,:id,:old,:next)
|
INSERT INTO item_move(household_id,item_id,from_path,to_path) VALUES (:household,:id,:old,:next)
|
||||||
""").param("household", household).param("id", id).param("old", current.locationPath())
|
""").param("household", household).param("id", id).param("old", current.locationPath())
|
||||||
.param("next", destination.path()).update();
|
.param("next", nextPath).update();
|
||||||
return item(household, id);
|
return item(household, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -365,8 +367,9 @@ class InventoryService {
|
||||||
try {
|
try {
|
||||||
access.requireWrite(household, delivery.actor());
|
access.requireWrite(household, delivery.actor());
|
||||||
for (ItemInput input : delivery.items()) {
|
for (ItemInput input : delivery.items()) {
|
||||||
var place = location(household, input.locationId());
|
var place = input.locationId() == null ? null : location(household, input.locationId());
|
||||||
if (delivery.expectedLocationPath() != null && !delivery.expectedLocationPath().equals(place.path())) {
|
if (delivery.expectedLocationPath() != null
|
||||||
|
&& (place == null || !delivery.expectedLocationPath().equals(place.path()))) {
|
||||||
throw new ResponseStatusException(CONFLICT, "录入位置已变化");
|
throw new ResponseStatusException(CONFLICT, "录入位置已变化");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE item ALTER COLUMN location_id DROP NOT NULL;
|
||||||
|
|
@ -14,6 +14,7 @@ def verify():
|
||||||
try:
|
try:
|
||||||
verify_inventory_appearance(root)
|
verify_inventory_appearance(root)
|
||||||
verify_search_and_voice(root)
|
verify_search_and_voice(root)
|
||||||
|
verify_optional_locations(root)
|
||||||
verify_direct_invitations(root)
|
verify_direct_invitations(root)
|
||||||
verify_community(root)
|
verify_community(root)
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -125,6 +126,51 @@ def verify_inventory_appearance(root):
|
||||||
print("PASS location and item icons, integer price, older clients and deduplicated creation", flush=True)
|
print("PASS location and item icons, integer price, older clients and deduplicated creation", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
def verify_optional_locations(root):
|
||||||
|
items = root + "/items"
|
||||||
|
place = call("POST", root + "/locations", {"name": "衣帽间 " + RUN}, status=201)
|
||||||
|
manual = call("POST", items, {"name": "待整理的手电 " + RUN, "quantity": 1, "aliases": ["备用照明 " + RUN]}, status=201)
|
||||||
|
assert manual["locationId"] is None and manual["locationPath"] == ""
|
||||||
|
address = items + "/" + manual["id"]
|
||||||
|
assert call("GET", address)["item"] == manual
|
||||||
|
assert [p["id"] for p in call("GET", items + "?" + urlencode({"q": manual["aliases"][0]}))] == [manual["id"]]
|
||||||
|
assert manual["id"] not in {p["id"] for p in call("GET", items + "?location=" + place["id"])}
|
||||||
|
|
||||||
|
stored = call("POST", items, {"name": "电池", "quantity": 1, "locationId": place["id"]}, status=201)
|
||||||
|
stored_path = items + "/" + stored["id"]
|
||||||
|
call("PUT", stored_path + "/relations", {"itemId": manual["id"], "kind": "ACCESSORY"}, status=204)
|
||||||
|
linked, = call("GET", stored_path)["relations"]
|
||||||
|
assert linked["itemId"] == manual["id"] and linked["locationPath"] == ""
|
||||||
|
|
||||||
|
call("POST", address + "/moves", {"version": manual["version"]}, status=400)
|
||||||
|
moved = call("POST", address + "/moves", {"locationId": place["id"], "version": manual["version"]})
|
||||||
|
assert moved["locationPath"] == place["name"]
|
||||||
|
call("POST", address + "/moves", {"locationId": None, "version": manual["version"]}, status=409)
|
||||||
|
cleared = call("POST", address + "/moves", {"locationId": None, "version": moved["version"]})
|
||||||
|
assert cleared["locationId"] is None
|
||||||
|
latest, initial = call("GET", address)["moves"]
|
||||||
|
assert (initial["fromPath"], initial["toPath"]) == ("", place["name"])
|
||||||
|
assert (latest["fromPath"], latest["toPath"]) == (place["name"], "")
|
||||||
|
|
||||||
|
name = "录入无位置手表 " + RUN
|
||||||
|
draft = call("POST", root + "/drafts", {"text": "记录两只手表", "source": "VOICE"}, status=201)
|
||||||
|
assert draft["candidates"] == [{"name": "手表", "quantity": 2, "action": "RECORD", "location": None}]
|
||||||
|
confirm = root + "/drafts/" + draft["id"] + "/confirm"
|
||||||
|
payload = {"version": draft["version"], "items": [{"name": name, "quantity": 1, "locationId": None},
|
||||||
|
{"name": "带位置的物品 " + RUN, "quantity": 1, "locationId": place["id"]}]}
|
||||||
|
call("POST", confirm, dict(payload, automatic=True), status=409)
|
||||||
|
call("POST", confirm, {"version": draft["version"], "items": [{"name": "手表", "quantity": 2}],
|
||||||
|
"automatic": True}, status=409)
|
||||||
|
operation = call("POST", confirm, payload, status=202)
|
||||||
|
await_operation(root + "/operations/" + operation["id"], "COMPLETED")
|
||||||
|
actual, = call("GET", items + "?" + urlencode({"q": name}))
|
||||||
|
assert actual["locationId"] is None and actual["locationPath"] == ""
|
||||||
|
with_location, = call("GET", items + "?" + urlencode({"q": payload["items"][1]["name"]}))
|
||||||
|
assert with_location["locationId"] == place["id"]
|
||||||
|
call("DELETE", address + "?version=" + str(cleared["version"]), status=204)
|
||||||
|
print("PASS unset positions in manual creation, search, links, move history and mixed draft confirmation", flush=True)
|
||||||
|
|
||||||
|
|
||||||
def verify_direct_invitations(root):
|
def verify_direct_invitations(root):
|
||||||
sent = root + "/direct-invitations"
|
sent = root + "/direct-invitations"
|
||||||
inbox = "/api/households/direct-invitations"
|
inbox = "/api/households/direct-invitations"
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,15 @@ flowchart LR
|
||||||
W --> P[物品服务事务写入]
|
W --> P[物品服务事务写入]
|
||||||
```
|
```
|
||||||
|
|
||||||
iOS 只启动支持本机转写的普通话识别。录音最多 25 秒,录入页面显示用时。点按与按住两种操作共用同一个录音会话。兼容的 iOS 26 及以上设备有本机语音资源时,使用 `SpeechAnalyzer` 和 `DictationTranscriber`,分开保留已定稿片段与正在更新的文字。录音时若设备支持但缺少资源,系统在后台下载本地识别模型。旧设备或模型未就绪时,回到 `SFSpeechRecognizer`,按语音时间范围和结果变化保留已说片段。音频在内存中处理,录音结束后只留下可编辑的文字。 [Apple SpeechAnalyzer](https://developer.apple.com/documentation/speech/speechanalyzer) · [Apple DictationTranscriber.Result](https://developer.apple.com/documentation/speech/dictationtranscriber/result)
|
iOS 只启动支持本机转写的普通话识别。录音最多 25 秒,录入页面显示用时。点按与按住两种操作共用同一个录音会话。按住使用 UIKit 触控按下、抬起和取消事件,按下同步进入准备状态。准备期间松手会取消该次启动,识别器的异步返回也不能让旧会话开始录音。录音态下松手开始收尾并保留转写。兼容的 iOS 26 及以上设备有本机语音资源时,使用 `SpeechAnalyzer` 和 `DictationTranscriber`,分开保留已定稿片段与正在更新的文字。录音时若设备支持但缺少资源,系统在后台下载本地识别模型。旧设备或模型未就绪时,回到 `SFSpeechRecognizer`,按语音时间范围和结果变化保留已说片段。音频在内存中处理,录音结束后只留下可编辑的文字。 [Apple SpeechAnalyzer](https://developer.apple.com/documentation/speech/speechanalyzer) · [Apple DictationTranscriber.Result](https://developer.apple.com/documentation/speech/dictationtranscriber/result)
|
||||||
|
|
||||||
`POST /api/households/{space}/drafts` 的 `source=VOICE` 调用规则,只识别一条明确的放置命令以及有限的数量表达。遇到否定、不确定、多件物品或超出语法的句子,返回空候选,保留原话。用户选择「用 AI 整理」才发起 `source=MODEL` 请求。旧客户端缺省字段时继续走模型。模型已有关闭思考、结构化校验、超时与单实例并发限制。
|
`POST /api/households/{space}/drafts` 的 `source=VOICE` 调用规则,能提取一条明确的放置命令,或者「记录两根数据线」这样的单件录入指令,位置可以为空。遇到否定、不确定、多件物品或超出语法的句子,返回空候选,保留原话。用户选择「用 AI 整理」才发起 `source=MODEL` 请求。旧客户端缺省字段时继续走模型。模型已有关闭思考、结构化校验、超时与单实例并发限制。
|
||||||
|
|
||||||
iOS 录音结束后可预生成草稿,核对并按下「保存物品」才发起确认。部分转写会保留原话并提示先核对。位置含糊时由用户在草稿中选择。确认操作复用已部署的 `draft_id + draft_version` 唯一键和 Outbox,物品服务在事务内重新核对当前角色和位置。兼容旧版客户端的 `automatic=true` 请求仍需要单件、物品及数量一致和唯一完整位置路径,投递时会再次核对路径。排错先看草稿来源和操作号,再查日志与 Outbox 指标。音频、转写原话和空间名称不进入指标标签。
|
iOS 录音结束后可预生成草稿,核对并按下「保存物品」才发起确认。部分转写会保留原话并提示先核对。客户端按空间内的完整路径、名称和路径尾段匹配草稿位置。同名位置在当前房间范围内只有一个时可预选。没有位置描述时用房间入口带来的默认位置,仍有歧义时留空。编辑或清除位置后按最终选择提交。确认操作复用已部署的 `draft_id + draft_version` 唯一键和 Outbox,物品服务在事务内重新核对当前角色和位置。兼容旧版客户端的 `automatic=true` 请求仍需要单件、物品及数量一致和唯一完整位置路径,投递时会再次核对路径。排错先看草稿来源和操作号,再查日志与 Outbox 指标。音频、转写原话和空间名称不进入指标标签。
|
||||||
|
|
||||||
|
物品库 Flyway V13 将 `item.location_id` 改为可空,已有物品和空间内复合外键保留。创建和草稿确认接受省略位置或传 `null`,位置查询采用左连接,未分配位置的响应为 `locationId: null`、`locationPath: ""`。列表、别名检索、关联和照片仍能正常读取。按具体位置筛选时,结果只包含该位置下的物品。移位接口必须传 `locationId`,显式传 `null` 表示清除位置,操作沿用版本检查并写历史。
|
||||||
|
|
||||||
|
发布时一并更新录入服务和物品服务,再交付 iOS 构建 14。更早的 iOS 构建将位置 ID 当成必填字段,需要升级才能正确读取无位置的物品。写入空位置后,旧物品服务的内连接会漏掉这些记录,回退时须使用支持 V13 的制品。
|
||||||
|
|
||||||
## 检索和权重
|
## 检索和权重
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,13 @@
|
||||||
|
|
||||||
## 录入
|
## 录入
|
||||||
|
|
||||||
底部依次是「找物」「位置」「社区」「我的」。「位置」顶部有「录入物品」。进入房间或子位置后,点「在这里录入」会带上当前的位置,手动添加时可以更改。语音草稿如果提到了其他位置,会按原话匹配,保存前可检查。
|
底栏是「找物」「位置」「社区」「我的」。中间的蓝色加号打开「录入物品」,关闭后回到刚才的页面。「找物」空页里的「添加物品」进入同一页。房间和子位置的「在这里录入」会带上当前位置。
|
||||||
|
|
||||||
默认点「开始录音」,说完再点「结束录音」。也可以在「录音设置」选择按住说、松手结束。每次最多 25 秒,录音中能看到经过的秒数和文字。停顿后继续说,前面的转写留在这一段里。
|
「智能录入」支持说话或输入文字。录音方式可选点按开始、再点结束,或者按住说、松手结束。看到录音状态再说,每次最多 25 秒,停顿前后的文字会留在同一段。
|
||||||
|
|
||||||
结束后可修改原话。见物先用规则生成物品和位置草稿,较长的描述可以点「用 AI 整理」。核对名称、数量和位置后,点「保存物品」。也可以直接点「手动添加物品」填写表单。录入页右上角的问号可以查看这两套操作。
|
例如说「记录两根数据线」,草稿可以只有名称和数量。提到的位置会尝试匹配现有路径。原话没有提位置时,可以使用进入录入时带来的当前位置。路径无法确定时留空。位置旁的叉号可以清除,点位置可以改选。核对后才会保存。
|
||||||
|
|
||||||
|
在「手动添加」可以填写名称、数量、照片和备注。位置是可选项。暂时没放好的物品也能在「找物」里搜到,之后可到详情设置位置。
|
||||||
|
|
||||||
## 我的
|
## 我的
|
||||||
|
|
||||||
|
|
@ -32,9 +34,9 @@
|
||||||
|
|
||||||
## 选存放位置
|
## 选存放位置
|
||||||
|
|
||||||
录音草稿、手动添加和移位使用同一个位置选择页。从房间或区域开始,逐层进入柜子、抽屉或收纳盒。房间和柜子本身也能作为存放位置,在对应页面点「选这个位置」。
|
智能草稿、手动添加和移位使用同一个位置选择页。从房间或区域开始,逐层进入柜子、抽屉或收纳盒。房间和柜子本身也能作为存放位置,在对应页面点「选这个位置」。
|
||||||
|
|
||||||
知道位置名称时可以直接搜索。结果显示完整路径,两个同名收纳盒也能区分。选中后把这条路径带回表单,等用户保存物品或确认移位。录音草稿支持清除某件物品的位置选择。
|
知道位置名称时可以直接搜索。结果显示完整路径,两个同名收纳盒也能区分。选中后把这条路径带回表单,等用户保存物品或确认移位。这三处都可以用位置旁的叉号清除选择。
|
||||||
|
|
||||||
## 家庭邀请
|
## 家庭邀请
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| R01 | 家庭和角色 | 登录后按当前账号展示空间。新空间显示空状态。两户数据互相隔离。所有者可签发和撤销邀请、调整普通成员角色及移除成员。两人同时兑换同一邀请时只有一人加入。查看者可找物,降权或移除后用原登录凭据也只能执行当前权限允许的请求。 |
|
| R01 | 家庭和角色 | 登录后按当前账号展示空间。新空间显示空状态。两户数据互相隔离。所有者可签发和撤销邀请、调整普通成员角色及移除成员。两人同时兑换同一邀请时只有一人加入。查看者可找物,降权或移除后用原登录凭据也只能执行当前权限允许的请求。 |
|
||||||
| R02 | 多层位置 | 可以建立房间、柜子、收纳盒。同名位置显示完整路径。禁止把上级移动到子节点下,有活动物品或下级的位置归档前须先处理关联。前三级位置有层级文字和对应的图标组,第四级起采用相同的内层样式。 |
|
| R02 | 多层位置 | 可以建立房间、柜子、收纳盒。同名位置显示完整路径。禁止把上级移动到子节点下,有活动物品或下级的位置归档前须先处理关联。前三级位置有层级文字和对应的图标组,第四级起采用相同的内层样式。 |
|
||||||
| R03 | 物品和移位 | 可以新增、修改、移位和归档物品。移位后同时查到当前和原来的位置,用旧版本写入时提示冲突。 |
|
| R03 | 物品和移位 | 可以新增、修改、移位和归档物品。新物品可以暂时不填位置,仍能按名称和别名找到。移位后同时查到当前和原来的位置,用旧版本写入时提示冲突。 |
|
||||||
| R04 | 搜索 | 可以按名称、别名和位置找物。完整名称优先于完整别名和部分匹配,结果带完整位置路径。 |
|
| R04 | 搜索 | 可以按名称、别名和位置找物。完整名称优先于完整别名和部分匹配,结果带完整位置路径。 |
|
||||||
| R05 | 物品关联 | 可以关联同一家庭里的配件、同类或常一起使用的物品。详情显示关联物品的位置。 |
|
| R05 | 物品关联 | 可以关联同一家庭里的配件、同类或常一起使用的物品。详情显示关联物品的位置。 |
|
||||||
| R06 | 批量草稿 | 同一句能拆成多条,处理数量、否定和不确定的位置。确认后可以查处理状态,同一次确认只写入一次。 |
|
| R06 | 批量草稿 | 同一句能拆成多条,处理数量、否定和不确定的位置。核对时可选、可清除或留空位置。确认后可以查处理状态,同一次确认只写入一次。 |
|
||||||
| R07 | 模型状态 | 模型待配置或不可用时显示对应状态,原始输入保留,可继续手工录入。云端调用由用户选择。 |
|
| R07 | 模型状态 | 模型待配置或不可用时显示对应状态,原始输入保留,可继续手工录入。云端调用由用户选择。 |
|
||||||
| R08 | 收藏和评分 | 可收藏、评 1–5 星或写短评,支持修改和清除。每件物品的个人评价按用户独立保存。 |
|
| R08 | 收藏和评分 | 可收藏、评 1–5 星或写短评,支持修改和清除。每件物品的个人评价按用户独立保存。 |
|
||||||
| R09 | 物品和位置照片 | 选择照片并在上传前剪裁,每件最多六张。列表加载缩略图,详情可看大图。查看权限与物品一致,删除图片、物品或空间后同步登记两份文件的清理。 |
|
| R09 | 物品和位置照片 | 选择照片并在上传前剪裁,每件最多六张。列表加载缩略图,详情可看大图。查看权限与物品一致,删除图片、物品或空间后同步登记两份文件的清理。 |
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,10 @@ R01–R10 对应[需求与验收](../product/requirements.md)。实现和当前
|
||||||
| TC-35 位置层级与个人图标 | R02、R09 | 建空间下五级位置。两个账号为同一个位置分别选择照片和预设图标。随后删除被选中的照片。 | 前三级与内层分组清楚。两人分别看到自己的设置。照片删除后,使用该照片的账号恢复空间默认,另一账号的图标保留。 |
|
| TC-35 位置层级与个人图标 | R02、R09 | 建空间下五级位置。两个账号为同一个位置分别选择照片和预设图标。随后删除被选中的照片。 | 前三级与内层分组清楚。两人分别看到自己的设置。照片删除后,使用该照片的账号恢复空间默认,另一账号的图标保留。 |
|
||||||
| TC-36 社区发布与搜索 | R10 | 新建物品后用另一账号搜索。所有者填写公开标题和描述后发布,分别搜索公开标题和私人位置名。 | 新建物品私有。发布后其他已登录账号可读,完整标题优先。家里的位置、物品记录和照片不随分享公开。 |
|
| TC-36 社区发布与搜索 | R10 | 新建物品后用另一账号搜索。所有者填写公开标题和描述后发布,分别搜索公开标题和私人位置名。 | 新建物品私有。发布后其他已登录账号可读,完整标题优先。家里的位置、物品记录和照片不随分享公开。 |
|
||||||
| TC-37 社区互动与撤回 | R10 | 连续修改评分、发表和删除自己的评论。撤回分享,再重新发布并归档源物品。 | 同一账号在同一个帖子只计一次评分。撤回后原地址失效,重新发布没有旧互动,物品归档后新地址失效。 |
|
| TC-37 社区互动与撤回 | R10 | 连续修改评分、发表和删除自己的评论。撤回分享,再重新发布并归档源物品。 | 同一账号在同一个帖子只计一次评分。撤回后原地址失效,重新发布没有旧互动,物品归档后新地址失效。 |
|
||||||
| TC-38 iOS 录入导航 | R03、R06 | 打开「位置」后点「录入物品」并返回。再进入一个房间,点「在这里录入」,打开手动添加。切到只读成员后检查入口。 | 底栏四项。录入从位置页进入,房间录入预填当前存放位置。只读成员无录入入口。 |
|
| TC-38 iOS 录入导航 | R03、R06 | 点底栏中央加号并返回。空空间从「找物」点「添加物品」。再进入一个房间,点「在这里录入」,打开手动添加。切到只读成员后检查入口。 | 四个导航项,中间是录入加号。三个入口打开同一页,房间录入预填当前存放位置。只读成员无录入入口。 |
|
||||||
| TC-39 iOS 首屏和后台刷新 | 质量 | 登录后打开找物、位置与社区,来回切换,分别保留有内容和空列表。断网重进,再恢复网络并下拉刷新。 | 有快照时保留已显示的列表。刷新失败可以重试,恢复后更新数据。搜索词不同的结果不混用。 |
|
| TC-39 iOS 首屏和后台刷新 | 质量 | 登录后打开找物、位置与社区,来回切换,分别保留有内容和空列表。断网重进,再恢复网络并下拉刷新。 | 有快照时保留已显示的列表。刷新失败可以重试,恢复后更新数据。搜索词不同的结果不混用。 |
|
||||||
| TC-40 iOS 会话缓存隔离 | R01 | 加载空间 A 的数据,切到空间 B,再退出并换另一个账号。 | 家庭数据按所在空间读取,旧账号的内存快照已经清除。 |
|
| TC-40 iOS 会话缓存隔离 | R01 | 加载空间 A 的数据,切到空间 B,再退出并换另一个账号。 | 家庭数据按所在空间读取,旧账号的内存快照已经清除。 |
|
||||||
|
| TC-41 无位置物品 | R03、R06 | 手动保存留空位置的物品。智能草稿中同时保存一件有位置和一件无位置的物品。按名称找物,并对无位置的物品设置、清除位置。 | 物品均可保存和搜索。位置调整保留历史,旧版本请求返回冲突。 |
|
||||||
|
| TC-42 智能匹配位置 | R06 | 在两个房间建同名抽屉。分别录入明确路径、同名抽屉和没有提位置的描述。在草稿里点叉号。 | 完整路径优先,同名只在当前房间唯一时预选。没提位置时使用当前房间。清除后仍能保存。 |
|
||||||
|
|
||||||
[测试与演示计划](plan.md)
|
[测试与演示计划](plan.md)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
- [iOS 整体方向稿](ios/design-overview.png) · [原生登录页设计稿](ios/native-sign-in.png) · [iOS 设计与交互](ios-welcome.md)
|
- [iOS 整体方向稿](ios/design-overview.png) · [原生登录页设计稿](ios/native-sign-in.png) · [iOS 设计与交互](ios-welcome.md)
|
||||||
- [低保真原型](wireframes.md) · [产品需求](../product/requirements.md) · [测试用例](../testing/cases.md)
|
- [低保真原型](wireframes.md) · [产品需求](../product/requirements.md) · [测试用例](../testing/cases.md)
|
||||||
|
|
||||||
找物列表采用小图和完整位置路径,柜子、收纳盒等末级位置加重显示。PC 左侧保留位置树,查看和移位可以在当前物品的详情里开始。草稿把待处理的内容放到最前面,用户仍可展开原话核对。iOS 将「录入物品」放在位置页顶部。进入房间或子位置后,入口改为「在这里录入」。待确认、可录入和跳过都用文字标明。
|
找物列表采用小图和完整位置路径,柜子、收纳盒等末级位置加重显示。PC 左侧保留位置树,查看和移位可以在当前物品的详情里开始。草稿把待处理的内容放到最前面,用户仍可展开原话核对。iOS 在四个导航项之间放独立的蓝色加号,打开同一个录入页面。进入房间或子位置后,「在这里录入」会附上当前位置。待确认、可录入和跳过都用文字标明。
|
||||||
|
|
||||||
深蓝用于导航,亮蓝用于主操作和选中状态,琥珀色用于待确认。管理后台沿用动作和状态颜色,表格根据实际字段定密度。可编辑稿由 [HTML](concept.html)、[样式](concept.css) 和[物品示例图](assets/item-catalog.png)组成。
|
深蓝用于导航,亮蓝用于主操作和选中状态,琥珀色用于待确认。管理后台沿用动作和状态颜色,表格根据实际字段定密度。可编辑稿由 [HTML](concept.html)、[样式](concept.css) 和[物品示例图](assets/item-catalog.png)组成。
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue