feat: 集成二维码扫描功能,优化视频流处理,添加 vconsole 和 SSL 插件

This commit is contained in:
2026-01-08 15:23:25 +07:00
parent 08939bec64
commit 04a5beed89
9 changed files with 108 additions and 371 deletions

View File

@@ -1,5 +1,4 @@
import { CapacitorBarcodeScanner } from "@capacitor/barcode-scanner";
import { Capacitor } from "@capacitor/core";
import { CapacitorBarcodeScanner, CapacitorBarcodeScannerCameraDirection, CapacitorBarcodeScannerTypeHint } from "@capacitor/barcode-scanner";
import { toastController } from "@ionic/vue";
export interface QRScanResult {
@@ -16,56 +15,41 @@ export interface ScannerOptions {
export function useQRScanner() {
const { t } = useI18n();
const { vibrate } = useHaptics();
const isSupported = Capacitor.isNativePlatform();
async function showError(message: string) {
const toast = await toastController.create({
message,
duration: 2000,
position: "bottom",
color: "danger",
});
await toast.present();
};
async function open(options?: ScannerOptions): Promise<QRScanResult | null> {
async function open(options?: ScannerOptions) {
try {
if (!isSupported) {
await showError(t("scanner.notSupported"));
return null;
}
vibrate();
const result = await CapacitorBarcodeScanner.scanBarcode({
hint: 0,
hint: CapacitorBarcodeScannerTypeHint.QR_CODE,
scanInstructions: options?.title || t("scanner.hint"),
cameraDirection: 1,
cameraDirection: CapacitorBarcodeScannerCameraDirection.BACK,
});
if (result.ScanResult) {
vibrate();
return {
text: result.ScanResult,
format: result.format?.toString() || "UNKNOWN",
rawValue: result.ScanResult,
displayValue: result.ScanResult,
};
}
return null;
vibrate();
return {
text: result.ScanResult,
format: result.format,
};
}
catch (error: any) {
console.log("error.message", error.message);
if (error.code !== "OS-PLUG-BARC-0006") {
await showError(t("scanner.openError"));
const toast = await toastController.create({
message: t("scanner.openError"),
duration: 2000,
position: "bottom",
color: "danger",
});
await toast.present();
}
return null;
}
}
function close() {
}
return {
isSupported,
open,
close,
};
}