Browse Source

页面编辑 拆分 进度条

OYXH\oyxh 1 year ago
parent
commit
a9d6ed3d0a

+ 76 - 31
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -29,10 +29,12 @@ namespace PDF_Master.Helper
 #if DEBUG
         //测试环境
         //纠错重写
-        
+
         private static string host = "https://ai.compdf.com";
+
         //百度翻译
         private static string translate = "http://101.132.103.13:8030";
+
 #else
         //纠错重写
         private static string host = "https://ai.compdf.com";
@@ -69,14 +71,16 @@ namespace PDF_Master.Helper
         /// chatGPT错误码
         /// </summary>
         public static string ChatGPTCode = "";
+
         #region AI服务器对接接口
+
         /// <summary>
         /// 获取
         /// </summary>
         /// <param name="content"></param>
         /// <param name="filename"></param>
         /// <returns></returns>
-        public async static Task<string> fileKeyTranslate(string content, string filename)
+        public static async Task<string> fileKeyTranslate(string content, string filename)
         {
             string Code = "Code" + "300";
             ServicePointManager.DefaultConnectionLimit = 200;
@@ -132,7 +136,6 @@ namespace PDF_Master.Helper
             }
             try
             {
-
                 // 获取HTTP响应
                 HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
                 using (StreamReader reader = new StreamReader(response2.GetResponseStream()))
@@ -156,8 +159,6 @@ namespace PDF_Master.Helper
                         return translation;
                     }
                     return "Code" + jobject["code"].ToObject<string>().ToLower();
-
-
                 }
             }
             catch (WebException ex)
@@ -167,7 +168,6 @@ namespace PDF_Master.Helper
                 {
                     //从网络异常信息里解析错误,后面的逻辑根据错误码判断会更准确
                     statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
-
                 }
                 Trace.WriteLine("HTTP异常:" + ex.Message);
                 if (statusCode == 401)
@@ -210,8 +210,6 @@ namespace PDF_Master.Helper
             return path;
         }
 
-
-
         /// <summary>
         /// 翻译指定内容,可以指定语言
         /// </summary>
@@ -325,7 +323,6 @@ namespace PDF_Master.Helper
                             folderPath = CommonHelper.CreateFilePath(folderPath);
                             client.DownloadProgressChanged += (sender, e) =>
                             {
-
                             };
                             client.DownloadFile(translate, folderPath);
                             clossProcess();
@@ -360,10 +357,8 @@ namespace PDF_Master.Helper
             {
                 return "300";
             }
-
         }
 
-
         /// <summary>
         /// 翻译指定内容,可以指定语言
         /// </summary>
@@ -373,7 +368,6 @@ namespace PDF_Master.Helper
         /// <returns></returns>
         public static String textTranslate(string content, string fromlanguage, string tolanguage, ref string translate)
         {
-
             HttpWebResponse response = null;
             ServicePointManager.DefaultConnectionLimit = 200;
             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_texttranslate);
@@ -453,7 +447,6 @@ namespace PDF_Master.Helper
             {
                 return "300";
             }
-
         }
 
         /// <summary>
@@ -461,9 +454,8 @@ namespace PDF_Master.Helper
         /// </summary>
         /// <param name="content"></param>
         /// <returns></returns>
-        public async static Task<string> Correction(string content)
+        public static async Task<string> Correction(string content)
         {
-
             intProcess(true, "Correcting...");
             App.mainWindowViewModel.Value = 1;
             ServicePointManager.DefaultConnectionLimit = 200;
@@ -499,9 +491,8 @@ namespace PDF_Master.Helper
         /// </summary>
         /// <param name="content"></param>
         /// <returns></returns>
-        public async static Task<string> Rewrite(string content)
+        public static async Task<string> Rewrite(string content)
         {
-
             intProcess(true, "Rewriting...");
             App.mainWindowViewModel.Value = 1;
             ServicePointManager.DefaultConnectionLimit = 200;
@@ -565,7 +556,7 @@ namespace PDF_Master.Helper
         /// <param name="request">请求体</param>
         /// /// <param name="key">值</param>
         /// <returns></returns>
-        private async static Task<string> PostStringHttpWeb(MultipartFormDataContent formData, HttpWebRequest request, string key = "message")
+        private static async Task<string> PostStringHttpWeb(MultipartFormDataContent formData, HttpWebRequest request, string key = "message")
         {
             App.mainWindowViewModel.Value = 6;
             string repsonseData = "";
@@ -575,7 +566,6 @@ namespace PDF_Master.Helper
             }
             try
             {
-
                 // 获取HTTP响应
                 HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
                 using (StreamReader reader = new StreamReader(response2.GetResponseStream()))
@@ -605,9 +595,6 @@ namespace PDF_Master.Helper
                     //repsonseData = Regex.Unescape(unicode);
                     repsonseData = unicode;
                     clossProcess();
-                   
-
-
                 }
             }
             catch (WebException ex)
@@ -627,7 +614,8 @@ namespace PDF_Master.Helper
                 clossProcess();
                 return null;
             }
