This commit is contained in:
2026-04-28 11:01:10 +08:00
parent 1b62e4d264
commit 8a5f599266
15 changed files with 419 additions and 32 deletions

View File

@@ -0,0 +1,27 @@
package com.example.defenseapplication.utils
import bean.LoginBean
import com.blankj.utilcode.util.SPUtils
import com.google.gson.Gson
//存储登录的token和userid
object UserinfoUtil {
private const val KEY_USER = "NAME_USER"
private val gson = Gson()
fun saveUserInfo(userinfo: LoginBean?) {
userinfo ?: return
val json = gson.toJson(userinfo)
SPUtils.getInstance().put(KEY_USER, json)
}
fun getUserInfo(): LoginBean? {
val string = SPUtils.getInstance().getString(KEY_USER)
if (string.isNullOrEmpty()) {
return null
}
return gson.fromJson(string, LoginBean::class.java)
}
}