feat(ios): 从物品详情查看平面图位置
continuous-integration/drone/push Build is passing Details

This commit is contained in:
dongjf 2026-11-28 09:24:31 +08:00
parent d238d5a022
commit 1c6e1e15f9
6 changed files with 205 additions and 7 deletions

View File

@ -117,7 +117,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 25;
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 = 24;
CURRENT_PROJECT_VERSION = 25;
GENERATE_INFOPLIST_FILE = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ATLAS_API_BASE_URL = "https://api-atlas.tutudog.com";

View File

@ -316,6 +316,13 @@ struct ItemDetailView: View {
List {
Section("当前位置") {
Label(item.locationLabel, systemImage: "location.fill").foregroundStyle(Color.atlasBlue)
if item.locationId != nil {
NavigationLink {
ItemLocationPlanView(store: store, item: item)
} label: {
Label("在平面图中查看", systemImage: "map")
}
}
if store.canWrite && detail != nil { Button(item.locationId == nil ? "设置位置" : "移位") { showingMove = true } }
}
Section("物品信息") {

View File

@ -0,0 +1,169 @@
import SwiftUI
struct ItemLocationPlanRoute {
struct Layer {
let parent: Place?
let marker: Place
}
let layers: [Layer]
init?(locationID: UUID, locations: [Place]) {
let locationsByID = Dictionary(locations.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
var visited: Set<UUID> = []
var chain: [Place] = []
var current: UUID? = locationID
while let id = current {
guard visited.insert(id).inserted, let location = locationsByID[id] else { return nil }
chain.append(location)
current = location.parentId
}
guard let root = chain.last else { return nil }
let overview = Layer(parent: nil, marker: root)
// A room plan draws only its immediate children, even when the item is stored deeper.
if let inside = chain.dropLast().last {
layers = [Layer(parent: root, marker: inside), overview]
} else {
layers = [overview]
}
}
}
struct ItemLocationPlanView: View {
let store: InventoryStore
private let itemID: UUID
@State private var item: Item?
@State private var state = ViewState.loading
@State private var requestID = UUID()
private enum ViewState {
case loading
case mapped(ItemLocationPlanRoute.Layer, LocationLayoutSnapshot)
case unplaced
case noLocation
case unavailable
case failed(String)
}
init(store: InventoryStore, item: Item) {
self.store = store
itemID = item.id
_item = State(initialValue: item)
}
var body: some View {
GeometryReader { viewport in
ScrollView {
VStack(alignment: .leading, spacing: 16) {
if let item {
VStack(alignment: .leading, spacing: 6) {
Text(item.name).font(.headline)
Label(item.locationLabel, systemImage: "location.fill")
.font(.subheadline)
.foregroundStyle(Color.atlasBlue)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(16)
.background(Color(uiColor: .secondarySystemGroupedBackground), in: .rect(cornerRadius: 14))
.accessibilityElement(children: .combine)
}
switch state {
case .loading:
ProgressView("正在读取平面图")
.frame(maxWidth: .infinity).padding(.vertical, 36)
case let .mapped(layer, snapshot):
plan(layer, snapshot: snapshot, height: max(280, viewport.size.height * 0.65))
case .unplaced:
ContentUnavailableView("还未摆放到平面图", systemImage: "map",
description: Text("可以按上方的路径找到这件物品。"))
case .noLocation:
ContentUnavailableView("物品暂无位置", systemImage: "location.slash",
description: Text("返回物品详情可以查看或设置位置。"))
case .unavailable:
ContentUnavailableView("位置不可用", systemImage: "location.slash",
description: Text("物品或位置可能已有变动,请返回详情或下拉刷新。"))
case let .failed(message):
ContentUnavailableView {
Label("平面图加载失败", systemImage: "map")
} description: {
Text(message)
} actions: {
Button("重试") { Task { await load(refresh: true) } }
}
}
}
.padding(.horizontal, 16)
.padding(.vertical, 12)
}
.refreshable { await load(refresh: true) }
}
.background(Color(uiColor: .systemGroupedBackground))
.navigationTitle("平面图定位")
.navigationBarTitleDisplayMode(.inline)
.toolbar(.visible, for: .navigationBar)
.task(id: store.revision) { await load() }
}
private func plan(_ layer: ItemLocationPlanRoute.Layer, snapshot: LocationLayoutSnapshot, height: CGFloat) -> some View {
VStack(alignment: .leading, spacing: 8) {
Text(layer.parent.map { "\($0.name)平面图" } ?? "空间平面图")
.font(.headline)
Label("图中标出「\(layer.marker.name)」", systemImage: "mappin.circle.fill")
.font(.subheadline)
.foregroundStyle(Color.atlasBlue)
LocationPlanCanvas(width: snapshot.widthMm, depth: snapshot.depthMm,
locations: snapshot.locations.filter { $0.geometry != nil },
selected: layer.marker.id, editing: false, open: nil, expanded: true)
.frame(height: height)
.id(layer.marker.id)
}
}
private func load(refresh: Bool = false) async {
let revision = store.revision
let request = UUID()
requestID = request
@MainActor func checkCurrent() throws {
guard request == requestID, revision == store.revision, !Task.isCancelled else {
throw CancellationError()
}
}
do {
let detail: ItemDetail = try await store.account.read(store.itemPath(itemID), refresh: refresh)
try checkCurrent()
if item?.locationId != detail.item.locationId || item?.locationPath != detail.item.locationPath {
state = .loading
}
item = detail.item
guard let locationID = detail.item.locationId else {
state = .noLocation
return
}
try await store.refreshLocations(refresh: refresh)
try checkCurrent()
guard let route = ItemLocationPlanRoute(locationID: locationID, locations: store.locations) else {
state = .unavailable
return
}
for layer in route.layers {
let snapshot = try await store.locationLayout(parent: layer.parent?.id, refresh: refresh)
try checkCurrent()
if snapshot.locations.contains(where: { $0.id == layer.marker.id && $0.geometry != nil }) {
state = .mapped(layer, snapshot)
return
}
}
state = .unplaced
} catch is CancellationError {
} catch where request == requestID && revision == store.revision && !Task.isCancelled {
if (error as? AtlasError)?.resourceUnavailable == true {
item = nil
state = .unavailable
} else {
state = .failed(error.localizedDescription)
}
} catch {}
}
}

View File

@ -6,7 +6,7 @@ struct LocationPlanCanvas: View {
let locations: [LayoutLocation]
let selected: UUID?
let editing: Bool
let open: (UUID) -> Void
let open: ((UUID) -> Void)?
var change: ((UUID, LocationGeometry) -> Void)? = nil
var expanded = false
var snapping = true
@ -46,12 +46,16 @@ struct LocationPlanCanvas: View {
PlanGrid(spacing: max(1, 100 * scale))
ForEach(locations) { place in
if let geometry = place.geometry {
let locating = open == nil && selected != nil
PlanTile(place: place, geometry: geometry, scale: scale,
selected: selected == place.id || highlighted.contains(place.id),
showingPin: locating && selected == place.id,
editing: editing, canvasWidth: width, canvasDepth: depth,
shapes: shapes, snapping: snapping,
open: { open(place.id) }, change: { change?(place.id, $0) },
open: open.map { action in { action(place.id) } },
change: { change?(place.id, $0) },
report: { guides = $0 })
.opacity(locating && selected != place.id ? 0.58 : 1)
.zIndex(geometry.template.kind == .furniture ? (selected == place.id ? 3 : 2) : (selected == place.id ? 1 : 0))
}
}
@ -186,12 +190,13 @@ private struct PlanTile: View {
let geometry: LocationGeometry
let scale: CGFloat
let selected: Bool
let showingPin: Bool
let editing: Bool
let canvasWidth: Int
let canvasDepth: Int
let shapes: [UUID: LocationGeometry]
let snapping: Bool
let open: () -> Void
let open: (() -> Void)?
let change: (LocationGeometry) -> Void
let report: (LocationPlanGuides) -> Void
@GestureState private var drag: Drag?
@ -221,15 +226,29 @@ private struct PlanTile: View {
RoundedRectangle(cornerRadius: 4).stroke(overlapping ? Color.red : .atlasBlue, lineWidth: 2)
}
}
.overlay(alignment: .topTrailing) {
if showingPin && min(width, depth) >= 22 {
Image(systemName: "mappin.circle.fill")
.font(.system(size: 18, weight: .semibold))
.foregroundStyle(Color.white, Color.atlasBlue)
.padding(2)
.accessibilityHidden(true)
}
}
.contentShape(Rectangle())
if editing {
if let open, editing {
tile
.onTapGesture(perform: open)
.highPriorityGesture(gesture(resizing: false))
.accessibilityAddTraits(.isButton)
.accessibilityAction { open() }
} else {
} else if let open {
Button(action: open) { tile }.buttonStyle(.plain)
} else {
tile
.accessibilityElement(children: .ignore)
.accessibilityValue(showingPin ? "已标出" : "")
.allowsHitTesting(false)
}
if selected && editing {
Circle()

View File

@ -56,6 +56,8 @@
搜索框接收名称、别名和位置。完整名称优先于完整别名,再排前缀、包含和位置。结果优先露出位置路径。录入或改名后,找物会重新请求最新结果。
有存放位置的物品可从详情点「在平面图中查看」。直接放在房间的物品会标出房间,放进柜子或抽屉的物品优先标出室内图里的柜子,上方保留完整位置。柜子还没摆到图里时,会先标出上一级房间。两张图都没有对应位置时,仍可按路径找物。
进空间时会预读物品和位置,登录后也会预读社区。切回已经加载过的页面会先显示上一份列表,包括空列表。稍后收到新数据时再更新,也可以下拉立即刷新。
## 社区

View File

@ -59,5 +59,6 @@ R01–R10 对应[需求与验收](../product/requirements.md)。实现和当前
| TC-48 布局权限与冲突 | R01、R11 | 两位可写成员同时编辑同一张图,先后保存。以只读成员尝试修改,再提交另一空间的位置 ID。 | 成员可以查看允许的布局。旧版本提示冲突并保留本地编辑。越权写入被拒绝,也不会留下部分变化。 |
| TC-49 AI 布局草稿 | R07、R12 | 用语音或文字描述新增区域、移动家具及有歧义的同名位置。核对后应用,同一请求重复提交。模拟模型不可用。 | 预览标出变化及待确认的条目。确认后布局原子更新,重复提交不会创建重复位置。模型不可用时原话仍可编辑,手动布局可继续。 |
| TC-50 iOS 全屏平面图编辑 | R11、R12 | 依次添加模型、拖向另一处位置边线、拉角缩放,再用「撤回」和「重做」检查。应用 AI 草稿后点「放弃」,重新打开平面图。最后从四个底栏页面各返回一次。 | 画布占满工具栏间空间,吸附时出现辅助线。撤回包括新增位置,重做恢复同一步。放弃后原平面图和位置列表保持不变,底栏顶部无透底的缝。 |
| TC-51 从物品查看平面图 | R04、R11 | 把一件物品放进「主卧 / 衣柜 / 抽屉」。从找物进详情,点「在平面图中查看」。依次取消衣柜和主卧在图上的摆放,下拉刷新。再用只读成员查看,并检查无位置的物品。 | 优先标出室内图的衣柜,回退时标出空间图的主卧,两处都未摆放时显示提示。完整存放路径始终可见。只读成员能查看,无位置的物品没有平面图入口。 |
[测试与演示计划](plan.md)