Browse Source

@fun: cad

bai 2 years ago
parent
commit
2f193d8f99
20 changed files with 321 additions and 285 deletions
  1. 5 10
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/FloorDao.kt
  2. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/ProjectDao.kt
  3. 0 3
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/BuildingWithFloors.kt
  4. 1 11
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/ExpandList.kt
  5. 8 12
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/Head.kt
  6. 36 23
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/HeadLeft.kt
  7. 56 83
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadContent.kt
  8. 0 68
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadHeadLeft.kt
  9. 98 49
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadScreen.kt
  10. 0 3
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadSide.kt
  11. 23 2
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/main/Route.kt
  12. 19 4
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/Offline.kt
  13. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineHeadLeft.kt
  14. 1 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineSide.kt
  15. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/TaskHeadLeft.kt
  16. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/Tasks.kt
  17. 28 5
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadRepository.kt
  18. 22 8
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadViewModel.kt
  19. 12 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineRepository.kt
  20. 8 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineViewModel.kt

+ 5 - 10
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/FloorDao.kt

@@ -1,9 +1,6 @@
 package com.ys.bdtp.adm.mvvm.model.db.dao.task
 
-import androidx.room.Dao
-import androidx.room.Insert
-import androidx.room.Query
-import androidx.room.Transaction
+import androidx.room.*
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
 import com.ys.bdtp.adm.mvvm.model.db.relation.FloorWithCads
 import kotlinx.coroutines.flow.Flow
@@ -20,16 +17,14 @@ interface FloorDao {
     @Query("select * from floor where id = :id")
     suspend fun getFloorById(id: String): FloorEntity?
 
-    @Insert
+    @Insert(onConflict = OnConflictStrategy.REPLACE)
     suspend fun insFloor(vararg floor: FloorEntity)
 
-    @Insert
+    @Insert(onConflict = OnConflictStrategy.REPLACE)
     suspend fun insFloors(floors: List<FloorEntity>)
 
-    /**
-     *
-     */
+
     @Transaction
     @Query("select * from floor where id = :id")
-    fun getFloorWithCadsById(id: String): Flow<FloorWithCads>
+    suspend fun getFloorWithCadsById(id: String): FloorWithCads
 }

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/ProjectDao.kt

