1
zhujie
2025-04-15 879ec1ae04b37eb7bf9357903d10acc860d84d5b
app/src/main/java/com/example/firstapp/activity/PhoneLoginActivity.kt
@@ -10,6 +10,7 @@
import com.example.firstapp.databinding.ActivityPhoneLoginBinding
import com.example.firstapp.ui.login.LoginViewModel
import com.example.firstapp.utils.Log
import com.example.firstapp.utils.PreferencesManager
class PhoneLoginActivity : AppCompatActivity() {
    private lateinit var binding: ActivityPhoneLoginBinding
@@ -28,6 +29,9 @@
    private fun setupViews() {
        binding.apply {
            // 设置上次登录的手机号
            etPhone.setText(PreferencesManager.getLastLoginPhone())
            btnBack.setOnClickListener {
                startActivity(Intent(this@PhoneLoginActivity, LoginActivity::class.java))
                finish()
@@ -39,19 +43,26 @@
                    viewModel.sendVerificationCode(phone)
                    startCountDown()
                } else {
                    Toast.makeText(this@PhoneLoginActivity,
                        "请输入正确的手机号", Toast.LENGTH_SHORT).show()
                    Toast.makeText(
                        this@PhoneLoginActivity,
                        "请输入正确的手机号", Toast.LENGTH_SHORT
                    ).show()
                }
            }
            btnLogin.setOnClickListener {
                val phone = etPhone.text.toString()
                val code = etCode.text.toString()
                val invite = etInvite.text.toString()
                if (phone.length == 11 && code.length == 6) {
                    viewModel.login(phone, code)
                    // 保存登录的手机号
                    PreferencesManager.saveLastLoginPhone(phone)
                    viewModel.login(phone, code, invite)
                } else {
                    Toast.makeText(this@PhoneLoginActivity,
                        "请输入完整信息", Toast.LENGTH_SHORT).show()
                    Toast.makeText(
                        this@PhoneLoginActivity,
                        "请输入完整信息", Toast.LENGTH_SHORT
                    ).show()
                }
            }
        }