// // CompanyGalleryView.swift // IOS_study // // Created by CC-star on 2025/7/22. // import SwiftUI struct CompanyGalleryView: View { @Environment(ProfileViewModel.self) var vm @Environment(\.dismiss) var dismiss @State var currentPage: Int @State var showConfirm = false var body: some View { TabView(selection: $currentPage) { ForEach(vm.companyUIImages.indices, id: \.self) { i in Image(uiImage: vm.companyUIImages[i]).resizable().scaledToFit().tag(i) } }.bg().tabViewStyle(.page) .toolbar { ToolbarItem(placement: .principal) { Text("\(currentPage + 1)/\(vm.companyUIImages.count)").tc().bold() } ToolbarItem(placement: .topBarTrailing) { Image(systemName: "trash").onTapGesture { showConfirm = true } } } .confirmationDialog("删除一张图片", isPresented: $showConfirm, actions: { Button { guard currentPage < vm.companyUIImages.count else { return } vm.companyUIImages.remove(at: currentPage) if vm.companyUIImages.isEmpty { dismiss() } else if currentPage >= vm.companyUIImages.count { currentPage = vm.companyUIImages.count - 1 } } label: { Text("删除") } }, message: { Text("要删除这张图片吗?") }) } }