Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="BootstrapBlazor.FluentSystemIcon" Version="10.0.0" />
<PackageReference Include="BootstrapBlazor.FontAwesome" Version="10.0.0" />
<PackageReference Include="BootstrapBlazor.Gantt" Version="10.0.0" />
<PackageReference Include="BootstrapBlazor.HikVision" Version="10.0.7" />
<PackageReference Include="BootstrapBlazor.HikVision" Version="10.0.8" />
<PackageReference Include="BootstrapBlazor.Holiday" Version="10.0.0" />
<PackageReference Include="BootstrapBlazor.Html2Image" Version="10.0.0" />
<PackageReference Include="BootstrapBlazor.Html2Pdf" Version="10.0.1" />
Expand Down
56 changes: 29 additions & 27 deletions src/BootstrapBlazor.Server/Components/Samples/HikVisions.razor
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,35 @@
</BootstrapInputGroup>
</div>
<div class="col-12">
<Button OnClick="OnLogin" IsDisabled="_loginStatus">
<span>登录</span>
</Button>
<Button OnClick="OnLogout" IsDisabled="_logoutStatus">
<span>退出</span>
</Button>
<Button OnClick="OnStartRealPlay" IsDisabled="_startRealPlayStatus">
<span>开始预览</span>
</Button>
<Button OnClick="OnStopRealPlay" IsDisabled="_stopRealPlayStatus">
<span>停止预览</span>
</Button>
<Button OnClick="OnOpenSound" IsDisabled="_openSoundStatus">
<span>打开声音</span>
</Button>
<Button OnClick="OnCloseSound" IsDisabled="_closeSoundStatus">
<span>关闭声音</span>
</Button>
<Button OnClick="OnCapture" IsDisabled="_stopRealPlayStatus">
<span>抓图</span>
</Button>
<Button OnClick="OnStartRecord" IsDisabled="_startRecordStatus">
<span>开始录像</span>
</Button>
<Button OnClick="OnStopRecord" IsDisabled="_stopRecordStatus">
<span>停止录像</span>
</Button>
<div style="width: 100%; display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));">
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline style uses .5rem which may not be valid CSS. While some browsers accept leading-zero-less decimal numbers, it's better to use 0.5rem for better compatibility and clarity.

Suggested change
<div style="width: 100%; display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));">
<div style="width: 100%; display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));">

Copilot uses AI. Check for mistakes.
<Button OnClick="OnLogin" IsDisabled="_loginStatus">
<span>登录</span>
</Button>
<Button OnClick="OnLogout" IsDisabled="_logoutStatus">
<span>退出</span>
</Button>
<Button OnClick="OnStartRealPlay" IsDisabled="_startRealPlayStatus">
<span>开始预览</span>
</Button>
<Button OnClick="OnStopRealPlay" IsDisabled="_stopRealPlayStatus">
<span>停止预览</span>
</Button>
<Button OnClick="OnOpenSound" IsDisabled="_openSoundStatus">
<span>打开声音</span>
</Button>
<Button OnClick="OnCloseSound" IsDisabled="_closeSoundStatus">
<span>关闭声音</span>
</Button>
<Button OnClick="OnCapture" IsDisabled="_stopRealPlayStatus">
<span>抓图</span>
</Button>
<Button OnClick="OnStartRecord" IsDisabled="_startRecordStatus">
<span>开始录像</span>
</Button>
<Button OnClick="OnStopRecord" IsDisabled="_stopRecordStatus">
<span>停止录像</span>
</Button>
</div>
</div>
}
</div>
Expand Down
61 changes: 9 additions & 52 deletions src/BootstrapBlazor.Server/Components/Samples/HikVisions.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public partial class HikVisions
private string _userName = "admin";
private bool _inited;

private bool _loginStatus = true;
private bool _logoutStatus = true;
private bool _startRealPlayStatus = true;
private bool _stopRealPlayStatus = true;
private bool _openSoundStatus = true;
private bool _closeSoundStatus = true;
private bool _startRecordStatus = true;
private bool _stopRecordStatus = true;
private bool _loginStatus => _hikVision.IsLogin;
private bool _logoutStatus => !_hikVision.IsLogin;
private bool _startRealPlayStatus => _hikVision is not { IsLogin: true, IsRealPlaying: false };
private bool _stopRealPlayStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true };
private bool _openSoundStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsOpenSound: false };
private bool _closeSoundStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsOpenSound: true };
private bool _startRecordStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsStartRecord: false };
private bool _stopRecordStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsStartRecord: true };

private List<SelectedItem> _analogChannels = [];
private int _channelId = 1;
Comment on lines 27 to 39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The new predicate-based disable flags are compact but fairly hard to parse; consider refactoring for clarity.

These predicates for real play, sound, and record use inverted logic (true = disabled), which makes them harder to reason about. Consider renaming them to reflect the disabled state (e.g. _startRealPlayDisabled) or extracting the conditions into clearly named helpers (e.g. CanStartRealPlay) to improve readability and future maintenance.

