Files
suixinkan_uikit/suixinkan/UI/Login/LoginViewModel.swift
汉秋 b7d74905b7 Add login flow, session routing, and MainTab shell aligned with reference UI.
Implement token-based root routing, Android-matched login screen, five-slot MainTabBar with scan action, and placeholder tab pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 15:12:34 +08:00

62 lines
1.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LoginViewModel.swift
// suixinkan
//
import Foundation
/// ViewModelUI Android `LoginViewModel`
final class LoginViewModel {
private(set) var account = ""
private(set) var password = ""
private(set) var isPrivacyChecked = false
private(set) var enableRegister = false
var isLoginEnabled: Bool {
!account.isEmpty && !password.isEmpty
}
var onStateChange: (() -> Void)?
func updateAccount(_ value: String) {
account = value
notifyStateChange()
}
func updatePassword(_ value: String) {
password = value
notifyStateChange()
}
func togglePrivacyChecked() {
isPrivacyChecked.toggle()
notifyStateChange()
}
func updateEnableRegister(_ enabled: Bool) {
enableRegister = enabled
notifyStateChange()
}
func login() {
guard isPrivacyChecked else {
onShowMessage?("请先阅读并同意用户协议与隐私政策")
return
}
guard isLoginEnabled else { return }
onLogin?()
}
var onShowMessage: ((String) -> Void)?
var onLogin: (() -> Void)?
var onLoginByCode: (() -> Void)?
var onRegister: (() -> Void)?
var onUserAgreement: (() -> Void)?
var onPrivacyPolicy: (() -> Void)?
private func notifyStateChange() {
onStateChange?()
}
}