-            catch {
+            catch
+            {
                 ChatGPTCode = "300";
                 clossProcess();
             }
@@ -635,14 +623,13 @@ namespace PDF_Master.Helper
             return repsonseData;
         }
 
-
         /// <summary>
         /// 从接口获取信息,获取message对应value值,WebClient没有设置请求时间参数换一种方案
         /// </summary>
         /// <param name="url"></param>
         /// <param name="namevalue"></param>
         /// <returns></returns>
-        private async static Task<string> PostStringWebClient(string url, System.Collections.Specialized.NameValueCollection namevalue, string key = "message")
+        private static async Task<string> PostStringWebClient(string url, System.Collections.Specialized.NameValueCollection namevalue, string key = "message")
         {
             App.mainWindowViewModel.Value = 5;
             string repsonseData = "";
@@ -706,6 +693,25 @@ namespace PDF_Master.Helper
             }
         }
 
+        /// <summary>
+        /// 初始进度条
+        /// </summary>
+        /// <param name="isprocess">是否需要进度条</param>
+        /// <param name="progressTitle">文案</param>
+        /// <param name="maxValue">进度条最大值</param>
+        /// <param name="ProcessCloseBtnVisible">进度条关闭按钮是否可见</param>
+        public static void SetIntProcess(bool isprocess = true, string progressTitle = "Splitting...", int maxValue = 10, System.Windows.Visibility ProcessCloseBtnVisible = System.Windows.Visibility.Collapsed)
+        {
+            if (isprocess)
+            {
+                App.mainWindowViewModel.ProgressTitle = progressTitle;
+                App.mainWindowViewModel.MaxValue = maxValue;
+                App.mainWindowViewModel.Value = 0;
+                App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
+                App.mainWindowViewModel.ProcessCloseBtnVisible = ProcessCloseBtnVisible;
+            }
+        }
+
         /// <summary>
         /// 关闭进度条
         /// </summary>
@@ -716,6 +722,17 @@ namespace PDF_Master.Helper
             App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
         }
 
+        /// <summary>
+        /// 关闭进度条
+        /// </summary>
+        /// <param name="value">进度条当前值</param>
+        public static void clossProcess(int value = 9)
+        {
+            App.mainWindowViewModel.Value = value;
+            App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
+            App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
+        }
+
         /// <summary>
         /// 判断word文档页面大小,如果接口有问题则交给服务器判断
         /// </summary>
@@ -751,14 +768,14 @@ namespace PDF_Master.Helper
                     }
                 }
                 return true;
-
             }
             catch
             {
                 return true;
             }
         }
-        #endregion
+
+        #endregion AI服务器对接接口
 
         #region 支持翻译的语言
 
@@ -766,6 +783,7 @@ namespace PDF_Master.Helper
         /// 当前语言列表
         /// </summary>
         public static List<string> FromlanguageFamily { set; get; } = new List<string>();
