Skip to content

Commit a7f8a93

Browse files
committed
feat: 增加下载功能
1 parent ac070e8 commit a7f8a93

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/components/BootstrapBlazor.HikVision/Components/HikVisionWebPlugin.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public async Task CapturePictureAndDownload()
324324
{
325325
if (IsLogin && IsRealPlaying)
326326
{
327-
var stream = await InvokeAsync<IJSStreamReference?>("capturePictureAndDownload", Id);
327+
await InvokeVoidAsync("capturePictureAndDownload", Id);
328328
}
329329
}
330330

src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,19 @@ export async function setVolume(id, value) {
410410
}
411411

412412
export async function capturePicture(id) {
413-
const vision = Data.get(id);
414-
const { iWndIndex, realPlaying, invoke } = vision;
413+
const vision = Data.get(id);
414+
const { realPlaying } = vision;
415415

416416
if (realPlaying !== true) {
417417
return "";
418418
}
419419

420420
try {
421421
const base64 = await WebVideoCtrl.I_CapturePicData();
422-
const bytes = base64ToArray(base64);
423-
return DotNet.createJSStreamReference(bytes.buffer);
422+
if (base64) {
423+
const bytes = base64ToArray(base64);
424+
return DotNet.createJSStreamReference(bytes.buffer);
425+
}
424426
}
425427
catch (ex) {
426428
return null;
@@ -440,21 +442,27 @@ const base64ToArray = base64String => {
440442
return bytes;
441443
}
442444

443-
export function capturePictureAndDownload(id) {
445+
export async function capturePictureAndDownload(id) {
444446
const vision = Data.get(id);
445-
const { iWndIndex, realPlaying, invoke } = vision;
447+
const { realPlaying } = vision;
446448

447449
if (realPlaying !== true) {
448-
return "";
450+
return;
449451
}
450452

451453
try {
452454
const base64 = await WebVideoCtrl.I_CapturePicData();
453-
const bytes = base64ToArray(base64);
454-
return DotNet.createJSStreamReference(bytes.buffer);
455+
if (base64) {
456+
const anchorElement = document.createElement('a');
457+
anchorElement.href = `data:image/jpg;base64,${base64}`;
458+
anchorElement.download = `capture_${new Date().getTime()}.jpg`;
459+
document.body.appendChild(anchorElement);
460+
anchorElement.click();
461+
document.body.removeChild(anchorElement);
462+
}
455463
}
456464
catch (ex) {
457-
return null;
465+
458466
}
459467
}
460468

0 commit comments

Comments
 (0)