This commit is contained in:
Đăng Nguyễn 2025-12-22 19:49:03 +07:00
commit b2eeb8cb3f
3 changed files with 52 additions and 26 deletions

View File

@ -16,13 +16,14 @@
<!-- CANCEL -->
<MudButton Variant="Variant.Filled"
Color="Color.Error"
StartIcon="@Icons.Material.Filled.Cancel"
Color="@CancelButtonColor"
StartIcon="@CancelButtonIcon"
Disabled="@DisableCancel"
OnClick="OnCancel">
Cancel
@CancelButtonText
</MudButton>
<!-- SEND -->
<MudButton Variant="Variant.Filled"
Color="@SendButtonColor"
@ -63,6 +64,7 @@
[Parameter] public bool Copied { get; set; }
[Parameter] public bool? SendSuccess { get; set; }
[Parameter] public bool DisableCancel { get; set; }
[Parameter] public bool? CancelSuccess { get; set; }
[Parameter] public EventCallback<string> OrderJsonChanged { get; set; }
@ -95,6 +97,31 @@
_ => Icons.Material.Filled.Send
};
private string CancelButtonText =>
CancelSuccess switch
{
true => "Done",
false => "Error",
_ => "Cancel"
};
private Color CancelButtonColor =>
CancelSuccess switch
{
true => Color.Success,
false => Color.Error,
_ => Color.Error
};
private string CancelButtonIcon =>
CancelSuccess switch
{
true => Icons.Material.Filled.CheckCircle,
false => Icons.Material.Filled.Error,
_ => Icons.Material.Filled.Cancel
};
private void OrderJsonChange(string value)
{
OrderJson = value;

View File

@ -7,7 +7,6 @@
@inject IJSRuntime JS
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject HttpClient Http
<MudMainContent Class="pa-0 ma-0">
@ -49,6 +48,7 @@
<JsonOutputPanel @bind-OrderJson="@OrderJson"
Copied="@copied"
SendSuccess="@sendSuccess"
CancelSuccess="@cancelSuccess"
OnCopy="CopyJsonToClipboard"
OnSend="SendOrderToServer"
OnImport="OpenImportDialog"
@ -66,6 +66,7 @@
private string OrderJson = ""; // 🔥 CACHE JSON (QUAN TRỌNG)
private bool copied;
private bool? sendSuccess;
private bool? cancelSuccess;
private CancellationTokenSource? _copyCts;
// ================= INIT =================
@ -247,35 +248,33 @@
async Task CancelOrder()
{
// reset trạng thái trước khi gửi
cancelSuccess = null;
StateHasChanged();
try
{
var res = await Http.PostAsync("/api/order/cancel", null);
sendSuccess = null; // reset trạng thái SEND
copied = false;
if (res.IsSuccessStatusCode)
{
Snackbar.Add(
"⛔ Order đã huỷ",
Severity.Info);
}
else
{
Snackbar.Add(
"❌ Huỷ order thất bại",
Severity.Error);
}
cancelSuccess = res.IsSuccessStatusCode;
}
catch (Exception ex)
catch
{
Snackbar.Add(
$"❌ Lỗi: {ex.Message}",
Severity.Error);
cancelSuccess = false;
}
StateHasChanged();
// 🔥 AUTO RESET SAU 2 GIÂY
_ = Task.Run(async () =>
{
await Task.Delay(2000);
cancelSuccess = null;
await InvokeAsync(StateHasChanged);
});
}
async Task CopyJsonToClipboard()
{
_copyCts?.Cancel();

View File

@ -131,7 +131,7 @@ public class OrderMessage
public string Version { get; set; } = "v1";
public string Manufacturer { get; set; } = "PNKX";
public string SerialNumber { get; set; } = "T800-002";
public string OrderId { get; set; } = Guid.NewGuid().ToString();
public string OrderId { get; set; }
public int OrderUpdateId { get; set; }
public string? ZoneSetId { get; set; }
@ -419,7 +419,7 @@ public class OrderMessage
manufacturer = Manufacturer,
serialNumber = SerialNumber,
orderId = OrderId,
orderId = OrderId= Guid.NewGuid().ToString(),
orderUpdateId = OrderUpdateId,
zoneSetId = string.IsNullOrWhiteSpace(ZoneSetId)