This commit is contained in:
马增飞
2025-11-19 13:00:15 +08:00
parent d10879ca29
commit b67ff51c45
6 changed files with 228 additions and 231 deletions
@@ -385,6 +385,11 @@ abstract class GoodsListActivity : ComponentActivity() {
} }
override fun onDestroy() { override fun onDestroy() {
try {
DialogManager.dismissAll()
} catch (e: Exception) {
e.printStackTrace()
}
super.onDestroy() super.onDestroy()
//cameraController?.unbind() //cameraController?.unbind()
//isCameraReady = false //isCameraReady = false
@@ -199,23 +199,23 @@ class AddGoodsDialog(
return return
} }
val netRate = (netRateText.toFloatOrNull() ?: 0f) / 100f val netRate = (netRateText.toFloatOrNull() ?: 0f) / 100f
val goodsType = binding.tvGoodsType.tag.toString() val goodsType = binding.tvGoodsType.tag
if (goodsType.isBlank()) { if (goodsType == null || goodsType.toString().isBlank()) {
context.toast("请录入物品类型") context.toast("请录入物品类型")
return return
} }
val storageType = binding.tvStorageType.tag.toString() val storageType = binding.tvStorageType.tag
if (storageType.isBlank()) { if (storageType == null || storageType.toString().isBlank()) {
context.toast("请录入存储方式") context.toast("请录入存储方式")
return return
} }
val warehouseUnit = binding.tvWarehouseUnit.tag.toString() val warehouseUnit = binding.tvWarehouseUnit.tag
if (warehouseUnit.isBlank()) { if (warehouseUnit == null || warehouseUnit.toString().isBlank()) {
context.toast("请录入库存单位") context.toast("请录入库存单位")
return return
} }
val purchaseUnit = binding.tvProcurementUnit.tag.toString() val purchaseUnit = binding.tvProcurementUnit.tag
if (purchaseUnit.isBlank()) { if (purchaseUnit == null || purchaseUnit.toString().isBlank()) {
context.toast("请录采购单位") context.toast("请录采购单位")
return return
} }
@@ -237,11 +237,11 @@ class AddGoodsDialog(
val param = GoodsAddParam( val param = GoodsAddParam(
goodName = goodsName, goodName = goodsName,
netRate = netRate, netRate = netRate,
goodType = goodsType, goodType = goodsType.toString(),
storageType = storageType, storageType = storageType.toString(),
unitId = warehouseUnit, unitId = warehouseUnit.toString(),
consumeValue = costValue, consumeValue = costValue,
purchaseUnit = purchaseUnit, purchaseUnit = purchaseUnit.toString(),
purchaseValue = goodsCount.toSafeFloat(), purchaseValue = goodsCount.toSafeFloat(),
purchasePrice = goodsPrice.toSafeBigDecimal(), purchasePrice = goodsPrice.toSafeBigDecimal(),
) )
@@ -212,7 +212,7 @@ class GoodsStoreDialog(
return@readWeightInfo return@readWeightInfo
} }
val unitTag = binding.tvProcurementUnit.tag val unitTag = binding.tvProcurementUnit.tag
if (unitTag == null) { if (unitTag == null || unitTag.toString().isBlank()) {
return@readWeightInfo return@readWeightInfo
} }
val id = unitTag.toString() val id = unitTag.toString()
@@ -4,7 +4,6 @@ import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut import androidx.compose.animation.fadeOut
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@@ -16,25 +15,18 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.paint
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.sw.inbound.GlobalKey import com.sw.inbound.GlobalKey
import com.sw.inbound.R import com.sw.inbound.R
import com.sw.inbound.ui.page.HomeScreen import com.sw.inbound.ui.page.HomeScreen
import com.sw.inbound.ui.page.LoginScreen
import com.sw.inbound.ui.page.PurchaseOrderScreen import com.sw.inbound.ui.page.PurchaseOrderScreen
//import com.sw.inbound.ui.page.ReceiptProductScreen
//import com.sw.inbound.ui.page.SelfProcurementScreen
//import com.sw.inbound.ui.page.TestScreen
import com.sw.inbound.ui.weight.GlobalLoading import com.sw.inbound.ui.weight.GlobalLoading
import com.sw.inbound.utils.SPUtil import com.sw.inbound.utils.SPUtil
import com.sw.inbound.utils.ToastUtils import com.sw.inbound.utils.ToastUtils
@@ -125,9 +117,9 @@ private fun NavHost(
HomeScreen(modifier = Modifier, navController, onBackRequest = onBackRequest) HomeScreen(modifier = Modifier, navController, onBackRequest = onBackRequest)
} }
// 登录 // 登录
composable(Screen.Login.route) { // composable(Screen.Login.route) {
LoginScreen(modifier = Modifier, navController) // LoginScreen(modifier = Modifier, navController)
} // }
// 采购单入库 // 采购单入库
composable( composable(
Screen.PurchaseOrder.route, Screen.PurchaseOrder.route,
@@ -163,7 +155,7 @@ private fun NavHost(
sealed class Screen(val route: String) { sealed class Screen(val route: String) {
data object Home : Screen("home") data object Home : Screen("home")
data object Login : Screen("login") // data object Login : Screen("login")
// 采购单入库 // 采购单入库
data object PurchaseOrder : Screen("purchase_order") data object PurchaseOrder : Screen("purchase_order")
@@ -57,12 +57,12 @@ fun HomeScreen(
Column(modifier = Modifier.fillMaxSize()) { Column(modifier = Modifier.fillMaxSize()) {
TopTitleBar(user = user, onLogoutClick = { TopTitleBar(user = user, onLogoutClick = {
viewModel.logout() // viewModel.logout()
navController.navigate(Screen.Login.route) { // navController.navigate(Screen.Login.route) {
popUpTo(Screen.Home.route) { // popUpTo(Screen.Home.route) {
inclusive = true // inclusive = true
} // }
} // }
}) })
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
@@ -1,202 +1,202 @@
package com.sw.inbound.ui.page //package com.sw.inbound.ui.page
//
import androidx.compose.foundation.Image //import androidx.compose.foundation.Image
import androidx.compose.foundation.border //import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement //import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box //import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column //import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer //import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize //import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth //import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height //import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding //import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size //import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width //import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape //import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions //import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Text //import androidx.compose.material3.Text
import androidx.compose.material3.TextField //import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults //import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable //import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect //import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue //import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf //import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember //import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue //import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment //import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier //import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color //import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap //import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.res.colorResource //import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.input.ImeAction //import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType //import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation //import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation //import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign //import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp //import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp //import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel //import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController //import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController //import androidx.navigation.compose.rememberNavController
import com.sw.inbound.GlobalData //import com.sw.inbound.GlobalData
import com.sw.inbound.GlobalKey //import com.sw.inbound.GlobalKey
import com.sw.inbound.R //import com.sw.inbound.R
import com.sw.inbound.ext.bold //import com.sw.inbound.ext.bold
import com.sw.inbound.ext.textAlign //import com.sw.inbound.ext.textAlign
import com.sw.inbound.ext.withSize //import com.sw.inbound.ext.withSize
import com.sw.inbound.ui.Screen //import com.sw.inbound.ui.Screen
import com.sw.inbound.ui.theme.AppTypography //import com.sw.inbound.ui.theme.AppTypography
import com.sw.inbound.ui.weight.CustomButton //import com.sw.inbound.ui.weight.CustomButton
import com.sw.inbound.utils.QRCodeUtil //import com.sw.inbound.utils.QRCodeUtil
import com.sw.inbound.utils.SPUtil //import com.sw.inbound.utils.SPUtil
import com.sw.inbound.viewmodel.UserViewModel //import com.sw.inbound.viewmodel.UserViewModel
import timber.log.Timber //import timber.log.Timber
//
/** ///**
* 登录界面 // * 登录界面
*/ // */
@Composable //@Composable
fun LoginScreen( //fun LoginScreen(
modifier: Modifier = Modifier, // modifier: Modifier = Modifier,
controller: NavController = rememberNavController(), // controller: NavController = rememberNavController(),
viewModel: UserViewModel = hiltViewModel<UserViewModel>() // viewModel: UserViewModel = hiltViewModel<UserViewModel>()
) { //) {
var username by remember { mutableStateOf<String>("") } // var username by remember { mutableStateOf<String>("") }
var password by remember { mutableStateOf<String>("") } // var password by remember { mutableStateOf<String>("") }
//
// val user by viewModel.user.collectAsState() //// val user by viewModel.user.collectAsState()
//
LaunchedEffect(Unit) { // LaunchedEffect(Unit) {
Timber.d(" user =") // Timber.d(" user =")
username = SPUtil.getInstance().get(GlobalKey.KEY_USER_NAME, "").toString() // username = SPUtil.getInstance().get(GlobalKey.KEY_USER_NAME, "").toString()
viewModel.user.collect { // viewModel.user.collect {
Timber.d(" user collect = ${it}") // Timber.d(" user collect = ${it}")
if (it != null) { // if (it != null) {
GlobalData.user = it // GlobalData.user = it
controller.navigate(Screen.Home.route) { // controller.navigate(Screen.Home.route) {
Timber.d("登录成功,跳转到主界面") // Timber.d("登录成功,跳转到主界面")
controller.popBackStack() // controller.popBackStack()
} // }
}
}
// if (user != null){
// controller.navigate(Screen.Home.route) {
// controller.popBackStack()
// } // }
// } // }
} //// if (user != null){
//// controller.navigate(Screen.Home.route) {
val qrCodeBmp by lazy { //// controller.popBackStack()
QRCodeUtil.generateQRCode( //// }
content = GlobalData.deviceId, //// }
size = 150 // }
) //
} // val qrCodeBmp by lazy {
// QRCodeUtil.generateQRCode(
Box(contentAlignment = Alignment.BottomStart) { // content = GlobalData.deviceId,
Column( // size = 150
modifier = Modifier.fillMaxSize(), // )
verticalArrangement = Arrangement.Center, // }
horizontalAlignment = Alignment.CenterHorizontally //
) { // Box(contentAlignment = Alignment.BottomStart) {
Text(text = "出入库管理", style = AppTypography.black141428TextStyle.withSize(60.sp).bold()) // Column(
Spacer(modifier = Modifier.height(91.dp)) // modifier = Modifier.fillMaxSize(),
// verticalArrangement = Arrangement.Center,
UserInputView(value = username, placeholderValue = "请输入用户名", onValueChange = { // horizontalAlignment = Alignment.CenterHorizontally
username = it // ) {
}) // Text(text = "出入库管理", style = AppTypography.black141428TextStyle.withSize(60.sp).bold())
// Spacer(modifier = Modifier.height(91.dp))
Spacer(modifier = Modifier.height(30.dp)) //
// UserInputView(value = username, placeholderValue = "请输入用户名", onValueChange = {
UserInputView(value = password, placeholderValue = "请输入密码", onValueChange = { // username = it
password = it // })
}, isPassword = true) //
// Spacer(modifier = Modifier.height(30.dp))
Spacer(modifier = Modifier.height(90.dp)) //
CustomButton( // UserInputView(value = password, placeholderValue = "请输入密码", onValueChange = {
modifier = modifier // password = it
.width(885.dp) // }, isPassword = true)
.height(120.dp), //
text = "登录", // Spacer(modifier = Modifier.height(90.dp))
onClick = { // CustomButton(
//if (username.isEmpty() || password.isEmpty()) { // modifier = modifier
// ToastUtils.showToast("用户名或密码不能为空") // .width(885.dp)
// return@CustomButton // .height(120.dp),
//} // text = "登录",
viewModel.login(username, password) // onClick = {
// TODO: 测试功能,临时打开新页面 // //if (username.isEmpty() || password.isEmpty()) {
controller.navigate(Screen.Home.route) // // ToastUtils.showToast("用户名或密码不能为空")
// controller.context.startActivity<ReceiptActivity> { // // return@CustomButton
// putExtra(GoodsListActivity.ID, "123123") // //}
// putExtra(GoodsListActivity.SUPPLIER_ID, "123123123123") // viewModel.login(username, password)
// } // // TODO: 测试功能,临时打开新页面
}, // controller.navigate(Screen.Home.route)
borderColor = colorResource(R.color.blue), //// controller.context.startActivity<ReceiptActivity> {
textColor = colorResource(R.color.white), //// putExtra(GoodsListActivity.ID, "123123")
fontSize = 36.sp //// putExtra(GoodsListActivity.SUPPLIER_ID, "123123123123")
) //// }
} // },
Image( // borderColor = colorResource(R.color.blue),
bitmap = qrCodeBmp!!.asImageBitmap(), // textColor = colorResource(R.color.white),
contentDescription = "", // fontSize = 36.sp
modifier = Modifier // )
.padding(start = 10.dp, bottom = 10.dp) // }
.size(80.dp, 80.dp) // Image(
) // bitmap = qrCodeBmp!!.asImageBitmap(),
} // contentDescription = "",
} // modifier = Modifier
// .padding(start = 10.dp, bottom = 10.dp)
// .size(80.dp, 80.dp)
@Composable // )
private fun UserInputView( // }
value: String, //}
placeholderValue: String, //
onValueChange: (String) -> Unit, //
isPassword: Boolean = false, //@Composable
isShowPassword: Boolean = false //private fun UserInputView(
) { // value: String,
val backgroundColor = Color.White.copy(alpha = 0.37f) // placeholderValue: String,
// onValueChange: (String) -> Unit,
TextField( // isPassword: Boolean = false,
value = value, // isShowPassword: Boolean = false
onValueChange = onValueChange, //) {
modifier = Modifier // val backgroundColor = Color.White.copy(alpha = 0.37f)
.height(120.dp) //
.width(885.dp) // TextField(
.border( // value = value,
width = 2.dp, // onValueChange = onValueChange,
color = backgroundColor, // modifier = Modifier
shape = RoundedCornerShape(10.dp) // .height(120.dp)
), // .width(885.dp)
colors = TextFieldDefaults.colors( // .border(
focusedContainerColor = backgroundColor, // width = 2.dp,
unfocusedContainerColor = backgroundColor, // color = backgroundColor,
disabledContainerColor = backgroundColor, // shape = RoundedCornerShape(10.dp)
focusedIndicatorColor = Color.Transparent, // ),
unfocusedIndicatorColor = Color.Transparent, // colors = TextFieldDefaults.colors(
disabledIndicatorColor = Color.Transparent // focusedContainerColor = backgroundColor,
), // unfocusedContainerColor = backgroundColor,
// 密码输入相关设置 // disabledContainerColor = backgroundColor,
visualTransformation = if (isPassword && !isShowPassword) { // focusedIndicatorColor = Color.Transparent,
PasswordVisualTransformation() // unfocusedIndicatorColor = Color.Transparent,
} else { // disabledIndicatorColor = Color.Transparent
VisualTransformation.None // ),
}, // // 密码输入相关设置
keyboardOptions = KeyboardOptions( // visualTransformation = if (isPassword && !isShowPassword) {
keyboardType = if (isPassword) KeyboardType.Password else KeyboardType.Text, // PasswordVisualTransformation()
imeAction = if (isPassword) ImeAction.Done else ImeAction.Next // } else {
), // VisualTransformation.None
shape = RoundedCornerShape(10.dp), // },
textStyle = AppTypography.gray96a0aaTextStyle.withSize(30.sp).textAlign(TextAlign.Center), // keyboardOptions = KeyboardOptions(
placeholder = { // keyboardType = if (isPassword) KeyboardType.Password else KeyboardType.Text,
Text( // imeAction = if (isPassword) ImeAction.Done else ImeAction.Next
text = placeholderValue, // ),
modifier = Modifier.fillMaxWidth(), // shape = RoundedCornerShape(10.dp),
textAlign = TextAlign.Center, // 占位符水平居中 // textStyle = AppTypography.gray96a0aaTextStyle.withSize(30.sp).textAlign(TextAlign.Center),
style = AppTypography.gray96a0aaTextStyle.textAlign(TextAlign.Center) // placeholder = {
) // Text(
}, // text = placeholderValue,
singleLine = true // 确保单行输入(避免换行导致高度变化) // modifier = Modifier.fillMaxWidth(),
) // textAlign = TextAlign.Center, // 占位符水平居中
// style = AppTypography.gray96a0aaTextStyle.textAlign(TextAlign.Center)
} // )
// },
// singleLine = true // 确保单行输入(避免换行导致高度变化)
// )
//
//}