|
@@ -12,22 +12,24 @@ import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.foundation.layout.width
|
|
|
import androidx.compose.foundation.layout.wrapContentWidth
|
|
|
-import androidx.compose.runtime.Composable
|
|
|
-import androidx.compose.runtime.LaunchedEffect
|
|
|
-import androidx.compose.runtime.mutableStateOf
|
|
|
-import androidx.compose.runtime.remember
|
|
|
-import androidx.compose.runtime.getValue
|
|
|
-import androidx.compose.runtime.setValue
|
|
|
+import androidx.compose.runtime.*
|
|
|
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.compose.ui.unit.dp
|
|
|
+import androidx.lifecycle.Lifecycle
|
|
|
+import androidx.lifecycle.flowWithLifecycle
|
|
|
import com.ys.bdtp.adm.app.theme.underColor
|
|
|
+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.ProjectEntity
|
|
|
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.screen.main.LocalNavHostController
|
|
|
+import com.ys.bdtp.adm.mvvm.ui.compose.LogoutPopup
|
|
|
+import com.ys.bdtp.adm.mvvm.ui.screen.main.*
|
|
|
import com.ys.bdtp.adm.mvvm.vm.task.TaskViewModel
|
|
|
+import kotlinx.coroutines.launch
|
|
|
import org.kodein.di.compose.rememberViewModel
|
|
|
|
|
|
@Composable
|
|
@@ -35,11 +37,28 @@ fun Task(projectId: String) {
|
|
|
val nav = LocalNavHostController.current!!
|
|
|
val vm by rememberViewModel<TaskViewModel>()
|
|
|
var project by remember { mutableStateOf<ProjectEntity?>(null) }
|
|
|
+ var popupState by remember { mutableStateOf(false) }
|
|
|
+ val scope = rememberCoroutineScope()
|
|
|
+
|
|
|
+ val lifecycleOwner = LocalLifecycleOwner.current
|
|
|
+ val userFlowLifecycleAware = remember(vm.userStateFlow, lifecycleOwner) {
|
|
|
+ vm.userStateFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
|
|
|
+ }
|
|
|
+
|
|
|
+ val userState = userFlowLifecycleAware.collectAsState(Data.loading())
|
|
|
+
|
|
|
+ if (userState.value.state == State.Success) {
|
|
|
+ val user = userState.value.data
|
|
|
+ if (user == null) {
|
|
|
+ nav.taskToLogin()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
LaunchedEffect(Unit) {
|
|
|
project = vm.getProject(projectId)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
Column(modifier = Modifier.fillMaxSize().background(Color.White)) {
|
|
|
Head(
|
|
|
left = {
|
|
@@ -50,12 +69,23 @@ fun Task(projectId: String) {
|
|
|
})
|
|
|
},
|
|
|
right = {
|
|
|
- HeadRight(
|
|
|
+ TaskHeadRight(
|
|
|
role = { "管家" },
|
|
|
- click = { println("heiheihei") }
|
|
|
+ click = { popupState = !popupState }
|
|
|
)
|
|
|
}
|
|
|
)
|
|
|
+ if (popupState) {
|
|
|
+ LogoutPopup(
|
|
|
+ click = {
|
|
|
+ scope.launch {
|
|
|
+ vm.logout()
|
|
|
+ }
|
|
|
+ popupState = false
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
Spacer(
|
|
|
modifier = Modifier.fillMaxWidth().height(1.dp).background(Color(0xFFEFF0F1))
|
|
|
)
|