123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- //
- // ContentView.swift
- // sdsz74
- //
- // Created by yunli on 2023/5/18.
- //
- import SwiftUI
- struct ContentView: View {
- @State private var examCount = 0
- @State private var messageCount = 0
- @State private var isLoggedIn = 0
- var body: some View {
- TabView{
- NavigationView {
- NavigationLink(destination: examListView(count:$examCount)) {
- Text("共 \(examCount) 场考试")
- }
- .navigationBarTitle("74 桌")
- }
- .tabItem({Image(systemName: "chart.bar.fill")
- Text("成绩分析")})
- NavigationView {
- List{
- NavigationLink(destination: messageView(count:$messageCount)) {
- Text("消息")
- .badge(messageCount)
- }
- }
- .navigationBarTitle("数字校园")
- }
- .tabItem({Image(systemName: "graduationcap")
- Text("数字校园")})
- NavigationView{
- if isLoggedIn != 0{
- accountView(isLoggedIn: $isLoggedIn)
- .navigationBarTitle("账号")
- }
- else{
- loginView(isLoggedIn:$isLoggedIn)
- .navigationBarTitle("登录")
- }
- }
- .tabItem({Image(systemName: "person")
- Text("账号")})
-
- }
- }
- }
- extension View {
- func hideKeyboard() {
- UIApplication.shared.sendAction(
- #selector(UIResponder.resignFirstResponder),
- to: nil,
- from: nil,
- for: nil
- )
- }
- }
- func doLogin(status:inout Int)->Void{
- status=1
- }
- struct loginView:View{
- @State var username: String = ""
- @State var password: String = ""
- @FocusState private var isFocused:Bool
- @Binding var isLoggedIn: Int
- var body: some View {
- VStack{
- Form {
- Section{
- TextField(text: $username, prompt: Text("数字校园号")) {
- Text("Username")
- }.focused($isFocused)
- SecureField(text: $password, prompt: Text("密码")) {
- Text("Password")
- }.focused($isFocused)
- }.onTapGesture {
- isFocused=false
- }
- Section{
- HStack{
- Spacer()
- Button(action:{doLogin(status: &isLoggedIn)}){
- VStack{
- Text("登录")
- }
- }.font(.title3)
- Spacer()
- }
- }
- }
- Spacer()
- }
- }
- }
- struct accountView:View{
- @State var username: String = ""
- @State var password: String = ""
- @FocusState private var isFocused:Bool
- @Binding var isLoggedIn: Int
- var body: some View {
- VStack{
- Form {
- Section(header:Text("hi")){
- Text("一些")
- Text("一些")
- Text("东西")
- }
- Section{
- Button(action:{isLoggedIn=0}){
- VStack{
- Text("退出").foregroundColor(.red)
- }
- }
- }
- }
- Spacer()
- }
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
|