ChatGPTAIRewritingContentViewModel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using PDF_Master.Helper;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Forms;
  10. using System.Windows.Threading;
  11. namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
  12. {
  13. public class ChatGPTAIRewritingContentViewModel : BindableBase
  14. {
  15. private string inputText;
  16. public string InputText
  17. {
  18. get { return inputText; }
  19. set
  20. {
  21. SetProperty(ref inputText, value);
  22. }
  23. }
  24. private string rewriteText;
  25. public string RewriteText
  26. {
  27. get { return rewriteText; }
  28. set
  29. {
  30. SetProperty(ref rewriteText, value);
  31. }
  32. }
  33. private Visibility showTip = Visibility.Collapsed;
  34. public Visibility ShowTip
  35. {
  36. get
  37. {
  38. return showTip;
  39. }
  40. set
  41. {
  42. SetProperty(ref showTip, value);
  43. }
  44. }
  45. private string errorTipText;
  46. public string ErrorTipText
  47. {
  48. get { return errorTipText; }
  49. set
  50. {
  51. SetProperty(ref errorTipText, value);
  52. }
  53. }
  54. private Visibility errorVisible = Visibility.Collapsed;
  55. public Visibility ErrorVisible
  56. {
  57. get
  58. {
  59. return errorVisible;
  60. }
  61. set
  62. {
  63. SetProperty(ref errorVisible, value);
  64. }
  65. }
  66. public DelegateCommand CopyCommand { get; set; }
  67. public DelegateCommand RewriteCommand { get; set; }
  68. public ChatGPTAIRewritingContentViewModel()
  69. {
  70. CopyCommand = new DelegateCommand(copy);
  71. RewriteCommand = new DelegateCommand(rewrite);
  72. }
  73. public void copy()
  74. {
  75. try
  76. {
  77. System.Windows.Forms.Clipboard.SetText(RewriteText);
  78. ShowTip=Visibility.Visible;
  79. }
  80. catch { }
  81. }
  82. public async void rewrite() {
  83. await Task.Run(async delegate
  84. {
  85. RewriteText = await ChatGTPAIHelper.Rewrite(InputText);
  86. });
  87. if (ChatGTPAIHelper.Code != "200")
  88. {
  89. ErrorVisible = Visibility.Visible;
  90. }
  91. }
  92. }
  93. }