1、添加校验登录使用(UniMp小程序)
2、抠图接口变更
This commit is contained in:
shenzuqiang 2026-03-13 11:54:15 +08:00
parent 62061c8fe6
commit c9d2217716
9 changed files with 89 additions and 24 deletions

View File

@ -4,7 +4,7 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-03-13T02:12:15.837405600Z"> <DropdownSelection timestamp="2026-03-13T03:47:40.083936900Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=Y5DELZR46DZTCI9D" /> <DeviceId pluginId="PhysicalDevice" identifier="serial=Y5DELZR46DZTCI9D" />

View File

@ -57,6 +57,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.permissions.ExperimentalPermissionsApi import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.img.rabbit.bean.response.UniVersionEntity import com.img.rabbit.bean.response.UniVersionEntity
import com.img.rabbit.bean.response.UserInfoEntity
import com.img.rabbit.components.GlobalToast import com.img.rabbit.components.GlobalToast
import com.img.rabbit.config.Constants import com.img.rabbit.config.Constants
import com.img.rabbit.config.Constants.agreementUrl import com.img.rabbit.config.Constants.agreementUrl
@ -65,6 +66,7 @@ import com.img.rabbit.pages.LoadingCallback
import com.img.rabbit.pages.LoginScreen import com.img.rabbit.pages.LoginScreen
import com.img.rabbit.pages.LoginScreenType import com.img.rabbit.pages.LoginScreenType
import com.img.rabbit.pages.MainScreen import com.img.rabbit.pages.MainScreen
import com.img.rabbit.pages.dialog.TipsDialog
import com.img.rabbit.pages.dialog.TipsUniMpDialog import com.img.rabbit.pages.dialog.TipsUniMpDialog
import com.img.rabbit.pages.dialog.TipsUniMpToPageDialog import com.img.rabbit.pages.dialog.TipsUniMpToPageDialog
import com.img.rabbit.pages.dialog.UpdateDialog import com.img.rabbit.pages.dialog.UpdateDialog
@ -115,6 +117,8 @@ class MainActivity : ComponentActivity(), LoadingCallback {
// 退出登录 // 退出登录
var isLogout by remember { mutableStateOf(false) } var isLogout by remember { mutableStateOf(false) }
// 登录提示
var showLoginDialog by remember { mutableStateOf(false) }
// 软件更新提示 // 软件更新提示
var showUpdateDialog by remember { mutableStateOf(false) } var showUpdateDialog by remember { mutableStateOf(false) }
// 下载小程序资源(在跳转指定页面时,未下载资源需要提示) // 下载小程序资源(在跳转指定页面时,未下载资源需要提示)
@ -144,11 +148,35 @@ class MainActivity : ComponentActivity(), LoadingCallback {
updateUniEntity = event.entity updateUniEntity = event.entity
showUniUpdateDialog = true showUniUpdateDialog = true
} }
// 登录提示
is GlobalEvent.ShowLoginNotify -> {
showLoginDialog = true
}
// ... 可以处理其他事件 // ... 可以处理其他事件
} }
} }
} }
// 处理全局事件类似与EventBus订阅
LaunchedEffect(Unit) {
AppEventBus.events.collect { event ->
when (event) {
is LoginBindEvent.Login -> {
if(!event.isLogin){
loginViewModel.reset()
isLogout = true
}else{
isLogout = false
}
loginViewModel.requestUserConfig()
}
is LoginBindEvent.Bind -> {
loginViewModel.requestUserConfig()
}
}
}
}
// 设置启动页显示条件 // 设置启动页显示条件
splashScreen.setKeepOnScreenCondition { splashScreen.setKeepOnScreenCondition {
splashViewModel.isLoading.value // 当为 true 时,启动页不消失 splashViewModel.isLoading.value // 当为 true 时,启动页不消失
@ -176,26 +204,6 @@ class MainActivity : ComponentActivity(), LoadingCallback {
} }
} }
// 处理全局事件类似与EventBus订阅
LaunchedEffect(Unit) {
AppEventBus.events.collect { event ->
when (event) {
is LoginBindEvent.Login -> {
if(!event.isLogin){
loginViewModel.reset()
isLogout = true
}else{
isLogout = false
}
loginViewModel.requestUserConfig()
}
is LoginBindEvent.Bind -> {
loginViewModel.requestUserConfig()
}
}
}
}
//提示下载小程序资源(在跳转指定页面时,未下载资源需要提示) //提示下载小程序资源(在跳转指定页面时,未下载资源需要提示)
val progressWGTToPageState = remember { mutableFloatStateOf(0f) } val progressWGTToPageState = remember { mutableFloatStateOf(0f) }
LaunchedEffect(showUniDownloadDialog) { LaunchedEffect(showUniDownloadDialog) {
@ -309,6 +317,27 @@ class MainActivity : ComponentActivity(), LoadingCallback {
} }
} }
if(showLoginDialog){
TipsDialog(
title = "温馨提示",
content1 = "在使用我们功能之前,需要您先登录!",
content2 = null,
cancel = "取消",
confirm = "立即登录",
data = null,
onStatusChange = { status, isCancel, _ ->
if(!isCancel){
// 隐藏TabBar
generalViewModel.apply {
setNavigationBarVisible(false)
navController.navigate("login?type=${LoginViewModel.JumpLoginType.FROM_ADD.type}")
}
}
showLoginDialog = status
}
)
}
//提示下载小程序资源(在跳转指定页面时,未下载资源需要提示) //提示下载小程序资源(在跳转指定页面时,未下载资源需要提示)
if(showUniDownloadDialog){ if(showUniDownloadDialog){
downloadUniEntity?.let { downloadUniEntity?.let {
@ -321,7 +350,6 @@ class MainActivity : ComponentActivity(), LoadingCallback {
} }
} }
//UniApp更新提示 //UniApp更新提示
val isDownloadingWGT = mutableStateOf(false) val isDownloadingWGT = mutableStateOf(false)
val progressWGTState = mutableFloatStateOf(0f) val progressWGTState = mutableFloatStateOf(0f)

View File

@ -18,7 +18,7 @@ class UserInfoEntity(
val name: String = "", val name: String = "",
val phone: String = "", val phone: String = "",
val role: String = "", val role: String = "",
val temp: Boolean = false, val temp: Boolean = true,
val unionid: String = "", val unionid: String = "",
val user_id: String = "", val user_id: String = "",
val vip: Int = 0, val vip: Int = 0,

View File

@ -71,6 +71,7 @@ fun MainScreen(generalViewModel: GeneralViewModel, loginViewModel: LoginViewMode
val isNavigationBarVisible by generalViewModel.isNavigationBarVisible.observeAsState(initial = true) val isNavigationBarVisible by generalViewModel.isNavigationBarVisible.observeAsState(initial = true)
val tabItems = listOf( TabItem.Home, TabItem.Mine ) val tabItems = listOf( TabItem.Home, TabItem.Mine )
var selectedTab: TabItem by remember { mutableStateOf(TabItem.Home) } var selectedTab: TabItem by remember { mutableStateOf(TabItem.Home) }
generalViewModel.navController = navController
// 获取当前路由状态 // 获取当前路由状态
val navBackStackEntry by navController.currentBackStackEntryAsState() val navBackStackEntry by navController.currentBackStackEntryAsState()

View File

@ -239,6 +239,9 @@ fun HomeScreen(
indication = null, indication = null,
interactionSource = remember { MutableInteractionSource() } interactionSource = remember { MutableInteractionSource() }
) { ) {
if(!loginViewModel.requiredLogin()){
return@clickable
}
val uniMp = uniVersionConfig[0] val uniMp = uniVersionConfig[0]
dealUniMpDownloadLaunch( dealUniMpDownloadLaunch(
context, context,
@ -309,6 +312,9 @@ fun HomeScreen(
indication = null, indication = null,
interactionSource = remember { MutableInteractionSource() } interactionSource = remember { MutableInteractionSource() }
) { ) {
if(!loginViewModel.requiredLogin()){
return@clickable
}
val uniMp = uniVersionConfig[1] val uniMp = uniVersionConfig[1]
dealUniMpDownloadLaunch( dealUniMpDownloadLaunch(
context, context,
@ -393,6 +399,9 @@ fun HomeScreen(
indication = null, indication = null,
interactionSource = remember { MutableInteractionSource() } interactionSource = remember { MutableInteractionSource() }
) { ) {
if(!loginViewModel.requiredLogin()){
return@clickable
}
val uniVersion = val uniVersion =
PreferenceUtil.getUserConfig()?.config?.uniVersionEntity?.firstOrNull { it.unimp_type == item.type } PreferenceUtil.getUserConfig()?.config?.uniVersionEntity?.firstOrNull { it.unimp_type == item.type }
@ -821,6 +830,7 @@ private fun dealUniMpDownloadLaunch(
} }
} }
@Preview(showBackground = true) @Preview(showBackground = true)
@Composable @Composable
private fun PreviewOtherItems() { private fun PreviewOtherItems() {

View File

@ -67,6 +67,7 @@ sealed class UniMpWXPayEvent {
// 可以定义一个事件密封类,方便扩展 // 可以定义一个事件密封类,方便扩展
sealed class GlobalEvent { sealed class GlobalEvent {
object ShowAppUpdateNotify : GlobalEvent() object ShowAppUpdateNotify : GlobalEvent()
object ShowLoginNotify : GlobalEvent()
data class ShowUniDownloadNotify(val entity: UniVersionEntity) : GlobalEvent() data class ShowUniDownloadNotify(val entity: UniVersionEntity) : GlobalEvent()
data class ShowUniUpdateNotify(val entity: UniVersionEntity) : GlobalEvent() data class ShowUniUpdateNotify(val entity: UniVersionEntity) : GlobalEvent()
} }

View File

@ -15,6 +15,8 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.img.rabbit.bean.response.UniVersionEntity import com.img.rabbit.bean.response.UniVersionEntity
import com.img.rabbit.config.Constants import com.img.rabbit.config.Constants
import com.img.rabbit.provider.api.ApiManager import com.img.rabbit.provider.api.ApiManager
@ -32,6 +34,7 @@ import kotlinx.coroutines.flow.asSharedFlow
class GeneralViewModel: BaseViewModel(){ class GeneralViewModel: BaseViewModel(){
lateinit var api: IWXAPI lateinit var api: IWXAPI
lateinit var receiver: BroadcastReceiver lateinit var receiver: BroadcastReceiver
lateinit var navController: NavHostController
private val _networkStatus = MutableLiveData<Boolean>() private val _networkStatus = MutableLiveData<Boolean>()
val networkStatus: LiveData<Boolean> = _networkStatus val networkStatus: LiveData<Boolean> = _networkStatus

View File

@ -439,6 +439,28 @@ class LoginViewModel : BaseViewModel() {
} }
} }
/**
* 检查是否登录
*/
fun isLogin(): Boolean{
val userInfo = PreferenceUtil.getUserInfo()
return userInfo!=null && !userInfo.temp
}
/**
* 检查登录未登录 则跳转登录页
*/
fun requiredLogin(): Boolean{
val isLogin = isLogin()
if(!isLogin){
viewModelScope.launch{
GlobalEventBus.emit(GlobalEvent.ShowLoginNotify)
}
}
return isLogin
}
enum class JumpLoginType(val type: Int,val desc: String){ enum class JumpLoginType(val type: Int,val desc: String){
NORMAL(0,"正常登录"), NORMAL(0,"正常登录"),
FROM_ADD(1,"添加账号"), FROM_ADD(1,"添加账号"),

View File

@ -121,6 +121,6 @@ interface ServiceVo {
* 图片扣取 * 图片扣取
*/ */
@Multipart @Multipart
@POST("/api/image/segment") @POST("/api/image/segment/blob")
suspend fun cutoutImage(@Part part: MultipartBody.Part): ResultVo<Any> suspend fun cutoutImage(@Part part: MultipartBody.Part): ResultVo<Any>
} }