Browse Source

ChatGTPAI-人工智能帮助类优化,添加loading

liyijie 1 year ago
parent
commit
fc11adce74

+ 13 - 6
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -118,21 +118,21 @@ namespace PDF_Master.Helper
                     {
                         request.Abort();
                     }
-
+                    string translation = "";
                     if (jobject["code"].ToObject<string>().ToLower() == "200")
                     {
-                        translate = jobject["data"]["fileKey"].ToObject<string>().ToLower();
+                        translation = jobject["data"]["fileKey"].ToObject<string>().ToLower();
+                        return translation;
                     }
-                    //return jobject["code"].ToObject<string>().ToLower();
+                    return "Code"+jobject["code"].ToObject<string>().ToLower();
 
-                    return translate;
+                    
                 }
-                return "";
             }
             catch (WebException ex)
             {
                 Console.WriteLine("HTTP异常:" + ex.Message);
-                return "";
+                return "Code"+"300";
             }
         }
 
@@ -177,6 +177,11 @@ namespace PDF_Master.Helper
             App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Collapsed;
             FileInfo file = new FileInfo(content);
             string fileKey = await fileKeyTranslate(content, file.Name);
+            if (fileKey.Contains("Code")) {
+                App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
+                App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
+                return fileKey.Replace("Code", "");
+            }
             App.mainWindowViewModel.Value = 2;
             HttpWebResponse response = null;
             ServicePointManager.DefaultConnectionLimit = 200;
@@ -253,6 +258,8 @@ namespace PDF_Master.Helper
                             return folderPath;
                         }
                     }
+                    App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
+                    App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
                     return jobject["code"].ToObject<string>().ToLower();
                 }
             }

+ 8 - 0
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs

@@ -1,6 +1,7 @@
 using ComPDFKitViewer;
 using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
+using PDF_Master.CustomControl;
 using PDF_Master.Helper;
 using PDF_Master.Model;
 using Prism.Commands;
@@ -91,6 +92,11 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
         }
         public async void translate()
         {
+            ////添加付费拦截锁
+            //if (!viewContentViewModel.IAPBeforeFunction())
+            //{
+            //    return;
+            //}
             string newfile = "";
             FileInfo fileInfo = new FileInfo(pdfViewer.Document.FilePath);
             if ((((float)fileInfo.Length) / 1024 / 1024) > 30)
@@ -114,6 +120,8 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             }
             else {
                 //newfile code
+                AlertsMessage alertsMessage = new AlertsMessage();
+                alertsMessage.ShowDialog("", newfile, App.ServiceLoader.GetString("Text_ok"));
             }
 
 

+ 7 - 0
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/SelectedTranslationDialogViewModel.cs

@@ -124,6 +124,12 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 
         public async void translate()
         {
+            ////添加付费拦截锁
+            //if (!ViewContentViewModel.IAPBeforeFunction())
+            //{
+            //    return;
+            //}
+            ErrorVisible = Visibility.Collapsed;
             string translatetext = "";
             string Code = "";
             await Task.Run( delegate
@@ -131,6 +137,7 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
                 Code=ChatGTPAIHelper.textTranslate(SelectedText, fromlanguage, tolanguage, ref translatetext);
             });
             if (Code != "200") {
+                ErrorTipText = Code;
                 ErrorVisible = Visibility.Visible;
             }
             

+ 39 - 6
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContentViewModel.cs

@@ -1,6 +1,8 @@
 using PDF_Master.Helper;
+using PDF_Master.Model;
 using Prism.Commands;
 using Prism.Mvvm;
+using Prism.Regions;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -10,9 +12,11 @@ using System.Windows.Forms;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 {
-    public class ChatGPTAIErrorCorrectionContentViewModel : BindableBase
+    public class ChatGPTAIErrorCorrectionContentViewModel : BindableBase, INavigationAware
     {
 
+        public HomeContentViewModel homeContentViewModel = null;
+
         private string inputText;
 
         public string InputText
@@ -48,7 +52,7 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
             }
         }
 
