Browse Source

导航以及页面修改

main
jasonsyf 1 year ago
parent
commit
1713f1ee83

+ 1
- 1
iOSFirst/SwiftUIToast.swift View File

@@ -63,7 +63,7 @@ public class SUIToastController : ObservableObject {
63 63
     
64 64
     func startTimer() {
65 65
         updateTimer = .scheduledTimer(
66
-            timeInterval: 0.1,
66
+            timeInterval: 0.05,
67 67
             target: self,
68 68
             selector: #selector(SUIToastController.onUpdate),
69 69
             userInfo: nil,

+ 34
- 0
iOSFirst/TestView.swift View File

@@ -0,0 +1,34 @@
1
+//
2
+//  TestView.swift
3
+//  iOSFirst
4
+//
5
+//  Created by 孙宇峰 on 2023/2/23.
6
+//
7
+
8
+import SwiftUI
9
+
10
+struct TestView: View {
11
+    @Binding var settingPagePresented: Bool
12
+    
13
+    var body: some View {
14
+        NavigationView {
15
+            Text("hello world")
16
+            .navigationTitle("设置")
17
+            .navigationBarItems(leading: Button(action: {
18
+                settingPagePresented = false
19
+            }, label: {
20
+                Image(systemName: "globe")
21
+                    .imageScale(.large)
22
+                    .foregroundColor(.accentColor)
23
+            
24
+            }))
25
+            .navigationBarTitleDisplayMode(.inline)
26
+        }
27
+    }
28
+}
29
+
30
+struct TestView_Previews: PreviewProvider {
31
+    static var previews: some View {
32
+        TestView(settingPagePresented: .constant(true))
33
+    }
34
+}

+ 31
- 16
iOSFirst/login/LoginView.swift View File

@@ -13,7 +13,9 @@ import RxRelay
13 13
 struct LoginView: View {
14 14
     private var viewModel = LoginViewModel()
15 15
     var bag = DisposeBag()
16
-    
16
+    @State private var inputAccountMessage:String = ""
17
+    @State private var isPresent:Bool = false
18
+    @State private var inputPasswordMessage:String = ""
17 19
     
18 20
     var body: some View {
19 21
         
@@ -47,8 +49,8 @@ struct LoginView: View {
47 49
                     .foregroundColor(.accentColor)
48 50
                     .frame(width: 240,height: 35)
49 51
             }.frame(height: 40)
50
-            .padding(.top,20)
51
-            .padding(.bottom,100)
52
+                .padding(.top,20)
53
+                .padding(.bottom,100)
52 54
             
53 55
             VStack(alignment: .leading, spacing: 400) {
54 56
                 HStack(alignment: .center, spacing: 15) {
@@ -56,8 +58,8 @@ struct LoginView: View {
56 58
                         .imageScale(.large)
57 59
                         .foregroundColor(.accentColor)
58 60
                     
59
-                    TextField("请输入手机号",text:.constant(""))
60
-                        .id("etPhoneNum")
61
+                    TextField("请输入手机号",text:$inputAccountMessage)
62
+                        .keyboardType(UIKeyboardType.namePhonePad)
61 63
                         .font(.system(size: 16))
62 64
                         .frame(maxWidth: .infinity,alignment: .center)
63 65
                     
@@ -73,8 +75,9 @@ struct LoginView: View {
73 75
                         .imageScale(.large)
74 76
                         .foregroundColor(.accentColor)
75 77
                     
76
-                    TextField("请输入密码",text:.constant(""))
77
-                        .id("etPassword")
78
+                    SecureField("请输入密码",text:$inputPasswordMessage)
79
+                        .textContentType(.oneTimeCode)
80
+                        .keyboardType(UIKeyboardType.namePhonePad)
78 81
                         .font(.system(size: 16))
79 82
                         .frame(maxWidth: .infinity,alignment: .center)
80 83
                     
@@ -88,15 +91,25 @@ struct LoginView: View {
88 91
             VStack(alignment: .trailing, spacing: 400) {
89 92
                 
90 93
                 VStack(alignment: .center, spacing: 15) {
94
+                    
91 95
                     Button(action: {
92
-//                        let msg="点击了登录按钮"
93
-//                        print(msg)
94
-                        viewModel.loginUser()
95
-//                        SUIToast.show(messageItem: .init(
96
-//                            message: msg,
97
-//                            bgColor: .gray,
98
-//                            messageColor: .white
99
-//                        ))
96
+                        if(inputAccountMessage.isEmpty){
97
+                            SUIToast.show(messageItem: .init(
98
+                                message: "账号不能为空",
99
+                                bgColor: .gray,
100
+                                messageColor: .white
101
+                            ))
102
+                        }else if(inputPasswordMessage.isEmpty){
103
+                            SUIToast.show(messageItem: .init(
104
+                                message: "密码不能为空",
105
+                                bgColor: .gray,
106
+                                messageColor: .white
107
+                            ))
108
+                        }else {
109
+                            viewModel.loginUser(username: inputAccountMessage, password: inputPasswordMessage)
110
+                            isPresent=true
111
+                        }
112
+                        
100 113
                     }) {
101 114
                         Text("登录")
102 115
                             .font(.system(size: 17))
@@ -106,6 +119,8 @@ struct LoginView: View {
106 119
                             .foregroundColor(.white)
107 120
                             .background(.blue)
108 121
                             .cornerRadius(30)
122
+                    }.fullScreenCover(isPresented: $isPresent) {
123
+                        TestView(settingPagePresented: $isPresent)
109 124
                     }
110 125
                     
111 126
                 }
@@ -141,7 +156,7 @@ struct LoginView: View {
141 156
         }.padding()
142 157
             .frame(width: .infinity,height: .infinity)
143 158
     }
144
-
159
+    
145 160
 }
146 161
 
147 162
 struct ContentView_Previews: PreviewProvider {

+ 27
- 27
iOSFirst/login/LoginViewModel.swift View File

@@ -13,33 +13,33 @@ import RxRelay
13 13
 
14 14
 
15 15
 class LoginViewModel  {
16
-
16
+    
17 17
     private let service:MoyaProvider<AccountService>
18
-       private var bag = DisposeBag()
19
-       var userResponse = PublishSubject<LoginUserInfo>()
20
-       
18
+    private var bag = DisposeBag()
19
+    var userResponse = PublishSubject<LoginUserInfo>()
20
+    
21 21
     init(service:MoyaProvider<AccountService> = accountProvider) {
22
-           self.service = service
23
-          
24
-       }
25
-       
26
-     
27
-    func loginUser() {
28
-           service.rx.request(.login("90012", "123456",false)).subscribe { [weak self] event in
29
-               switch event {
30
-               case let .success(response):
31
-                   do {
32
-                       let response = try response.mapJSON()
33
-                       log.info( response )
34
-                       
35
-                   } catch let error {
36
-                       log.error(error.localizedDescription)
37
-                   }
38
-               case .failure(let error):
39
-                   log.error(error.localizedDescription)
40
-               }
41
-           }.disposed(by: bag)
42
-
43
-       }
44
-       
22
+        self.service = service
23
+        
24
+    }
25
+    
26
+    
27
+    func loginUser(username:String,password:String) {
28
+        service.rx.request(.login(username, password,false)).subscribe { [weak self] event in
29
+            switch event {
30
+            case let .success(response):
31
+                do {
32
+                    let response = try response.mapString()
33
+                    log.info( response )
34
+                    
35
+                } catch let error {
36
+                    log.error(error.localizedDescription)
37
+                }
38
+            case .failure(let error):
39
+                log.error(error.localizedDescription)
40
+            }
41
+        }.disposed(by: bag)
42
+        
43
+    }
44
+    
45 45
 }

+ 0
- 1
iOSFirst/network/service/AccountService.swift View File

@@ -58,7 +58,6 @@ extension AccountService: TargetType {
58 58
             
59 59
             return [
60 60
                 "st":"false",
61
-
62 61
                 "Content-type":"application/json"]
63 62
         default:
64 63
             return nil

Loading…
Cancel
Save