123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- using PDF_Master.CustomControl;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Properties;
- using PDFReader_WPF.Helper;
- 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 文案
- private string T_title;
- public string T_Title
- {
- get { return T_title; }
- set
- {
- SetProperty(ref T_title, value);
- }
- }
- private string T_limitTip;
- public string T_LimitTip
- {
- get { return T_limitTip; }
- set
- {
- SetProperty(ref T_limitTip, value);
- }
- }
- private string T_textBoxWatermark;
- public string T_TextBoxWatermark
- {
- get { return T_textBoxWatermark; }
- set
- {
- SetProperty(ref T_textBoxWatermark, value);
- }
- }
- private string T_copy;
- public string T_Copy
- {
- get { return T_copy; }
- set
- {
- SetProperty(ref T_copy, value);
- }
- }
- private string T_result;
- public string T_Result
- {
- get { return T_result; }
- set
- {
- SetProperty(ref T_result, value);
- }
- }
- private string T_rewritingBtn;
- public string T_RewritingBtn
- {
- get { return T_rewritingBtn; }
- set
- {
- SetProperty(ref T_rewritingBtn, value);
- }
- }
- private string T_copied;
- public string T_Copied
- {
- get { return T_copied; }
- set
- {
- SetProperty(ref T_copied, value);
- }
- }
- private void InitString()
- {
- T_Title = App.HomePageLoader.GetString("AIRewriteBtn_Title");
- T_LimitTip = App.HomePageLoader.GetString("ChatGTPAI_LimitTip");
- T_TextBoxWatermark = App.HomePageLoader.GetString("ChatGTPAI_TextBoxWatermark");
- T_Copy = App.HomePageLoader.GetString("ChatGTPAI_Copy");
- T_Result = App.HomePageLoader.GetString("ChatGTPAI_Result");
- T_RewritingBtn = App.HomePageLoader.GetString("AIRewriteBtn_RewritingBtn");
- T_Copied = App.HomePageLoader.GetString("ChatGTPAI_Copied");
- }
- #endregion
- #region 参数和属性
- public HomeContentViewModel homeContentViewModel = null;
- public IDialogService dialogs;
- 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);
- if ((RewriteText == null || RewriteText.Length == 0) && ErrorVisible == Visibility.Collapsed)
- {
- NullStateVisible = Visibility.Visible;
- }
- else
- {
- NullStateVisible = Visibility.Collapsed;
- }
- }
- }
- private Visibility showTip = Visibility.Collapsed;
- public Visibility ShowTip
- {
- get
- {
- return showTip;
- }
- set
- {
- SetProperty(ref showTip, value);
- }
- }
- private string errorTipText= App.HomePageLoader.GetString("ChatGTPLimit150");
- 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);
- if ((RewriteText == null || RewriteText.Length == 0) && ErrorVisible == Visibility.Collapsed)
- {
- NullStateVisible = Visibility.Visible;
- }
- else
- {
- NullStateVisible = Visibility.Collapsed;
- }
- }
- }
- private Visibility nullStateVisible = Visibility.Visible;
- public Visibility NullStateVisible
- {
- get
- {
- return nullStateVisible;
- }
- set
- {
- SetProperty(ref nullStateVisible, value);
- }
- }
- #endregion
- #region 委托声明
- public DelegateCommand CopyCommand { get; set; }
- public DelegateCommand RewriteCommand { get; set; }
- public DelegateCommand<object> textBoxEnterCharactersTextChangedCommad { get; set; }
- #endregion
- public ChatGPTAIRewritingContentViewModel(IDialogService dialogService)
- {
- dialogs = dialogService;
- CopyCommand = new DelegateCommand(copy);
- RewriteCommand = new DelegateCommand(rewrite);
- textBoxEnterCharactersTextChangedCommad = new DelegateCommand<object>(textBoxEnterCharactersTextChanged);
- InitString();
- }
- #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 = App.HomePageLoader.GetString("ChatGTPLimit150"); ;
- 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()
- {
- DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_AI, DataTrackingHelper.EntryPathKeyType.Home_Tools);
- DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.AIRewrite);
-
- //添加付费拦截锁
- if (!ServiceHelper.IAPBeforeFunction())
- {
- return;
- }
- #region 暂时关闭权益弹窗
- //bool flg = false;
- ////权益弹窗
- //if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)
- //{
- // DialogParameters value = new DialogParameters();
- // value.Add(ParameterNames.Open, "AI");
- // dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
- // {
- // if (dialogResult.Result == ButtonResult.OK)
- // {
- // flg = true;
- // }
- // else
- // {
- // flg = false;
- // }
- // });
- // if (flg == false)
- // {
- // return;
- // }
- //}
- #endregion
- ErrorVisible = Visibility.Collapsed;
- await Task.Run(async delegate
- {
- RewriteText = await ChatGTPAIHelper.Rewrite(InputText);
- });
- if (ChatGTPAIHelper.ChatGPTCode != "200")
- {
- //错误码文案,报错样式
- ErrorTipText = ChatGTPAIHelper.GetChatGPTCode(ChatGTPAIHelper.ChatGPTCode);
- 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
- }
- }
|