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