Suggested change
private bool _inited;
private bool _loginStatus = true;
private bool _logoutStatus = true;
private bool _startRealPlayStatus = true;
private bool _stopRealPlayStatus = true;
private bool _openSoundStatus = true;
private bool _closeSoundStatus = true;
private bool _startRecordStatus = true;
private bool _stopRecordStatus = true;
private bool _loginStatus => _hikVision.IsLogin;
private bool _logoutStatus => !_hikVision.IsLogin;
private bool _startRealPlayStatus => _hikVision is not { IsLogin: true, IsRealPlaying: false };
private bool _stopRealPlayStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true };
private bool _openSoundStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsOpenSound: false };
private bool _closeSoundStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsOpenSound: true };
private bool _startRecordStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsStartRecord: false };
private bool _stopRecordStatus => _hikVision is not { IsLogin: true, IsRealPlaying: true, IsStartRecord: true };
private List<SelectedItem> _analogChannels = [];
private int _channelId = 1;
private bool _inited;
// Capability predicates (positive logic) for readability
private bool CanLogin => !_hikVision.IsLogin;
private bool CanLogout => _hikVision.IsLogin;
private bool CanStartRealPlay => _hikVision is { IsLogin: true, IsRealPlaying: false };
private bool CanStopRealPlay => _hikVision is { IsLogin: true, IsRealPlaying: true };
private bool CanOpenSound => _hikVision is { IsLogin: true, IsRealPlaying: true, IsOpenSound: false };
private bool CanCloseSound => _hikVision is { IsLogin: true, IsRealPlaying: true, IsOpenSound: true };
private bool CanStartRecord => _hikVision is { IsLogin: true, IsRealPlaying: true, IsStartRecord: false };
private bool CanStopRecord => _hikVision is { IsLogin: true, IsRealPlaying: true, IsStartRecord: true };
// Status flags are used as disabled predicates in the UI (true => disabled)
private bool _loginStatus => !CanLogin;
private bool _logoutStatus => !CanLogout;
private bool _startRealPlayStatus => !CanStartRealPlay;
private bool _stopRealPlayStatus => !CanStopRealPlay;
private bool _openSoundStatus => !CanOpenSound;
private bool _closeSoundStatus => !CanCloseSound;
private bool _startRecordStatus => !CanStartRecord;
private bool _stopRecordStatus => !CanStopRecord;
private List<SelectedItem> _analogChannels = [];
private int _channelId = 1;

Expand All @@ -48,36 +48,22 @@ public partial class HikVisions

private async Task OnLogin()
{
_loginStatus = true;
_logoutStatus = true;
_loginStatus = await _hikVision.Login(_ip, _port, _userName, _password, HikVisionLoginType.Http);
await _hikVision.Login(_ip, _port, _userName, _password, HikVisionLoginType.Http);
}

private async Task OnLogout()
{
_analogChannels.Clear();
_loginStatus = true;
_logoutStatus = true;
_startRealPlayStatus = true;
_stopRealPlayStatus = true;
_openSoundStatus = true;
_closeSoundStatus = true;
await _hikVision.Logout();
}

private async Task OnStartRealPlay()
{
_startRealPlayStatus = true;
_stopRealPlayStatus = true;
await _hikVision.StartRealPlay(_streamType, _channelId);
}

private async Task OnStopRealPlay()
{
_startRealPlayStatus = true;
_stopRealPlayStatus = true;
_openSoundStatus = true;
_closeSoundStatus = true;
await _hikVision.StopRealPlay();
}

Expand All @@ -86,8 +72,6 @@ private async Task OnOpenSound()
var result = await _hikVision.OpenSound();
if (result)
{
_openSoundStatus = true;
_closeSoundStatus = false;
await ToastService.Success("消息通知", "打开声音成功");
}
else
Expand All @@ -101,8 +85,6 @@ private async Task OnCloseSound()
var result = await _hikVision.CloseSound();
if (result)
{
_openSoundStatus = false;
_closeSoundStatus = true;
await ToastService.Success("消息通知", "关闭声音成功");
}
else
Expand All @@ -121,8 +103,6 @@ private async Task OnStartRecord()
var result = await _hikVision.StartRecord();
if (result)
{
_startRecordStatus = true;
_stopRecordStatus = false;
await ToastService.Success("消息通知", "开始录像成功");
}
else
Expand All @@ -136,8 +116,6 @@ private async Task OnStopRecord()
var result = await _hikVision.StopRecord();
if (result)
{
_startRecordStatus = false;
_stopRecordStatus = true;
await ToastService.Success("消息通知", "结束录像成功");
}
else
Expand All @@ -151,7 +129,6 @@ private async Task OnInitedAsync(bool initialized)
_inited = initialized;
if (_inited)
{
_loginStatus = false;
StateHasChanged();
}
else
Expand Down Expand Up @@ -181,10 +158,6 @@ await SwalService.Show(new SwalOption()

private Task OnLoginAsync()
{
_loginStatus = true;
_logoutStatus = !_loginStatus;
_startRealPlayStatus = _logoutStatus;
_stopRealPlayStatus = !_startRealPlayStatus;
StateHasChanged();
return Task.CompletedTask;
}
Expand All @@ -199,34 +172,18 @@ private Task OnGetChannelsAsync(HikVisionChannel channel)

private Task OnLogoutAsync()
{
_loginStatus = _hikVision.IsLogin;
_logoutStatus = !_loginStatus;
_startRealPlayStatus = true;
_stopRealPlayStatus = true;
StateHasChanged();
return Task.CompletedTask;
}

private Task OnStartRealPlayedAsync()
{
_startRealPlayStatus = _hikVision.IsRealPlaying;
_stopRealPlayStatus = !_startRealPlayStatus;
_openSoundStatus = false;
_closeSoundStatus = true;
_startRecordStatus = false;
_stopRecordStatus = true;
StateHasChanged();
return Task.CompletedTask;
}

private Task OnStopRealPlayedAsync()
{
_startRealPlayStatus = _hikVision.IsRealPlaying;
_stopRealPlayStatus = !_startRealPlayStatus;
_openSoundStatus = true;
_closeSoundStatus = true;
_startRecordStatus = true;
_stopRecordStatus = true;
StateHasChanged();
return Task.CompletedTask;
}
Expand Down

This file was deleted.

Loading