Browse Source

@fun: account and project

bai 3 years ago
parent
commit
3a3e062401
31 changed files with 532 additions and 216 deletions
  1. 4 2
      app/src/main/java/com/ys/bdtp/adm/app/interceptor/GzipRequestInterceptor.kt
  2. 21 0
      app/src/main/java/com/ys/bdtp/adm/app/interceptor/TokenInterceptor.kt
  3. 18 4
      app/src/main/java/com/ys/bdtp/adm/di/Di.kt
  4. 2 2
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/Http.kt
  5. 5 5
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/Response.kt
  6. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/UserEntity.kt
  7. 3 17
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/vo/request/Account.kt
  8. 6 4
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/Alert.kt
  9. 3 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/flash/FlashScreen.kt
  10. 2 2
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/home/HomeScreen.kt
  11. 29 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/Login.kt
  12. 6 3
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/LoginContent.kt
  13. 3 4
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/LoginSide.kt
  14. 2 3
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/main/MainScreen.kt
  15. 0 50
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/Project.kt
  16. 0 30
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectBlank.kt
  17. 83 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectContent.kt
  18. 32 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectHeadLeft.kt
  19. 14 8
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectItem.kt
  20. 67 66
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectScreen.kt
  21. 1 8
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectRecentTask.kt
  22. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectRecentTaskItem.kt
  23. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectRecentTaskTitle.kt
  24. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectTaskScreen.kt
  25. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectTitleList.kt
  26. 94 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/TaskScreen.kt
  27. 2 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/flash/FlashViewModel.kt
  28. 13 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/login/LoginViewModel.kt
  29. 63 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/project/ProjectRepository.kt
  30. 54 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/project/ProjectViewModel.kt
  31. 0 0
      identifier.sqlite

+ 4 - 2
app/src/main/java/com/ys/bdtp/adm/app/interceptor/GzipRequestInterceptor.kt

@@ -4,9 +4,11 @@ import okhttp3.*
 import okio.*
 
 /**
- * Gzip 压缩
+ * Gzip 压缩拦截器
+ *
+ * @author bai
  */
