ChatGPTAIRewritingContentViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using PDF_Master.Helper;
  2. using PDF_Master.Model;
  3. using Prism.Commands;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Forms;
  12. using System.Windows.Threading;
  13. namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
  14. {
  15. public class ChatGPTAIRewritingContentViewModel : BindableBase, INavigationAware
  16. {
  17. public HomeContentViewModel homeContentViewModel = null;
  18. private string inputText;
  19. public string InputText
  20. {
  21. get { return inputText; }
  22. set
  23. {
  24. SetProperty(ref inputText, value);
  25. }
  26. }
  27. private string rewriteText;
  28. public string RewriteText
  29. {
  30. get { return rewriteText; }
  31. set
  32. {
  33. SetProperty(ref rewriteText, value);
  34. }
  35. }
  36. private Visibility showTip = Visibility.Collapsed;
  37. public Visibility ShowTip
  38. {
  39. get
  40. {
  41. return showTip;
  42. }
  43. set
  44. {
  45. SetProperty(ref showTip, value);
  46. }
  47. }
  48. private string errorTipText;
  49. public string ErrorTipText
  50. {
  51. get { return errorTipText; }
  52. set
  53. {
  54. SetProperty(ref errorTipText, value);
  55. }
  56. }
  57. private Visibility errorVisible = Visibility.Collapsed;
  58. public Visibility ErrorVisible
  59. {
  60. get
  61. {
  62. return errorVisible;
  63. }
  64. set
  65. {
  66. SetProperty(ref errorVisible, value);
  67. }
  68. }
  69. public DelegateCommand CopyCommand { get; set; }
  70. public DelegateCommand RewriteCommand { get; set; }
  71. public ChatGPTAIRewritingContentViewModel()
  72. {
  73. CopyCommand = new DelegateCommand(copy);
  74. RewriteCommand = new DelegateCommand(rewrite);
  75. }
  76. public void copy()
  77. {
  78. try
  79. {
  80. System.Windows.Forms.Clipboard.SetText(RewriteText);
  81. ShowTip=Visibility.Visible;
  82. }
  83. catch { }
  84. }
  85. public async void rewrite()
  86. {
  87. //添加付费拦截锁
  88. if (!ServiceHelper.IAPBeforeFunction())
  89. {
  90. return;
  91. }
  92. ErrorVisible = Visibility.Collapsed;
  93. await Task.Run(async delegate
  94. {
  95. RewriteText = await ChatGTPAIHelper.Rewrite(InputText);
  96. });
  97. if (ChatGTPAIHelper.Code != "200")
  98. {
  99. ErrorTipText = ChatGTPAIHelper.Code;
  100. ErrorVisible = Visibility.Visible;
  101. }
  102. }
  103. public void OnNavigatedTo(NavigationContext navigationContext)
  104. {
  105. navigationContext.Parameters.TryGetValue<HomeContentViewModel>(ParameterNames.HomeContentViewModel, out homeContentViewModel);
  106. }
  107. public bool IsNavigationTarget(NavigationContext navigationContext)
  108. {
  109. return true;
  110. }
  111. public void OnNavigatedFrom(NavigationContext navigationContext)
  112. {
  113. }
  114. }
  115. }