From d216edd0e9931d71664f33e625cff6d8131a0fad Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 13 三月 2026 16:00:40 +0800
Subject: [PATCH] 重构: 实现前后端分离架构

---
 Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs |   25 +++++++++----------------
 1 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs
index 2ddd774..b0e97db 100644
--- a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs
+++ b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Web/Pages/Create.cshtml.cs
@@ -3,21 +3,23 @@
 using System.ComponentModel.DataAnnotations;
 using WIDESEAWCS_S7Simulator.Core.Entities;
 using WIDESEAWCS_S7Simulator.Core.Enums;
+using WIDESEAWCS_S7Simulator.Web.Services;
 
 namespace WIDESEAWCS_S7Simulator.Web.Pages;
 
 /// <summary>
 /// 鍒涘缓瀹炰緥椤�
 /// </summary>
-public class CreateModel : PageModel
+public class CreateModel : BasePageModel
 {
     private readonly ILogger<CreateModel> _logger;
-    private readonly IHttpClientFactory _httpClientFactory;
+    private readonly ApiHttpClient _apiClient;
 
-    public CreateModel(ILogger<CreateModel> logger, IHttpClientFactory httpClientFactory)
+    public CreateModel(ILogger<CreateModel> logger, IConfiguration configuration, ApiHttpClient apiClient)
+        : base(configuration)
     {
         _logger = logger;
-        _httpClientFactory = httpClientFactory;
+        _apiClient = apiClient;
     }
 
     [BindProperty]
@@ -37,10 +39,6 @@
 
         try
         {
-            // 鍒涘缓HttpClient骞惰缃瓸aseAddress
-            var httpClient = _httpClientFactory.CreateClient();
-            httpClient.BaseAddress = new Uri($"{Request.Scheme}://{Request.Host}");
-
             var config = new InstanceConfig
             {
                 Id = Input.Id,
@@ -61,22 +59,17 @@
                 }
             };
 
-            var response = await httpClient.PostAsJsonAsync("/api/SimulatorInstances", config);
+            var result = await _apiClient.CreateInstanceAsync(config);
 
-            if (response.IsSuccessStatusCode)
+            if (result != null)
             {
                 _logger.LogInformation("Instance {InstanceId} created successfully", Input.Id);
                 TempData["SuccessMessage"] = $"瀹炰緥 \"{Input.Id}\" 鍒涘缓鎴愬姛!";
                 return RedirectToPage("/Index");
             }
-            else if (response.StatusCode == System.Net.HttpStatusCode.Conflict)
-            {
-                ModelState.AddModelError(string.Empty, "瀹炰緥ID宸插瓨鍦紝璇蜂娇鐢ㄥ叾浠朓D");
-            }
             else
             {
-                var error = await response.Content.ReadFromJsonAsync<object>();
-                ModelState.AddModelError(string.Empty, error?.ToString() ?? "鍒涘缓瀹炰緥澶辫触");
+                ModelState.AddModelError(string.Empty, "鍒涘缓瀹炰緥澶辫触");
             }
         }
         catch (HttpRequestException ex)

--
Gitblit v1.9.3