// // SettginsView.swift // IOS_study // // Created by CC-star on 2025/7/10. // import SwiftUI struct SettginsView: View { @Environment(ProfileViewModel.self) var ProfileVM @Environment(HUD.self) var hud @Binding var naviPath: NavigationPath @State var showSignOutDialog = false @State var showRemoveUserDialog = false @State var showRemoveUserAlert = false var isLogin = true var body: some View { List { Section("客服/商业合作") { Button { UIPasteboard.general.string = KdevContact hud.show("复制成功") } label: { HStack { Text("微信号") Spacer() Text(KdevContact).secondary() } }.settingsStyle() } if isLogin { Section("账号") { HStack { Button { showSignOutDialog = true } label: { Text("退出登录").push(to: .leading).settingsStyle() }.settingsStyle() .confirmationDialog("确定退出吗?", isPresented: $showSignOutDialog, titleVisibility: .visible) { Button("确定", role: .destructive) { if !naviPath.isEmpty { naviPath.removeLast() } ProfileVM.logOut() NotificationCenter.default.post(name: .logoutSuccess, object: nil) } Button("取消", role: .cancel) { } } } HStack { Button { showRemoveUserDialog = true } label: { Text("注销账号").push(to: .leading).settingsStyle() }.settingsStyle() .confirmationDialog("确定注销吗?", isPresented: $showRemoveUserDialog, titleVisibility: .visible) { Button("确定", role: .destructive) { showRemoveUserAlert = true } Button("取消", role: .cancel) { } } .alert("注销之后不可恢复,请再次确认", isPresented: $showRemoveUserAlert) { Button("确定", role: .destructive) { Task { await ProfileVM.deletUserAll() } } Button("取消", role: .cancel) { } } } } } }.listStyle(.grouped) .toolbarBackgroundVisibility(.visible, for: .navigationBar) .navigationBarBackButtonHidden(isLogin).navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .principal) { Text("设置") } if isLogin { ToolbarItem(placement: .topBarLeading) { Button { if !naviPath.isEmpty { naviPath.removeLast() } } label: { Image(systemName: "chevron.left").secondary().padding(.horizontal,6) } } } } } }