puzhibing
2026-08-21 5fa94b3718b4a78a4fcea4c97652b0ef20b7de3a
app/src/main/java/com/xw/yunwei/ui/MainVM.kt
@@ -7,25 +7,38 @@
import com.xw.yunwei.MyApp
import com.xw.yunwei.R
import com.xw.yunwei.model.AppVersionModel
import com.xw.yunwei.model.SwitchTabTask
import com.xw.yunwei.net.UserRepository
import org.greenrobot.eventbus.EventBus
import org.koin.core.component.inject
import kotlin.getValue
class MainVM(application: Application) : BaseViewModel(application) {
    val userRepository: UserRepository by inject()
    val selectIndex = MutableLiveData<Int>()
    val selectIndex = MutableLiveData<Int>(0)
    //上一次显示fragment下标
    var lastSelectIndex = 0
    val taskPermissions = MutableLiveData(false) // 任务中心权限
    val workPermissions = MutableLiveData(false) // 工作台权限
    val onClick = View.OnClickListener {
        when (it.id) {
            R.id.navWork -> selectIndex.value = 0
            R.id.navTask -> selectIndex.value = 1
            R.id.navMine -> selectIndex.value = 2
            R.id.navWork -> changeSelectFragmentIndex(0)
            R.id.navTask -> {
                changeSelectFragmentIndex(1)
                EventBus.getDefault().post(SwitchTabTask(1))
            }
            R.id.navMine -> changeSelectFragmentIndex(2)
        }
    }
    //改变选择fragment下标
    fun changeSelectFragmentIndex(index: Int) {
        if (selectIndex.value != index) {
            lastSelectIndex = selectIndex.value ?: 0
            selectIndex.postValue(index)
        }
    }