Add TravelAlbum, ProfileSpace, and wired camera transfer modules.
Introduce travel album entry with Sony PTP tethering pipeline, profile space settings page, home routing updates, Launch Screen storyboard, and related tests/docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -0,0 +1,158 @@
|
||||
//
|
||||
// CreateTravelAlbumSheet.swift
|
||||
// suixinkan
|
||||
//
|
||||
// Created by Codex on 2026/6/29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// 新建相册任务弹窗,支持先拍再买与买了再拍两种模式。
|
||||
struct CreateTravelAlbumSheet: View {
|
||||
let orders: [TravelAlbumAvailableOrder]
|
||||
let isCreating: Bool
|
||||
let onConfirm: (Int, String, String, String, TravelAlbumAvailableOrder?) -> Void
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@State private var mode = TravelAlbumEntryViewModel.modePreShoot
|
||||
@State private var freeCount = ""
|
||||
@State private var singlePrice = ""
|
||||
@State private var packagePrice = ""
|
||||
@State private var selectedOrder: TravelAlbumAvailableOrder?
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
ScrollView {
|
||||
VStack(spacing: AppMetrics.Spacing.medium) {
|
||||
modeCard(
|
||||
title: "先拍再买",
|
||||
description: "拍完后分享给用户,用户在小程序上选择性购买",
|
||||
selected: mode == TravelAlbumEntryViewModel.modePreShoot
|
||||
) {
|
||||
mode = TravelAlbumEntryViewModel.modePreShoot
|
||||
}
|
||||
|
||||
modeCard(
|
||||
title: "买了再拍",
|
||||
description: "用户已在小程序下单,绑定订单后用户可直接选片",
|
||||
selected: mode == TravelAlbumEntryViewModel.modePreOrder
|
||||
) {
|
||||
mode = TravelAlbumEntryViewModel.modePreOrder
|
||||
}
|
||||
|
||||
if mode == TravelAlbumEntryViewModel.modePreShoot {
|
||||
preShootFields
|
||||
} else {
|
||||
preOrderFields
|
||||
}
|
||||
}
|
||||
.padding(AppMetrics.Spacing.pageHorizontal)
|
||||
.padding(.vertical, AppMetrics.Spacing.medium)
|
||||
}
|
||||
.background(Color(hex: 0xF5F7FA))
|
||||
.navigationTitle("新建相册任务")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("取消") { dismiss() }
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(isCreating ? "创建中" : "确认创建") {
|
||||
onConfirm(mode, freeCount, singlePrice, packagePrice, selectedOrder)
|
||||
}
|
||||
.disabled(isCreating)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var preShootFields: some View {
|
||||
VStack(spacing: AppMetrics.Spacing.small) {
|
||||
fieldRow(title: "免费张数", placeholder: "请输入免费张数", text: $freeCount, keyboard: .numberPad)
|
||||
fieldRow(title: "单张价格(元)", placeholder: "请输入单张照片价格", text: $singlePrice, keyboard: .decimalPad)
|
||||
fieldRow(title: "打包价(元)", placeholder: "可选", text: $packagePrice, keyboard: .decimalPad)
|
||||
}
|
||||
}
|
||||
|
||||
private var preOrderFields: some View {
|
||||
VStack(alignment: .leading, spacing: AppMetrics.Spacing.small) {
|
||||
Text("选择绑定订单")
|
||||
.font(.system(size: AppMetrics.FontSize.subheadline, weight: .medium))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
|
||||
if orders.isEmpty {
|
||||
Text("暂无可绑定订单")
|
||||
.foregroundStyle(AppDesign.placeholder)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding()
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
} else {
|
||||
ForEach(orders) { order in
|
||||
Button {
|
||||
selectedOrder = order
|
||||
} label: {
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(order.projectName)
|
||||
.font(.system(size: AppMetrics.FontSize.body, weight: .medium))
|
||||
.foregroundStyle(AppDesign.textPrimary)
|
||||
Text("\(order.orderNumber) · \(order.userPhone)")
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
Spacer()
|
||||
Image(systemName: selectedOrder?.orderNumber == order.orderNumber ? "checkmark.circle.fill" : "circle")
|
||||
.foregroundStyle(selectedOrder?.orderNumber == order.orderNumber ? AppDesign.primary : AppDesign.placeholder)
|
||||
}
|
||||
.padding(AppMetrics.Spacing.medium)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func modeCard(title: String, description: String, selected: Bool, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
HStack(alignment: .top, spacing: AppMetrics.Spacing.medium) {
|
||||
Image(systemName: selected ? "largecircle.fill.circle" : "circle")
|
||||
.foregroundStyle(selected ? AppDesign.primary : AppDesign.placeholder)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title)
|
||||
.font(.system(size: AppMetrics.FontSize.body, weight: .semibold))
|
||||
.foregroundStyle(AppDesign.textPrimary)
|
||||
Text(description)
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
.multilineTextAlignment(.leading)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding(AppMetrics.Spacing.large)
|
||||
.background(Color.white)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card)
|
||||
.stroke(selected ? AppDesign.primary : Color.clear, lineWidth: 1.5)
|
||||
)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private func fieldRow(title: String, placeholder: String, text: Binding<String>, keyboard: UIKeyboardType) -> some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text(title)
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
TextField(placeholder, text: text)
|
||||
.keyboardType(keyboard)
|
||||
.padding(AppMetrics.Spacing.medium)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
//
|
||||
// TravelAlbumCodeSheet.swift
|
||||
// suixinkan
|
||||
//
|
||||
// Created by Codex on 2026/6/29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// 旅拍相册小程序码弹窗。
|
||||
struct TravelAlbumCodeSheet: View {
|
||||
let state: TravelAlbumCodeSheetState
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
VStack(spacing: AppMetrics.Spacing.large) {
|
||||
Text(state.albumName)
|
||||
.font(.system(size: AppMetrics.FontSize.title3, weight: .semibold))
|
||||
|
||||
if state.isLoading {
|
||||
ProgressView("加载小程序码…")
|
||||
.frame(height: 220)
|
||||
} else if state.qrImageURL.isEmpty {
|
||||
AppContentUnavailableView("暂无小程序码", systemImage: "qrcode")
|
||||
.frame(height: 220)
|
||||
} else {
|
||||
RemoteImage(urlString: state.qrImageURL) {
|
||||
Image(systemName: "qrcode")
|
||||
.font(.system(size: 48))
|
||||
.foregroundStyle(AppDesign.placeholder)
|
||||
}
|
||||
.frame(width: 220, height: 220)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
|
||||
Text("用户可扫码进入小程序选片")
|
||||
.font(.system(size: AppMetrics.FontSize.subheadline))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
.padding(AppMetrics.Spacing.pageHorizontal)
|
||||
.navigationTitle("相册码")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
.presentationDetents([.medium])
|
||||
}
|
||||
}
|
||||
156
suixinkan/Features/TravelAlbum/Views/TravelAlbumDetailView.swift
Normal file
156
suixinkan/Features/TravelAlbum/Views/TravelAlbumDetailView.swift
Normal file
@ -0,0 +1,156 @@
|
||||
//
|
||||
// TravelAlbumDetailView.swift
|
||||
// suixinkan
|
||||
//
|
||||
// Created by Codex on 2026/6/29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// 旅拍相册详情页,展示素材网格与管理操作。
|
||||
struct TravelAlbumDetailView: View {
|
||||
let albumID: Int
|
||||
|
||||
@EnvironmentObject private var accountContext: AccountContext
|
||||
@Environment(\.travelAlbumAPI) private var travelAlbumAPI
|
||||
@EnvironmentObject private var toastCenter: ToastCenter
|
||||
@Environment(\.globalLoading) private var globalLoading
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@StateObject private var viewModel = TravelAlbumDetailViewModel()
|
||||
@State private var showDeleteConfirm = false
|
||||
|
||||
private var photoStore: WiredTransferPhotoStore {
|
||||
WiredTransferPhotoStore(
|
||||
accountPrefixProvider: { accountContext.accountCachePrefix ?? "guest_" },
|
||||
userIDProvider: { accountContext.profile?.userId ?? "" }
|
||||
)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: AppMetrics.Spacing.medium) {
|
||||
if let album = viewModel.album {
|
||||
albumHeader(album)
|
||||
}
|
||||
|
||||
if viewModel.materials.isEmpty, !viewModel.isLoading {
|
||||
AppContentUnavailableView("暂无素材", systemImage: "photo.on.rectangle")
|
||||
.frame(maxWidth: .infinity, minHeight: 200)
|
||||
} else {
|
||||
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())], spacing: 8) {
|
||||
ForEach(viewModel.materials) { material in
|
||||
materialCell(material)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, AppMetrics.Spacing.pageHorizontal)
|
||||
.padding(.vertical, AppMetrics.Spacing.medium)
|
||||
}
|
||||
.background(Color(hex: 0xF5F7FA))
|
||||
.navigationTitle(viewModel.album?.name ?? "相册详情")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||
if let album = viewModel.album {
|
||||
NavigationLink {
|
||||
WiredCameraTransferView(context: WiredTransferContext(
|
||||
albumId: album.id,
|
||||
albumName: album.name,
|
||||
phone: album.displayPhone,
|
||||
orderNumber: album.orderNumber
|
||||
))
|
||||
} label: {
|
||||
Image(systemName: "cable.connector")
|
||||
}
|
||||
.accessibilityLabel("有线传图")
|
||||
}
|
||||
|
||||
Button(role: .destructive) {
|
||||
showDeleteConfirm = true
|
||||
} label: {
|
||||
Image(systemName: "trash")
|
||||
}
|
||||
.accessibilityLabel("删除相册")
|
||||
}
|
||||
}
|
||||
.confirmationDialog("确认删除该相册?", isPresented: $showDeleteConfirm, titleVisibility: .visible) {
|
||||
Button("删除", role: .destructive) {
|
||||
Task { await deleteAlbum() }
|
||||
}
|
||||
Button("取消", role: .cancel) {}
|
||||
}
|
||||
.task(id: albumID) {
|
||||
globalLoading.show()
|
||||
defer { globalLoading.hide() }
|
||||
await viewModel.load(api: travelAlbumAPI, albumID: albumID)
|
||||
}
|
||||
.refreshable {
|
||||
await viewModel.load(api: travelAlbumAPI, albumID: albumID)
|
||||
}
|
||||
.onChange(of: viewModel.errorMessage) { message in
|
||||
guard let message, !message.isEmpty else { return }
|
||||
toastCenter.show(message)
|
||||
}
|
||||
}
|
||||
|
||||
private func albumHeader(_ album: TravelAlbumItem) -> some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(album.type == 1 ? "先拍再买" : "买了再拍")
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.primary)
|
||||
if !album.displayPhone.isEmpty {
|
||||
Label(album.displayPhone, systemImage: "phone.fill")
|
||||
.font(.system(size: AppMetrics.FontSize.subheadline))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
if !album.orderNumber.isEmpty {
|
||||
Text("订单号:\(album.orderNumber)")
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(AppMetrics.Spacing.large)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
}
|
||||
|
||||
private func materialCell(_ material: TravelAlbumMaterial) -> some View {
|
||||
ZStack(alignment: .topTrailing) {
|
||||
RemoteImage(urlString: material.coverURL.isEmpty ? material.fileURL : material.coverURL) {
|
||||
Color(hex: 0xE5E7EB)
|
||||
}
|
||||
.aspectRatio(1, contentMode: .fill)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||||
|
||||
Menu {
|
||||
Button(role: .destructive) {
|
||||
Task {
|
||||
await viewModel.deleteMaterial(api: travelAlbumAPI, materialID: material.id, albumID: albumID)
|
||||
}
|
||||
} label: {
|
||||
Label("删除", systemImage: "trash")
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "ellipsis")
|
||||
.padding(6)
|
||||
.background(Color.black.opacity(0.35))
|
||||
.foregroundStyle(.white)
|
||||
.clipShape(Circle())
|
||||
.padding(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func deleteAlbum() async {
|
||||
globalLoading.show()
|
||||
defer { globalLoading.hide() }
|
||||
let success = await viewModel.deleteAlbum(api: travelAlbumAPI, albumID: albumID, photoStore: photoStore)
|
||||
if success {
|
||||
toastCenter.show("相册已删除")
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
207
suixinkan/Features/TravelAlbum/Views/TravelAlbumEntryView.swift
Normal file
207
suixinkan/Features/TravelAlbum/Views/TravelAlbumEntryView.swift
Normal file
@ -0,0 +1,207 @@
|
||||
//
|
||||
// TravelAlbumEntryView.swift
|
||||
// suixinkan
|
||||
//
|
||||
// Created by Codex on 2026/6/29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// 旅拍相册入口页,展示任务列表与新建入口。
|
||||
struct TravelAlbumEntryView: View {
|
||||
@EnvironmentObject private var accountContext: AccountContext
|
||||
@Environment(\.travelAlbumAPI) private var travelAlbumAPI
|
||||
@EnvironmentObject private var toastCenter: ToastCenter
|
||||
@Environment(\.globalLoading) private var globalLoading
|
||||
|
||||
@StateObject private var viewModel = TravelAlbumEntryViewModel()
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: AppMetrics.Spacing.medium) {
|
||||
createHeroCard
|
||||
if viewModel.isLoading, viewModel.albums.isEmpty {
|
||||
ProgressView()
|
||||
.frame(maxWidth: .infinity, minHeight: 200)
|
||||
} else if viewModel.albums.isEmpty {
|
||||
AppContentUnavailableView("暂无相册任务", systemImage: "photo.on.rectangle.angled", description: Text("点击“新建相册任务”开始创建任务"))
|
||||
.frame(maxWidth: .infinity, minHeight: 240)
|
||||
} else {
|
||||
LazyVStack(spacing: AppMetrics.Spacing.medium) {
|
||||
ForEach(viewModel.albums) { album in
|
||||
TravelAlbumCard(
|
||||
album: album,
|
||||
onOpenDetail: { TravelAlbumSession.currentAlbum = album },
|
||||
onOpenWiredTransfer: { TravelAlbumSession.currentAlbum = album },
|
||||
onOpenCode: {
|
||||
Task {
|
||||
await viewModel.openAlbumCode(api: travelAlbumAPI, album: album)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, AppMetrics.Spacing.pageHorizontal)
|
||||
.padding(.vertical, AppMetrics.Spacing.medium)
|
||||
}
|
||||
.background(Color(hex: 0xF5F7FA))
|
||||
.navigationTitle("新增相册")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.refreshable {
|
||||
await reload(showLoading: false)
|
||||
}
|
||||
.task {
|
||||
await reload(showLoading: viewModel.albums.isEmpty)
|
||||
}
|
||||
.sheet(isPresented: $viewModel.showCreateSheet) {
|
||||
CreateTravelAlbumSheet(
|
||||
orders: viewModel.bindableOrders,
|
||||
isCreating: viewModel.isCreating,
|
||||
onConfirm: { mode, freeCount, singlePrice, packagePrice, order in
|
||||
Task {
|
||||
let success = await viewModel.confirmCreateTask(
|
||||
api: travelAlbumAPI,
|
||||
mode: mode,
|
||||
freeCount: freeCount,
|
||||
singlePrice: singlePrice,
|
||||
packagePrice: packagePrice,
|
||||
order: order,
|
||||
scenicSelected: accountContext.currentScenic != nil
|
||||
)
|
||||
if success {
|
||||
toastCenter.show("任务创建成功")
|
||||
} else if let message = viewModel.errorMessage {
|
||||
toastCenter.show(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
.presentationDetents([.large])
|
||||
}
|
||||
.sheet(item: $viewModel.codeSheet) { state in
|
||||
TravelAlbumCodeSheet(state: state)
|
||||
}
|
||||
.onChange(of: viewModel.errorMessage) { message in
|
||||
guard let message, !message.isEmpty, !viewModel.showCreateSheet else { return }
|
||||
toastCenter.show(message)
|
||||
}
|
||||
}
|
||||
|
||||
private var createHeroCard: some View {
|
||||
Button {
|
||||
Task {
|
||||
await viewModel.openCreateSheet(
|
||||
api: travelAlbumAPI,
|
||||
scenicSelected: accountContext.currentScenic != nil
|
||||
)
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: AppMetrics.Spacing.medium) {
|
||||
Image(systemName: "plus.circle.fill")
|
||||
.font(.system(size: 28))
|
||||
.foregroundStyle(AppDesign.primary)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(viewModel.isCreating ? "新建中..." : "新建相册任务")
|
||||
.font(.system(size: AppMetrics.FontSize.title3, weight: .semibold))
|
||||
.foregroundStyle(AppDesign.textPrimary)
|
||||
Text("创建旅拍相册并开始有线传图")
|
||||
.font(.system(size: AppMetrics.FontSize.subheadline))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.foregroundStyle(AppDesign.placeholder)
|
||||
}
|
||||
.padding(AppMetrics.Spacing.large)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(viewModel.isCreating)
|
||||
}
|
||||
|
||||
private func reload(showLoading: Bool) async {
|
||||
if showLoading { globalLoading.show() }
|
||||
defer { if showLoading { globalLoading.hide() } }
|
||||
await viewModel.loadAlbums(api: travelAlbumAPI)
|
||||
}
|
||||
}
|
||||
|
||||
private struct TravelAlbumCard: View {
|
||||
let album: TravelAlbumItem
|
||||
let onOpenDetail: () -> Void
|
||||
let onOpenWiredTransfer: () -> Void
|
||||
let onOpenCode: () -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: AppMetrics.Spacing.small) {
|
||||
HStack(alignment: .top, spacing: AppMetrics.Spacing.medium) {
|
||||
RemoteImage(urlString: album.coverURL) {
|
||||
Color(hex: 0xE5E7EB)
|
||||
.overlay { Image(systemName: "photo").foregroundStyle(AppDesign.placeholder) }
|
||||
}
|
||||
.frame(width: 72, height: 72)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||||
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text(album.name)
|
||||
.font(.system(size: AppMetrics.FontSize.title3, weight: .semibold))
|
||||
.foregroundStyle(AppDesign.textPrimary)
|
||||
.lineLimit(1)
|
||||
if !album.displayPhone.isEmpty {
|
||||
Label(album.displayPhone, systemImage: "phone.fill")
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
Text(album.type == 1 ? "先拍再买" : "买了再拍")
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.primary)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
|
||||
HStack(spacing: AppMetrics.Spacing.small) {
|
||||
NavigationLink {
|
||||
WiredCameraTransferView(context: WiredTransferContext(
|
||||
albumId: album.id,
|
||||
albumName: album.name,
|
||||
phone: album.displayPhone,
|
||||
orderNumber: album.orderNumber
|
||||
))
|
||||
.onAppear { onOpenWiredTransfer() }
|
||||
} label: {
|
||||
actionChip(title: "拍传", systemImage: "cable.connector")
|
||||
}
|
||||
|
||||
Button(action: onOpenCode) {
|
||||
actionChip(title: "相册码", systemImage: "qrcode")
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
TravelAlbumDetailView(albumID: album.id)
|
||||
.onAppear { onOpenDetail() }
|
||||
} label: {
|
||||
actionChip(title: "详情", systemImage: "info.circle")
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(AppMetrics.Spacing.large)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
}
|
||||
|
||||
private func actionChip(title: String, systemImage: String) -> some View {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: systemImage)
|
||||
Text(title)
|
||||
}
|
||||
.font(.system(size: AppMetrics.FontSize.caption, weight: .medium))
|
||||
.foregroundStyle(AppDesign.primary)
|
||||
.padding(.horizontal, 10)
|
||||
.padding(.vertical, 6)
|
||||
.background(AppDesign.primary.opacity(0.08))
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,301 @@
|
||||
//
|
||||
// WiredCameraTransferView.swift
|
||||
// suixinkan
|
||||
//
|
||||
// Created by Codex on 2026/6/29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
/// 有线传图页,连接相机并上传照片到旅拍相册。
|
||||
struct WiredCameraTransferView: View {
|
||||
let context: WiredTransferContext
|
||||
|
||||
@EnvironmentObject private var accountContext: AccountContext
|
||||
@Environment(\.travelAlbumAPI) private var travelAlbumAPI
|
||||
@Environment(\.ossUploadService) private var ossUploadService
|
||||
@EnvironmentObject private var toastCenter: ToastCenter
|
||||
|
||||
@StateObject private var viewModel: WiredCameraTransferViewModel
|
||||
|
||||
init(context: WiredTransferContext) {
|
||||
self.context = context
|
||||
_viewModel = StateObject(
|
||||
wrappedValue: WiredCameraTransferViewModel(
|
||||
context: context,
|
||||
cameraService: CameraServiceFactory.make(brand: .sony)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private let tabTitles = ["全部", "已上传", "失败"]
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
headerSection
|
||||
tabSection
|
||||
photoListSection
|
||||
bottomBar
|
||||
}
|
||||
.background(Color(hex: 0xF5F7FA))
|
||||
.navigationTitle("有线传图")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.task {
|
||||
await viewModel.start(
|
||||
api: travelAlbumAPI,
|
||||
ossService: ossUploadService,
|
||||
scenicID: accountContext.currentScenic?.id ?? 0,
|
||||
accountContext: accountContext
|
||||
)
|
||||
}
|
||||
.onDisappear {
|
||||
Task { await viewModel.stop() }
|
||||
}
|
||||
.onChange(of: viewModel.errorMessage) { message in
|
||||
guard let message, !message.isEmpty else { return }
|
||||
toastCenter.show(message)
|
||||
}
|
||||
.onChange(of: viewModel.connectionState) { state in
|
||||
switch state {
|
||||
case .connected(let name):
|
||||
toastCenter.show("已连接 \(name)")
|
||||
case .disconnected:
|
||||
break
|
||||
case .error(let message):
|
||||
toastCenter.show(message)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
.confirmationDialog("指定上传", isPresented: $viewModel.showSpecifyUploadSheet, titleVisibility: .visible) {
|
||||
Button("上传全部待上传") {
|
||||
Task { await viewModel.batchUploadAll() }
|
||||
}
|
||||
Button("上传选中项") {
|
||||
Task { await viewModel.uploadSelected() }
|
||||
}
|
||||
Button("取消", role: .cancel) {}
|
||||
}
|
||||
}
|
||||
|
||||
private var headerSection: some View {
|
||||
VStack(spacing: AppMetrics.Spacing.small) {
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(context.albumName)
|
||||
.font(.system(size: AppMetrics.FontSize.title3, weight: .semibold))
|
||||
if !context.phone.isEmpty {
|
||||
Text(context.phone)
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
connectionBadge
|
||||
}
|
||||
|
||||
Picker("传输模式", selection: Binding(
|
||||
get: { viewModel.transferModeOption },
|
||||
set: { newValue in
|
||||
viewModel.selectTransferMode(
|
||||
newValue,
|
||||
api: travelAlbumAPI,
|
||||
ossService: ossUploadService,
|
||||
scenicID: accountContext.currentScenic?.id ?? 0
|
||||
)
|
||||
}
|
||||
)) {
|
||||
Text(WiredCameraTransferViewModel.modeLiveCapture).tag(WiredCameraTransferViewModel.modeLiveCapture)
|
||||
Text(WiredCameraTransferViewModel.modePostShootTransfer).tag(WiredCameraTransferViewModel.modePostShootTransfer)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
}
|
||||
.padding(AppMetrics.Spacing.pageHorizontal)
|
||||
.padding(.vertical, AppMetrics.Spacing.medium)
|
||||
.background(Color.white)
|
||||
}
|
||||
|
||||
private var connectionBadge: some View {
|
||||
VStack(spacing: 4) {
|
||||
Circle()
|
||||
.stroke(connectionColor, lineWidth: 3)
|
||||
.frame(width: 44, height: 44)
|
||||
.overlay {
|
||||
Image(systemName: "camera.fill")
|
||||
.foregroundStyle(connectionColor)
|
||||
}
|
||||
Text(connectionText)
|
||||
.font(.system(size: 10))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
.multilineTextAlignment(.center)
|
||||
.frame(width: 72)
|
||||
}
|
||||
}
|
||||
|
||||
private var connectionColor: Color {
|
||||
switch viewModel.connectionState {
|
||||
case .connected: AppDesign.success
|
||||
case .error: Color.red
|
||||
case .searching, .connecting: AppDesign.warning
|
||||
case .disconnected: AppDesign.placeholder
|
||||
}
|
||||
}
|
||||
|
||||
private var connectionText: String {
|
||||
switch viewModel.connectionState {
|
||||
case .connected(let name):
|
||||
name
|
||||
default:
|
||||
viewModel.connectionState.displayText
|
||||
}
|
||||
}
|
||||
|
||||
private var tabSection: some View {
|
||||
let counts = viewModel.photos.transferTabCounts
|
||||
return HStack(spacing: 0) {
|
||||
ForEach(Array(tabTitles.enumerated()), id: \.offset) { index, title in
|
||||
Button {
|
||||
viewModel.selectedTabIndex = index
|
||||
} label: {
|
||||
VStack(spacing: 4) {
|
||||
Text(title)
|
||||
.font(.system(size: AppMetrics.FontSize.subheadline, weight: viewModel.selectedTabIndex == index ? .semibold : .regular))
|
||||
Text("\(counts[index])")
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
}
|
||||
.foregroundStyle(viewModel.selectedTabIndex == index ? AppDesign.primary : AppDesign.textSecondary)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 10)
|
||||
.background(viewModel.selectedTabIndex == index ? AppDesign.primarySoft : Color.clear)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.background(Color.white)
|
||||
}
|
||||
|
||||
private var photoListSection: some View {
|
||||
let visiblePhotos = viewModel.photos.filtered(byTabIndex: viewModel.selectedTabIndex)
|
||||
return ScrollView {
|
||||
if visiblePhotos.isEmpty {
|
||||
AppContentUnavailableView("暂无照片", systemImage: "photo")
|
||||
.frame(maxWidth: .infinity, minHeight: 260)
|
||||
} else {
|
||||
LazyVStack(spacing: AppMetrics.Spacing.small) {
|
||||
ForEach(visiblePhotos) { photo in
|
||||
photoRow(photo)
|
||||
}
|
||||
}
|
||||
.padding(AppMetrics.Spacing.pageHorizontal)
|
||||
.padding(.vertical, AppMetrics.Spacing.medium)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func photoRow(_ photo: WiredTransferPhotoItem) -> some View {
|
||||
HStack(spacing: AppMetrics.Spacing.medium) {
|
||||
if viewModel.selectUploadMode, photo.canSelectForSpecifyUpload {
|
||||
Button {
|
||||
viewModel.togglePhotoSelection(id: photo.id)
|
||||
} label: {
|
||||
Image(systemName: viewModel.selectedPhotoIDs.contains(photo.id) ? "checkmark.circle.fill" : "circle")
|
||||
.foregroundStyle(viewModel.selectedPhotoIDs.contains(photo.id) ? AppDesign.primary : AppDesign.placeholder)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
thumbnailView(for: photo)
|
||||
.frame(width: 64, height: 64)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(photo.fileName)
|
||||
.font(.system(size: AppMetrics.FontSize.subheadline, weight: .medium))
|
||||
.lineLimit(1)
|
||||
Text(photo.capturedAt)
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
HStack {
|
||||
Text(photo.status.displayLabel)
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(statusColor(photo.status))
|
||||
if photo.status == .uploading || photo.status == .transferring {
|
||||
Text("\(photo.progress)%")
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
.foregroundStyle(AppDesign.textSecondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
if photo.status == .failed {
|
||||
Button("重试") {
|
||||
Task { await viewModel.retryPhoto(id: photo.id) }
|
||||
}
|
||||
.font(.system(size: AppMetrics.FontSize.caption))
|
||||
}
|
||||
}
|
||||
.padding(AppMetrics.Spacing.medium)
|
||||
.background(Color.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: AppMetrics.CornerRadius.card))
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func thumbnailView(for photo: WiredTransferPhotoItem) -> some View {
|
||||
if photo.thumbnailURL.hasPrefix("file://"), let url = URL(string: photo.thumbnailURL) {
|
||||
if let uiImage = UIImage(contentsOfFile: url.path) {
|
||||
Image(uiImage: uiImage)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
} else {
|
||||
placeholderThumbnail
|
||||
}
|
||||
} else {
|
||||
RemoteImage(urlString: photo.thumbnailURL) {
|
||||
placeholderThumbnail
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var placeholderThumbnail: some View {
|
||||
Color(hex: 0xE5E7EB)
|
||||
.overlay {
|
||||
Image(systemName: "photo")
|
||||
.foregroundStyle(AppDesign.placeholder)
|
||||
}
|
||||
}
|
||||
|
||||
private func statusColor(_ status: WiredTransferUploadStatus) -> Color {
|
||||
switch status {
|
||||
case .uploaded: AppDesign.success
|
||||
case .failed: Color.red
|
||||
case .uploading, .transferring: AppDesign.warning
|
||||
case .pending: AppDesign.textSecondary
|
||||
}
|
||||
}
|
||||
|
||||
private var bottomBar: some View {
|
||||
HStack(spacing: AppMetrics.Spacing.small) {
|
||||
Button("同步历史") {
|
||||
Task { await viewModel.syncExistingPhotos() }
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
|
||||
Button("批量上传") {
|
||||
Task { await viewModel.batchUploadAll() }
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
|
||||
Button("指定上传") {
|
||||
viewModel.selectUploadMode = true
|
||||
viewModel.showSpecifyUploadSheet = true
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
.padding(AppMetrics.Spacing.pageHorizontal)
|
||||
.padding(.vertical, AppMetrics.Spacing.medium)
|
||||
.background(Color.white)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user