fix(AI,Web): Optimize the experience

This commit is contained in:
ShiYu
2025-06-07 10:00:08 +08:00
parent 38efca8bc0
commit bbf4e30847
3 changed files with 28 additions and 14 deletions
+17 -3
View File
@@ -17,13 +17,27 @@ public class AiService(IHttpClientFactory httpClientFactory, IConfigService conf
string apiKey = configService["AI:ApiKey"]; string apiKey = configService["AI:ApiKey"];
string baseUrl = configService["AI:ApiEndpoint"]; string baseUrl = configService["AI:ApiEndpoint"];
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new InvalidOperationException("AI API Key 未配置或为空。请检查配置文件中的 AI:ApiKey 设置。");
}
if (string.IsNullOrWhiteSpace(baseUrl))
{
throw new InvalidOperationException("AI API Endpoint 未配置或为空。请检查配置文件中的 AI:ApiEndpoint 设置。");
}
if (!Uri.TryCreate(baseUrl, UriKind.Absolute, out Uri? validUri))
{
throw new InvalidOperationException($"AI API Endpoint 格式无效: {baseUrl}。请提供有效的 URL。");
}
if (_httpClient == null || _currentApiKey != apiKey || _currentBaseUrl != baseUrl) if (_httpClient == null || _currentApiKey != apiKey || _currentBaseUrl != baseUrl)
{ {
_httpClient?.Dispose();
_httpClient = httpClientFactory.CreateClient(); _httpClient = httpClientFactory.CreateClient();
_httpClient.BaseAddress = new Uri(baseUrl); _httpClient.BaseAddress = validUri;
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
// 更新当前配置记录
_currentApiKey = apiKey; _currentApiKey = apiKey;
_currentBaseUrl = baseUrl; _currentBaseUrl = baseUrl;
} }
+1 -1
View File
@@ -13,7 +13,7 @@ import { Link, useNavigate, useLocation } from 'react-router';
import { useAuth } from '../../auth/AuthContext'; import { useAuth } from '../../auth/AuthContext';
import { getMainRoutes, getAdminRoutes, type RouteConfig } from '../../routes'; import { getMainRoutes, getAdminRoutes, type RouteConfig } from '../../routes';
import UserAvatar from '../../components/UserAvatar'; import UserAvatar from '../../components/UserAvatar';
import { UserRole } from '../../api/types'; import { UserRole } from '../../api';
import SearchDialog from '../../components/search/SearchDialog'; import SearchDialog from '../../components/search/SearchDialog';
import useIsMobile from '../../hooks/useIsMobile'; import useIsMobile from '../../hooks/useIsMobile';
+1 -1
View File
@@ -181,7 +181,7 @@ const Sidebar: React.FC<SidebarProps> = ({ collapsed, isMobile = false, onClose,
height: isMobile ? '56px' : '64px', height: isMobile ? '56px' : '64px',
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: collapsed ? 'center' : 'flex-start', justifyContent: 'center',
padding: collapsed ? '0' : '0 20px', padding: collapsed ? '0' : '0 20px',
color: '#001529', color: '#001529',
fontWeight: 'bold', fontWeight: 'bold',