IdentifyCodeTimerViewModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //----------------------------------------------------------------
  6. //Module Name: $safeprojectname$
  7. //Purpose:
  8. //CopyRight: Muchinfo
  9. //History:
  10. //----------------------------------------------------------------
  11. //DateTime 2017/3/3 17:44:09
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Threading;
  16. using System.Windows.Threading;
  17. using GalaSoft.MvvmLight;
  18. using Muchinfo.MTPClient.Resources;
  19. namespace Muchinfo.MTPClient.Bank.ViewModels
  20. {
  21. public class IdentifyCodeTimerViewModel:ViewModelBase
  22. {
  23. private const int c_tick = 60;
  24. private DispatcherTimer indentifyCodeTimer;
  25. private bool _isEnable=true;
  26. /// <summary>
  27. /// 是否可以点验证码
  28. /// </summary>
  29. public bool IsEnalbe
  30. {
  31. get { return _isEnable; }
  32. set { Set(() => IsEnalbe, ref _isEnable, value); }
  33. }
  34. /// <summary>
  35. /// 当前倒数多少秒
  36. /// </summary>
  37. public string CurrentTick
  38. {
  39. // get { return _currentTick; }
  40. get
  41. {
  42. if (_curerntSconds <= 0)
  43. {
  44. return Client_Resource.Content_GetIdentifyCode;
  45. }
  46. return _curerntSconds + "s";
  47. }
  48. }
  49. /// <summary>
  50. /// 当前秒数
  51. /// </summary>
  52. private int _curerntSconds=0;
  53. /// <summary>
  54. /// 当前秒数
  55. /// </summary>
  56. public int CurerntSconds
  57. {
  58. get { return _curerntSconds; }
  59. set
  60. {
  61. Set(() => CurerntSconds, ref _curerntSconds, value);
  62. RaisePropertyChanged(() => CurrentTick);
  63. }
  64. }
  65. public IdentifyCodeTimerViewModel()
  66. {
  67. indentifyCodeTimer=new DispatcherTimer();
  68. indentifyCodeTimer.Interval =new TimeSpan(0,0,0, 1);
  69. indentifyCodeTimer.Tick += indentifyCodeTimer_Tick;
  70. }
  71. void indentifyCodeTimer_Tick(object sender, EventArgs e)
  72. {
  73. CurerntSconds -= 1;
  74. if (CurerntSconds <= 0)
  75. {
  76. indentifyCodeTimer.Stop();
  77. IsEnalbe = true;
  78. }
  79. }
  80. /// <summary>
  81. /// 启动计时
  82. /// </summary>
  83. public void Start()
  84. {
  85. if (indentifyCodeTimer != null)
  86. {
  87. indentifyCodeTimer.Start();
  88. CurerntSconds = c_tick;
  89. IsEnalbe = false;
  90. }
  91. }
  92. }
  93. }