feat(ios): 精简空间切换并支持分级选位置
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
60131fac58
commit
5a805cf89f
|
|
@ -117,7 +117,7 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 8;
|
||||
CURRENT_PROJECT_VERSION = 9;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com";
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 8;
|
||||
CURRENT_PROJECT_VERSION = 9;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com";
|
||||
|
|
|
|||
|
|
@ -120,19 +120,6 @@ struct MoveEditor: View {
|
|||
}
|
||||
}
|
||||
|
||||
struct LocationPicker: View {
|
||||
let store: InventoryStore
|
||||
@Binding var selection: UUID?
|
||||
|
||||
var body: some View {
|
||||
Picker("位置", selection: $selection) {
|
||||
Text("请选择").tag(nil as UUID?)
|
||||
ForEach(store.locations) { location in Text(location.path).tag(Optional(location.id)) }
|
||||
}
|
||||
.pickerStyle(.navigationLink)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func dismissibleKeyboard(active: Bool, action: @escaping () -> Void) -> some View {
|
||||
scrollDismissesKeyboard(.interactively)
|
||||
|
|
|
|||
|
|
@ -111,10 +111,9 @@ struct IntakeView: View {
|
|||
if let hint = candidate.location, !hint.isEmpty {
|
||||
Text("原话位置:\(hint)").font(.footnote).foregroundStyle(.secondary)
|
||||
}
|
||||
Picker("存放位置", selection: Binding(get: { selections[index] }, set: { selections[index] = $0 })) {
|
||||
Text("未选择").tag(nil as UUID?)
|
||||
ForEach(store.locations) { place in Text(place.path).tag(Optional(place.id)) }
|
||||
}
|
||||
LocationPicker(store: store,
|
||||
selection: Binding(get: { selections[index] }, set: { selections[index] = $0 }),
|
||||
title: "存放位置", allowsClearing: true)
|
||||
}.disabled(operation != nil)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,69 @@ import SwiftUI
|
|||
|
||||
struct InventoryView: View {
|
||||
let store: InventoryStore
|
||||
let switcher: SpaceMenu.Actions
|
||||
|
||||
var body: some View {
|
||||
NavigationStack { ItemListView(store: store) }
|
||||
NavigationStack {
|
||||
ItemListView(store: store)
|
||||
.toolbar {
|
||||
if #available(iOS 26.0, *) {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
SpaceMenu(current: store.space, actions: switcher)
|
||||
}
|
||||
.sharedBackgroundVisibility(.hidden)
|
||||
} else {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
SpaceMenu(current: store.space, actions: switcher)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SpaceMenu: View {
|
||||
struct Actions {
|
||||
let spaces: [Space]
|
||||
let select: (Space) -> Void
|
||||
let manage: () -> Void
|
||||
}
|
||||
|
||||
let current: Space
|
||||
let actions: Actions
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
Section("切换空间") {
|
||||
ForEach(actions.spaces) { space in
|
||||
Button {
|
||||
if space.id != current.id { actions.select(space) }
|
||||
} label: {
|
||||
if space.id == current.id {
|
||||
Label(space.name, systemImage: "checkmark")
|
||||
} else {
|
||||
Text(space.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Button(action: actions.manage) {
|
||||
Label("我的空间", systemImage: "house")
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 4) {
|
||||
Text(current.name)
|
||||
.font(.subheadline.weight(.medium))
|
||||
.lineLimit(1)
|
||||
.frame(maxWidth: 94, alignment: .trailing)
|
||||
Image(systemName: "chevron.down")
|
||||
.font(.caption2.weight(.semibold))
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
.foregroundStyle(Color.atlasBlue)
|
||||
}
|
||||
.accessibilityLabel("切换空间")
|
||||
.accessibilityValue(current.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,13 +103,6 @@ struct ItemListView: View {
|
|||
}
|
||||
.navigationTitle(favoritesOnly ? "我的收藏" : "找物")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Text(store.space.name).font(.caption).foregroundStyle(.secondary)
|
||||
.lineLimit(1).frame(maxWidth: 108, alignment: .trailing)
|
||||
.accessibilityLabel("当前空间:\(store.space.name)")
|
||||
}
|
||||
}
|
||||
.task(id: results.loadID(query: query, revision: store.revision)) {
|
||||
await results.load(store: store, query: query, favorites: favoritesOnly)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ private struct SpacesView: View {
|
|||
var body: some View {
|
||||
Group {
|
||||
if let selected {
|
||||
SpaceTabs(account: account, space: selected, openSpaces: { self.selected = nil })
|
||||
SpaceTabs(account: account, space: selected, spaces: spaces, selectSpace: select,
|
||||
openSpaces: { self.selected = nil })
|
||||
.id(selected)
|
||||
} else {
|
||||
NavigationStack {
|
||||
|
|
@ -64,7 +65,7 @@ private struct SpacesView: View {
|
|||
}
|
||||
}
|
||||
ForEach(spaces) { space in
|
||||
Button { selected = space } label: { Label(space.name, systemImage: "house") }
|
||||
Button { select(space) } label: { Label(space.name, systemImage: "house") }
|
||||
}
|
||||
Button("新建空间") { showingCreate = true }.disabled(!loaded)
|
||||
}
|
||||
|
|
@ -82,16 +83,25 @@ private struct SpacesView: View {
|
|||
NavigationStack { MyView(account: account, openSpaces: { showingMyProfile = false }) }
|
||||
}
|
||||
.sheet(isPresented: $showingCreate) {
|
||||
SpaceEditor(account: account, joining: false) { selected = $0 }
|
||||
SpaceEditor(account: account, joining: false, saved: select)
|
||||
}
|
||||
.sheet(isPresented: $showingJoin) {
|
||||
SpaceEditor(account: account, joining: true) { selected = $0 }
|
||||
SpaceEditor(account: account, joining: true, saved: select)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func select(_ space: Space) {
|
||||
if let index = spaces.firstIndex(where: { $0.id == space.id }) {
|
||||
spaces[index] = space
|
||||
} else {
|
||||
spaces.append(space)
|
||||
}
|
||||
selected = space
|
||||
}
|
||||
|
||||
private func load(chooseSingle: Bool = false) async {
|
||||
do {
|
||||
let bytes = try await account.request("/api/households")
|
||||
|
|
@ -117,8 +127,7 @@ private struct SpacesView: View {
|
|||
if accepting {
|
||||
let response = try await account.request(path + "/accept", method: "POST")
|
||||
let space = try JSONDecoder().decode(Space.self, from: response)
|
||||
if !spaces.contains(where: { $0.id == space.id }) { spaces.append(space) }
|
||||
selected = space
|
||||
select(space)
|
||||
} else {
|
||||
_ = try await account.request(path, method: "DELETE")
|
||||
}
|
||||
|
|
@ -129,16 +138,19 @@ private struct SpacesView: View {
|
|||
|
||||
private struct SpaceTabs: View {
|
||||
@State private var store: InventoryStore
|
||||
let switcher: SpaceMenu.Actions
|
||||
let openSpaces: () -> Void
|
||||
|
||||
init(account: AtlasAccount, space: Space, openSpaces: @escaping () -> Void) {
|
||||
init(account: AtlasAccount, space: Space, spaces: [Space], selectSpace: @escaping (Space) -> Void,
|
||||
openSpaces: @escaping () -> Void) {
|
||||
_store = State(initialValue: InventoryStore(account: account, space: space))
|
||||
switcher = SpaceMenu.Actions(spaces: spaces, select: selectSpace, manage: openSpaces)
|
||||
self.openSpaces = openSpaces
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
TabView {
|
||||
InventoryView(store: store).tabItem { Label("找物", systemImage: "magnifyingglass") }
|
||||
InventoryView(store: store, switcher: switcher).tabItem { Label("找物", systemImage: "magnifyingglass") }
|
||||
LocationView(store: store).tabItem { Label("位置", systemImage: "square.stack") }
|
||||
IntakeView(store: store).tabItem { Label("录入", systemImage: "square.and.pencil") }
|
||||
NavigationStack {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,177 @@
|
|||
import SwiftUI
|
||||
|
||||
struct LocationPicker: View {
|
||||
let store: InventoryStore
|
||||
@Binding var selection: UUID?
|
||||
var title = "位置"
|
||||
var allowsClearing = false
|
||||
@State private var showingPicker = false
|
||||
|
||||
var body: some View {
|
||||
let path = store.locations.first { $0.id == selection }?.path
|
||||
Button { showingPicker = true } label: {
|
||||
HStack(spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title).foregroundStyle(.primary)
|
||||
Text(path ?? "请选择").font(.subheadline).foregroundStyle(.secondary)
|
||||
}
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.footnote.weight(.semibold))
|
||||
.foregroundStyle(.tertiary)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel(title)
|
||||
.accessibilityValue(path ?? "未选择")
|
||||
.sheet(isPresented: $showingPicker) {
|
||||
LocationSelection(places: store.locations, selected: selection, allowsClearing: allowsClearing) { chosen in
|
||||
selection = chosen
|
||||
showingPicker = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LocationTree {
|
||||
private let places: [Place]
|
||||
private let byParent: [UUID?: [Place]]
|
||||
|
||||
init(_ places: [Place]) {
|
||||
self.places = places
|
||||
byParent = Dictionary(grouping: places, by: \.parentId)
|
||||
}
|
||||
|
||||
var isEmpty: Bool { places.isEmpty }
|
||||
|
||||
func place(_ id: UUID) -> Place? { places.first { $0.id == id } }
|
||||
|
||||
func children(of parent: UUID?) -> [Place] { byParent[parent] ?? [] }
|
||||
|
||||
func matching(_ query: String) -> [Place] {
|
||||
let words = Self.words(in: query)
|
||||
guard !words.isEmpty else { return [] }
|
||||
return places.filter { place in
|
||||
let pathWords = Self.words(in: place.path)
|
||||
let spacedPath = pathWords.joined(separator: " ")
|
||||
return words.allSatisfy { spacedPath.contains($0) } ||
|
||||
pathWords.joined().contains(words.joined())
|
||||
}
|
||||
}
|
||||
|
||||
private static func words(in value: String) -> [String] {
|
||||
value.folding(options: [.caseInsensitive, .widthInsensitive, .diacriticInsensitive], locale: .current)
|
||||
.split { $0.isWhitespace || $0 == "/" }
|
||||
.map(String.init)
|
||||
}
|
||||
}
|
||||
|
||||
struct LocationSelection: View {
|
||||
let places: [Place]
|
||||
let selected: UUID?
|
||||
let allowsClearing: Bool
|
||||
let pick: (UUID?) -> Void
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var query = ""
|
||||
|
||||
var body: some View {
|
||||
let tree = LocationTree(places)
|
||||
NavigationStack {
|
||||
root(tree)
|
||||
.navigationDestination(for: UUID.self) { id in
|
||||
if let parent = tree.place(id) {
|
||||
level(parent, tree: tree)
|
||||
}
|
||||
}
|
||||
.navigationTitle("选择位置")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always),
|
||||
prompt: "搜位置或完整路径")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("取消") { dismiss() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func root(_ tree: LocationTree) -> some View {
|
||||
List {
|
||||
if tree.isEmpty {
|
||||
ContentUnavailableView("还没有位置", systemImage: "folder",
|
||||
description: Text("请先在「位置」里新建一个存放位置。"))
|
||||
} else if query.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
Section("房间和区域") {
|
||||
children(tree.children(of: nil), tree: tree)
|
||||
}
|
||||
} else {
|
||||
let matches = tree.matching(query)
|
||||
if matches.isEmpty {
|
||||
ContentUnavailableView.search(text: query)
|
||||
} else {
|
||||
ForEach(matches) { place in
|
||||
choice(place, showsPath: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
if allowsClearing && selected != nil {
|
||||
Button("清除位置选择") { pick(nil) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func level(_ parent: Place, tree: LocationTree) -> some View {
|
||||
List {
|
||||
Section {
|
||||
Button { pick(parent.id) } label: {
|
||||
row("选这个位置", detail: parent.path, symbol: "location",
|
||||
checked: selected == parent.id)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
Section("子位置") {
|
||||
children(tree.children(of: parent.id), tree: tree)
|
||||
}
|
||||
}
|
||||
.navigationTitle(parent.name)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
|
||||
private func children(_ places: [Place], tree: LocationTree) -> some View {
|
||||
ForEach(places) { place in
|
||||
if tree.children(of: place.id).isEmpty {
|
||||
choice(place)
|
||||
} else {
|
||||
NavigationLink(value: place.id) {
|
||||
row(place.name, detail: nil, symbol: "folder", checked: selected == place.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func choice(_ place: Place, showsPath: Bool = false) -> some View {
|
||||
Button { pick(place.id) } label: {
|
||||
row(place.name, detail: showsPath ? place.path : nil, symbol: "folder",
|
||||
checked: selected == place.id)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private func row(_ title: String, detail: String?, symbol: String, checked: Bool) -> some View {
|
||||
HStack(spacing: 11) {
|
||||
Image(systemName: symbol).foregroundStyle(Color.atlasBlue).accessibilityHidden(true)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title).foregroundStyle(.primary)
|
||||
if let detail { Text(detail).font(.footnote).foregroundStyle(.secondary) }
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
if checked {
|
||||
Image(systemName: "checkmark").foregroundStyle(Color.atlasBlue).accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.accessibilityAddTraits(checked ? .isSelected : [])
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,14 @@
|
|||
|
||||
找物、位置、录入、我的使用同一套紧凑导航栏。录入页右上角的问号保留四步说明。
|
||||
|
||||
找物页右上角显示当前空间。点开可看到可访问的空间和当前选中项,也可以进入完整的「我的空间」列表。
|
||||
|
||||
## 选存放位置
|
||||
|
||||
录音草稿、手动添加和移位使用同一个位置选择页。从房间或区域开始,逐层进入柜子、抽屉或收纳盒。房间和柜子本身也能作为存放位置,在对应页面点「选这个位置」。
|
||||
|
||||
知道位置名称时可以直接搜索。结果显示完整路径,两个同名收纳盒也能区分。选中后把这条路径带回表单,等用户保存物品或确认移位。录音草稿支持清除某件物品的位置选择。
|
||||
|
||||
## 家庭邀请
|
||||
|
||||
空间所有者输入对方的见物账号并选择角色。对方在「我的空间」看到邀请,接受后才获得访问权限。单独用手机号查找需要可验证的手机号和防枚举机制,首版按用户已知的见物账号精确发送。现有码仍可兑换。
|
||||
|
|
|
|||
|
|
@ -33,5 +33,7 @@ R01–R09 对应[需求与验收](../product/requirements.md)。实现和当前
|
|||
| TC-27 停顿与录音时长 | R06 | 点按开始,说一句后停两秒再说另一句。分别测试手动结束、录满 25 秒和按住说后松手。 | 两句都在转写中,录音进度显示用时。手动结束、松手或时长达到上限后结束采集。 |
|
||||
| TC-28 我的和账号资料 | R01 | 已登录打开「我的」,编辑头像、昵称、签名。重新打开后再用另一个账号查看资料。 | 资料随账号保存,默认头像可用,两个账号互相独立。没有空间时可从空间列表打开资料。 |
|
||||
| TC-29 我的收藏 | R08 | 从「我的」进入收藏,检查空状态。收藏一件物品后再次进入,再切换空间,模拟一次加载失败并重试。 | 空、有内容和加载失败各有状态。当前空间的个人收藏在列表显示,失败后可重试。 |
|
||||
| TC-30 找物页切换空间 | R01 | 用有多个空间的账号进入找物,点右上角的空间名。检查选中项,切换另一个空间,再打开「我的空间」。 | 空间名与账号的空间列表一致。只有可访问的空间可选,切换后搜索读取新空间。 |
|
||||
| TC-31 分级选位置 | R02 | 建两个带同名收纳盒的分支,其中一个有三级。从录音草稿、添加物品和移位分别打开位置选择,逐级找一次,再用完整路径搜索。 | 叶子和上级节点都能选。搜索显示完整路径,选好后返回原表单,取消时保留原选择。 |
|
||||
|
||||
[测试与演示计划](plan.md)
|
||||
|
|
|
|||
Loading…
Reference in New Issue