初始提交

This commit is contained in:
2026-06-22 11:28:01 +08:00
commit 0a0d4fbd79
84 changed files with 8899 additions and 0 deletions

View File

@ -0,0 +1,63 @@
//
// AppTab.swift
// suixinkan
//
// Created by Codex on 2026/6/18.
//
import SwiftUI
/// Tab
enum AppTab: String, CaseIterable, Identifiable, Hashable {
case home
case orders
case statistics
case profile
var id: Self { self }
var title: String {
switch self {
case .home:
"首页"
case .orders:
"订单"
case .statistics:
"数据"
case .profile:
"我的"
}
}
var systemImage: String {
switch self {
case .home:
"house"
case .orders:
"doc.text"
case .statistics:
"chart.bar"
case .profile:
"person"
}
}
@ViewBuilder
var rootView: some View {
switch self {
case .home:
HomeRootView()
case .orders:
OrdersRootView()
case .statistics:
StatisticsRootView()
case .profile:
ProfileRootView()
}
}
@ViewBuilder
var label: some View {
Label(title, systemImage: systemImage)
}
}

View File

@ -0,0 +1,88 @@
//
// NavigationRouter.swift
// suixinkan
//
// Created by Codex on 2026/6/18.
//
import Observation
import SwiftUI
/// Tab
enum AppRoute: Hashable {
case placeholder(title: String)
case home(HomeRoute)
/// NavigationStack push TabBar
var hidesTabBarWhenPushed: Bool {
true
}
///
@ViewBuilder
var destinationView: some View {
switch self {
case .placeholder(let title):
PlaceholderDetailView(title: title)
case .home(let route):
route.destinationView
}
}
}
@MainActor
@Observable
/// NavigationStack Tab
final class RouterPath {
var path: [AppRoute] = []
/// Tab
func navigate(to route: AppRoute) {
path.append(route)
}
/// Tab
func reset() {
path = []
}
}
@MainActor
@Observable
/// Tab Tab NavigationStack
final class AppRouter {
var selectedTab: AppTab = .home
private var routers: [AppTab: RouterPath] = [:]
/// Tab
func router(for tab: AppTab) -> RouterPath {
if let router = routers[tab] {
return router
}
let router = RouterPath()
routers[tab] = router
return router
}
/// SwiftUI NavigationStack 使
func binding(for tab: AppTab) -> Binding<[AppRoute]> {
let router = router(for: tab)
return Binding(
get: { router.path },
set: { router.path = $0 }
)
}
/// Tab
func select(_ tab: AppTab) {
selectedTab = tab
}
/// Tab Tab
func reset() {
selectedTab = .home
routers.values.forEach { $0.reset() }
}
}