-        private string errorTipText= "Limit 150 characters at a time";
+        private string errorTipText = "Limit 150 characters at a time";
 
         public string ErrorTipText
         {
@@ -86,7 +90,7 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
             try
             {
                 System.Windows.Forms.Clipboard.SetText(ErrorCorrectionText);
-                ShowTip=Visibility.Visible;
+                ShowTip = Visibility.Visible;
             }
             catch { }
 
@@ -94,14 +98,43 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 
         public async void errorCorrection()
         {
-            
+            ////添加付费拦截锁
+            //if (!ViewContentViewModel.IAPBeforeFunction())
+            //{
+            //    return;
+            //}
+            if (homeContentViewModel != null)
+            {
+                homeContentViewModel.IsLoading = Visibility.Visible;
+            }
+            ErrorVisible = Visibility.Collapsed;
             await Task.Run(async delegate
             {
                 ErrorCorrectionText = await ChatGTPAIHelper.Correction(InputText);
             });
-            if (ChatGTPAIHelper.Code != "200") {
-                ErrorVisible=Visibility.Visible;
+            if (ChatGTPAIHelper.Code != "200")
+            {
+                ErrorTipText = ChatGTPAIHelper.Code;
+                ErrorVisible = Visibility.Visible;
             }
+            if (homeContentViewModel != null)
+            {
+                homeContentViewModel.IsLoading = Visibility.Collapsed;
+            }
+        }
+        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)
+        {
+
         }
     }
 }

+ 36 - 2
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIRewritingContentViewModel.cs

@@ -1,6 +1,8 @@
 using PDF_Master.Helper;
+using PDF_Master.Model;
 using Prism.Commands;
 using Prism.Mvvm;
+using Prism.Regions;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -11,9 +13,11 @@ using System.Windows.Threading;
 
 namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 {
-    public class ChatGPTAIRewritingContentViewModel : BindableBase
+    public class ChatGPTAIRewritingContentViewModel : BindableBase, INavigationAware
     {
 
+        public HomeContentViewModel homeContentViewModel = null;
+
         private string inputText;
 
         public string InputText
@@ -93,15 +97,45 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 
         }
 
-        public async void rewrite() {
+        public async void rewrite() 
+        {
+            ////添加付费拦截锁
+            //if (!ViewContentViewModel.IAPBeforeFunction())
+            //{
+            //    return;
+            //}
+            if (homeContentViewModel != null)
+            {
+                homeContentViewModel.IsLoading = Visibility.Visible;
+            }
+            ErrorVisible = Visibility.Collapsed;
             await Task.Run(async delegate
             {
                 RewriteText = await ChatGTPAIHelper.Rewrite(InputText);
             });
             if (ChatGTPAIHelper.Code != "200")
             {
+                ErrorTipText = ChatGTPAIHelper.Code;
                 ErrorVisible = Visibility.Visible;
             }
+            if (homeContentViewModel != null)
+            {
+                homeContentViewModel.IsLoading = Visibility.Collapsed;
+            }
+        }
+        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)
+        {
+
         }
     }
 }

+ 7 - 0
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAITranslationContentViewModel.cs

@@ -115,6 +115,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 
         public async void selectFiles()
         {
+            ////添加付费拦截锁
+            //if (!ViewContentViewModel.IAPBeforeFunction())
+            //{
+            //    return;
+            //}
             string word = Properties.Resources.wordex;
             string pdf = Properties.Resources.pdf;
             string allfiles = pdf + word;
@@ -125,6 +130,7 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
            $"Microsoft Office Word({word})|{word}");
             if ((bool)dialog.ShowDialog())
             {
+                ErrorTipVisible = Visibility.Collapsed;
                 FileInfo fileInfo = new FileInfo(dialog.FileName);
                 if ((((float)fileInfo.Length) / 1024 / 1024) > 30) {
                     ErrorTipVisible = Visibility.Visible;
@@ -148,6 +154,7 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
                     }
                 }
                 //newfile code
+                ErrorTipText = newfile;
                 ErrorTipVisible =Visibility.Visible;
             }
         }

+ 0 - 5
PDF Office/Views/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialog.xaml

@@ -78,11 +78,6 @@
                     Command="{Binding CancelCommand}"
                     Content="Cancel" 
                     Style="{StaticResource btn.sec}">
-                    <i:Interaction.Triggers>
-                        <i:EventTrigger EventName="PreviewMouseDown">
-                            <i:InvokeCommandAction Command="{Binding PreviewCancelDownCommand}" CommandParameter="{Binding ElementName=PageRangeComboBox}" />
-                        </i:EventTrigger>
-                    </i:Interaction.Triggers>
                 </Button>
                 <Button
                     Width="98"