/// <summary> /// 主页面的ViewModel /// </summary> public MainPageViewModel(MapControl map) : base(false) { Map = map; Map.MapTapped += MapTappedAsync; Map.CenterChanged += MapCenterChanged; GeoPosition = Map.Center; CanExitApplication = true; var amapConfig = new AmapConfig() { AppName = "common.ofo.so", Key = "0afcd8a0b0fe5b9b89469e3531dc23ea", LogVersion = 2.0F, Platform = "JS", SdkVersion = 1.3F }; AmapWebApi = new AmapWebAPIs(amapConfig); OpenWithEdgeCommand = new RelayCommand(async(state) => { if ((await MessageDialogUtility.ShowMessageAsync("确定要使用Web版本吗?", "确认")) == MessageDialogResult.OK) { ContentPageArgs args = new ContentPageArgs() { Name = "ofo共享单车", ContentElement = new WebPageContentView(Global.MAIN_WEBPAGE_URL) }; TryNavigate(typeof(ContentPageView), args); } }); ReLocationCommand = new RelayCommand(async(state) => { await LocationNowAsync(); }); BlueBarVisibilityCommand = new RelayCommand((state) => { if (BlueBarButtonVisibility == Visibility.Collapsed) { BlueBarButtonVisibility = Visibility.Visible; BlueBarVisibility = Visibility.Collapsed; } else { BlueBarButtonVisibility = Visibility.Collapsed; BlueBarVisibility = Visibility.Visible; } }); _locationMoveTimer = new Timer(LocationMoveTimerCallBack, null, Timeout.Infinite, Timeout.Infinite); var loadTask = InitializationAsync(); }
protected override async void NavigationActionAsync(object state) { await StatusBarUtility.ShowAsync(); ContentPageArgs args = new ContentPageArgs() { Name = "登录", HeaderVisibility = Visibility.Collapsed, }; args.ContentElement = new LoginFirstStepContentView(); TryReplaceNavigate(typeof(ContentPageView), args); }
/// <summary> /// 红包弹出内容VM /// </summary> public RedPacketPupopContentViewModel() : base(null) { OpenRedPacketCommand = new RelayCommand((state) => { CloseAction(); ContentPageArgs args = new ContentPageArgs() { Name = PaymentInfo.title, ContentElement = new WebPageContentView(PaymentInfo.url) }; TryNavigate(typeof(ContentPageView), args); }); }
protected override void NavigationActionAsync(object state) { if (state is string param) { if (param.Equals("CreditScoreInfo")) { ContentPageArgs args = new ContentPageArgs() { Name = "信用分", ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?CreditPoints"), }; ContentNavigation(args); } } }
protected override void NavigationActionAsync(object state) { if (state is string param) { if (state.Equals("WebPay")) { ContentPageArgs args = new ContentPageArgs() { Name = "ofo小黄车", ContentElement = new WebPageContentView(Global.MAIN_WEBPAGE_URL), }; TryNavigate(typeof(ContentPageView), args); } } }
/// <summary> /// 活动弹出界面VM /// </summary> public ActivityPopupContentViewModel() : base(null) { ViewActivityCommand = new RelayCommand((state) => { ContentPageArgs args = new ContentPageArgs() { Name = "OFO活动" }; args.ContentElement = new WebPageContentView(Url); TryNavigate(typeof(ContentPageView), args); CloseAction(); }); }
public override void Dispose() { _contentElement = null; _contentPageArgs = null; while (ContentStack.TryPop(out var contentArgs)) { if (contentArgs.ContentElement is UserControl content) { if (content.DataContext is BaseContentViewModel viewModel) //是否是内容页面 { viewModel.NavigationToContentEvent -= NavigationToContent; } } } base.Dispose(); }
/// <summary> /// 解锁车辆 /// </summary> /// <param name="state"></param> private void UnlockCar(object state) { IsEnableUnlock = false; Task.Run(async() => { try { var unlockCarResult = await OfoApi.UnlockCarAsync(CarNumber); if (await CheckOfoApiResult(unlockCarResult)) { if (unlockCarResult.Data.Password.Length > 8) //此处为加密的密码? { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { ContentPageArgs args = new ContentPageArgs() { Name = "ofo共享单车", ContentElement = new WebPageContentView(Global.MAIN_WEBPAGE_URL) }; TryReplaceNavigate(typeof(ContentPageView), args); }); } else { Global.AppConfig.LastOrderNum = unlockCarResult.Data.OrderNumber; Global.AppConfig.LastOrderPwd = unlockCarResult.Data.Password; Global.SaveAppConfig(); await TryReplaceNavigateAsync(typeof(UnlockedView), unlockCarResult.Data); } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { IsEnableUnlock = true; }); } }); }
/// <summary> /// 导航事件 /// </summary> /// <param name="state"></param> protected override void NavigationActionAsync(object state) { if (state is string param) { ContentPageArgs args = new ContentPageArgs() { Name = param }; switch (param) { case "个人信息": args.ContentElement = new UserProfileContentView(UserInfo); break; case "我的行程": args.ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?MeineReise"); break; case "我的钱包": args.ContentElement = new UserWalletContentView(); break; case "邀请好友": args.ContentElement = new WebPageContentView($"https://common.ofo.so/about/new_invitation/invite.html?update&refcode={OfoApi.CurUser.TelPhone}"); break; case "我的客服": args.ContentElement = new WebPageContentView("https://common.ofo.so/about/customer/"); break; case "设置": args.ContentElement = new SettingContentView(); break; } if (args.ContentElement != null) { TryNavigate(typeof(ContentPageView), args); } } }
/// <summary> /// 提交验证码 /// </summary> /// <param name="state"></param> private async Task SubmitCaptchaCodeAsync() { if (string.IsNullOrWhiteSpace(CaptchaCode)) { return; } OfoApi.CurUser.TelPhone = TelPhone; var verifyCode = await OfoApi.GetVerifyCodeAsync(CaptchaCode.Trim(), VerifyId); if (await CheckOfoApiResult(verifyCode)) { ContentPageArgs args = new ContentPageArgs() { Name = "登录第二步", HeaderVisibility = Visibility.Collapsed, ContentElement = new LoginSecondStepContentView(), }; ContentNavigation(args); } }
/// <summary> /// 内容导航 /// </summary> /// <param name="args"></param> public void ContentNavication(ContentPageArgs args) { if (args.IsGoBack) //后退 { if (ContentStack.TryPop(out var contentArgs)) { ContentPageArgs = null; ContentPageArgs = contentArgs; } } else { if (args.ContentElement is Control control) { if (control.DataContext is BaseContentViewModel baseContentViewModel) { baseContentViewModel.NavigationToContentEvent += NavigationToContent; } } ContentPageArgs = args; } }
protected override void ContentNavigation(object state) { if (state is string param) { var args = new ContentPageArgs() { Name = param, }; switch (param) { case "卡包": args.ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?CardPackagePage"); break; case "余额": args.ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?NewBalancePage"); break; case "红包收入": args.ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?MyPacketPage"); break; case "优惠券": args.ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?Packets"); break; case "押金": args.ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?ForegiftWithdrawSuccess"); break; } if (args.ContentElement != null) { ContentNavigation(args); } } }
protected override async void NavigationActionAsync(object state) { if (state is string param) { switch (param) { case "UsingCar": TryNavigate(typeof(ScanQrcodeView)); break; case "UserCenter": TryNavigate(typeof(UserCenterView)); break; case "ActivityCenter": ContentPageArgs args = new ContentPageArgs() { Name = "我的消息", ContentElement = new WebPageContentView("https://common.ofo.so/newdist/?DiscoverPage") }; TryNavigate(typeof(ContentPageView), args); //TryNavigate(typeof(ActivityCenterView)); break; case "BlueBar": if (BlueBarInfo.MainType == 1 && BlueBarInfo.Text.Contains("认证")) { var identificationResult = await OfoApi.GetIdentificationInfoAsync(GeoPosition.Position); if (await CheckOfoApiResult(identificationResult)) { ContentPageArgs blueBarArgs = new ContentPageArgs() { Name = "ofo小黄车", ContentElement = new WebPageContentView($"https://common.ofo.so/newdist/?Identification&~result={identificationResult.SourceHtml}&~lat={GeoPosition.Position.Latitude}&~lng={GeoPosition.Position.Longitude}"), }; TryNavigate(typeof(ContentPageView), blueBarArgs); } } else { ContentPageArgs blueBarArgs = new ContentPageArgs() { Name = "ofo小黄车", ContentElement = new WebPageContentView(BlueBarInfo.Action), }; TryNavigate(typeof(ContentPageView), blueBarArgs); } break; case "MainPageReport": ContentPageArgs args1 = new ContentPageArgs() { Name = "我的客服", ContentElement = new WebPageContentView("https://common.ofo.so/about/customer/") }; TryNavigate(typeof(ContentPageView), args1); break; } } }
public SettingContentViewModel() { LoginOutCommand = new RelayCommand(async(state) => { var dialogResult = await MessageDialogUtility.ShowMessageAsync("您确认要退出登录吗?", "退出登录"); if (dialogResult == MessageDialogResult.OK) { Global.ClearUserStatus(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (Window.Current?.Content is Frame rootFrame) { rootFrame.BackStack.Clear(); } }); await TryNavigateAsync(typeof(NoLoginView)); } }); ClearCacheCommand = new RelayCommand(async(state) => { var dialogResult = await MessageDialogUtility.ShowMessageAsync("您确认要清除所有缓存吗?", "缓存清理"); if (dialogResult == MessageDialogResult.OK) { Global.ClearCacheSetting(); await LocalCacheUtility.ClearLocalCacheFile(); await MessageDialogUtility.ShowMessageAsync("缓存清理完成", "缓存清理", MessageDialogType.OK); var cacheSize = await LocalCacheUtility.GetLocalCacheSizeAsync(true); CacheSize = VariousUtility.ByteSizeToString(cacheSize); } }); AboutSoftWareLicenseCommand = new RelayCommand((state) => { var args = new ContentPageArgs() { Name = "软件授权", ContentElement = new SoftWareLicenseContentView(), }; ContentNavigation(args); }); AboutUsCommand = new RelayCommand((state) => { var args = new ContentPageArgs() { Name = "关于我们", ContentElement = new AboutUsContentView(), }; ContentNavigation(args); }); AboutSoftWareCommand = new RelayCommand((state) => { var args = new ContentPageArgs() { Name = "免责声明", ContentElement = new AboutSoftWareContentView(), }; ContentNavigation(args); }); }
/// <summary> /// 内容页导航 /// </summary> /// <param name="args"></param> protected void ContentNavigation(ContentPageArgs args) { NavigationToContentEvent?.Invoke(args); }
/// <summary> /// 内容事件触发 /// </summary> /// <param name="args"></param> private void NavigationToContent(ContentPageArgs args) { ContentNavication(args); }