瀏覽代碼

1.处理拦截器默认返回值为-1,处理退出登录时可能存在的无法请求接口导致的退出登录失败。

0423x6e6f
wangwanlei 1 月之前
父節點
當前提交
d1de267a4e

+ 10
- 0
app/src/main/java/com/xhly/manageapp/viewmodel/BaseViewModel.kt 查看文件

@@ -1,5 +1,6 @@
1 1
 package com.xhly.manageapp.viewmodel
2 2
 
3
+import android.app.usage.UsageEvents.Event
3 4
 import androidx.lifecycle.LiveData
4 5
 import androidx.lifecycle.MutableLiveData
5 6
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
@@ -7,6 +8,7 @@ import com.xhly.corelib.network.RetrofitService
7 8
 import com.xhly.corelib.utils.LogShow
8 9
 import com.xhly.corelib.utils.MD5Utils
9 10
 import com.xhly.corelib.utils.SystemUtil
11
+import com.xhly.manageapp.bean.EventLog
10 12
 import com.xhly.manageapp.bean.log.LogEventBean
11 13
 import com.xhly.manageapp.bean.log.LogPushBean
12 14
 import com.xhly.manageapp.bean.log.LogPushResultBean
@@ -97,6 +99,14 @@ open class BaseViewModel : CommonBaseViewModel() {
97 99
                 logEventBean.enableFlag = true
98 100
                 logEventBean.logEventType = operateBean.doEvent
99 101
                 logEventResult.value = logEventBean
102
+            }else{
103
+                if (result.code==-1&&operateBean.doEvent== EventLog.ACCOUNTQUITEVENT){
104
+                    //请求遇到问题时,退出登录直接成功
105
+                    val logEventBean = LogEventBean()
106
+                    logEventBean.enableFlag = true
107
+                    logEventBean.logEventType = operateBean.doEvent
108
+                    logEventResult.value = logEventBean
109
+                }
100 110
             }
101 111
         }
102 112
     }

+ 2
- 2
corelib/src/main/java/com/xhly/corelib/network/ResponseInterceptor.kt 查看文件

@@ -59,12 +59,12 @@ class ResponseInterceptor : Interceptor {
59 59
     }
60 60
     fun createDefaultResponse(): Response {
61 61
         // 创建默认的响应体内容
62
-        val responseBody = "{\"code\":1,\"msg\":\"\",\"obj\":false}" // 替换为您想要返回的默认响应体内容
62
+        val responseBody = "{\"code\":-1,\"msg\":\"\",\"obj\":false}" // 替换为您想要返回的默认响应体内容
63 63
 
64 64
         // 创建默认的响应对象
65 65
         val response = Response.Builder()
66 66
             .code(200) // 替换为您想要的响应码
67
-            .message("{\"code\":1,\"msg\":\"\",\"obj\":false}") // 替换为您想要的响应消息
67
+            .message("{\"code\":-1,\"msg\":\"\",\"obj\":false}") // 替换为您想要的响应消息
68 68
             .protocol(okhttp3.Protocol.HTTP_1_1) // 替换为您想要的协议
69 69
             .request(okhttp3.Request.Builder().url("http://example.com").build()) // 替换为请求对象
70 70
             .body(responseBody.toResponseBody()) // 设置响应体

Loading…
取消
儲存