Browse Source

导航以及页面修改

main
jasonsyf 1 year ago
parent
commit
1713f1ee83

+ 1
- 1
iOSFirst/SwiftUIToast.swift View File

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

+ 34
- 0
iOSFirst/TestView.swift View File

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
 struct LoginView: View {
13
 struct LoginView: View {
14
     private var viewModel = LoginViewModel()
14
     private var viewModel = LoginViewModel()
15
     var bag = DisposeBag()
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
     var body: some View {
20
     var body: some View {
19
         
21
         
47
                     .foregroundColor(.accentColor)
49
                     .foregroundColor(.accentColor)
48
                     .frame(width: 240,height: 35)
50
                     .frame(width: 240,height: 35)
49
             }.frame(height: 40)
51
             }.frame(height: 40)
50
-            .padding(.top,20)
51
-            .padding(.bottom,100)
52
+                .padding(.top,20)
53
+                .padding(.bottom,100)
52
             
54
             
53
             VStack(alignment: .leading, spacing: 400) {
55
             VStack(alignment: .leading, spacing: 400) {
54
                 HStack(alignment: .center, spacing: 15) {
56
                 HStack(alignment: .center, spacing: 15) {
56
                         .imageScale(.large)
58
                         .imageScale(.large)
57
                         .foregroundColor(.accentColor)
59
                         .foregroundColor(.accentColor)
58
                     
60
                     
59
-                    TextField("请输入手机号",text:.constant(""))
60
-                        .id("etPhoneNum")
61
+                    TextField("请输入手机号",text:$inputAccountMessage)
62
+                        .keyboardType(UIKeyboardType.namePhonePad)
61
                         .font(.system(size: 16))
63
                         .font(.system(size: 16))
62
                         .frame(maxWidth: .infinity,alignment: .center)
64
                         .frame(maxWidth: .infinity,alignment: .center)
63
                     
65
                     
73
                         .imageScale(.large)
75
                         .imageScale(.large)
74
                         .foregroundColor(.accentColor)
76
                         .foregroundColor(.accentColor)
75
                     
77
                     
76
-                    TextField("请输入密码",text:.constant(""))
77
-                        .id("etPassword")
78
+                    SecureField("请输入密码",text:$inputPasswordMessage)
79
+                        .textContentType(.oneTimeCode)
80
+                        .keyboardType(UIKeyboardType.namePhonePad)
78
                         .font(.system(size: 16))
81
                         .font(.system(size: 16))
79
                         .frame(maxWidth: .infinity,alignment: .center)
82
                         .frame(maxWidth: .infinity,alignment: .center)
80
                     
83
                     
88
             VStack(alignment: .trailing, spacing: 400) {
91
             VStack(alignment: .trailing, spacing: 400) {
89
                 
92
                 
90
                 VStack(alignment: .center, spacing: 15) {
93
                 VStack(alignment: .center, spacing: 15) {
94
+                    
91
                     Button(action: {
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
                         Text("登录")
114
                         Text("登录")
102
                             .font(.system(size: 17))
115
                             .font(.system(size: 17))
106
                             .foregroundColor(.white)
119
                             .foregroundColor(.white)
107
                             .background(.blue)
120
                             .background(.blue)
108
                             .cornerRadius(30)
121
                             .cornerRadius(30)
122
+                    }.fullScreenCover(isPresented: $isPresent) {
123
+                        TestView(settingPagePresented: $isPresent)
109
                     }
124
                     }
110
                     
125
                     
111
                 }
126
                 }
141
         }.padding()
156
         }.padding()
142
             .frame(width: .infinity,height: .infinity)
157
             .frame(width: .infinity,height: .infinity)
143
     }
158
     }
144
-
159
+    
145
 }
160
 }
146
 
161
 
147
 struct ContentView_Previews: PreviewProvider {
162
 struct ContentView_Previews: PreviewProvider {

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

13
 
13
 
14
 
14
 
15
 class LoginViewModel  {
15
 class LoginViewModel  {
16
-
16
+    
17
     private let service:MoyaProvider<AccountService>
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
     init(service:MoyaProvider<AccountService> = accountProvider) {
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
             
58
             
59
             return [
59
             return [
60
                 "st":"false",
60
                 "st":"false",
61
-
62
                 "Content-type":"application/json"]
61
                 "Content-type":"application/json"]
63
         default:
62
         default:
64
             return nil
63
             return nil

Loading…
Cancel
Save