feat(ios): 将录音和确认保存移到底部
continuous-integration/drone/push Build is passing Details

This commit is contained in:
dongjf 2026-11-27 10:26:03 +08:00
parent 9181ac766d
commit cbcd5d7b8d
4 changed files with 117 additions and 66 deletions

View File

@ -117,7 +117,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20; CURRENT_PROJECT_VERSION = 21;
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 = 20; CURRENT_PROJECT_VERSION = 21;
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";

View File

@ -14,6 +14,7 @@ struct IntakeView: View {
@State private var selections: [Int: UUID] = [:] @State private var selections: [Int: UUID] = [:]
@State private var operation: Operation? @State private var operation: Operation?
@State private var busy = false @State private var busy = false
@State private var supplementing = false
@State private var showingAdd = false @State private var showingAdd = false
@State private var error: String? @State private var error: String?
@State private var showingHelp = false @State private var showingHelp = false
@ -43,6 +44,8 @@ struct IntakeView: View {
!text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
} }
private var canReview: Bool { draft?.candidates.contains { $0.action != "SKIP" } == true }
var body: some View { var body: some View {
if let onReturnToChooser { if let onReturnToChooser {
if showingAdd { if showingAdd {
@ -69,11 +72,12 @@ struct IntakeView: View {
.font(.subheadline).foregroundStyle(.secondary) .font(.subheadline).foregroundStyle(.secondary)
.accessibilityLabel("默认位置," + initialLocation.path) .accessibilityLabel("默认位置," + initialLocation.path)
} }
smartCard if operation == nil {
manualEntry inputCard.id("intake.original")
if voice.phase == .idle && operation == nil { if let draft, !supplementing, voice.phase == .idle {
inputCard reviewCard(draft).id(draft.id)
if let draft { reviewCard(draft).id(draft.id) } }
if voice.phase == .idle && !supplementing { manualEntry }
} }
if let operation { operationCard(operation) } if let operation { operationCard(operation) }
if let error { Text(error).font(.callout).foregroundStyle(.red) } if let error { Text(error).font(.callout).foregroundStyle(.red) }
@ -83,11 +87,16 @@ struct IntakeView: View {
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
} }
.onChange(of: draft?.id) { _, id in .onChange(of: draft?.id) { _, id in
if let id { withAnimation { scroll.scrollTo(id, anchor: .top) } } if let id { withAnimation { scroll.scrollTo(id) } }
}
.onChange(of: supplementing) { _, active in
if active { withAnimation { scroll.scrollTo("intake.original", anchor: .top) } }
} }
} }
.background(Color(uiColor: .systemGroupedBackground)) .background(Color(uiColor: .systemGroupedBackground))
.scrollDismissesKeyboard(.interactively) .safeAreaInset(edge: .bottom, spacing: 0) {
if !typing && operation == nil { bottomBar }
}
.dismissibleKeyboard(active: typing) { typing = false } .dismissibleKeyboard(active: typing) { typing = false }
.navigationTitle("录入物品") .navigationTitle("录入物品")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
@ -97,9 +106,18 @@ struct IntakeView: View {
if let onReturnToChooser { onReturnToChooser() } if let onReturnToChooser { onReturnToChooser() }
else { dismiss() } else { dismiss() }
} }
.disabled(busy) .disabled(busy || voice.phase != .idle)
} }
ToolbarItem(placement: .topBarTrailing) { ToolbarItemGroup(placement: .topBarTrailing) {
Menu {
Picker("录音方式", selection: $recordingMode) {
Text("点按开始,再点结束").tag(RecordingMode.tap)
Text("按住说,松手结束").tag(RecordingMode.hold)
}
} label: {
Label("录音设置", systemImage: "slider.horizontal.3")
}
.disabled(voice.phase != .idle)
Button { showingHelp = true } label: { Label("录入说明", systemImage: "questionmark.circle") } Button { showingHelp = true } label: { Label("录入说明", systemImage: "questionmark.circle") }
.disabled(voice.phase != .idle) .disabled(voice.phase != .idle)
} }
@ -114,47 +132,37 @@ struct IntakeView: View {
if operation == nil && draft?.originalText != updated { if operation == nil && draft?.originalText != updated {
draft = nil draft = nil
selections = [:] selections = [:]
supplementing = false
} }
} }
.sheet(isPresented: $showingHelp) { help } .sheet(isPresented: $showingHelp) { help }
} }
private var smartCard: some View { private var bottomBar: some View {
VStack(alignment: .leading, spacing: 12) { VStack(spacing: 8) {
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 { if voice.phase == .recording || voice.phase == .finishing {
ProgressView(value: Double(voice.elapsedSeconds), total: Double(VoiceCapture.maximumDuration)) { ProgressView(value: Double(voice.elapsedSeconds), total: Double(VoiceCapture.maximumDuration)) {
Text("\(voice.elapsedSeconds) / \(VoiceCapture.maximumDuration) 秒") Text("\(voice.elapsedSeconds) / \(VoiceCapture.maximumDuration) 秒")
.font(.caption.monospacedDigit()) .font(.caption.monospacedDigit())
} }
} }
if !voice.transcript.isEmpty { if let draft, canReview, !supplementing, voice.phase == .idle {
Text(voice.transcript).font(.callout) Button { Task { await submit(draft) } } label: {
.frame(maxWidth: .infinity, alignment: .leading) primaryLabel(busy ? "正在保存" : "保存物品", symbol: "checkmark",
color: .atlasBlue, enabled: !busy)
} }
if let error = voice.error { Text(error).font(.footnote).foregroundStyle(.secondary) } .buttonStyle(.plain)
.disabled(busy)
} else {
voiceButton
} }
.padding(16) }
.background(Color.atlasBlue.opacity(0.10), in: .rect(cornerRadius: 20)) .frame(maxWidth: 560)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.frame(maxWidth: .infinity)
.background(.bar)
.overlay(alignment: .top) { Divider() }
} }
private var manualEntry: some View { private var manualEntry: some View {
@ -186,19 +194,39 @@ struct IntakeView: View {
private var inputCard: some View { private var inputCard: some View {
VStack(alignment: .leading, spacing: 10) { VStack(alignment: .leading, spacing: 10) {
HStack {
Text("物品描述").font(.headline).accessibilityAddTraits(.isHeader) Text("物品描述").font(.headline).accessibilityAddTraits(.isHeader)
TextField("录音文字会显示在这里,也可以直接输入", text: $text, axis: .vertical) Spacer()
if supplementing {
Button("取消补录") { supplementing = false }
.disabled(voice.phase != .idle)
} else if draft != nil {
Button("再说一句", action: supplement)
.disabled(busy || typing)
}
}
.font(.subheadline)
if voice.phase == .idle {
TextField("例如:把两根数据线放在书房抽屉", text: $text, axis: .vertical)
.lineLimit(3...7) .lineLimit(3...7)
.focused($typing) .focused($typing)
.accessibilityLabel("物品描述") .accessibilityLabel("物品描述")
.disabled(busy) .disabled(busy)
} else {
let original = [text, voice.transcript].filter { !$0.isEmpty }.joined(separator: "\n")
Text(original.isEmpty ? "听到的文字会显示在这里。" : original)
.foregroundStyle(original.isEmpty ? Color.secondary : Color.primary)
.lineLimit(3...)
.frame(maxWidth: .infinity, alignment: .leading)
}
if text.utf16.count > 4000 { if text.utf16.count > 4000 {
Text("最多 4,000 字,可以分开整理。").font(.footnote).foregroundStyle(.secondary) Text("最多 4,000 字,可以分开整理。").font(.footnote).foregroundStyle(.secondary)
} }
if !text.isEmpty && draft == nil { if !text.isEmpty && draft == nil && !supplementing && voice.phase == .idle {
Button("整理成物品草稿") { typing = false; Task { await parse() } }.disabled(!canParse) Button("整理成物品草稿") { typing = false; Task { await parse() } }.disabled(!canParse)
} }
if busy && draft == nil { ProgressView("正在整理") } if let error = voice.error { Text(error).font(.footnote).foregroundStyle(.secondary) }
if busy && !canReview { ProgressView("正在整理") }
} }
.padding(16) .padding(16)
.background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16)) .background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16))
@ -233,14 +261,6 @@ struct IntakeView: View {
.background(Color(uiColor: .systemGroupedBackground), in: .rect(cornerRadius: 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) .padding(16)
.background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16)) .background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 16))
@ -270,10 +290,10 @@ struct IntakeView: View {
NavigationStack { NavigationStack {
List { List {
Section("智能录入") { Section("智能录入") {
Text("1. 点按开始录音,或者选择按住录音。") Text("1. 在屏幕底部开始录音。右上角可以切换录音方式。")
Text("2. 看到录音状态再说。一次最多 25 秒,可以停顿。") Text("2. 看到录音状态再说。一次最多 25 秒,可以停顿。")
Text("3. 说完松手或再次点按。可以修改转写,也可以直接打字。") Text("3. 说完松手或再次点按。可以修改转写,也可以直接打字。")
Text("4. 核对物品后保存。位置可以调整、清除或留空。") Text("4. 可以再说一句,也可以核对物品后在底部保存。位置可以调整、清除或留空。")
} }
Section("手动添加") { Section("手动添加") {
Text("填写名称就能录入单件物品。需要时再加位置、照片或备注。") Text("填写名称就能录入单件物品。需要时再加位置、照片或备注。")
@ -308,7 +328,9 @@ struct IntakeView: View {
private var recordingTitle: String { private var recordingTitle: String {
switch voice.phase { switch voice.phase {
case .idle: recordingMode == .hold ? "按住说" : "开始录音" case .idle:
if recordingMode == .hold { "按住说" }
else { supplementing ? "开始补录" : "开始录音" }
case .preparing: "麦克风准备中" case .preparing: "麦克风准备中"
case .recording: recordingMode == .hold ? "松手结束" : "结束录音" case .recording: recordingMode == .hold ? "松手结束" : "结束录音"
case .finishing: "正在转写" case .finishing: "正在转写"
@ -316,13 +338,17 @@ struct IntakeView: View {
} }
private var recordingLabel: some View { private var recordingLabel: some View {
Label(recordingTitle, systemImage: voice.phase == .recording ? "waveform" : "mic.fill") primaryLabel(recordingTitle, symbol: voice.phase == .recording ? "waveform" : "mic.fill",
color: voice.phase == .recording ? .atlasNavy : .atlasBlue, enabled: voiceEnabled)
}
private func primaryLabel(_ title: String, symbol: String, color: Color, enabled: Bool) -> some View {
Label(title, systemImage: symbol)
.font(.headline) .font(.headline)
.frame(maxWidth: .infinity, minHeight: 54) .frame(maxWidth: .infinity, minHeight: 54)
.foregroundStyle(.white) .foregroundStyle(.white)
.background(voice.phase == .recording ? Color.atlasNavy : Color.atlasBlue, .background(color, in: .rect(cornerRadius: 14))
in: .rect(cornerRadius: 14)) .opacity(enabled ? 1 : 0.55)
.opacity(voiceEnabled ? 1 : 0.55)
.contentShape(Rectangle()) .contentShape(Rectangle())
} }
@ -330,16 +356,40 @@ struct IntakeView: View {
if voice.phase == .idle { beginRecording() } else { voice.stop() } if voice.phase == .idle { beginRecording() } else { voice.stop() }
} }
private func supplement() {
supplementing = true
if recordingMode == .tap { beginRecording() }
}
private func beginRecording() { private func beginRecording() {
guard voiceEnabled, voice.phase == .idle else { return } guard voiceEnabled, voice.phase == .idle else { return }
typing = false typing = false
voice.start(context: store.locations.map(\.name)) { phrase, complete in voice.start(context: store.locations.map(\.name)) { phrase, complete in
let previous = text.trimmingCharacters(in: .whitespacesAndNewlines) text = transcript(appending: phrase)
text = previous.isEmpty ? phrase : previous + "\n" + phrase supplementing = false
if complete { Task { await parse() } } if complete { Task { await parse() } }
} }
} }
private func transcript(appending phrase: String) -> String {
let previous = text.trimmingCharacters(in: .whitespacesAndNewlines)
guard !previous.isEmpty else { return phrase }
guard !phrase.isEmpty else { return previous }
if supplementing, let draft, draft.candidates.count <= 1, draft.candidates.first?.location == nil,
let verb = ["放在", "放到", "放进", "收进", "放"].first(where: { phrase.hasPrefix($0) }) {
let hint = String(phrase.dropFirst(verb.count)).trimmingCharacters(in: .whitespacesAndNewlines)
let subject = previous.trimmingCharacters(in: CharacterSet(charactersIn: "。.!!"))
// Keep a standalone location with its item so it can still use the single-sentence parser.
if !subject.isEmpty && !hint.isEmpty &&
(verb != "放" || IntakeLocationMatcher.match(hint, locations: store.locations,
defaultID: initialLocation?.id) != nil) {
return subject + (verb == "放" ? "放在" : verb) + hint
}
}
return previous + "\n" + phrase
}
private func parse(source: String = "VOICE") async { private func parse(source: String = "VOICE") async {
guard canParse else { return } guard canParse else { return }
let original = text let original = text

View File

@ -8,9 +8,9 @@
底栏是「找物」「位置」「社区」「我的」。中间的蓝色加号略高于栏面,点开进入「录入物品」,关闭后回到刚才的页面。「找物」空页里的「添加物品」进入同一页。房间和子位置的「在这里录入」会带上当前位置。 底栏是「找物」「位置」「社区」「我的」。中间的蓝色加号略高于栏面,点开进入「录入物品」,关闭后回到刚才的页面。「找物」空页里的「添加物品」进入同一页。房间和子位置的「在这里录入」会带上当前位置。
「智能录入」支持说话或输入文字。录音方式可选点按开始、再点结束,或者按住说、松手结束。看到录音状态再说,每次最多 25 秒,停顿前后的文字会留在同一段。 录音按钮固定在屏幕底部。右上角「录音设置」可切换点按开始、再点结束,或按住说、松手结束。录音用时显示在按钮上方,每次最多 25 秒。边说边看到转写,结束后可以在同一处修改文字。用键盘输入时,底部只显示「收起键盘」。
例如说「记录两根数据线」,草稿可以只有名称和数量。提到的位置会尝试匹配现有路径。原话没有提位置时,可以使用进入录入时带来的当前位置。路径无法确定时留空。位置旁的叉号可以清除,点位置可以改选。核对后才会保存。 例如说「记录两根数据线」,草稿可以只有名称和数量。可以点「再说一句」补充「放在书房抽屉」,文字和草稿会一起更新。提到的位置会尝试匹配现有路径。原话没有提位置时,可以使用进入录入时带来的当前位置。路径无法确定时留空。位置旁的叉号可以清除,点位置可以改选。核对后点底部「保存物品」才会入库。
在「手动添加」可以填写名称、数量、照片和备注。位置是可选项。暂时没放好的物品也能在「找物」里搜到,之后可到详情设置位置。 在「手动添加」可以填写名称、数量、照片和备注。位置是可选项。暂时没放好的物品也能在「找物」里搜到,之后可到详情设置位置。

View File

@ -49,5 +49,6 @@ R01–R10 对应[需求与验收](../product/requirements.md)。实现和当前
| TC-43 导航栏与删除位置 | R02 | 在 iPhone 打开房间详情并滑到列表末尾,再检查四个底栏入口的选中状态。 | 删除位置可完整显示和点击。四个图标的视觉大小一致,当前选中项为实心,中央加号仍进入录入页。 | | TC-43 导航栏与删除位置 | R02 | 在 iPhone 打开房间详情并滑到列表末尾,再检查四个底栏入口的选中状态。 | 删除位置可完整显示和点击。四个图标的视觉大小一致,当前选中项为实心,中央加号仍进入录入页。 |
| TC-44 购入总额和记录数 | R03 | 同一所有者在两个空间并发录入,修改一件物品的数量和单价,发布、撤回并删除物品,再删除其所在空间。用另一账号查自己的概览。 | 每步统计与物品状态一致,已删除物品从金额扣除,超上限单价被拒绝,查询只读取当前账号的汇总。 | | TC-44 购入总额和记录数 | R03 | 同一所有者在两个空间并发录入,修改一件物品的数量和单价,发布、撤回并删除物品,再删除其所在空间。用另一账号查自己的概览。 | 每步统计与物品状态一致,已删除物品从金额扣除,超上限单价被拒绝,查询只读取当前账号的汇总。 |
| TC-45 社区资料和评价 | R08、R10 | 从帖子和评论点进不同作者主页,查公开物品。从已公开物品的详情进入社区评价,改星并发表评论。 | 公开主页只显示昵称、头像和公开物品及数量。个人短评和购入总额仅当前账号可见。 | | TC-45 社区资料和评价 | R08、R10 | 从帖子和评论点进不同作者主页,查公开物品。从已公开物品的详情进入社区评价,改星并发表评论。 | 公开主页只显示昵称、头像和公开物品及数量。个人短评和购入总额仅当前账号可见。 |
| TC-46 iOS 底部录音与补录 | R06 | 单手点底部录音,说「记录两根数据线」,等草稿出现。点「再说一句」补充「放在书房抽屉」。切换按住说再试一次,并测试取消补录、用键盘修改原话。 | 两种录音方式的按钮都在底部,计时位于其上方。转写和修改使用同一区域,补录更新草稿,取消补录保留已有草稿。键盘打开时可收起键盘,核对时底部可保存。 |
[测试与演示计划](plan.md) [测试与演示计划](plan.md)