|
@@ -6,14 +6,21 @@ import androidx.compose.material.Button
|
|
|
import androidx.compose.material.ButtonDefaults
|
|
|
import androidx.compose.material.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.collectAsState
|
|
|
+import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.platform.LocalLifecycleOwner
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
+import androidx.lifecycle.Lifecycle
|
|
|
+import androidx.lifecycle.flowWithLifecycle
|
|
|
import com.ys.bdtp.adm.app.theme.bgBlueColor
|
|
|
import com.ys.bdtp.adm.app.theme.underColor
|
|
|
import com.ys.bdtp.adm.app.theme.whiteColor
|
|
|
+import com.ys.bdtp.adm.mvvm.model.Data
|
|
|
+import com.ys.bdtp.adm.mvvm.model.State
|
|
|
import com.ys.bdtp.adm.mvvm.model.vo.request.requestBody
|
|
|
import com.ys.bdtp.adm.mvvm.vm.offline.OfflineViewModel
|
|
|
import org.kodein.di.compose.rememberViewModel
|
|
@@ -23,9 +30,18 @@ import org.kodein.di.compose.rememberViewModel
|
|
|
* 离线数据左侧UI
|
|
|
*/
|
|
|
@Composable
|
|
|
-fun OfflineSide2() {
|
|
|
+fun OfflineSide2(projectId: String) {
|
|
|
val vm by rememberViewModel<OfflineViewModel>()
|
|
|
val scope = rememberCoroutineScope()
|
|
|
+
|
|
|
+
|
|
|
+ val lifecycleOwner = LocalLifecycleOwner.current
|
|
|
+ val projectsAware = remember(vm.projectWithBuildingsFlow, lifecycleOwner) {
|
|
|
+ vm.projectWithBuildingsFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
+ }
|
|
|
+
|
|
|
+ val projectsState = projectsAware.collectAsState(Data.loading())
|
|
|
+
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
|
.width(280.dp)
|
|
@@ -65,19 +81,31 @@ fun OfflineSide2() {
|
|
|
Button(
|
|
|
modifier = Modifier.size(220.dp, 42.dp),
|
|
|
onClick = {
|
|
|
- vm.getDict(
|
|
|
- body = requestBody(
|
|
|
- userId = "17337681032",
|
|
|
- groupCode = "JDKJ",
|
|
|
- projectId = "Pj1101080665",
|
|
|
- ),
|
|
|
- success = {
|
|
|
- println("success: $it")
|
|
|
- },
|
|
|
- failure = {
|
|
|
- println("failure: $it")
|
|
|
+ when (projectsState.value.state) {
|
|
|
+ is State.Loading -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ is State.Success -> {
|
|
|
+ projectsState.value.data?.forEach {
|
|
|
+ vm.getDict(
|
|
|
+ body = requestBody(
|
|
|
+ userId = it.project.userId,
|
|
|
+ groupCode = it.project.groupCode,
|
|
|
+ projectId = it.project.projectId,
|
|
|
+ ),
|
|
|
+ success = {
|
|
|
+ println("success: $it")
|
|
|
+ },
|
|
|
+ failure = {
|
|
|
+ println("failure: $it")
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ is State.Failure -> {
|
|
|
+
|
|
|
}
|
|
|
- )
|
|
|
+ }
|
|
|
},
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
contentColor = whiteColor,
|
|
@@ -91,7 +119,32 @@ fun OfflineSide2() {
|
|
|
Button(
|
|
|
modifier = Modifier.size(220.dp, 42.dp),
|
|
|
onClick = {
|
|
|
- vm.getConfig(
|
|
|
+ when (projectsState.value.state) {
|
|
|
+ is State.Loading -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ is State.Success -> {
|
|
|
+ projectsState.value.data?.forEach {
|
|
|
+ vm.getConfig(
|
|
|
+ body = requestBody(
|
|
|
+ userId = it.project.userId,
|
|
|
+ groupCode = it.project.groupCode,
|
|
|
+ projectId = it.project.projectId,
|
|
|
+ ),
|
|
|
+ success = {
|
|
|
+ println("success: $it")
|
|
|
+ },
|
|
|
+ failure = {
|
|
|
+ println("failure: $it")
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ is State.Failure -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*vm.getConfig(
|
|
|
body = requestBody(
|
|
|
userId = "17337681032",
|
|
|
groupCode = "JDKJ",
|
|
@@ -103,7 +156,7 @@ fun OfflineSide2() {
|
|
|
failure = {
|
|
|
println("failure: $it")
|
|
|
}
|
|
|
- )
|
|
|
+ )*/
|
|
|
},
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
contentColor = whiteColor,
|
|
@@ -117,19 +170,45 @@ fun OfflineSide2() {
|
|
|
Button(
|
|
|
modifier = Modifier.size(220.dp, 42.dp),
|
|
|
onClick = {
|
|
|
- vm.getBuildingsAndFloors(
|
|
|
- body = requestBody(
|
|
|
- userId = "17337681032",
|
|
|
- groupCode = "JDKJ",
|
|
|
- projectId = "Pj1101080665",
|
|
|
- ),
|
|
|
- success = {
|
|
|
- println("success: $it")
|
|
|
- },
|
|
|
- failure = {
|
|
|
- println("failure: $it")
|
|
|
+ when (projectsState.value.state) {
|
|
|
+ is State.Loading -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ is State.Success -> {
|
|
|
+ projectsState.value.data?.forEach {
|
|
|
+ vm.getBuildingsAndFloors(
|
|
|
+ body = requestBody(
|
|
|
+ userId = it.project.userId,
|
|
|
+ groupCode = it.project.groupCode,
|
|
|
+ projectId = it.project.projectId,
|
|
|
+ ),
|
|
|
+ success = {
|
|
|
+ println("success: $it")
|
|
|
+ },
|
|
|
+ failure = {
|
|
|
+ println("failure: $it")
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ is State.Failure -> {
|
|
|
+
|
|
|
}
|
|
|
- )
|
|
|
+ }
|
|
|
+
|
|
|
+ /* vm.getBuildingsAndFloors(
|
|
|
+ body = requestBody(
|
|
|
+ userId = "17337681032",
|
|
|
+ groupCode = "JDKJ",
|
|
|
+ projectId = "Pj1101080665",
|
|
|
+ ),
|
|
|
+ success = {
|
|
|
+ println("success: $it")
|
|
|
+ },
|
|
|
+ failure = {
|
|
|
+ println("failure: $it")
|
|
|
+ }
|
|
|
+ )*/
|
|
|
},
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
contentColor = whiteColor,
|
|
@@ -139,24 +218,54 @@ fun OfflineSide2() {
|
|
|
) {
|
|
|
Text(text = "获取建筑与楼层数据")
|
|
|
}
|
|
|
+
|
|
|
Spacer(modifier = Modifier.height(32.dp))
|
|
|
Button(
|
|
|
modifier = Modifier.size(220.dp, 42.dp),
|
|
|
onClick = {
|
|
|
- vm.getMission(
|
|
|
+ when (projectsState.value.state) {
|
|
|
+ is State.Loading -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ is State.Success -> {
|
|
|
+ projectsState.value.data?.forEach { project ->
|
|
|
+ project.buildings.forEach { building ->
|
|
|
+ vm.getMission(
|
|
|
+ body = requestBody(
|
|
|
+ userId = project.project.userId,
|
|
|
+ groupCode = project.project.groupCode,
|
|
|
+ projectId = project.project.projectId,
|
|
|
+ buildingId = building.id
|
|
|
+ ),
|
|
|
+ success = {
|
|
|
+ println("success: ")
|
|
|
+ },
|
|
|
+ failure = {
|
|
|
+ println("failure: $it")
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ is State.Failure -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*vm.getMission(
|
|
|
body = requestBody(
|
|
|
- userId = "17337681032",
|
|
|
- groupCode = "JDKJ",
|
|
|
- projectId = "Pj1101080665",
|
|
|
- buildingId = "Bd990999000204fb9e7d54f54f43a0280b616623d91e"
|
|
|
+ userId = "1468407036472936433",
|
|
|
+ groupCode = "XG",
|
|
|
+ projectId = "Pj5001120003",
|
|
|
+ buildingId = "Bd5001120003a9b2f891b91d11ea82bfaf908bb0a852"
|
|
|
),
|
|
|
success = {
|
|
|
- println("success: $it")
|
|
|
+ println("success: ")
|
|
|
},
|
|
|
failure = {
|
|
|
println("failure: $it")
|
|
|
}
|
|
|
- )
|
|
|
+ )*/
|
|
|
},
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
contentColor = whiteColor,
|
|
@@ -173,5 +282,5 @@ fun OfflineSide2() {
|
|
|
@Preview
|
|
|
@Composable
|
|
|
fun PreviewOfflineSide2() {
|
|
|
- OfflineSide2()
|
|
|
+ OfflineSide2("")
|
|
|
}
|