package com.example.smart.ui.splash
|
|
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.viewModelScope
|
import com.example.basecore.base.BaseContextViewModel
|
import com.example.basecore.net.http.OssBaseResponse
|
import com.example.basecore.net.http.Result
|
import com.example.smart.reqeust.RetrofitClient
|
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.launch
|
|
|
class SplashViewModel : BaseContextViewModel() {
|
|
val bean = MutableLiveData<OssBaseResponse>()
|
|
fun requestOssKey() {
|
viewModelScope.launch(Dispatchers.Main) {
|
safeCall {
|
callOSSToken(RetrofitClient.ossApi.getStsToken())
|
}.apply {
|
if (this is Result.Success) {
|
bean.value = this.data
|
}
|
}
|
}
|
}
|
|
|
fun callLoginStatus(fail: (String) -> Unit) {
|
viewModelScope.launch {
|
val result = safeCall { execute(RetrofitClient.api.getProfileInfo()) }
|
if (result is Result.Error) {
|
fail(result.exception.message ?: "未知错误")
|
}
|
}
|
}
|
|
|
}
|