|
@@ -8,24 +8,20 @@ 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.State
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
-import androidx.compose.ui.graphics.Color
|
|
|
-import androidx.compose.ui.platform.LocalLifecycleOwner
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
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.R
|
|
|
import com.ys.bdtp.adm.app.theme.bgBlueColor
|
|
|
-import com.ys.bdtp.adm.app.theme.blueColor
|
|
|
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.db.relation.ProjectWithBuildings
|
|
|
import com.ys.bdtp.adm.mvvm.model.vo.request.requestBody
|
|
|
import com.ys.bdtp.adm.mvvm.ui.compose.Div
|
|
|
import com.ys.bdtp.adm.mvvm.vm.offline.OfflineViewModel
|
|
@@ -37,16 +33,10 @@ import org.kodein.di.compose.rememberViewModel
|
|
|
* 离线数据左侧UI
|
|
|
*/
|
|
|
@Composable
|
|
|
-fun OfflineSide() {
|
|
|
+fun OfflineSide(state: State<Data<ProjectWithBuildings>>) {
|
|
|
val vm by rememberViewModel<OfflineViewModel>()
|
|
|
-
|
|
|
- val lifecycleOwner = LocalLifecycleOwner.current
|
|
|
- val projectsAware = remember(vm.projectWithBuildingsFlow, lifecycleOwner) {
|
|
|
- vm.projectWithBuildingsFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
- }
|
|
|
-
|
|
|
- val projectsState = projectsAware.collectAsState(Data.loading())
|
|
|
val scope = rememberCoroutineScope()
|
|
|
+ val projectsState = remember { state }
|
|
|
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
@@ -62,12 +52,13 @@ fun OfflineSide() {
|
|
|
onClick = {
|
|
|
scope.launch {
|
|
|
// 下载字典
|
|
|
- projectsState.value.data?.forEach {
|
|
|
+ val data = projectsState.value.data
|
|
|
+ data?.project?.let {
|
|
|
vm.getDict(
|
|
|
body = requestBody(
|
|
|
- userId = it.project.userId,
|
|
|
- groupCode = it.project.groupCode,
|
|
|
- projectId = it.project.projectId,
|
|
|
+ userId = it.userId,
|
|
|
+ groupCode = it.groupCode,
|
|
|
+ projectId = it.projectId,
|
|
|
),
|
|
|
success = {
|
|
|
println("success: $it")
|
|
@@ -80,12 +71,13 @@ fun OfflineSide() {
|
|
|
}
|
|
|
scope.launch {
|
|
|
// 下载配置
|
|
|
- projectsState.value.data?.forEach {
|
|
|
+ val data = projectsState.value.data
|
|
|
+ data?.project?.let {
|
|
|
vm.getConfig(
|
|
|
body = requestBody(
|
|
|
- userId = it.project.userId,
|
|
|
- groupCode = it.project.groupCode,
|
|
|
- projectId = it.project.projectId,
|
|
|
+ userId = it.userId,
|
|
|
+ groupCode = it.groupCode,
|
|
|
+ projectId = it.projectId,
|
|
|
),
|
|
|
success = {
|
|
|
println("success: $it")
|
|
@@ -98,15 +90,37 @@ fun OfflineSide() {
|
|
|
}
|
|
|
scope.launch {
|
|
|
// 下载建筑与楼层数据
|
|
|
- projectsState.value.data?.forEach {
|
|
|
- vm.getBuildingsAndFloors(
|
|
|
+ val data = projectsState.value.data
|
|
|
+ val project = data?.project
|
|
|
+ vm.getBuildingsAndFloors(
|
|
|
+ body = requestBody(
|
|
|
+ userId = project?.userId ?: "",
|
|
|
+ groupCode = project?.groupCode ?: "",
|
|
|
+ projectId = project?.projectId ?: "",
|
|
|
+ ),
|
|
|
+ success = {
|
|
|
+ println("success: $it")
|
|
|
+ },
|
|
|
+ failure = {
|
|
|
+ println("failure: $it")
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ scope.launch {
|
|
|
+ // 任务数据
|
|
|
+ val data = projectsState.value.data
|
|
|
+ val project = data?.project
|
|
|
+ val buildings = data?.buildings
|
|
|
+ buildings?.forEach { building ->
|
|
|
+ vm.getMission(
|
|
|
body = requestBody(
|
|
|
- userId = it.project.userId,
|
|
|
- groupCode = it.project.groupCode,
|
|
|
- projectId = it.project.projectId,
|
|
|
+ userId = project?.userId ?: "",
|
|
|
+ groupCode = project?.groupCode ?: "",
|
|
|
+ projectId = project?.projectId ?: "",
|
|
|
+ buildingId = building.id
|
|
|
),
|
|
|
success = {
|
|
|
- println("success: $it")
|
|
|
+ println("success: ")
|
|
|
},
|
|
|
failure = {
|
|
|
println("failure: $it")
|
|
@@ -114,7 +128,6 @@ fun OfflineSide() {
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
},
|
|
|
colors = ButtonDefaults.buttonColors(
|
|
|
contentColor = whiteColor,
|
|
@@ -258,5 +271,5 @@ fun OfflineSide() {
|
|
|
@Preview
|
|
|
@Composable
|
|
|
fun PreviewOfflineSide() {
|
|
|
- OfflineSide()
|
|
|
+ // OfflineSide(projectsState)
|
|
|
}
|