@@ -47,7 +47,7 @@ interface ProjectDao {
      */
     @Transaction
     @Query("select * from project where id = :id")
-    fun getProjectWithBuildingAndFloorsById(id: String): Flow<ProjectWithBuildingAndFloors>
+    suspend fun getProjectWithBuildingAndFloorsById(id: String): ProjectWithBuildingAndFloors
 
     @Transaction
     @Query("select * from project where id = :id")

+ 0 - 3
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/BuildingWithFloors.kt

@@ -2,11 +2,8 @@ package com.ys.bdtp.adm.mvvm.model.db.relation
 
 import androidx.room.Embedded
 import androidx.room.Relation
-import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.BuildingEntity
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
-import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
-import com.ys.bdtp.adm.mvvm.ui.compose.Building
 
 /**
  * Building 与 Floor 一对多关系表

+ 1 - 11
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/ExpandList.kt

@@ -31,16 +31,6 @@ import com.ys.bdtp.adm.app.theme.underColor
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
 import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
 
-data class Building(val id: String, val name: String, val floors: List<String>)
-
-val buildings = listOf(
-    Building("1", "建筑 A", listOf("A1", "B1", "C1", "D1", "E1", "F1", "G1")),
-    Building("2", "建筑 B", listOf("A2", "B2", "C2", "D2", "E2", "F2", "G2")),
-    Building("3", "建筑 C", listOf("A3", "B3", "C3", "D3", "E3", "F3", "G3")),
-    Building("4", "建筑 D", listOf("A4", "B4", "C4", "D4", "E4", "F4", "G4")),
-    Building("5", "建筑 E", listOf("A5", "B5", "C5", "D5", "E5", "F5", "G5"))
-)
-
 
 @Composable
 fun ExpandList(items: List<BuildingWithFloors>, click: (FloorEntity) -> Unit) {
@@ -94,7 +84,7 @@ fun ExpandList(items: List<BuildingWithFloors>, click: (FloorEntity) -> Unit) {
                     ) {
                         Spacer(modifier = Modifier.width(48.dp))
                         Text(
-                            text = floor.name,
+                            text = floor.localId,
                             color = textBlackColor,
                         )
                     }

+ 8 - 12
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/Head.kt

@@ -24,25 +24,21 @@ import com.google.accompanist.insets.rememberInsetsPaddingValues
 
 @Composable
 fun Head(
-    modifier: Modifier = Modifier.fillMaxWidth()
-        .wrapContentHeight()
-        .background(Color.White)
-        .padding(
-            rememberInsetsPaddingValues(
-                LocalWindowInsets.current.statusBars
-            )
-        ),
     left: (@Composable () -> Unit)? = null,
     middle: (@Composable () -> Unit)? = null,
     right: (@Composable () -> Unit)? = null
 ) {
     Box(
-        modifier = modifier
+        modifier = Modifier.padding(
+            rememberInsetsPaddingValues(
+                LocalWindowInsets.current.statusBars
+            )
+        )
     ) {
         Row(
-            modifier = Modifier
+            modifier = Modifier.fillMaxWidth()
                 .height(56.dp)
-                .fillMaxWidth(),
+                .background(Color.White),
             horizontalArrangement = Arrangement.SpaceBetween,
             verticalAlignment = Alignment.CenterVertically
         ) {
@@ -63,7 +59,7 @@ fun Head(
 @Composable
 fun PreviewTop() {
     Head(
-        left = { HeadLeft() },
+        left = { HeadLeft("禹数") },
         right = {
             HeadRight(
                 role = { "管家" },

+ 36 - 23
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/HeadLeft.kt

@@ -3,63 +3,76 @@ package com.ys.bdtp.adm.mvvm.ui.compose
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.*
+import androidx.compose.material.IconButton
 import androidx.compose.material.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.font.FontWeight
 import androidx.compose.ui.text.font.FontWeight.Companion.Bold
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import com.ys.bdtp.adm.R
+import com.ys.bdtp.adm.app.theme.divColor
+import com.ys.bdtp.adm.app.theme.textBlackColor
+
 
 @Composable
-fun HeadLeft() {
+fun HeadLeft(
+    title: String,
+    back: (() -> Unit)? = null,
+    space: Int = 16
+) {
     Row(
         verticalAlignment = Alignment.CenterVertically,
         horizontalArrangement = Arrangement.Start
     ) {
 
-        Spacer(modifier = Modifier.width(32.dp))
-
-        Image(
-            painter = painterResource(R.drawable.arrow_back),
-            contentDescription = "",
-            modifier = Modifier.size(24.dp)
-        )
+        Spacer(modifier = Modifier.width(space.dp))
 
-        Spacer(
-            modifier = Modifier.width(16.dp)
-        )
+        IconButton(
+            modifier = Modifier.size(56.dp),
+            onClick = {
+                back?.invoke()
+            }
+        ) {
+            Image(
+                painter = painterResource(R.drawable.arrow_back),
+                contentDescription = "",
+                modifier = Modifier.size(24.dp)
+            )
+        }
 
         Spacer(
             modifier = Modifier
                 .width(1.dp)
                 .height(16.dp)
-                .background(Color(0xFFD8D8D8))
+                .background(divColor)
         )
 
         Spacer(
-            modifier = Modifier.width(16.dp)
+            modifier = Modifier
+                .width(16.dp)
+                .background(divColor)
         )
 
-        Text(text = "京东", fontSize = 16.sp, fontWeight = Bold, color = Color(0xFF1F2329))
-
-        Spacer(modifier = Modifier.width(16.dp))
+        Text(text = title, fontSize = 16.sp, fontWeight = FontWeight.Bold, color = textBlackColor)
 
-        Image(
-            painter = painterResource(R.drawable.arrow_down),
-            contentDescription = "",
-            modifier = Modifier.size(16.dp)
+        Spacer(
+            modifier = Modifier
+                .width(16.dp)
+                .background(divColor)
         )
+
     }
 }
 
 
-@Preview
+@Preview(backgroundColor = 0xFF000000)
 @Composable
-fun PreviewTopLeft() {
-    HeadLeft()
+fun PreviewHeadLeft() {
+    HeadLeft("京东")
 }

+ 56 - 83
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadContent.kt

@@ -12,6 +12,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
+import androidx.core.graphics.scaleMatrix
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.flowWithLifecycle
 import com.ys.bdtp.adm.app.theme.textBlackColor
@@ -21,24 +22,27 @@ import com.ys.bdtp.adm.mvvm.model.Data
 import com.ys.bdtp.adm.mvvm.model.State
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.CadEntity
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.FloorWithCads
 import com.ys.bdtp.adm.mvvm.ui.compose.Blank
 import com.ys.bdtp.adm.mvvm.ui.compose.SelectState
 import com.ys.bdtp.adm.mvvm.ui.compose.Table
 import com.ys.bdtp.adm.mvvm.vm.cad.CadViewModel
+import kotlinx.coroutines.launch
 import org.kodein.di.compose.rememberViewModel
 
-@Composable
+/*@Composable
 fun CadContent(selectState: SelectState, floorEntity: FloorEntity?) {
     val vm by rememberViewModel<CadViewModel>()
-    val floorState by remember { mutableStateOf(floorEntity) }
-    // 根据floor 获取 cad 文件
-    val lifecycleOwner = LocalLifecycleOwner.current
-    val lifecycleWare = remember(lifecycleOwner) {
-        vm.getFloorWithCads(floorEntity?.id ?: "")
-            .flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
+    val floor by rememberUpdatedState(floorEntity)
+    println("floor::::: $floor")
+
+    var floorState by remember { mutableStateOf<FloorWithCads?>(null) }
+    LaunchedEffect(Unit) {
+        if (floorEntity != null) {
+            floorState = vm.getFloorWithCads(floor?.id ?: "")
+            println("floorState: $floorState")
+        }
 
-    }
-    val projectData = lifecycleWare.collectAsState(Data.loading())
 
     Column(
         modifier = Modifier
@@ -46,93 +50,62 @@ fun CadContent(selectState: SelectState, floorEntity: FloorEntity?) {
             .background(whiteColor)
             .padding(horizontal = 50.dp, vertical = 50.dp)
     ) {
-        if (selectState == SelectState.Left) {
-            Table(
-                name = {
-                    Text(text = "土建图纸核查", color = textBlackColor, fontSize = 16.sp)
-                },
-                th = {
-                    CadDrawingTitle()
-                },
-                tr = {
-                    val data = projectData.value
-                    when (data.state) {
-                        is State.Loading -> {}
-                        is State.Success -> {
-                            LazyColumn(modifier = Modifier.fillMaxSize()) {
-                                data.data?.let {
-                                    items(it.cads) { cad: CadEntity ->
-                                        Box {
-                                            CadDrawingItem(cad)
-                                            Spacer(
-                                                modifier = Modifier
-                                                    .align(Alignment.BottomCenter)
-                                                    .fillMaxWidth().height(1.dp)
-                                                    .background(trDivColor)
-                                            )
-                                        }
-                                    }
-                                }
+        val title = if (selectState == SelectState.Left) "土建图纸核查" else "机电图纸核查"
+        Table(
+            name = {
+                Text(text = title, color = textBlackColor, fontSize = 16.sp)
+            },
+            th = {
+                CadDrawingTitle()
+            },
+            tr = {
+                LazyColumn(modifier = Modifier.fillMaxSize()) {
+                    floorState?.cads?.let { cads ->
+                        items(cads) { cad: CadEntity ->
+                            Box {
+                                CadDrawingItem(cad)
+                                Spacer(
+                                    modifier = Modifier
+                                        .align(Alignment.BottomCenter)
+                                        .fillMaxWidth().height(1.dp)
+                                        .background(trDivColor)
+                                )
                             }
                         }
-                        is State.Failure -> {}
                     }
                 }
-            )
-        } else {
-            Table(
-                name = {
-                    Text(text = "机电图纸核查", color = textBlackColor, fontSize = 16.sp)
-                },
-                th = {
-                    CadDrawingTitle()
-                },
-                tr = {
-                    val data = projectData.value
-                    when (data.state) {
-                        is State.Loading -> {}
-                        is State.Success -> {
-                            LazyColumn(modifier = Modifier.fillMaxSize()) {
-                                data.data?.let {
-                                    items(it.cads) { cad: CadEntity ->
-                                        Box {
-                                            CadDrawingItem(cad)
-                                            Spacer(
-                                                modifier = Modifier
-                                                    .align(Alignment.BottomCenter)
-                                                    .fillMaxWidth().height(1.dp)
-                                                    .background(trDivColor)
-                                            )
-                                        }
+
+                *//*val data = projectData.value
+                when (data.state) {
+                    is State.Loading -> {}
+                    is State.Success -> {
+                        LazyColumn(modifier = Modifier.fillMaxSize()) {
+                            data.data?.let {
+                                items(it.cads) { cad: CadEntity ->
+                                    Box {
+                                        CadDrawingItem(cad)
+                                        Spacer(
+                                            modifier = Modifier
+                                                .align(Alignment.BottomCenter)
+                                                .fillMaxWidth().height(1.dp)
+                                                .background(trDivColor)
+                                        )
                                     }
                                 }
                             }
                         }
-                        is State.Failure -> {}
                     }
+                    is State.Failure -> {}*//*
+            }
 
-                    /*   LazyColumn(modifier = Modifier.fillMaxSize()) {
-                           items(20) {
-                               Box {
-                                   CadDrawingItem()
-                                   Spacer(
-                                       modifier = Modifier
-                                           .align(Alignment.BottomCenter)
-                                           .fillMaxWidth().height(1.dp)
-                                           .background(trDivColor)
-                                   )
-                               }
-                           }
-                       }*/
-                }
-            )
-        }
-
+        )
     }
