This commit is contained in:
mmrbnjd
2025-08-18 14:18:08 +03:30
parent 7ce8812098
commit 067607d98a
19 changed files with 715 additions and 55 deletions

View File

@@ -7,21 +7,27 @@
@inject ToastService toastService
@inject IJSRuntime JS
@layout UserPanelLayout
@using Common.Dtos.Company
@using HushianWebApp.Service
@using HushianWebApp.Services
@using Microsoft.AspNetCore.Components.Web
@inject CompanyService companyService
@inject ToastService toastService
<div class="container-fluid">
<div class="row" style="height:85vh">
@if (isReady)
{
@if (isLogin)
{
<div class="col-md-12 d-flex flex-column">
<div class="input-group mb-2">
<p class="form-control fw-bold text-primary" style="border:none;align-self:center">گفتگو هوش مصنوعی</p>
<div class="col-md-12 d-flex flex-column" style="margin-top:10px">
<div class="input-group">
<p type="text" class="form-control fw-bold text-primary" style="border:none;align-self: center;" aria-describedby="basic-addon1">دستیار هوشمند @CompanyInfo.FullName</p>
<div class="d-flex gap-2 ms-auto">
<Button Color="ButtonColor.Secondary" Size=ButtonSize.ExtraSmall Outline="true" @onclick="Logout">خروج</Button>
<Button Color="ButtonColor.Secondary" Size=ButtonSize.ExtraSmall Outline="true" @onclick="Logout" Class="logout-btn">
<Icon Name="IconName.BoxArrowRight" Class="me-1" /> خروج
</Button>
</div>
</div>
<div class="flex-fill chat-area-container" id="ai-chat">
@@ -32,7 +38,7 @@
{
<div class="d-flex mb-2 justify-content-start">
<div class="chat-bubble chat-other">
@msg.requestText
@msg.requestText
</div>
</div>
@@ -79,39 +85,44 @@
</div>
@code {
ReadANDUpdate_CompanyDto? CompanyInfo = new();
[Parameter] public int CompanyID { get; set; }
List<aiResponseDto> messages = new();
string inputText = string.Empty;
bool isLogin = false;
bool isReady = false;
public string aikeyUser { get; set; }
protected override async Task OnInitializedAsync()
{
await EnsureAuth();
if (isLogin)
{
await LoadMessages();
CompanyInfo = await companyService.GetCompany(CompanyID);
if (CompanyInfo != null)
await LoadMessages();
else
{
toastService.Notify(new ToastMessage(ToastType.Danger, "شناسه شرکت صحیح نمی باشد"));
}
}
}
private async Task EnsureAuth()
{
var token = await localStorageService.GetItem<string>("U/key");
if (string.IsNullOrEmpty(token))
aikeyUser = await localStorageService.GetItem<string>("aikeyUser");
if (string.IsNullOrEmpty(aikeyUser))
{
isLogin = false;
isReady = true;
return;
aikeyUser = Guid.NewGuid().ToString();
await localStorageService.SetItem("aikeyUser", aikeyUser);
}
await baseController.RemoveToken();
await baseController.SetToken(token);
isLogin = await authService.IsOnline();
isLogin = true;
isReady = true;
}
private async Task LoadMessages()
{
messages = await conversationService.GetAiCurrentResponses(CompanyID);
messages = await conversationService.GetAiCurrentResponses(CompanyID,aikeyUser);
StateHasChanged();
await JS.InvokeVoidAsync("scrollToBottom", "ai-chat");
}
@@ -119,13 +130,8 @@
private async Task Send()
{
if (string.IsNullOrWhiteSpace(inputText)) return;
var token = await localStorageService.GetItem<string>("U/key");
if (!isLogin || string.IsNullOrEmpty(token))
{
toastService.Notify(new ToastMessage(ToastType.Warning, "ابتدا وارد شوید"));
return;
}
var dto = new aiNewResponseDto { companyId = CompanyID, userId = 0, requestText = inputText };
var dto = new aiNewResponseDto { companyId = CompanyID, aiKeyUser = aikeyUser, requestText = inputText };
var okmodel = await conversationService.AiNewResponse(dto);
if (okmodel!=null)
{
@@ -147,8 +153,7 @@
private async Task Logout()
{
await baseController.RemoveToken();
await localStorageService.RemoveItem("U/key");
await localStorageService.RemoveItem("aiKeyUser");
isLogin = false;
}
}
@@ -196,6 +201,43 @@
.input-wrapper { display:flex; align-items:center; gap:.75rem; }
.message-input { flex:1; border:none; background:transparent; padding:.5rem .75rem; font-size:.95rem; color:#495057; outline:none; border-radius:20px; }
.send-btn { border-radius:50%; width:38px; height:38px; padding:0; display:flex; align-items:center; justify-content:center; background:linear-gradient(135deg,#0d6efd 0%,#0b5ed7 100%); border:none; box-shadow:0 4px 12px rgba(13,110,253,.3); color:white; }
.logout-btn {
border-radius: 20px;
font-weight: 600;
font-size: 0.875rem;
padding: 0.375rem 0.75rem;
transition: all 0.3s ease;
border-width: 2px;
box-shadow: 0 2px 4px rgba(108, 117, 125, 0.2);
background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}
.logout-btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(108, 117, 125, 0.3);
border-color: #6c757d;
background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
color: white;
}
/* Improved input group styling */
.input-group {
margin-bottom: 1rem;
border-radius: 0.5rem;
overflow: hidden;
}
.input-group p {
margin: 0;
font-size: 1.1rem;
font-weight: 700;
background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
</style>
<script>