You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
3.3 KiB
83 lines
3.3 KiB
package com.gyf.csams.account.ui
|
|
|
|
import android.content.Intent
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.material.OutlinedButton
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.res.stringResource
|
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.gyf.csams.R
|
|
import com.gyf.csams.account.model.LoginViewModel
|
|
import com.gyf.csams.main.ui.MainActivity
|
|
import com.gyf.lib.uikit.*
|
|
|
|
/**
|
|
* 登录
|
|
*
|
|
*/
|
|
class LoginActivity : ComponentActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContent {
|
|
Body {
|
|
MainBoxFrame(
|
|
background = { /*TODO 背景图*/ },
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.height(300.dp),
|
|
verticalArrangement = Arrangement.SpaceEvenly,
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
) {
|
|
val model: LoginViewModel = viewModel()
|
|
val scaffoldModel: ScaffoldModel = viewModel()
|
|
val idStatus by model.id.statusForm.observeAsState()
|
|
val passwordStatus by model.password.statusForm.observeAsState()
|
|
BaseTextField(form = model.id)
|
|
|
|
BaseTextField(
|
|
form = model.password,
|
|
visualTransformation = PasswordVisualTransformation()
|
|
)
|
|
OutlinedButton(
|
|
onClick = {
|
|
model.login {
|
|
scaffoldModel.update(message = it)
|
|
}
|
|
},
|
|
enabled = idStatus == FormStatus.Valid && passwordStatus == FormStatus.Valid
|
|
) {
|
|
Text(text = stringResource(id = R.string.login_btn))
|
|
}
|
|
val finishLogin: Boolean? by model.finishLogin.observeAsState()
|
|
if (finishLogin == true) {
|
|
startActivity(
|
|
Intent(
|
|
LocalContext.current,
|
|
MainActivity::class.java
|
|
)
|
|
)
|
|
finish()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |