UserOutCodeRegionViewModel.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using PDF_Office.Helper;
  2. using PDF_Office.Properties;
  3. using Prism.Commands;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Threading;
  14. namespace PDF_Office.ViewModels.Dialog.ServiceDialog
  15. {
  16. public class UserOutCodeRegionViewModel : BindableBase, INavigationAware
  17. {
  18. private static Guid myuuid = Guid.NewGuid();
  19. private string uuid = myuuid.ToString();
  20. public IDialogService dialogs;
  21. private UserDialogViewModel UserDialogViewModel;
  22. private int time = 60;
  23. private bool _EnableNextStep = true;
  24. public bool EnableNextStep
  25. {
  26. get { return _EnableNextStep; }
  27. set { SetProperty(ref _EnableNextStep, value); }
  28. }
  29. private string _codetime = "60";
  30. public string Codetime
  31. {
  32. get { return _codetime; }
  33. set { SetProperty(ref _codetime, value); }
  34. }
  35. private string _Codesum = "";
  36. public string Codesum
  37. {
  38. get { return _Codesum; }
  39. set { SetProperty(ref _Codesum, value); }
  40. }
  41. private string _Code1 = "";
  42. public string Code1
  43. {
  44. get { return _Code1; }
  45. set { SetProperty(ref _Code1, value); }
  46. }
  47. private string _Code2 = "";
  48. public string Code2
  49. {
  50. get { return _Code2; }
  51. set { SetProperty(ref _Code2, value); }
  52. }
  53. private string _Code3 = "";
  54. public string Code3
  55. {
  56. get { return _Code3; }
  57. set { SetProperty(ref _Code3, value); }
  58. }
  59. private string _Code4 = "";
  60. public string Code4
  61. {
  62. get { return _Code4; }
  63. set { SetProperty(ref _Code4, value); }
  64. }
  65. private string _Code5 = "";
  66. public string Code5
  67. {
  68. get { return _Code5; }
  69. set { SetProperty(ref _Code5, value); }
  70. }
  71. private string _Code6 = "";
  72. public string Code6
  73. {
  74. get { return _Code6; }
  75. set { SetProperty(ref _Code6, value); }
  76. }
  77. private string _UserCodemsg = "";
  78. public string UserCodemsg
  79. {
  80. get { return _UserCodemsg; }
  81. set { SetProperty(ref _UserCodemsg, value); }
  82. }
  83. private Visibility _codeagin = Visibility.Collapsed;
  84. public Visibility Codeagin
  85. {
  86. get { return _codeagin; }
  87. set { SetProperty(ref _codeagin, value); }
  88. }
  89. private Visibility _UserCodemsgVis = Visibility.Collapsed;
  90. public Visibility UserCodemsgVis
  91. {
  92. get { return _UserCodemsgVis; }
  93. set { SetProperty(ref _UserCodemsgVis, value); }
  94. }
  95. public bool IsNavigationTarget(NavigationContext navigationContext)
  96. {
  97. return true;
  98. }
  99. public void OnNavigatedFrom(NavigationContext navigationContext)
  100. {
  101. }
  102. public void OnNavigatedTo(NavigationContext navigationContext)
  103. {
  104. navigationContext.Parameters.TryGetValue<UserDialogViewModel>("UserDialogViewModel", out UserDialogViewModel);
  105. }
  106. public DelegateCommand UserOutCancelCommand { get; set; }
  107. public DelegateCommand CodetooCommand { get; set; }
  108. public DelegateCommand Code6ChangedCommand { get; set; }
  109. public DelegateCommand UserOutCommand { get; set; }
  110. public UserOutCodeRegionViewModel(IRegionManager regionManager, IDialogService dialogService)
  111. {
  112. Timebegin();
  113. dialogs = dialogService;
  114. UserOutCancelCommand = new DelegateCommand(UserOutCancel);
  115. CodetooCommand = new DelegateCommand(Codetoo);
  116. Code6ChangedCommand = new DelegateCommand(Code6Changed);
  117. UserOutCommand = new DelegateCommand(UserOut);
  118. }
  119. private void UserOutCancel()
  120. {
  121. UserDialogViewModel.Close();
  122. }
  123. private void UserOut()
  124. {
  125. Codesum = Code1 + Code2 + Code3 + Code4 + Code5 + Code6;
  126. if (Codesum.Length == 6)
  127. {
  128. if (ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off") == "success")
  129. {
  130. if (ServiceHelper.Usergout(Codesum) == "success")
  131. {
  132. Settings.Default.AppProperties.LoginToken = "";
  133. Settings.Default.Save();
  134. App.mainWindowViewModel.UserVis = Visibility.Collapsed;
  135. App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
  136. App.mainWindowViewModel.LoginVis = Visibility.Visible;
  137. UserDialogViewModel.Close();
  138. }
  139. else
  140. {
  141. UserCodemsg = ServiceHelper.Usergout(Codesum);
  142. UserCodemsgVis = Visibility.Visible;
  143. }
  144. }
  145. else
  146. {
  147. UserCodemsg = ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off");
  148. UserCodemsgVis = Visibility.Visible;
  149. }
  150. }
  151. else
  152. {
  153. UserCodemsg = "请输入六位数验证码";
  154. }
  155. }
  156. private void Code6Changed()
  157. {
  158. if (Code6.Length == 1)
  159. {
  160. if (ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off") == "success")
  161. {
  162. if (ServiceHelper.Usergout(Codesum) == "success")
  163. {
  164. UserDialogViewModel.Close();
  165. }
  166. else
  167. {
  168. UserCodemsg = ServiceHelper.Usergout(Codesum);
  169. UserCodemsgVis = Visibility.Visible;
  170. }
  171. }
  172. else
  173. {
  174. UserCodemsg = ServiceHelper.Ok_code(UserDialogViewModel.UserEmail, Codesum, "user_log_off");
  175. UserCodemsgVis = Visibility.Visible;
  176. }
  177. }
  178. else
  179. {
  180. UserCodemsg = "请输入六位数验证码";
  181. UserCodemsgVis = Visibility.Visible;
  182. }
  183. }
  184. private void Codetoo()
  185. {
  186. Codeagin = Visibility.Collapsed;
  187. time = 60;
  188. ServiceHelper.Get_code("user_log_off", UserDialogViewModel.UserEmail);
  189. }
  190. public void disTimer_Tick(object sender, EventArgs e)
  191. {
  192. if (time == 0)
  193. {
  194. Codeagin = Visibility.Visible;
  195. Codetime = "";
  196. }
  197. else
  198. {
  199. time--;
  200. Codetime = "(" + time.ToString() + ")";
  201. }
  202. }
  203. private DispatcherTimer disTimer = new DispatcherTimer();
  204. public void Timebegin()
  205. {
  206. time = 60;
  207. //设置定时器
  208. disTimer.Tick += new EventHandler(disTimer_Tick);//每一秒执行的方法
  209. disTimer.Interval = new TimeSpan(10000000); //时间间隔为一秒。
  210. disTimer.Start();//计时开始
  211. }
  212. }
  213. }