139 lines
4.6 KiB
Swift
139 lines
4.6 KiB
Swift
import SwiftUI
|
||
|
||
/// 设置页面视图
|
||
struct SettingsView: View {
|
||
// MARK: - 属性
|
||
|
||
/// 环境变量 - 用于dismiss视图
|
||
@Environment(\.dismiss) private var dismiss
|
||
|
||
/// 状态 - 控制视图显示/隐藏
|
||
@Binding var isPresented: Bool
|
||
@State private var isShowingAccountView = false
|
||
|
||
// MARK: - 动画配置
|
||
|
||
/// 动画配置
|
||
private let animation = Animation.spring(
|
||
response: 0.6, // 响应时间
|
||
dampingFraction: 0.9, // 阻尼系数
|
||
blendDuration: 0.8 // 混合时间
|
||
)
|
||
|
||
// MARK: - 主体视图
|
||
|
||
var body: some View {
|
||
ZStack {
|
||
// Theme background color
|
||
Color.themeTextWhiteSecondary.edgesIgnoringSafeArea(.all)
|
||
|
||
VStack(spacing: 0) {
|
||
// 简洁导航头
|
||
SimpleNaviHeader(title: "Setting") {
|
||
withAnimation(animation) {
|
||
isPresented = false
|
||
}
|
||
}
|
||
|
||
// 设置项列表
|
||
List {
|
||
// 账号与安全
|
||
settingRow(
|
||
icon: "Account",
|
||
title: "Account & Security",
|
||
action: {
|
||
Router.shared.navigate(to: .account)
|
||
}
|
||
)
|
||
|
||
// 权限管理
|
||
settingRow(
|
||
icon: "Permission",
|
||
title: "Permission Management",
|
||
action: {
|
||
Router.shared.navigate(to: .permissionManagement)
|
||
}
|
||
)
|
||
|
||
// 支持与服务
|
||
settingRow(
|
||
icon: "Suport",
|
||
title: "Support & Service",
|
||
action: {}
|
||
)
|
||
|
||
// 关于我们
|
||
settingRow(
|
||
icon: "AboutUs",
|
||
title: "About Us",
|
||
action: {
|
||
Router.shared.navigate(to: .about)
|
||
}
|
||
)
|
||
}
|
||
.background(Color.white)
|
||
.cornerRadius(12)
|
||
.padding()
|
||
.listStyle(PlainListStyle())
|
||
.listRowSeparator(.hidden)
|
||
.listRowInsets(EdgeInsets())
|
||
.frame(height: CGFloat(5 * 60)) // 4 rows × 60 points each
|
||
.frame(maxWidth: .infinity)
|
||
Spacer()
|
||
}
|
||
}
|
||
.navigationBarHidden(true)
|
||
}
|
||
|
||
// MARK: - 私有方法
|
||
|
||
/// 配置TableView外观
|
||
private func configureTableView() {
|
||
// 移除列表底部分隔线
|
||
UITableView.appearance().tableFooterView = UIView()
|
||
// 移除列表顶部分隔线
|
||
UITableView.appearance().tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
|
||
// 移除分隔线缩进
|
||
UITableView.appearance().separatorInset = .zero
|
||
// 移除列表顶部额外间距
|
||
UITableView.appearance().contentInset = .zero
|
||
}
|
||
|
||
/// 创建设置项行视图
|
||
/// - Parameters:
|
||
/// - icon: 图标名称
|
||
/// - title: 标题
|
||
/// - action: 点击动作
|
||
/// - Returns: 返回设置项行视图
|
||
private func settingRow(icon: String, title: String, action: @escaping () -> Void) -> some View {
|
||
Button(action: action) {
|
||
HStack {
|
||
// 左侧图标
|
||
SVGImage(svgName: icon)
|
||
.frame(width: 22, height: 22)
|
||
|
||
// 标题
|
||
Text(title)
|
||
.foregroundColor(.primary)
|
||
|
||
Spacer()
|
||
|
||
// 右侧箭头
|
||
Image(systemName: "chevron.right")
|
||
.font(.system(size: 14))
|
||
.foregroundColor(.gray)
|
||
}
|
||
.padding(.vertical, 12) // 增加垂直内边距
|
||
.background(Color.white)
|
||
}
|
||
.buttonStyle(PlainButtonStyle())
|
||
.listRowBackground(Color.white)
|
||
.listRowSeparator(.hidden)
|
||
}
|
||
}
|
||
|
||
// MARK: - 预览
|
||
#Preview {
|
||
SettingsView(isPresented: .constant(true))
|
||
}
|