diff --git a/apps/ios/ItemAtlas.xcodeproj/project.pbxproj b/apps/ios/ItemAtlas.xcodeproj/project.pbxproj index 68e48d3..6647211 100644 --- a/apps/ios/ItemAtlas.xcodeproj/project.pbxproj +++ b/apps/ios/ItemAtlas.xcodeproj/project.pbxproj @@ -117,7 +117,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 26; GENERATE_INFOPLIST_FILE = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com"; @@ -126,7 +126,7 @@ INFOPLIST_KEY_CFBundleDisplayName = "见物"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; - MARKETING_VERSION = 0.1.0; + MARKETING_VERSION = 0.1.26; PRODUCT_BUNDLE_IDENTIFIER = com.tutudog.itematlas; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; @@ -138,7 +138,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 26; GENERATE_INFOPLIST_FILE = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com"; @@ -147,7 +147,7 @@ INFOPLIST_KEY_CFBundleDisplayName = "见物"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; - MARKETING_VERSION = 0.1.0; + MARKETING_VERSION = 0.1.26; PRODUCT_BUNDLE_IDENTIFIER = com.tutudog.itematlas; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; diff --git a/apps/ios/ItemAtlas/LocationFloorDrawing.swift b/apps/ios/ItemAtlas/LocationFloorDrawing.swift index b5be734..55067c4 100644 --- a/apps/ios/ItemAtlas/LocationFloorDrawing.swift +++ b/apps/ios/ItemAtlas/LocationFloorDrawing.swift @@ -244,6 +244,7 @@ private struct PlanTile: View { .accessibilityAction { open() } } else if let open { Button(action: open) { tile }.buttonStyle(.plain) + .accessibilityAddTraits(selected ? .isSelected : []) } else { tile .accessibilityElement(children: .ignore) diff --git a/apps/ios/ItemAtlas/LocationPicker.swift b/apps/ios/ItemAtlas/LocationPicker.swift index 26bfced..6c7dfbe 100644 --- a/apps/ios/ItemAtlas/LocationPicker.swift +++ b/apps/ios/ItemAtlas/LocationPicker.swift @@ -42,7 +42,7 @@ struct LocationPicker: View { } } .sheet(isPresented: $showingPicker) { - LocationSelection(store: store, places: store.locations, selected: selection, allowsClearing: allowsClearing) { chosen in + LocationSelection(store: store, selected: selection, allowsClearing: allowsClearing) { chosen in selection = chosen showingPicker = false } @@ -83,9 +83,13 @@ struct LocationTree { } } +enum LocationSelectionDestination: Hashable { + case plan(UUID?) + case level(UUID) +} + struct LocationSelection: View { let store: InventoryStore - let places: [Place] let selected: UUID? let allowsClearing: Bool let pick: (UUID?) -> Void @@ -93,13 +97,11 @@ struct LocationSelection: View { @State private var query = "" var body: some View { - let tree = LocationTree(places) + let tree = LocationTree(store.locations) NavigationStack { root(tree) - .navigationDestination(for: UUID.self) { id in - if let parent = tree.place(id) { - level(parent, tree: tree) - } + .navigationDestination(for: LocationSelectionDestination.self) { route in + destination(route, tree: tree) } .navigationTitle("选择位置") .navigationBarTitleDisplayMode(.inline) @@ -113,12 +115,41 @@ struct LocationSelection: View { } } + @ViewBuilder private func destination(_ route: LocationSelectionDestination, tree: LocationTree) -> some View { + switch route { + case .plan(nil): + LocationPlanPicker(store: store, parent: nil, selected: selected, pick: pick) + case .plan(let id?): + if let parent = tree.place(id) { + LocationPlanPicker(store: store, parent: parent, selected: selected, pick: pick) + } else { + unavailable + } + case .level(let id): + if let parent = tree.place(id) { + level(parent, tree: tree) + } else { + unavailable + } + } + } + + private var unavailable: some View { + ContentUnavailableView("位置不可用", systemImage: "location.slash", + description: Text("请返回后重新选择。")) + } + private func root(_ tree: LocationTree) -> some View { List { if tree.isEmpty { ContentUnavailableView("还没有位置", systemImage: "folder", description: Text("请先在「位置」里新建一个存放位置。")) } else if query.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + Section { + NavigationLink(value: LocationSelectionDestination.plan(nil)) { + Label("从平面图选择", systemImage: "map") + } + } Section { children(tree.children(of: nil), tree: tree) } header: { @@ -164,7 +195,7 @@ struct LocationSelection: View { if tree.children(of: place.id).isEmpty { choice(place) } else { - NavigationLink(value: place.id) { + NavigationLink(value: LocationSelectionDestination.level(place.id)) { row(place.name, detail: nil, place: place, checked: selected == place.id) } } diff --git a/apps/ios/ItemAtlas/LocationPlanPicker.swift b/apps/ios/ItemAtlas/LocationPlanPicker.swift new file mode 100644 index 0000000..002653a --- /dev/null +++ b/apps/ios/ItemAtlas/LocationPlanPicker.swift @@ -0,0 +1,162 @@ +import SwiftUI + +struct LocationPlanPicker: View { + let store: InventoryStore + let parent: Place? + let pick: (UUID?) -> Void + @State private var focusID: UUID? + @State private var snapshot: LocationLayoutSnapshot? + @State private var error: String? + @State private var unavailable = false + @State private var attempt = 0 + + init(store: InventoryStore, parent: Place?, selected: UUID?, pick: @escaping (UUID?) -> Void) { + self.store = store + self.parent = parent + self.pick = pick + let route = selected.flatMap { ItemLocationPlanRoute(locationID: $0, locations: store.locations) } + _focusID = State(initialValue: route?.layers.first { $0.parent?.id == parent?.id }?.marker.id) + } + + private var choices: [Place] { + Place.displayOrder(store.locations.filter { $0.parentId == parent?.id }) + } + + private var placed: [LayoutLocation] { + let choiceIDs = Set(choices.map(\.id)) + return snapshot?.locations.filter { $0.geometry != nil && choiceIDs.contains($0.id) } ?? [] + } + + private var canChoose: Bool { !store.locationAccessLost && !unavailable } + + var body: some View { + GeometryReader { viewport in + List { + Section { + canvas(height: max(250, viewport.size.height * 0.55)) + } header: { + Text(parent?.path ?? store.space.name) + .textCase(nil) + } + if canChoose && !choices.isEmpty { + let placedIDs = Set(placed.map(\.id)) + Section("位置列表") { + ForEach(choices) { place in + row(place, offPlan: snapshot != nil && !placedIDs.contains(place.id)) + } + } + } + } + .safeAreaInset(edge: .bottom, spacing: 0) { + if canChoose, let focus = choices.first(where: { $0.id == focusID }) { + selectionPanel(focus) + } + } + } + .navigationTitle(parent == nil ? "从平面图选择" : "选择室内位置") + .navigationBarTitleDisplayMode(.inline) + .task(id: [store.revision, attempt]) { await load(refresh: attempt > 0) } + } + + @ViewBuilder private func canvas(height: CGFloat) -> some View { + if let error { + VStack(alignment: .leading, spacing: 8) { + Text(error).font(.subheadline).foregroundStyle(.secondary) + Button("重新读取平面图") { attempt += 1 } + } + } else if let snapshot { + if placed.isEmpty { + Text(choices.isEmpty ? "这里还没有下级位置。" : "这张图还没摆放位置,可以在下面选择。") + .font(.subheadline).foregroundStyle(.secondary) + } else { + LocationPlanCanvas(width: snapshot.widthMm, depth: snapshot.depthMm, locations: placed, + selected: focusID, editing: false, open: { focusID = $0 }, expanded: true) + .frame(height: height) + .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) + .listRowBackground(Color.clear) + } + } else { + ProgressView("正在读取平面图") + } + } + + private func row(_ place: Place, offPlan: Bool) -> some View { + Button { focusID = place.id } label: { + HStack(spacing: 11) { + LocationMark(store: store, place: place) + VStack(alignment: .leading, spacing: 3) { + Text(place.name).foregroundStyle(.primary) + if offPlan { + Text("未摆放在图中").font(.caption).foregroundStyle(.secondary) + } + } + Spacer() + if focusID == place.id { + Image(systemName: "checkmark") + .foregroundStyle(Color.atlasBlue) + .accessibilityHidden(true) + } + } + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .accessibilityAddTraits(focusID == place.id ? .isSelected : []) + } + + private func selectionPanel(_ place: Place) -> some View { + VStack(alignment: .leading, spacing: 10) { + Label(place.path, systemImage: "location.fill") + .font(.subheadline.weight(.semibold)) + .foregroundStyle(Color.atlasBlue) + Button { + pick(place.id) + } label: { + Text("选这个位置").frame(maxWidth: .infinity, minHeight: 30) + } + .buttonStyle(.borderedProminent) + .tint(Color.atlasBlue) + if store.locations.contains(where: { $0.parentId == place.id }) { + if parent == nil { + NavigationLink(value: LocationSelectionDestination.plan(place.id)) { + Text("查看室内位置").frame(maxWidth: .infinity, minHeight: 30) + } + .buttonStyle(.bordered) + } else { + NavigationLink(value: LocationSelectionDestination.level(place.id)) { + Text("查看下级位置").frame(maxWidth: .infinity, minHeight: 30) + } + .buttonStyle(.bordered) + } + } + } + .padding(.horizontal, 16) + .padding(.vertical, 10) + .background(.regularMaterial) + } + + private func load(refresh: Bool) async { + let revision = store.revision + error = nil + do { + try await store.refreshLocations(refresh: refresh) + guard !Task.isCancelled, revision == store.revision else { return } + if let parent, !store.locations.contains(where: { $0.id == parent.id && $0.parentId == nil }) { + snapshot = nil + unavailable = true + error = "这个位置可能已被移除,请返回后重新选择。" + return + } + let layout = try await store.locationLayout(parent: parent?.id, refresh: refresh) + guard !Task.isCancelled, revision == store.revision else { return } + snapshot = layout + unavailable = false + } catch is CancellationError { + } catch where !Task.isCancelled && revision == store.revision { + if (error as? AtlasError)?.resourceUnavailable == true { + snapshot = nil + unavailable = true + } + self.error = error.localizedDescription + } catch {} + } +} diff --git a/docs/product/ios-experience.md b/docs/product/ios-experience.md index 5fcfabe..5675b4b 100644 --- a/docs/product/ios-experience.md +++ b/docs/product/ios-experience.md @@ -48,6 +48,8 @@ 知道位置名称时可以直接搜索。结果显示完整路径,两个同名收纳盒也能区分。选中后把这条路径带回表单,等用户保存物品或确认移位。这三处都可以用位置旁的叉号清除选择。 +也可以点「从平面图选择」。点图上的房间或家具,底部显示完整路径,可选当前位置或继续查看室内和更深的子位置。图下方的位置列表也包括还没摆到图上的位置。 + ## 家庭邀请 空间所有者输入对方的见物账号并选择角色。对方在「我的空间」看到邀请,接受后才获得访问权限。单独用手机号查找需要可验证的手机号和防枚举机制,首版按用户已知的见物账号精确发送。现有码仍可兑换。 diff --git a/docs/testing/cases.md b/docs/testing/cases.md index ff0248f..38c3dcc 100644 --- a/docs/testing/cases.md +++ b/docs/testing/cases.md @@ -60,5 +60,6 @@ R01–R10 对应[需求与验收](../product/requirements.md)。实现和当前 | TC-49 AI 布局草稿 | R07、R12 | 用语音或文字描述新增区域、移动家具及有歧义的同名位置。核对后应用,同一请求重复提交。模拟模型不可用。 | 预览标出变化及待确认的条目。确认后布局原子更新,重复提交不会创建重复位置。模型不可用时原话仍可编辑,手动布局可继续。 | | TC-50 iOS 全屏平面图编辑 | R11、R12 | 依次添加模型、拖向另一处位置边线、拉角缩放,再用「撤回」和「重做」检查。应用 AI 草稿后点「放弃」,重新打开平面图。最后从四个底栏页面各返回一次。 | 画布占满工具栏间空间,吸附时出现辅助线。撤回包括新增位置,重做恢复同一步。放弃后原平面图和位置列表保持不变,底栏顶部无透底的缝。 | | TC-51 从物品查看平面图 | R04、R11 | 把一件物品放进「主卧 / 衣柜 / 抽屉」。从找物进详情,点「在平面图中查看」。依次取消衣柜和主卧在图上的摆放,下拉刷新。再用只读成员查看,并检查无位置的物品。 | 优先标出室内图的衣柜,回退时标出空间图的主卧,两处都未摆放时显示提示。完整存放路径始终可见。只读成员能查看,无位置的物品没有平面图入口。 | +| TC-52 从平面图选存放位置 | R03、R06、R11 | 在手动添加、智能草稿或移位中打开位置选择,点「从平面图选择」。点房间,进入室内位置,再从家具进入抽屉。另选一次没有摆在图上的位置,并取消一次选择。 | 标记和底部路径随点选更新。可直接选房间或家具,也可进入抽屉。未摆放位置可从列表选。选中只回填表单,取消保留原位置。 | [测试与演示计划](plan.md)