89 lines
3.1 KiB
Swift
89 lines
3.1 KiB
Swift
//
|
|
// ProfileView.swift
|
|
// IOS_study
|
|
//
|
|
// Created by CC-star on 2025/7/15.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Kingfisher
|
|
|
|
struct ProfileView: View {
|
|
@Environment(HUD.self) var hud
|
|
@Environment(AuthViewModel.self) var authVM
|
|
@Environment(SignInPhoneViewModel.self) var SignInPhoneVM
|
|
@Environment(ProfileViewModel.self) var ProfileVM
|
|
@Environment(PLJobViewModel.self) var plJobVM
|
|
@Environment(\.horizontalSizeClass) var sizeClass
|
|
@State var naviPath = NavigationPath()
|
|
@State var logoAspectRatio: CGFloat = 1
|
|
@State var isExpand = false
|
|
@State var showLogo = false
|
|
var user: DBUser { ProfileVM.user }
|
|
|
|
var body: some View {
|
|
if authVM.isLogin {
|
|
NavigationStack(path: $naviPath) {
|
|
List {
|
|
myCompanyView//我的公司
|
|
myJobsView//我发布的工作
|
|
}.listStyle().naviBarStyle().refreshable { await getUsersData() }
|
|
.toolbar {
|
|
ToolbarItem(placement: .principal) { Text("我的").tc().bold() }
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
Button {
|
|
naviPath.append(Navi5.Tosetting)
|
|
} label: {
|
|
Text("设置")
|
|
}.tc2().size15()
|
|
}
|
|
}
|
|
.navigationDestination(isPresented: $showLogo, destination: {
|
|
KFImage(URL(string: user.cLogoURLStr)).resizable().scaledToFit()
|
|
.toolbarVisibility(.hidden, for: .tabBar)
|
|
})
|
|
.navigationDestination(for: Navi5.self) { navi in
|
|
switch navi {
|
|
case .AddCompany: PostCompanyView(naviPath: $naviPath)
|
|
case .EditCompany: PostCompanyView(isEditing: true, naviPath: $naviPath)
|
|
case .PLJobsToPLJob: PLJobView(canEdit: true, showBoss: false, naviPath: $naviPath)
|
|
case .PLJobToEdit: PostPLJobIView(isEditing: true,naviPath: $naviPath)
|
|
case .Tosetting: SettginsView(naviPath: $naviPath)
|
|
}
|
|
}
|
|
.overlay {
|
|
if ProfileVM.isFcSome {
|
|
BprogressView()
|
|
}
|
|
}
|
|
.onAppear {
|
|
Task {
|
|
if !ProfileVM.viewDidLoad {
|
|
await getUsersData()
|
|
ProfileVM.viewDidLoad = true
|
|
} else { await refreshIFNeed() }
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
SignInPhoneView()
|
|
}
|
|
|
|
}
|
|
|
|
func getUsersData() async {
|
|
do { try await ProfileVM.getUsersData() } catch {
|
|
hud.show("数据加载失败,请刷新\n错误信息:\n\(error.localizedDescription)")
|
|
print("个人页有数据加载失败:\(error)")
|
|
}
|
|
}
|
|
|
|
func refreshIFNeed() async {
|
|
do { try await ProfileVM.refreshIFNeed() } catch {
|
|
hud.show("数据加载失败,请刷新\n错误信息:\n\(error.localizedDescription)")
|
|
print("个人页有数据加载失败:\(error)")
|
|
}
|
|
}
|
|
|
|
}
|