Explorar el Código

1.添加退出登录事件处理,接口成功后再退出

20241218TB223FC(测试jar包)
wangwanlei hace 9 meses
padre
commit
7f22d3711c

+ 14
- 0
app/src/main/java/com/xhly/manageapp/bean/log/LogEventBean.kt Ver fichero

@@ -0,0 +1,14 @@
1
+package com.xhly.manageapp.bean.log
2
+
3
+/**
4
+ * 记录事件接口存储是否成功,目前主要用于退出登录
5
+ */
6
+class LogEventBean {
7
+    /**
8
+     *从EventLog取
9
+     */
10
+    var logEventType = 0
11
+
12
+    //是否成功
13
+    var enableFlag = false
14
+}

+ 1
- 1
app/src/main/java/com/xhly/manageapp/network/log/LogService.kt Ver fichero

@@ -17,7 +17,7 @@ interface LogService {
17 17
      * 设备事件日志-添加
18 18
      */
19 19
     @POST(UriAdress.LOGDOPERATEADD)
20
-    suspend fun postLogdoperateAdd(@Body logDay: LogdOperateBean)
20
+    suspend fun postLogdoperateAdd(@Body logDay: LogdOperateBean):ResponseData<Any>
21 21
 
22 22
     /**
23 23
      * 设备启动日志-添加

+ 24
- 8
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt Ver fichero

@@ -98,7 +98,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
98 98
     override fun initData() {
99 99
         val json = spUtils.getFromJson(Const.USERINFO, UserBean().javaClass)
100 100
         if (json == null) {
101
-            loginOut()
101
+            loginOut(false)
102 102
             return
103 103
         } else {
104 104
             userBean = json as UserBean
@@ -328,6 +328,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
328 328
                 }
329 329
             }
330 330
         }
331
+        viewModel.logEventData.observe(this){
332
+            when(it.logEventType){
333
+                EventLog.ACCOUNTQUITEVENT->{
334
+                    loginOutSucess()
335
+                }
336
+            }
337
+        }
331 338
         startWorkManager()
332 339
         updateAllStrategy()
333 340
     }
@@ -1057,14 +1064,23 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
1057 1064
             .setAlign(CustomDialog.ALIGN.CENTER).show()
1058 1065
     }
1059 1066
 
1060
-    private fun loginOut() {
1061
-        val data = LogdOperateBean()
1062
-        ManageApplication.getDeviceInfo()?.let {
1063
-            data.sn = it
1067
+    private fun loginOut(hasUser:Boolean=true) {
1068
+        //没有用户信息时,判断为初次调用,直接跳转登录页面
1069
+        if (hasUser){
1070
+            //调用接口传递退出事件,成功则退出登录
1071
+            val data = LogdOperateBean()
1072
+            ManageApplication.getDeviceInfo()?.let {
1073
+                data.sn = it
1074
+            }
1075
+            data.comm = "退出登录"
1076
+            data.doEvent = EventLog.ACCOUNTQUITEVENT
1077
+            viewModel.eventLog(data)
1078
+        }else{
1079
+            loginOutSucess()
1064 1080
         }
1065
-        data.comm = "退出登录"
1066
-        data.doEvent = EventLog.ACCOUNTQUITEVENT
1067
-        viewModel.eventLog(data)
1081
+    }
1082
+
1083
+    private fun loginOutSucess(){
1068 1084
         WorkManager.getInstance(this).cancelAllWork()
1069 1085
         deleteSharedPreferences(SharedPreferencesUtils.SP_FILE_NAME)
1070 1086
         Const.USERID = null

+ 10
- 2
app/src/main/java/com/xhly/manageapp/viewmodel/BaseViewModel.kt Ver fichero

@@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
5 5
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
6 6
 import com.xhly.corelib.network.RetrofitService
7 7
 import com.xhly.corelib.utils.MD5Utils
8
+import com.xhly.manageapp.bean.log.LogEventBean
8 9
 import com.xhly.manageapp.bean.log.LogPushBean
9 10
 import com.xhly.manageapp.bean.log.LogPushResultBean
10 11
 import com.xhly.manageapp.bean.log.LogdOperateBean
@@ -26,7 +27,8 @@ open class BaseViewModel : CommonBaseViewModel() {
26 27
     val resetlResultData: LiveData<Boolean> = resetResult
27 28
     private val logResult=MutableLiveData<LogPushResultBean>()
28 29
     val logResultData:LiveData<LogPushResultBean> =logResult
29
-
30
+    private val logEventResult=MutableLiveData<LogEventBean>()
31
+    val logEventData:LiveData<LogEventBean> =logEventResult
30 32
     /**
31 33
      * 解除当前锁屏
32 34
      */
@@ -65,7 +67,13 @@ open class BaseViewModel : CommonBaseViewModel() {
65 67
      */
66 68
     fun eventLog(operateBean: LogdOperateBean) {
67 69
         launchUI {
68
-            logService.postLogdoperateAdd(operateBean)
70
+            var result = logService.postLogdoperateAdd(operateBean)
71
+            if (result.code==0){
72
+                val logEventBean=LogEventBean()
73
+                logEventBean.enableFlag=true
74
+                logEventBean.logEventType=operateBean.doEvent
75
+                logEventResult.value=logEventBean
76
+            }
69 77
         }
70 78
     }
71 79
 

Loading…
Cancelar
Guardar