123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using PDF_Master.CustomControl;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Properties;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Forms;
- using System.Windows.Threading;
- namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
- {
- public class ChatGPTAIRewritingContentViewModel : BindableBase, INavigationAware
- {
- #region 参数和属性
- public HomeContentViewModel homeContentViewModel = null;
- private string inputText;
- public string InputText
- {
- get { return inputText; }
- set
- {
- SetProperty(ref inputText, value);
- }
- }
- private string rewriteText;
- public string RewriteText
- {
- get { return rewriteText; }
- set
- {
- SetProperty(ref rewriteText, value);
- }
- }
- private Visibility showTip = Visibility.Collapsed;
- public Visibility ShowTip
- {
- get
- {
- return showTip;
- }
- set
- {
- SetProperty(ref showTip, value);
- }
- }
- private string errorTipText;
- public string ErrorTipText
- {
- get { return errorTipText; }
- set
- {
- SetProperty(ref errorTipText, value);
- }
- }
- private Visibility errorVisible = Visibility.Collapsed;
- public Visibility ErrorVisible
- {
- get
- {
- return errorVisible;
- }
- set
- {
- SetProperty(ref errorVisible, value);
- }
- }
- #endregion
- #region 委托声明
- public DelegateCommand CopyCommand { get; set; }
- public DelegateCommand RewriteCommand { get; set; }
- public DelegateCommand<object> textBoxEnterCharactersTextChangedCommad { get; set; }
- #endregion
- public ChatGPTAIRewritingContentViewModel()
- {
- CopyCommand = new DelegateCommand(copy);
- RewriteCommand = new DelegateCommand(rewrite);
- textBoxEnterCharactersTextChangedCommad = new DelegateCommand<object>(textBoxEnterCharactersTextChanged);
- }
- #region 逻辑函数
- /// <summary>
- /// 检查文字是否超出范围
- /// </summary>
- /// <param name="e"></param>
- private void textBoxEnterCharactersTextChanged(object e)
- {
- var ConverterPreview = e as TextBoxEx;
- if (ConverterPreview != null)
- {
- //结果置空
- RewriteText = "";
- if (ConverterPreview.Text.Length > 150)
- {
- ErrorTipText = "Limit 150 characters at a time";
- ErrorVisible = Visibility.Visible;
- }
- else
- {
- ErrorVisible = Visibility.Collapsed;
- }
- }
- }
- /// <summary>
- /// 复制到剪切板
- /// </summary>
- public void copy()
- {
- try
- {
- System.Windows.Forms.Clipboard.SetText(RewriteText);
- //Copy成功显示
- ShowTip=Visibility.Visible;
- }
- catch { }
- }
- /// <summary>
- /// 重写逻辑
- /// </summary>
- public async void rewrite()
- {
- //添加付费拦截锁
- if (!ServiceHelper.IAPBeforeFunction())
- {
- return;
- }
- if (Settings.Default.UserDate.subscribestatus != 1)
- {
- App.mainWindowViewModel.dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- ErrorVisible = Visibility.Collapsed;
- await Task.Run(async delegate
- {
- RewriteText = await ChatGTPAIHelper.Rewrite(InputText);
- });
- if (ChatGTPAIHelper.Code != "200")
- {
- //错误码文案,报错样式
- ErrorTipText = ChatGTPAIHelper.Code;
- ErrorVisible = Visibility.Visible;
- }
- }
- #endregion
- #region 构架行为
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<HomeContentViewModel>(ParameterNames.HomeContentViewModel, out homeContentViewModel);
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- #endregion
- }
- }
|