Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwmt committed Oct 7, 2024
1 parent dbe1bd2 commit b037c7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/app/isbn/isbn.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
[(ngModel)]="isbn"
(change)="onScanSuccess($any($event.target).value)"
/>
<zxing-scanner
[formats]="formatsEnabled"
(camerasFound)="onCamerasFound($event)"
(scanSuccess)="onScanSuccess($event)"
(permissionResponse)="onHasPermission($event)"
[autostart]="true"
[device]="selectedDevice"
[videoConstraints]="videoConstraints"
>
/>
</zxing-scanner>

<div (click)="triggerManualFocus()">
<zxing-scanner
[formats]="formatsEnabled"
(camerasFound)="onCamerasFound($event)"
(scanSuccess)="onScanSuccess($event)"
(permissionResponse)="onHasPermission($event)"
[autostart]="true"
[device]="selectedDevice"
[videoConstraints]="videoConstraints"
>
/>
</zxing-scanner>
</div>
<div *ngIf="isbn">
<p>掃描到的 ISBN: {{ isbn }}</p>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/app/isbn/isbn.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export class IsbnComponent implements OnInit {
});
}

triggerManualFocus() {
// 重新啟用相機或觸發新的對焦
this.videoConstraints = {
...this.videoConstraints,
focusMode: 'manual', // 試圖手動觸發
};
}

onCamerasFound(devices: MediaDeviceInfo[]): void {
this.availableDevices = devices;
this.hasDevices = Boolean(devices && devices.length);
Expand Down

0 comments on commit b037c7d

Please sign in to comment.