public MyPageViewModel() { preferenceButtons = new() { PreferenceButtonViewModel.Create(PreferenceButton.UserProfile, this), PreferenceButtonViewModel.Create(PreferenceButton.BindPhoneNumber, this), PreferenceButtonViewModel.Create(PreferenceButton.Settings, this, 1), PreferenceButtonViewModel.Create(PreferenceButton.About, this, 1), }; UserService.Current.WhenAnyValue(x => x.User).Subscribe(value => { if (value == null) { nickNameNullValLangChangeSubscribe?.RemoveTo(this); nickNameNullValLangChangeSubscribe = R.Current.WhenAnyValue(x => x.Res) .Subscribe(_ => { // 未登录时显示的文本,多语言绑定 NickName = NickNameNullVal; }).AddTo(this); //PreferenceButtonViewModel.RemoveAuthorized(preferenceButtons, this); } else { nickNameNullValLangChangeSubscribe?.RemoveTo(this); nickNameNullValLangChangeSubscribe = null; NickName = value.NickName; //var editProfile = preferenceButtons.FirstOrDefault(x => x.Id == PreferenceButton.EditProfile); //if (editProfile == null) //{ // editProfile = PreferenceButtonViewModel.Create(PreferenceButton.EditProfile, this); // preferenceButtons.Insert(0, editProfile); //} //var phoneNumber = preferenceButtons.FirstOrDefault(x => PreferenceButtonViewModel.IsPhoneNumber(x.Id)); //if (phoneNumber == null) //{ // phoneNumber = PreferenceButtonViewModel.Create(PreferenceButtonViewModel.GetPhoneNumberId(UserService.Current.HasPhoneNumber), this); // preferenceButtons.Insert(1, phoneNumber); //} } }).AddTo(this); UserService.Current.WhenAnyValue(x => x.HasPhoneNumber).Subscribe(value => { var id = PreferenceButtonViewModel.GetPhoneNumberId(value); foreach (var item in preferenceButtons) { if (item.Id != id && PreferenceButtonViewModel.IsPhoneNumber(item.Id)) { item.Id = id; } } }).AddTo(this); }
public AboutPageViewModel() { preferenceButtons = new(Enum2.GetAll <PreferenceButton>().Select(x => PreferenceButtonViewModel.Create(x, this))); UserService.Current.WhenAnyValue(x => x.User).Subscribe(value => { if (value == null) { PreferenceButtonViewModel.RemoveAuthorized(preferenceButtons, this); } else { var delAccount = preferenceButtons.FirstOrDefault(x => x.Id == PreferenceButton.账号注销); if (delAccount == null) { delAccount = PreferenceButtonViewModel.Create(PreferenceButton.账号注销, this); preferenceButtons.Add(delAccount); } } }).AddTo(this); }