-}
+}*/
+/*
 
 @Preview(widthDp = 910, heightDp = 711)
 @Composable
 fun PreviewCadContent() {
     // CadContent(SelectState.Left)
-}
+}
+    */

+ 0 - 68
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadHeadLeft.kt

@@ -1,68 +0,0 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.cad
-
-import androidx.compose.foundation.Image
-import androidx.compose.foundation.background
-import androidx.compose.foundation.clickable
-import androidx.compose.foundation.layout.*
-import androidx.compose.material.IconButton
-import androidx.compose.material.Text
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.text.font.FontWeight
-import androidx.compose.ui.tooling.preview.Preview
-import androidx.compose.ui.unit.dp
-import androidx.compose.ui.unit.sp
-import com.ys.bdtp.adm.R
-
-
-@Composable
-fun CadHeadLeft(
-    title: String,
-    click: () -> Unit
-) {
-    Row(
-        verticalAlignment = Alignment.CenterVertically,
-        horizontalArrangement = Arrangement.Start
-    ) {
-
-        Spacer(modifier = Modifier.width(32.dp))
-
-        IconButton(
-            modifier = Modifier.height(56.dp),
-            onClick = {
-                click()
-            }
-        ) {
-            Image(
-                painter = painterResource(R.drawable.arrow_back),
-                contentDescription = "",
-                modifier = Modifier.size(24.dp)
-            )
-        }
-
-        Spacer(
-            modifier = Modifier
-                .width(1.dp)
-                .height(16.dp)
-                .background(Color(0xFFD8D8D8))
-        )
-
-        Spacer(
-            modifier = Modifier
-                .width(16.dp)
-                .background(Color(0xFFD8D8D8))
-        )
-
-        Text(text = title, fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Color(0xFF1F2329))
-    }
-}
-
-
-@Preview
-@Composable
-fun PreviewCadHeadLeft() {
-    CadHeadLeft("京东", {})
-}

