Преглед изворни кода

人工智能-文本翻译弹窗取消请求

liyijie пре 1 година
родитељ
комит
f8720b10cb

+ 27 - 2
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -4,6 +4,7 @@ using ImTools;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using PDF_Master.Properties;
+using PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics;
@@ -75,6 +76,23 @@ namespace PDF_Master.Helper
 
             ServicePointManager.DefaultConnectionLimit = 200;
             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_fileKeytranslate);
+            //关闭请求
+            //弹窗内进度条关闭
+            DocumentaryTranslationDialogViewModel.CancelProgress = () =>
+            {
+                if (request != null)
+                {
+                    request.Abort();
+                }
+            };
+            //进度条关闭
+            App.mainWindowViewModel.ProcessCloseAction = () =>
+            {
+                if (request != null)
+                {
+                    request.Abort();
+                }
+            };
             request.Method = "Post";
             //request.Accept = "application/vnd.api+json;version=1";
             request.UserAgent = "Apifox/1.0.0 (https://www.apifox.cn)";
@@ -177,7 +195,7 @@ namespace PDF_Master.Helper
         /// <returns></returns>
         public static async Task<string> fileTranslate(string content, string fromlanguage, string tolanguage, bool isprocess = true)
         {
-            intProcess(isprocess,"Translating");
+            intProcess(isprocess,"Translating", System.Windows.Visibility.Visible);
             
             FileInfo file = new FileInfo(content);
             string fileKey = await fileKeyTranslate(content, file.Name);
@@ -191,7 +209,14 @@ namespace PDF_Master.Helper
             ServicePointManager.DefaultConnectionLimit =200;
             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_filetranslate);
             //关闭请求
-            App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
+            DocumentaryTranslationDialogViewModel.CancelProgress=()=> 
+            {
+                if (request != null)
+                {
+                    request.Abort();
+                }
+            };
+
             App.mainWindowViewModel.ProcessCloseAction = () =>
             {
                 if (request != null)

+ 20 - 3
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs

@@ -129,12 +129,14 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             TolanguageFamily = ChatGTPAIHelper.SetTolanguageOrigin();
         }
 
+        public static Action CancelProgress { get; set; }
+
         #endregion
 
         #region 委托声明
         public DelegateCommand TranslateCommand { get; set; }
         public DelegateCommand CancelCommand { get; set; }
-
+        public DelegateCommand CancelProgressCommand { get; set; }
         #endregion
         public DocumentaryTranslationDialogViewModel(IRegionManager regionManager)
         {
@@ -142,6 +144,7 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             CancelCommand = new DelegateCommand(cancel);
             TranslateCommand = new DelegateCommand(translate);
             ViewerRegionName = Guid.NewGuid().ToString();
+            CancelProgressCommand = new DelegateCommand(cancelprogress);
             init();
         }
         #region 逻辑函数
@@ -154,6 +157,18 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             GetFromlanguageOrigin();
             GetTolanguageOrigin();
         }
+        /// <summary>
+        /// 进度条取消
+        /// </summary>
+        private void cancelprogress()
+        {
+            if (CancelProgress != null)
+            {
+                CancelProgress.Invoke();
+            }
+
+
+        }
 
         /// <summary>
         /// 关闭窗口
@@ -193,9 +208,11 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
                 return;
             }
             //判断文件页数
-            if (fileInfo.Extension.ToLower() == ".pdf") {
+            if (fileInfo.Extension.ToLower() == ".pdf")
+            {
                 CPDFDocument cPDFDocument = CPDFDocument.InitWithFilePath(pdfViewer.Document.FilePath);
-                if (cPDFDocument.PageCount > 30) {
+                if (cPDFDocument.PageCount > 30)
+                {
                     Value = 9;
                     AlertsMessage alertsMessage = new AlertsMessage();
                     alertsMessage.ShowDialog("", "The uploaded file cannot exceed 30Pages", App.ServiceLoader.GetString("Text_ok"));

+ 2 - 1
PDF Office/Views/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialog.xaml

@@ -52,7 +52,8 @@
                         VerticalAlignment="Top"
                         Background="{StaticResource color.sys.layout.dark.bg}"
                         BorderThickness="0"
-                        Visibility="Collapsed">
+                        Visibility="Visible"
+                                Command="{Binding CancelProgressCommand}">
                                 <Path Data="M6.00006 7.06072L9.46973 10.5304L10.5304 9.46973L7.06072 6.00006L10.5304 2.53039L9.46973 1.46973L6.00006 4.9394L2.53039 1.46973L1.46973 2.53039L4.9394 6.00006L1.46973 9.46973L2.53039 10.5304L6.00006 7.06072Z" Fill="#CED0D4" />
                             </Button>
                             <ProgressBar