+
         public static List<string> SetFromlanguageOrigin()
         {
             FromlanguageFamily.Clear();
@@ -803,6 +821,7 @@ namespace PDF_Master.Helper
         /// 需要翻译成对应语言列表
         /// </summary>
         public static List<string> TolanguageFamily { set; get; } = new List<string>();
+
         public static List<string> SetTolanguageOrigin()
         {
             TolanguageFamily.Clear();
@@ -845,61 +864,88 @@ namespace PDF_Master.Helper
             {
                 case 0:
                     return "auto";
+
                 case 1:
                     return "en";
+
                 case 2:
                     return "zh";
+
                 case 3:
                     return "cht";
+
                 case 4:
                     return "jp";
+
                 case 5:
                     return "kor";
+
                 case 6:
                     return "fra";
+
                 case 7:
                     return "spa";
+
                 case 8:
                     return "it";
+
                 case 9:
                     return "de";
+
                 case 10:
                     return "pt";
+
                 case 11:
                     return "ru";
+
                 case 12:
                     return "vie";
+
                 case 13:
                     return "th";
+
                 case 14:
                     return "ara";
+
                 case 15:
                     return "el";
+
                 case 16:
                     return "bul";
+
                 case 17:
                     return "fin";
+
                 case 18:
                     return "slo";
+
                 case 19:
                     return "nl";
+
                 case 20:
                     return "cs";
+
                 case 21:
                     return "swe";
+
                 case 22:
                     return "pl";
+
                 case 23:
                     return "dan";
+
                 case 24:
                     return "rom";
+
                 case 25:
                     return "hu";
+
                 default:
                     return "";
             }
         }
-        #endregion
+
+        #endregion 支持翻译的语言
 
         #region 错误码
 
@@ -923,7 +969,6 @@ namespace PDF_Master.Helper
             return code;
         }
 
-        #endregion
+        #endregion 错误码
     }
-}
-
+}

+ 16 - 2
PDF Office/ViewModels/PageEdit/PageEditContentViewModel.cs

@@ -1,4 +1,5 @@
 using ComPDFKit.PDFDocument;
+using ComPDFKit_Conversion.Converter;
 using ComPDFKitViewer.PdfViewer;
 using Dropbox.Api.Team;
 using Microsoft.Win32;
@@ -2549,13 +2550,17 @@ namespace PDF_Master.ViewModels.PageEdit
                     Directory.CreateDirectory(directory);
                 }
                 string filename = "";
+                int index = 0;
                 if (data.Mode == HomePageSplitDialogModel.SplitMode.AveragePages)
                 {
                     int perPages = Convert.ToInt32(data.GetModeCount);
-                    int SplitCount = (int)Math.Ceiling((double)PageCount / (double)perPages);
+                    int splitCount = (int)Math.Ceiling((double)PageCount / (double)perPages);
+                    index = splitCount;
+                    ChatGTPAIHelper.SetIntProcess(true, "Splitting...", index, System.Windows.Visibility.Visible);
+
                     //TODO:命名规则是否要调整
                     selectedfile = data.FileName + " " + "1.pdf";
-                    for (int i = 0; i < SplitCount; i++)
+                    for (int i = 0; i < splitCount; i++)
                     {
                         int startNum = i * perPages + 1;
                         int endNum = Math.Min(PageCount, (i + 1) * perPages);
@@ -2585,6 +2590,10 @@ namespace PDF_Master.ViewModels.PageEdit
                 {
                     int docCount = Convert.ToInt32(data.GetModeCount);
                     int avePages = (int)Math.Floor((double)PageCount / (double)docCount);
+
+                    index = avePages;
+                    ChatGTPAIHelper.SetIntProcess(true, "Splitting...", index, System.Windows.Visibility.Visible);
+
                     int remain = PageCount % docCount;
                     int startNum = 1;
                     //TODO:命名规则是否要调整
@@ -2645,6 +2654,10 @@ namespace PDF_Master.ViewModels.PageEdit
                     //如果是自定义输入页面范围的话,直接解析
                     CommonHelper.GetPagesInRange(ref pageList1, pageRange, PageCount, new char[] { ',' }, new char[] { '-' });
 
+                    index = pageList1.Count;
+                    ChatGTPAIHelper.SetIntProcess(true, "Splitting...", index, System.Windows.Visibility.Visible);
+
+
                     #region //part1
 
                     selectedfile = "";
@@ -2707,6 +2720,7 @@ namespace PDF_Master.ViewModels.PageEdit
 
                 //显示文件夹,并选中一个文件
                 Process.Start("explorer", "/select,\"" + selectedfile + "\"");
+                ChatGTPAIHelper.clossProcess(index);
             }
             catch
             {