-class GzipRequestInterceptor : Interceptor {
+class GzipInterceptor : Interceptor {
     override fun intercept(chain: Interceptor.Chain): Response {
         val originalRequest: Request = chain.request()
         if (originalRequest.body == null || originalRequest.header("Content-Encoding") != "gzip") {

+ 21 - 0
app/src/main/java/com/ys/bdtp/adm/app/interceptor/TokenInterceptor.kt

@@ -0,0 +1,21 @@
+package com.ys.bdtp.adm.app.interceptor
+
+import android.content.SharedPreferences
+import com.ys.bdtp.adm.app.Token
+import okhttp3.Interceptor
+import okhttp3.Response
+
+/**
+ * token 拦截器
+ *
+ * @author bai
+ */
+class TokenInterceptor(private val sp: SharedPreferences) : Interceptor {
+    override fun intercept(chain: Interceptor.Chain): Response {
+        val originalRequest = chain.request()
+        val quest = originalRequest.newBuilder()
+            .header("token", sp.getString(Token, "")!!)
+            .build()
+        return chain.proceed(quest)
+    }
+}

+ 18 - 4
app/src/main/java/com/ys/bdtp/adm/di/Di.kt

@@ -1,9 +1,11 @@
 package com.ys.bdtp.adm.di
 
+import android.content.Context
 import android.util.Log
 import com.ys.bdtp.adm.app.IP
 import com.ys.bdtp.adm.app.converter.NullOrEmptyConverter
-import com.ys.bdtp.adm.app.interceptor.GzipRequestInterceptor
+import com.ys.bdtp.adm.app.interceptor.GzipInterceptor
+import com.ys.bdtp.adm.app.interceptor.TokenInterceptor
 import com.ys.bdtp.adm.mvvm.model.db.AdmDatabase
 import com.ys.bdtp.adm.mvvm.model.nt.Api
 import com.ys.bdtp.adm.mvvm.vm.flash.FlashRepository
@@ -12,6 +14,8 @@ import com.ys.bdtp.adm.mvvm.vm.login.LoginRepository
 import com.ys.bdtp.adm.mvvm.vm.login.LoginViewModel
 import com.ys.bdtp.adm.mvvm.vm.main.MainRepository
 import com.ys.bdtp.adm.mvvm.vm.main.MainViewModel
+import com.ys.bdtp.adm.mvvm.vm.project.ProjectRepository
+import com.ys.bdtp.adm.mvvm.vm.project.ProjectViewModel
 import okhttp3.OkHttpClient
 import okhttp3.logging.HttpLoggingInterceptor
 import org.kodein.di.*
@@ -41,13 +45,14 @@ val httpModule = DI.Module("httpModule") {
                 .connectTimeout(100, TimeUnit.SECONDS)
                 .readTimeout(3000, TimeUnit.SECONDS)
                 .writeTimeout(3000, TimeUnit.SECONDS)
+                .addInterceptor(instance<TokenInterceptor>())
                 .addInterceptor(instance<HttpLoggingInterceptor>())
-                .addInterceptor(instance<GzipRequestInterceptor>())
+                .addInterceptor(instance<GzipInterceptor>())
                 .build()
         }
     }
 
-    // 构建 HttpLoggingInterceptor 对象
+    //  Logging 拦截器单例
     bind {
         singleton {
             HttpLoggingInterceptor { message ->
@@ -61,12 +66,19 @@ val httpModule = DI.Module("httpModule") {
         }
     }
 
+    // Gzip 压缩拦截器单例
     bind {
         singleton {
-            GzipRequestInterceptor()
+            GzipInterceptor()
         }
     }
 
+    // Token 拦截器单例
+    bind {
+        singleton {
+            TokenInterceptor(on(instance<Context>()).instance())
+        }
+    }
     // Api 对象
     bind {
         singleton { instance<Retrofit>().create(Api::class.java) }
@@ -77,12 +89,14 @@ val repositoryModule = DI.Module("repository") {
     bind { provider { FlashRepository(instance(), instance()) } }
     bind { provider { LoginRepository(instance(), instance()) } }
     bind { provider { MainRepository(instance()) } }
+    bind { provider { ProjectRepository(instance(), instance()) } }
 }
 
 val viewModelModule = DI.Module("viewModel") {
     bind { provider { FlashViewModel(instance()) } }
     bind { provider { LoginViewModel(instance()) } }
     bind { provider { MainViewModel(instance()) } }
+    bind { provider { ProjectViewModel(instance()) } }
 }
 
 val dbModule = DI.Module("dbModule") {

+ 2 - 2
app/src/main/java/com/ys/bdtp/adm/mvvm/model/Http.kt

@@ -15,7 +15,7 @@ suspend fun <T> request(block: suspend () -> Model<T>): Response<T> {
         } else {
             Response.create(model.message ?: "request ok, but no data")
         }
-    } catch (e: Throwable) {
-        Response.create(e.message ?: "request crash but nothing")
+    } catch (t: Throwable) {
+        Response.create(t.message ?: "request crash and nothing")
     }
 }

+ 5 - 5
app/src/main/java/com/ys/bdtp/adm/mvvm/model/Response.kt

@@ -7,18 +7,18 @@ package com.ys.bdtp.adm.mvvm.model
  */
 sealed class Response<T> {
     companion object {
-        fun <T> create(message: String): FailureResponse<T> {
-            return FailureResponse(message)
-        }
-
         fun <T> create(data: T): SuccessResponse<T> {
             return SuccessResponse(data)
         }
+
+        fun <T> create(message: String): FailureResponse<T> {
+            return FailureResponse(message)
+        }
     }
 }
 
 /**
- * 网络请求成功
+ * 网络请求成功, 数据成功返回
  *
  * @author bai
  */

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/UserEntity.kt

@@ -26,5 +26,5 @@ data class UserEntity(
     @ColumnInfo(name = "email") val email: String,
     @ColumnInfo(name = "phone") val phone: String,
     @ColumnInfo(name = "name") val name: String,
-    @ColumnInfo(name = "state") val state: Int,
+    @ColumnInfo(name = "state") var state: Int,
 )

+ 3 - 17
app/src/main/java/com/ys/bdtp/adm/mvvm/model/vo/request/Account.kt

@@ -1,5 +1,7 @@
 package com.ys.bdtp.adm.mvvm.model.vo.request
 
+import com.ys.bdtp.adm.mvvm.model.db.entity.ProjectEntity
+
 /**
  * 账号信息
  *
@@ -20,21 +22,5 @@ data class Account(
     val id: String,
     val name: String,
     val phone: String,
-    val projects: List<Project>
-)
-
-/**
- * 项目信息
- *
- * @author bai
- * @param projectId 项目id
- * @param projectName 项目名称
- * @param groupCode 集团编码
- * @param groupName 集团名称
- */
-data class Project(
-    val groupCode: String,
-    val groupName: String,
-    val projectId: String,
-    val projectName: String
+    val projects: List<ProjectEntity>
 )

+ 6 - 4
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/Alert.kt

@@ -23,7 +23,10 @@ import androidx.compose.ui.unit.sp
 import androidx.compose.ui.window.Dialog
 
 @Composable
-fun Alert() {
+fun Alert(
+    title: String = "数据更新提示",
+    message: String = "离线数据下载同步更新完成",
+) {
     var flag by remember { mutableStateOf(true) }
     if (flag) {
         Dialog(
@@ -39,7 +42,7 @@ fun Alert() {
                     modifier = Modifier.height(24.dp)
                 )
                 Text(
-                    text = "数据更新提示",
+                    text = title,
                     color = Color(0xFF1F2529),
                     fontSize = 18.sp,
                 )
@@ -47,7 +50,7 @@ fun Alert() {
                     modifier = Modifier.height(10.dp)
                 )
                 Text(
-                    text = "离线数据下载同步更新完成",
+                    text = message,
                     color = Color(0xFF1F2529),
                     fontSize = 14.sp,
                 )
@@ -77,7 +80,6 @@ fun Alert() {
                         fontSize = 16.sp,
                     )
                 }
-
             }
         }
     }

+ 3 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/flash/FlashScreen.kt

@@ -2,6 +2,7 @@ package com.ys.bdtp.adm.mvvm.ui.screen.flash
 
 import android.content.SharedPreferences
 import android.net.ConnectivityManager
+import android.util.Log
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.*
@@ -34,7 +35,7 @@ fun FlashScreen(block: (Zygote) -> Unit) {
     val zygote by rememberUpdatedState(block)
     val sp by rememberInstance<SharedPreferences>()
     LaunchedEffect(Unit) {
-        delay(5000)
+
         val user = vm.getCurrentUser()
         val isNet = isNet(cm)
 
@@ -56,6 +57,7 @@ fun FlashScreen(block: (Zygote) -> Unit) {
                         },
                         failure = {
                             zygote(Zygote.Login)
+                            Log.d("failure", it)
                         }
                     )
             }

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

@@ -9,7 +9,7 @@ import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import com.ys.bdtp.adm.mvvm.ui.compose.*
-import com.ys.bdtp.adm.mvvm.ui.screen.project.Project
+import com.ys.bdtp.adm.mvvm.ui.screen.project.ProjectScreen
 
 @OptIn(ExperimentalFoundationApi::class)
 @Composable
@@ -30,7 +30,7 @@ fun HomeScreen() {
         )
 
         Content {
-            Project()
+            ProjectScreen()
         }
     }
 }

+ 29 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/Login.kt

@@ -0,0 +1,29 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.login
+
+import android.annotation.SuppressLint
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.compositionLocalOf
+import androidx.navigation.NavHostController
+import androidx.navigation.compose.NavHost
+import androidx.navigation.compose.composable
+import androidx.navigation.compose.rememberNavController
+import com.ys.bdtp.adm.mvvm.ui.screen.project.ProjectScreen
+
+@SuppressLint("CompositionLocalNaming")
+val LoginNavHostController = compositionLocalOf<NavHostController?> { null }
+
+@Composable
+fun Login() {
+    val navController: NavHostController = rememberNavController()
+    CompositionLocalProvider(LoginNavHostController provides navController) {
+        NavHost(navController = navController, startDestination = "login") {
+            composable("login") {
+                LoginScreen()
+            }
+            composable("project") {
+                ProjectScreen()
+            }
+        }
+    }
+}

+ 6 - 3
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/LoginContent.kt

@@ -23,6 +23,7 @@ import com.ys.bdtp.adm.app.theme.blueColor
 import com.ys.bdtp.adm.app.theme.grayColor
 import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.mvvm.model.vo.request.Login
+import com.ys.bdtp.adm.mvvm.ui.compose.Alert
 import com.ys.bdtp.adm.mvvm.vm.login.LoginViewModel
 import kotlinx.coroutines.launch
 import org.kodein.di.compose.rememberInstance
@@ -47,6 +48,8 @@ fun LoginContent() {
     val snackbarHostState by remember { mutableStateOf(SnackbarHostState()) }
     val scope = rememberCoroutineScope()
 
+    val nav = LoginNavHostController.current!!
+
     Column(
         modifier = Modifier.fillMaxSize()
             .padding(start = 56.dp, end = 96.dp),
@@ -195,8 +198,9 @@ fun LoginContent() {
                         passWord = password,
                     ),
                     success = { token ->
-                        sp.edit {
-                            putString(Token, token)
+                        sp.edit { putString(Token, token) }
+                        nav.navigate("project") {
+                            popUpTo("login") { inclusive = true }
                         }
                     },
                     failure = { message ->
@@ -204,7 +208,6 @@ fun LoginContent() {
                             snackbarHostState
                                 .showSnackbar(message = message)
                         }
-                        println("failure::::$message")
                     }
                 )
             },

+ 3 - 4
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/login/LoginSide.kt

@@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.*
 import androidx.compose.material.Text
 import androidx.compose.runtime.Composable
 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.compose.ui.tooling.preview.Preview
@@ -14,6 +13,7 @@ import androidx.compose.ui.unit.sp
 import androidx.constraintlayout.compose.ConstraintLayout
 import com.google.accompanist.insets.statusBarsHeight
 import com.ys.bdtp.adm.R
+import com.ys.bdtp.adm.app.theme.textBlackColor
 
 /**
  * 登录页侧边
@@ -56,9 +56,8 @@ fun LoginSide() {
             end.linkTo(parent.end)
             bottom.linkTo(guideline)
         }) {
-            Text(text = "Yushu", fontSize = 36.sp, color = Color(0XFF1F2429))
-            Text("智慧建筑运维平台", fontSize = 48.sp, color = Color(0XFF1F2429))
-            Text("为您提供什么服务,能够用一句话概括出来吧。", fontSize = 16.sp, color = Color(0XFF8D9399))
+            Text(text = "Yushu", fontSize = 36.sp, color = textBlackColor)
+            Text("智慧建筑运维平台", fontSize = 48.sp, color = textBlackColor)
         }
     }
 }

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

@@ -6,7 +6,7 @@ import androidx.compose.runtime.remember
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.setValue
 import com.ys.bdtp.adm.mvvm.ui.screen.flash.FlashScreen
-import com.ys.bdtp.adm.mvvm.ui.screen.login.LoginScreen
+import com.ys.bdtp.adm.mvvm.ui.screen.login.Login
 import com.ys.bdtp.adm.mvvm.ui.screen.project.ProjectScreen
 
 sealed interface Zygote {
@@ -18,7 +18,6 @@ sealed interface Zygote {
 @Composable
 fun MainScreen() {
     var state by remember { mutableStateOf<Zygote>(Zygote.Flash) }
-
     when (state) {
         Zygote.Flash -> {
             FlashScreen(
@@ -27,7 +26,7 @@ fun MainScreen() {
                 })
         }
         Zygote.Login -> {
-            LoginScreen()
+            Login()
         }
         Zygote.Project -> {
             ProjectScreen()

+ 0 - 50
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/Project.kt

@@ -1,50 +0,0 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.project
-
-import androidx.compose.foundation.ExperimentalFoundationApi
-import androidx.compose.foundation.layout.*
-import androidx.compose.foundation.lazy.GridCells
-import androidx.compose.foundation.lazy.LazyVerticalGrid
-import androidx.compose.material.Text
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-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
-
-
-@OptIn(ExperimentalFoundationApi::class)
-@Composable
-fun Project() {
-    Column {
-        Text(text = "可进入的项目(10)", fontSize = 20.sp, fontWeight = FontWeight.Bold, color = Color(0xFF1F2329))
-        Spacer(modifier = Modifier.height(12.dp))
-        LazyVerticalGrid(
-            cells = GridCells.Fixed(2),
-        ) {
-            items(20) {
-                if (it % 2 == 0)
-                    Row(modifier = Modifier.padding(end = 10.dp, bottom = 20.dp)) {
-                        ProjectItem()
-                    }
-                else {
-                    Row(modifier = Modifier.padding(start = 10.dp, bottom = 20.dp)) {
-                        ProjectItem()
-                    }
-                }
-            }
-        }
-    }
-}
-
-@Preview(
-    widthDp = 1280,
-    heightDp = 800,
-    showBackground = true,
-    backgroundColor = 0xFFFFFFFF
-)
-@Composable
-fun PreviewProject() {
-    Project()
-}

+ 0 - 30
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectBlank.kt

@@ -1,30 +0,0 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.project
-
-import androidx.compose.foundation.Image
-import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.tooling.preview.Preview
-import com.ys.bdtp.adm.R
-
-@Composable
-fun ProjectBlank() {
-    Box(
-        modifier = Modifier.fillMaxSize(),
-        contentAlignment = Alignment.Center
-    ) {
-        Image(
-            painter = painterResource(R.drawable.blank),
-            contentDescription = ""
-        )
-    }
-}
-
-@Preview
-@Composable
-fun PreviewProjectBlank() {
-    ProjectBlank()
-}

+ 83 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectContent.kt

@@ -0,0 +1,83 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.project
+
+
+import androidx.compose.foundation.ExperimentalFoundationApi
+import androidx.compose.foundation.layout.*
+import androidx.compose.foundation.lazy.GridCells
+import androidx.compose.foundation.lazy.LazyVerticalGrid
+import androidx.compose.foundation.lazy.itemsIndexed
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+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.app.theme.textBlackColor
+import com.ys.bdtp.adm.mvvm.model.db.entity.ProjectEntity
+
+@ExperimentalFoundationApi
+@Composable
+fun ProjectContent(projects: List<ProjectEntity>) {
+    Column {
+        Text(text = "可进入的项目(${projects.size})", fontSize = 18.sp, fontWeight = FontWeight.Bold, color = textBlackColor)
+        Spacer(modifier = Modifier.height(14.dp))
+        LazyVerticalGrid(
+            cells = GridCells.Fixed(2),
+        ) {
+            itemsIndexed(projects) { index, item ->
+                if (index % 2 == 0)
+                    Row(modifier = Modifier.padding(end = 15.dp, bottom = 20.dp)) {
+                        ProjectItem(item)
+                    }
+                else {
+                    Row(modifier = Modifier.padding(start = 15.dp, bottom = 20.dp)) {
+                        ProjectItem(item)
+                    }
+                }
+            }
+        }
+    }
+
+}
+
+@OptIn(ExperimentalFoundationApi::class)
+@Preview(widthDp = 1137, heightDp = 711)
+@Composable
+fun PreviewProjectContent() {
+    ProjectContent(
+        listOf(
+            ProjectEntity(
+                projectId = "112233",
+                projectName = "京东科技大厦",
+                groupCode = "JD",
+                groupName = "京东"
+            ),
+            ProjectEntity(
+                projectId = "112233",
+                projectName = "京东科技大厦",
+                groupCode = "JD",
+                groupName = "京东"
+            ),
+            ProjectEntity(
+                projectId = "112233",
+                projectName = "京东科技大厦",
+                groupCode = "JD",
+                groupName = "京东"
+            ),
+            ProjectEntity(
+                projectId = "112233",
+                projectName = "京东科技大厦",
+                groupCode = "JD",
+                groupName = "京东"
+            ),
+            ProjectEntity(
+                projectId = "112233",
+                projectName = "京东科技大厦",
+                groupCode = "JD",
+                groupName = "京东"
+            )
+        )
+    )
+}
+

+ 32 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectHeadLeft.kt

@@ -0,0 +1,32 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.project
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.width
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.ys.bdtp.adm.app.theme.textBlackColor
+
+@Composable
+fun ProjectHeadLeft() {
+    Row(
+        verticalAlignment = Alignment.CenterVertically,
+        horizontalArrangement = Arrangement.Start
+    ) {
+
+        Spacer(modifier = Modifier.width(32.dp))
+        Text(text = "禹数数字化交付工具", fontSize = 16.sp, color = textBlackColor)
+    }
+}
+
+@Preview
+@Composable
+fun PreviewProjectHeadLeft() {
+    ProjectHeadLeft()
+}

+ 14 - 8
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectItem.kt

@@ -15,16 +15,17 @@ 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.mvvm.model.db.entity.ProjectEntity
 
 @Composable
-fun ProjectItem() {
+fun ProjectItem(project: ProjectEntity) {
     Card(
         modifier = Modifier
             .fillMaxWidth()
             .height(170.dp),
         backgroundColor = Color.White,
         shape = RoundedCornerShape(8),
-        border = BorderStroke(1.dp, Color(0xFFE5E5E5)),
+        border = BorderStroke(0.8.dp, Color(0xFFE5E5E5)),
         elevation = 0.dp
     ) {
         Row(
@@ -44,12 +45,10 @@ fun ProjectItem() {
                 modifier = Modifier.fillMaxHeight(),
                 verticalArrangement = Arrangement.SpaceAround
             ) {
-                Text(text = "京东科技大厦", color = Color(0xFF1F2429), fontSize = 20.sp)
-                Text(text = "项目ID:Ewq2123", color = Color(0xFF1F2429), fontSize = 16.sp)
-                Text(text = "项目角色:项目管理", color = Color(0xFF1F2429), fontSize = 16.sp)
+                Text(text = project.projectName, color = Color(0xFF1F2429), fontSize = 20.sp)
+                Text(text = "项目ID:${project.projectId}", color = Color(0xFF1F2429), fontSize = 16.sp)
+                Text(text = "项目角色:暂无", color = Color(0xFF1F2429), fontSize = 16.sp)
             }
-
-
         }
     }
 }
@@ -57,5 +56,12 @@ fun ProjectItem() {
 @Preview
 @Composable
 fun PreviewProjectItem() {
-    ProjectItem()
+    ProjectItem(
+        ProjectEntity(
+            projectId = "112233",
+            projectName = "京东科技大厦",
+            groupCode = "JD",
+            groupName = "京东"
+        )
+    )
 }

+ 67 - 66
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectScreen.kt

@@ -1,95 +1,96 @@
 package com.ys.bdtp.adm.mvvm.ui.screen.project
 
+import android.net.ConnectivityManager
+import androidx.compose.foundation.ExperimentalFoundationApi
 import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxHeight
-import androidx.compose.foundation.layout.fillMaxSize
-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.foundation.layout.wrapContentWidth
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Alignment
+import androidx.compose.foundation.layout.*
+import androidx.compose.runtime.*
 import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
-import com.ys.bdtp.adm.R
+import com.ys.bdtp.adm.app.isNet
+import com.ys.bdtp.adm.app.theme.underColor
+import com.ys.bdtp.adm.mvvm.model.FailureResponse
+import com.ys.bdtp.adm.mvvm.model.SuccessResponse
+import com.ys.bdtp.adm.mvvm.model.vo.request.Account
+import com.ys.bdtp.adm.mvvm.ui.compose.Blank
+import com.ys.bdtp.adm.mvvm.ui.compose.Div
 import com.ys.bdtp.adm.mvvm.ui.compose.Head
-import com.ys.bdtp.adm.mvvm.ui.compose.TaskType
-import com.ys.bdtp.adm.mvvm.ui.compose.HeadLeft
 import com.ys.bdtp.adm.mvvm.ui.compose.HeadRight
+import com.ys.bdtp.adm.mvvm.vm.project.ProjectViewModel
+import kotlinx.coroutines.launch
+import org.kodein.di.compose.rememberInstance
+import org.kodein.di.compose.rememberViewModel
 
+
+@OptIn(ExperimentalFoundationApi::class)
 @Composable
 fun ProjectScreen() {
+    val vm by rememberViewModel<ProjectViewModel>()
+    val cm by rememberInstance<ConnectivityManager>()
+
+    var account by remember { mutableStateOf<Account?>(null) }
+    val scope = rememberCoroutineScope()
+
+    LaunchedEffect(Unit) {
+        // isNet 联网,进行网络通信,获取账号信息也判断 token是否能用
+        if (isNet(cm)) {
+            scope.launch {
+                when (val response = vm.getAccount()) {
+                    is SuccessResponse -> {
+                        val a = response.data
+                        account = a
+                        vm.setCurrentAccount(a)
+                    }
 
-    Column(modifier = Modifier.fillMaxSize().background(Color.White)) {
+                    is FailureResponse -> {
+                        // 纯联网问题
+                    }
+                }
+            }
+        }
+    }
+
+    Column(
+        modifier = Modifier.fillMaxSize()
+    ) {
         Head(
-            left = { HeadLeft() },
+            left = {
+                ProjectHeadLeft()
+            },
             right = {
                 HeadRight(
-                    role = { "管家" },
-                    click = { println("heiheihei") }
+                    role = { "项目管家" },
+                    click = {}
                 )
             }
         )
-
-        Spacer(
-            modifier = Modifier.fillMaxWidth().height(1.dp).background(Color(0xFFEFF0F1))
-        )
-
-
-        Row {
-            Box(
-                modifier = Modifier
-                    .fillMaxHeight()
-                    .wrapContentWidth()
-                    .padding(horizontal = 32.dp, vertical = 42.dp)
-            ) {
-                // 工作分类
-                Column(
-                    horizontalAlignment = Alignment.CenterHorizontally
-                ) {
-                    TaskType(R.drawable.project_task_cad, "CAD核查")
-                    Spacer(modifier = Modifier.height(20.dp))
-                    TaskType(R.drawable.project_task_space, "空间模型核查")
-                    Spacer(modifier = Modifier.height(20.dp))
-                    TaskType(R.drawable.project_task_electric, "机电核查")
-                    Spacer(modifier = Modifier.height(20.dp))
-                    TaskType(R.drawable.project_task_relation, "交付关系")
-                    Spacer(modifier = Modifier.height(20.dp))
-                    TaskType(R.drawable.project_task_offline, "离线数据")
+        Div(Div.Row)
+        Column(
+            modifier = Modifier
+                .fillMaxHeight()
+                .wrapContentWidth()
+                .background(underColor)
+                .padding(horizontal = 32.dp, vertical = 40.dp)
+        ) {
+            account?.let {
+                if (it.projects.isEmpty()) {
+                    Blank()
+                } else {
+                    ProjectContent(it.projects)
                 }
-
-                // 项目切换
-
-            }
-
-            Spacer(modifier = Modifier.width(1.dp).fillMaxHeight().background(Color(0xFFE5E5E5)))
-
-            Column(
-                modifier = Modifier
-                    .fillMaxHeight()
-                    .wrapContentWidth()
-                    .padding(horizontal = 32.dp, vertical = 42.dp)
-            ) {
-                //ProjectBlank()
-                ProjectTask()
             }
         }
     }
 }
 
-
 @Preview(
-    widthDp = 1137,
-    heightDp = 711,
+    widthDp = 1280,
+    heightDp = 800,
+    showBackground = true,
+    backgroundColor = 0xFFFFFFFF
 )
 @Composable
-fun PreviewProjectScreen() {
+fun PreviewProject() {
     ProjectScreen()
 }

+ 1 - 8
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/project/ProjectRecentTask.kt

@@ -1,20 +1,13 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.project
+package com.ys.bdtp.adm.mvvm.ui.screen.task
 
 import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Row
 import androidx.compose.foundation.layout.Spacer
 import androidx.compose.foundation.layout.fillMaxSize
 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.foundation.lazy.LazyColumn
-import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.material.LinearProgressIndicator
-import androidx.compose.material.Surface
 import androidx.compose.material.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Alignment

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

@@ -1,4 +1,4 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.project
+package com.ys.bdtp.adm.mvvm.ui.screen.task
 
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Arrangement

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

@@ -1,4 +1,4 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.project
+package com.ys.bdtp.adm.mvvm.ui.screen.task
 
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Arrangement

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

@@ -1,4 +1,4 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.project
+package com.ys.bdtp.adm.mvvm.ui.screen.task
 
 import androidx.compose.foundation.BorderStroke
 import androidx.compose.foundation.background

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

@@ -1,4 +1,4 @@
-package com.ys.bdtp.adm.mvvm.ui.screen.project
+package com.ys.bdtp.adm.mvvm.ui.screen.task
 
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Arrangement

+ 94 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/TaskScreen.kt

@@ -0,0 +1,94 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.task
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxSize
+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.foundation.layout.wrapContentWidth
+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.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
+import com.ys.bdtp.adm.R
+import com.ys.bdtp.adm.mvvm.ui.compose.Head
+import com.ys.bdtp.adm.mvvm.ui.compose.TaskType
+import com.ys.bdtp.adm.mvvm.ui.compose.HeadLeft
+import com.ys.bdtp.adm.mvvm.ui.compose.HeadRight
+
+@Composable
+fun TaskScreen() {
+    Column(modifier = Modifier.fillMaxSize().background(Color.White)) {
+        Head(
+            left = { HeadLeft() },
+            right = {
+                HeadRight(
+                    role = { "管家" },
+                    click = { println("heiheihei") }
+                )
+            }
+        )
+
+        Spacer(
+            modifier = Modifier.fillMaxWidth().height(1.dp).background(Color(0xFFEFF0F1))
+        )
+
+
+        Row {
+            Box(
+                modifier = Modifier
+                    .fillMaxHeight()
+                    .wrapContentWidth()
+                    .padding(horizontal = 32.dp, vertical = 42.dp)
+            ) {
+                // 工作分类
+                Column(
+                    horizontalAlignment = Alignment.CenterHorizontally
+                ) {
+                    TaskType(R.drawable.project_task_cad, "CAD核查")
+                    Spacer(modifier = Modifier.height(20.dp))
+                    TaskType(R.drawable.project_task_space, "空间模型核查")
+                    Spacer(modifier = Modifier.height(20.dp))
+                    TaskType(R.drawable.project_task_electric, "机电核查")
+                    Spacer(modifier = Modifier.height(20.dp))
+                    TaskType(R.drawable.project_task_relation, "交付关系")
+                    Spacer(modifier = Modifier.height(20.dp))
+                    TaskType(R.drawable.project_task_offline, "离线数据")
+                }
+
+                // 项目切换
+
+            }
+
+            Spacer(modifier = Modifier.width(1.dp).fillMaxHeight().background(Color(0xFFE5E5E5)))
+
+            Column(
+                modifier = Modifier
+                    .fillMaxHeight()
+                    .wrapContentWidth()
+                    .padding(horizontal = 32.dp, vertical = 42.dp)
+            ) {
+                //ProjectBlank()
+                ProjectTask()
+            }
+        }
+    }
+}
+
+
+@Preview(
+    widthDp = 1137,
+    heightDp = 711,
+)
+@Composable
+fun PreviewProjectScreen() {
+    TaskScreen()
+}

+ 2 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/flash/FlashViewModel.kt

@@ -32,12 +32,13 @@ class FlashViewModel(private val repo: FlashRepository) : ViewModel() {
      * @param success 获取成功回调
      * @param failure 获取失败回调
      */
-    suspend fun getAccount(success: (Account) -> Unit, failure: (String) -> Unit) {
+    suspend fun getAccount(success: (Account) -> Unit,  failure: (String) -> Unit) {
         viewModelScope.launch {
             when (val response = repo.getAccount()) {
                 is SuccessResponse -> {
                     success(response.data)
                 }
+
                 is FailureResponse -> {
                     failure(response.message)
                 }

+ 13 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/login/LoginViewModel.kt

@@ -7,8 +7,20 @@ import com.ys.bdtp.adm.mvvm.model.SuccessResponse
 import com.ys.bdtp.adm.mvvm.model.vo.request.Login
 import kotlinx.coroutines.launch
 
+/**
+ * LoginViewModel
+ *
+ * @author bai
+ */
 class LoginViewModel(private val repo: LoginRepository) : ViewModel() {
-    fun login(login: Login, success: (String) -> Unit, failure: (String) -> Unit) {
+    /**
+     * 登录
+     */
+    fun login(
+        login: Login,
+        success: (String) -> Unit,
+        failure: (String) -> Unit,
+    ) {
         viewModelScope.launch {
             when (val response = repo.login(login)) {
                 is SuccessResponse -> {

+ 63 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/project/ProjectRepository.kt

@@ -0,0 +1,63 @@
+package com.ys.bdtp.adm.mvvm.vm.project
+
+import com.ys.bdtp.adm.mvvm.model.Response
+import com.ys.bdtp.adm.mvvm.model.db.AdmDatabase
+import com.ys.bdtp.adm.mvvm.model.db.entity.ProjectEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
+import com.ys.bdtp.adm.mvvm.model.nt.Api
+import com.ys.bdtp.adm.mvvm.model.request
+import com.ys.bdtp.adm.mvvm.model.vo.request.Account
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+
+
+/**
+ * ProjectRepository
+ *
+ * @author bai
+ *
+ * @param
+ */
+class ProjectRepository(private val api: Api, private val db: AdmDatabase) {
+    /**
+     * 获取账号信息
+     */
+    suspend fun getAccount(): Response<Account> {
+        return withContext(Dispatchers.IO) {
+            request {
+                api.getAccount()
+            }
+        }
+    }
+
+    /**
+     * 获取项目信息
+     */
+    suspend fun getProjects(): List<ProjectEntity> {
+        return withContext(Dispatchers.IO) {
+            db.projectDao().getProjects()
+        }
+    }
+
+    /**
+     * 设置当前账号信息
+     */
+    suspend fun setCurrentAccount(account: Account) {
+        return withContext(Dispatchers.IO) {
+            val user = UserEntity(
+                password = "",
+                state = 1,
+                id = account.id,
+                account = account.account,
+                deptId = account.deptId,
+                email = account.email,
+                phone = account.phone,
+                name = account.name,
+            )
+            val users = db.userDao().getUsers().onEach { u -> u.state = 0 }
+            db.userDao().insUsers(users)
+            db.userDao().insUser(user)
+            db.projectDao().insProjects(account.projects)
+        }
+    }
+}

+ 54 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/project/ProjectViewModel.kt

@@ -0,0 +1,54 @@
+package com.ys.bdtp.adm.mvvm.vm.project
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.ys.bdtp.adm.mvvm.model.FailureResponse
+import com.ys.bdtp.adm.mvvm.model.Response
+import com.ys.bdtp.adm.mvvm.model.SuccessResponse
+import com.ys.bdtp.adm.mvvm.model.db.entity.ProjectEntity
+import com.ys.bdtp.adm.mvvm.model.vo.request.Account
+import kotlinx.coroutines.launch
+
+/**
+ * ProjectViewModel
+ *
+ * @author bai
+ *
+ * @param
+ */
+class ProjectViewModel(private val repo: ProjectRepository) : ViewModel() {
+
+    /**
+     * 获取项目信息
+     */
+    suspend fun getProjects(): List<ProjectEntity> {
+        return repo.getProjects()
+    }
+
+    /**
+     * 获取账号信息
+     */
+    suspend fun getAccount(success: (Account) -> Unit, failure: (String) -> Unit) {
+        viewModelScope.launch {
+            when (val response = repo.getAccount()) {
+                is SuccessResponse -> {
+                    success(response.data)
+                }
+                is FailureResponse -> {
+                    failure(response.message)
+                }
+            }
+        }
+    }
+
+    /**
+     * 获取账号信息
+     */
+    suspend fun getAccount(): Response<Account> {
+        return repo.getAccount()
+    }
+
+    suspend fun setCurrentAccount(account: Account) {
+        repo.setCurrentAccount(account)
+    }
+}

+ 0 - 0
identifier.sqlite