初始代码提交
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
package com.sw.inbound.ui
|
||||
|
||||
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.layout.Box
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
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.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.sw.inbound.GlobalKey
|
||||
import com.sw.inbound.R
|
||||
import com.sw.inbound.ui.page.HomeScreen
|
||||
import com.sw.inbound.ui.page.PurchaseOrderScreen
|
||||
import com.sw.inbound.ui.weight.GlobalLoading
|
||||
import com.sw.inbound.utils.SPUtil
|
||||
import com.sw.inbound.utils.ToastUtils
|
||||
|
||||
@Composable
|
||||
fun AppScreen(
|
||||
onBackRequest: () -> Unit
|
||||
) {
|
||||
val navController = rememberNavController()
|
||||
val currentBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
var canBack by remember { mutableStateOf(false) }
|
||||
|
||||
// 拦截物理返回键
|
||||
// BackHandler(
|
||||
// onBack = {
|
||||
// val currentRoute = currentBackStackEntry?.destination?.route
|
||||
// Timber.d("BackHandler currentRouter = ${currentRoute}")
|
||||
// if (currentRoute == Screen.Home.route && !canBack) {
|
||||
// ToastUtils.showToast("再次点击退出")
|
||||
// canBack = true
|
||||
// } else if (currentRoute == Screen.Login.route) {
|
||||
// onBackRequest()
|
||||
// } else {
|
||||
// navController.popBackStack()
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
//
|
||||
// BackHandler(canBack) {
|
||||
// Timber.d("canBack = $canBack")
|
||||
// if (canBack) {
|
||||
// onBackRequest()
|
||||
// }
|
||||
// }
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
//.paint(painter = painterResource(R.mipmap.bg)),
|
||||
,containerColor = Color.Transparent,
|
||||
content = { padding ->
|
||||
Box {
|
||||
// Image(
|
||||
// painter = painterResource(R.mipmap.bg),
|
||||
// contentDescription = null,
|
||||
// modifier = Modifier.fillMaxSize(),
|
||||
// contentScale = ContentScale.Crop
|
||||
// )
|
||||
Image(
|
||||
painter = painterResource(id = R.mipmap.bg),
|
||||
contentDescription = "背景图片",
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
NavHost(padding, navController, onBackRequest)
|
||||
}
|
||||
}
|
||||
)
|
||||
ToastUtils.ToastComposable()
|
||||
GlobalLoading() // 全局Loading
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 导航
|
||||
*/
|
||||
@Composable
|
||||
private fun NavHost(
|
||||
padding: PaddingValues,
|
||||
navController: NavHostController,
|
||||
onBackRequest: () -> Unit = {}
|
||||
) {
|
||||
val spUtil = SPUtil.getInstance()
|
||||
val token = spUtil.get(GlobalKey.KEY_TOKEN, "")!!
|
||||
NavHost(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding),
|
||||
navController = navController,
|
||||
//startDestination = if (token.isEmpty()) Screen.Login.route else Screen.Home.route
|
||||
startDestination = Screen.Home.route
|
||||
) {
|
||||
// composable(Screen.Test.route) {
|
||||
// TestScreen(modifier = Modifier, navController)
|
||||
// }
|
||||
// 首页
|
||||
composable(Screen.Home.route) {
|
||||
HomeScreen(modifier = Modifier, navController, onBackRequest = onBackRequest)
|
||||
}
|
||||
// 登录
|
||||
// composable(Screen.Login.route) {
|
||||
// LoginScreen(modifier = Modifier, navController)
|
||||
// }
|
||||
// 采购单入库
|
||||
composable(
|
||||
Screen.PurchaseOrder.route,
|
||||
enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
|
||||
exitTransition = { fadeOut(animationSpec = tween(0)) } // 无退出动画
|
||||
) {
|
||||
PurchaseOrderScreen(modifier = Modifier.fillMaxSize(), navController)
|
||||
}
|
||||
// // 自采单
|
||||
// composable(
|
||||
// Screen.SelfProcurement.route,
|
||||
// enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
|
||||
// exitTransition = { fadeOut(animationSpec = tween(0)) } // 无退出动画
|
||||
// ) {
|
||||
// SelfProcurementScreen(modifier = Modifier, navController)
|
||||
// }
|
||||
// // 收货
|
||||
// composable(
|
||||
// Screen.ReceiptProduct.route,
|
||||
// enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
|
||||
// exitTransition = { fadeOut(animationSpec = tween(0)) }, // 无退出动画
|
||||
// arguments = listOf(
|
||||
// navArgument(name = "id", builder = { type = NavType.IntType }),
|
||||
// navArgument(name = "supplierId", builder = { type = NavType.IntType })
|
||||
// )
|
||||
// ) { backStackEntry ->
|
||||
// val id = backStackEntry.arguments?.getString("id") ?: ""
|
||||
// val supplierId = backStackEntry.arguments?.getString("supplierId") ?: ""
|
||||
// ReceiptProductScreen(modifier = Modifier, navController, id, supplierId)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Screen(val route: String) {
|
||||
data object Home : Screen("home")
|
||||
// data object Login : Screen("login")
|
||||
|
||||
// 采购单入库
|
||||
data object PurchaseOrder : Screen("purchase_order")
|
||||
|
||||
// 自采单入库
|
||||
// data object SelfProcurement : Screen("self_procurement")
|
||||
|
||||
// 收货
|
||||
// data object ReceiptProduct : Screen("receipt_product?id={id}&supplierId={supplierId}") {
|
||||
// fun createRoute(id: Int, supplierId: Int) =
|
||||
// "receipt_product?id=${id}&supplierId=${supplierId}"
|
||||
// }
|
||||
|
||||
// 添加物品
|
||||
// data object AddProduct : Screen("addProduct")
|
||||
// data object Test : Screen("Test")
|
||||
}
|
||||
Reference in New Issue
Block a user