+ 98 - 49
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadScreen.kt

@@ -1,47 +1,52 @@
 package com.ys.bdtp.adm.mvvm.ui.screen.cad
 
 import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.collectAsState
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.setValue
+import androidx.compose.foundation.layout.*
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material.Text
+import androidx.compose.runtime.*
+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.tooling.preview.Preview
-import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.flowWithLifecycle
-import com.ys.bdtp.adm.mvvm.model.Data
-import com.ys.bdtp.adm.mvvm.model.State
-import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.ys.bdtp.adm.app.theme.textBlackColor
+import com.ys.bdtp.adm.app.theme.trDivColor
+import com.ys.bdtp.adm.app.theme.underColor
+import com.ys.bdtp.adm.app.theme.whiteColor
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.CadEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.FloorWithCads
+import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildingAndFloors
 import com.ys.bdtp.adm.mvvm.ui.compose.*
 import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
+import com.ys.bdtp.adm.mvvm.ui.screen.main.cadToLogin
 import com.ys.bdtp.adm.mvvm.vm.cad.CadViewModel
+import kotlinx.coroutines.launch
 import org.kodein.di.compose.rememberViewModel
 
 @Composable
 fun CadScreen(projectId: String) {
-    var selectState by remember { mutableStateOf<SelectState>(SelectState.Left) }
     val nav = LocalNavHostController.current!!
     val vm by rememberViewModel<CadViewModel>()
+    val scope = rememberCoroutineScope()
+
+    var popupState by remember { mutableStateOf(false) }
+    var floor by remember { mutableStateOf<FloorWithCads?>(null) }
+    var selectState by remember { mutableStateOf<SelectState>(SelectState.Left) }
+    var project by remember { mutableStateOf<ProjectWithBuildingAndFloors?>(null) }
 
-    val lifecycleOwner = LocalLifecycleOwner.current
-    val lifecycleWare = remember(lifecycleOwner) {
-        vm.getProjectWithBuildingAndFloors(projectId)
-            .flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
+    LaunchedEffect(Unit) {
+        project = vm.getProject(projectId)
     }
-    val projectData = lifecycleWare.collectAsState(Data.loading())
-    var floorState by remember { mutableStateOf<FloorEntity?>(null) }
+
     Column(modifier = Modifier.background(Color.White)) {
         Head(
             left = {
-                CadHeadLeft(
+                HeadLeft(
                     title = "CAD图纸核查",
-                    click = {
+                    back = {
                         nav.navigateUp()
                     }
                 )
@@ -58,41 +63,85 @@ fun CadScreen(projectId: String) {
                 HeadRight(
                     role = { "物业管家" },
                     click = {
-
+                        popupState = !popupState
                     }
                 )
             }
         )
-        Div(Div.Row)
-        Body(
-            modifier = Modifier.fillMaxSize(),
-            side = {
-                when (projectData.value.state) {
-                    is State.Loading -> {
 
+        if (popupState) {
+            LogoutPopup(
+                click = {
+                    scope.launch {
+                        vm.logout()
                     }
-                    is State.Success -> {
-                        val project = projectData.value.data
-                        if (project != null) {
-                            CadSide(
-                                buildings = project.buildings,
-                                click = { floorEntity ->
-                                    floorState = floorEntity
-                                }
+                    popupState = false
+                    nav.cadToLogin()
+                }
+            )
+        }
 
-                            )
+        Div(Div.Row)
+        Row(modifier = Modifier.fillMaxSize()) {
+            // side
+            Column(
+                modifier = Modifier
+                    .width(280.dp)
+                    .fillMaxHeight()
+                    .background(color = underColor)
+            ) {
+                Row(
+                    modifier = Modifier
+                        .wrapContentHeight()
+                        .padding(top = 20.dp, start = 32.dp)
+                ) {
+                    Text(text = "选择楼层", fontSize = 16.sp, color = textBlackColor)
+                }
+                if (project != null) {
+                    ExpandList(
+                        items = project!!.buildings,
+                        click = {
+                            scope.launch {
+                                floor = vm.getFloorWithCads(it.id)
+                            }
+                        })
+                }
+            }
+            Div(Div.Col)
+            Column(
+                modifier = Modifier
+                    .fillMaxSize()
+                    .background(whiteColor)
+                    .padding(horizontal = 50.dp, vertical = 50.dp)
+            ) {
+                val title = if (selectState == SelectState.Left) "土建图纸核查" else "机电图纸核查"
+                Table(
+                    name = {
+                        Text(text = title, color = textBlackColor, fontSize = 16.sp)
+                    },
+                    th = {
+                        CadDrawingTitle()
+                    },
+                    tr = {
+                        LazyColumn(modifier = Modifier.fillMaxSize()) {
+                            floor?.let {
+                                items(it.cads) { cad: CadEntity ->
+                                    Box {
+                                        CadDrawingItem(cad)
+                                        Spacer(
+                                            modifier = Modifier
+                                                .align(Alignment.BottomCenter)
+                                                .fillMaxWidth().height(1.dp)
+                                                .background(trDivColor)
+                                        )
+                                    }
+                                }
+                            }
                         }
                     }
-                    is State.Failure -> {
-
-                    }
-                }
-            },
-            content = {
-                CadContent(selectState, floorState)
-            },
-            div = { Div(Div.Col) }
-        )
+                )
+            }
+        }
     }
 }
 

+ 0 - 3
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadSide.kt

@@ -12,9 +12,7 @@ import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.app.theme.underColor
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
 import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
-import com.ys.bdtp.adm.mvvm.ui.compose.Building
 import com.ys.bdtp.adm.mvvm.ui.compose.ExpandList
-import com.ys.bdtp.adm.mvvm.ui.compose.buildings
 
 @Composable
 fun CadSide(buildings: List<BuildingWithFloors>, click: (FloorEntity) -> Unit) {
@@ -23,7 +21,6 @@ fun CadSide(buildings: List<BuildingWithFloors>, click: (FloorEntity) -> Unit) {
             .width(280.dp)
             .fillMaxHeight()
             .background(color = underColor)
-        /*.padding(horizontal = 30.dp, vertical = 20.dp)*/
     ) {
         Row(
             modifier = Modifier

+ 23 - 2
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/main/Route.kt

@@ -51,7 +51,6 @@ fun NavHostController.loginToProject() {
             inclusive = true
         }
     }
-
 }
 
 /**
@@ -64,7 +63,6 @@ fun NavHostController.projectToLogin() {
             inclusive = true
         }
     }
-
 }
 
 /**
@@ -77,6 +75,29 @@ fun NavHostController.taskToLogin() {
             inclusive = true
         }
     }
+}
 
+/**
+ * Task 跳转到 Login 界面
+ */
+fun NavHostController.offlineToLogin() {
+    navigate(Route.Login) {
+        launchSingleTop = true
+        popUpTo(Route.Offline) {
+            inclusive = true
+        }
+    }
 }
 
+
+/**
+ * Task 跳转到 Login 界面
+ */
+fun NavHostController.cadToLogin() {
+    navigate(Route.Login) {
+        launchSingleTop = true
+        popUpTo(Route.Cad) {
+            inclusive = true
+        }
+    }
+}

+ 19 - 4
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/Offline.kt

@@ -10,9 +10,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.height
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.width
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.collectAsState
-import androidx.compose.runtime.remember
+import androidx.compose.runtime.*
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.platform.LocalLifecycleOwner
@@ -23,14 +21,19 @@ import androidx.lifecycle.flowWithLifecycle
 import com.ys.bdtp.adm.mvvm.model.Data
 import com.ys.bdtp.adm.mvvm.ui.compose.Head
 import com.ys.bdtp.adm.mvvm.ui.compose.HeadRight
+import com.ys.bdtp.adm.mvvm.ui.compose.LogoutPopup
 import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
+import com.ys.bdtp.adm.mvvm.ui.screen.main.offlineToLogin
 import com.ys.bdtp.adm.mvvm.vm.offline.OfflineViewModel
+import kotlinx.coroutines.launch
 import org.kodein.di.compose.rememberViewModel
 
 @Composable
 fun Offline(projectId: String) {
     val nav = LocalNavHostController.current!!
     val vm by rememberViewModel<OfflineViewModel>()
+    val scope = rememberCoroutineScope()
+    var popupState by remember { mutableStateOf(false) }
 
     val lifecycleOwner = LocalLifecycleOwner.current
     val lifecycleWare = remember(lifecycleOwner) {
@@ -47,12 +50,24 @@ fun Offline(projectId: String) {
                 HeadRight(
                     role = { "业务角色" },
                     click = {
-
+                        popupState = !popupState
                     }
                 )
             }
         )
 
+        if (popupState) {
+            LogoutPopup(
+                click = {
+                    scope.launch {
+                        vm.logout()
+                    }
+                    popupState = false
+                    nav.offlineToLogin()
+                }
+            )
+        }
+
         Spacer(
             modifier = Modifier
                 .height(1.dp)

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineHeadLeft.kt

@@ -24,7 +24,7 @@ fun OfflineHeadLeft(back: () -> Unit) {
         horizontalArrangement = Arrangement.Start
     ) {
 
-        Spacer(modifier = Modifier.width(32.dp))
+        Spacer(modifier = Modifier.width(16.dp))
 
         IconButton(
             modifier = Modifier.size(56.dp),

+ 1 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineSide.kt

@@ -108,6 +108,7 @@ fun OfflineSide(state: State<Data<ProjectWithBuildings>>) {
                 }
                 scope.launch {
                     // 任务数据
+                    // 需要单独隔离出来
                     val data = projectsState.value.data
                     val project = data?.project
                     val buildings = data?.buildings

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/TaskHeadLeft.kt

@@ -26,7 +26,7 @@ fun TaskHeadLeft(
         horizontalArrangement = Arrangement.Start
     ) {
 
-        Spacer(modifier = Modifier.width(32.dp))
+        Spacer(modifier = Modifier.width(16.dp))
 
         IconButton(
             modifier = Modifier.size(56.dp),

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/Tasks.kt

@@ -34,7 +34,7 @@ fun Tasks() {
     var value by remember { mutableStateOf("") }
     Column(modifier = Modifier.fillMaxSize().background(Color.White)) {
         Head(
-            left = { HeadLeft() },
+            left = { HeadLeft("") },
             right = {
                 HeadRight(
                     role = { "管家" },

+ 28 - 5
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadRepository.kt

@@ -7,22 +7,45 @@ import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
 import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildingAndFloors
 import com.ys.bdtp.adm.mvvm.model.nt.Api
 import com.ys.bdtp.adm.mvvm.model.toStateFlow
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.collect
+import kotlinx.coroutines.withContext
 
 
 class CadRepository(private val api: Api, private val db: AdmDatabase) {
 
 
-
     /**
      * 获取项目以及项目下的建筑和楼层
      */
-    fun getProjectWithBuildingAndFloors(id: String): Flow<Data<ProjectWithBuildingAndFloors>> {
-        return db.projectDao().getProjectWithBuildingAndFloorsById(id).toStateFlow()
+    /* fun getProjectWithBuildingAndFloors(id: String): Flow<Data<ProjectWithBuildingAndFloors>> {
+         return db.projectDao().getProjectWithBuildingAndFloorsById(id).toStateFlow()
+     }*/
+
+    suspend fun getProject(id: String): ProjectWithBuildingAndFloors {
+        return withContext(Dispatchers.IO) {
+            db.projectDao().getProjectWithBuildingAndFloorsById(id)
+        }
     }
 
-    fun getFloorWithCads(id: String): Flow<Data<FloorWithCads>> {
-        return db.floorDao().getFloorWithCadsById(id).toStateFlow()
+    suspend fun getFloorWithCads(id: String): FloorWithCads {
+        return withContext(Dispatchers.IO) {
+            db.floorDao().getFloorWithCadsById(id)
+        }
     }
 
+
+    suspend fun logout() {
+        withContext(Dispatchers.IO) {
+            db.userDao().getUser().collect {
+                it?.let {
+                    it.state = 0
+                    db.userDao().updUser(it)
+                }
+            }
+        }
+    }
+
+
 }

+ 22 - 8
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadViewModel.kt

@@ -3,6 +3,7 @@ package com.ys.bdtp.adm.mvvm.vm.cad
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import com.ys.bdtp.adm.mvvm.model.Data
+import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildingAndFloors
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.stateIn
 
@@ -13,18 +14,31 @@ class CadViewModel(private val repo: CadRepository) : ViewModel() {
      */
 
 
-    fun getProjectWithBuildingAndFloors(id: String) = repo.getProjectWithBuildingAndFloors(id)
+    /*fun getProjectWithBuildingAndFloors(id: String) = repo.getProjectWithBuildingAndFloors(id)
         .stateIn(
             scope = viewModelScope,
             started = SharingStarted.WhileSubscribed(5000),
             initialValue = Data.loading()
-        )
+        )*/
 
-    fun getFloorWithCads(id: String) = repo.getFloorWithCads(id)
-        .stateIn(
-            scope = viewModelScope,
-            started = SharingStarted.WhileSubscribed(5000),
-            initialValue = Data.loading()
-        )
+    suspend fun getProject(id: String): ProjectWithBuildingAndFloors {
+        return repo.getProject(id)
+    }
+    /* fun getFloorWithCads(id: String) = repo.getFloorWithCads(id)
+         .stateIn(
+             scope = viewModelScope,
+             started = SharingStarted.WhileSubscribed(5000),
+             initialValue = Data.loading()
+         )
+ */
 
+    suspend fun getFloorWithCads(id: String) = repo.getFloorWithCads(id)
+
+
+    /**
+     * 退出
+     */
+    suspend fun logout() {
+        repo.logout()
+    }
 }

+ 12 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineRepository.kt

@@ -17,6 +17,7 @@ import com.ys.bdtp.adm.mvvm.model.vo.BuildingsAndFloors
 import com.ys.bdtp.adm.mvvm.model.vo.Mission
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.collect
 import kotlinx.coroutines.withContext
 
 /**
@@ -260,4 +261,15 @@ class OfflineRepository(
         return db.projectDao().getProjectWithBuildingsById(id).toStateFlow()
     }
 
+    suspend fun logout() {
+        withContext(Dispatchers.IO) {
+            db.userDao().getUser().collect {
+                it?.let {
+                    it.state = 0
+                    db.userDao().updUser(it)
+                }
+            }
+        }
+    }
+
 }

+ 8 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineViewModel.kt

@@ -109,4 +109,12 @@ class OfflineViewModel(private val repo: OfflineRepository) : ViewModel() {
             initialValue = Data.loading()
         )
 
+
+    /**
+     * 退出
+     */
+    suspend fun logout() {
+        repo.logout()
+    }
+
 }