|
|
@ -1,14 +1,25 @@ |
|
|
|
package com.gyf.csams.main.model |
|
|
|
package com.gyf.csams.main.model |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity |
|
|
|
|
|
|
|
import android.content.Intent |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
import androidx.lifecycle.MutableLiveData |
|
|
|
import androidx.lifecycle.MutableLiveData |
|
|
|
import androidx.lifecycle.ViewModel |
|
|
|
import androidx.lifecycle.ViewModel |
|
|
|
import androidx.lifecycle.viewModelScope |
|
|
|
import androidx.lifecycle.viewModelScope |
|
|
|
|
|
|
|
import com.google.gson.reflect.TypeToken |
|
|
|
|
|
|
|
import com.gyf.csams.AccountApi |
|
|
|
|
|
|
|
import com.gyf.csams.Api |
|
|
|
import com.gyf.csams.NOT_IMPL_TIP |
|
|
|
import com.gyf.csams.NOT_IMPL_TIP |
|
|
|
|
|
|
|
import com.gyf.csams.account.ui.AccountActivity |
|
|
|
import com.gyf.csams.uikit.SendInterface |
|
|
|
import com.gyf.csams.uikit.SendInterface |
|
|
|
|
|
|
|
import com.gyf.csams.util.AppDatabase |
|
|
|
|
|
|
|
import com.gyf.csams.util.SimpleCallback |
|
|
|
|
|
|
|
import com.gyf.csams.util.TokenManager |
|
|
|
import com.gyf.lib.ScrollList |
|
|
|
import com.gyf.lib.ScrollList |
|
|
|
import com.gyf.lib.uikit.PersonInfoVo |
|
|
|
import com.gyf.lib.uikit.PersonInfoVo |
|
|
|
import com.gyf.lib.uikit.StringForm |
|
|
|
import com.gyf.lib.uikit.StringForm |
|
|
|
|
|
|
|
import com.gyf.lib.util.ApiResponse |
|
|
|
|
|
|
|
import com.gyf.lib.util.HttpClient |
|
|
|
import com.gyf.lib.util.randomChinese |
|
|
|
import com.gyf.lib.util.randomChinese |
|
|
|
import com.gyf.lib.util.randomNum |
|
|
|
import com.gyf.lib.util.randomNum |
|
|
|
import com.orhanobut.logger.Logger |
|
|
|
import com.orhanobut.logger.Logger |
|
|
@ -173,6 +184,8 @@ data class InfoVo( |
|
|
|
override val desc: String |
|
|
|
override val desc: String |
|
|
|
) : PersonInfoVo() |
|
|
|
) : PersonInfoVo() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data class UserLogoutVo(val studentId: String) |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 个人中心 |
|
|
|
* 个人中心 |
|
|
|
* |
|
|
|
* |
|
|
@ -202,4 +215,41 @@ class CenterViewModel : ViewModel() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun logout(context: Activity, callback: (message: String) -> Unit) { |
|
|
|
|
|
|
|
val studentId = TokenManager.token?.studentId |
|
|
|
|
|
|
|
if (studentId != null) { |
|
|
|
|
|
|
|
Logger.i("帐号$studentId 将要退出登录") |
|
|
|
|
|
|
|
viewModelScope.launch { |
|
|
|
|
|
|
|
HttpClient.post(Api.buildUrl(AccountApi.Logout), |
|
|
|
|
|
|
|
SimpleCallback<Boolean>(action = "登出", onSuccess = { it -> |
|
|
|
|
|
|
|
it.body?.let { |
|
|
|
|
|
|
|
if (it) { |
|
|
|
|
|
|
|
viewModelScope.launch { |
|
|
|
|
|
|
|
val db = AppDatabase.getInstance(context = context) |
|
|
|
|
|
|
|
db?.tokenDao()?.deleteAll() |
|
|
|
|
|
|
|
Logger.i("退出登陆成功") |
|
|
|
|
|
|
|
context.finish() |
|
|
|
|
|
|
|
context.startActivity( |
|
|
|
|
|
|
|
Intent( |
|
|
|
|
|
|
|
context, |
|
|
|
|
|
|
|
AccountActivity::class.java |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
TokenManager.token = null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
callback(it.message) |
|
|
|
|
|
|
|
}, onFail = { callback("退出登陆失败") }, |
|
|
|
|
|
|
|
type = object : TypeToken<ApiResponse<Boolean>>() {}.type |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
param = UserLogoutVo(studentId = studentId) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
callback("操作异常,请联系管理员") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|