refactor: 重命名 QRScanner 函数,统一调用方式
This commit is contained in:
@@ -18,17 +18,17 @@ export function useQRScanner() {
|
|||||||
const { vibrate } = useHaptics();
|
const { vibrate } = useHaptics();
|
||||||
const isSupported = Capacitor.isNativePlatform();
|
const isSupported = Capacitor.isNativePlatform();
|
||||||
|
|
||||||
const showError = async (message: string) => {
|
async function showError(message: string) {
|
||||||
const toast = await toastController.create({
|
const toast = await toastController.create({
|
||||||
message,
|
message,
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
position: "top",
|
position: "bottom",
|
||||||
color: "danger",
|
color: "danger",
|
||||||
});
|
});
|
||||||
await toast.present();
|
await toast.present();
|
||||||
};
|
};
|
||||||
|
|
||||||
const openScanner = async (options?: ScannerOptions): Promise<QRScanResult | null> => {
|
async function open(options?: ScannerOptions): Promise<QRScanResult | null> {
|
||||||
try {
|
try {
|
||||||
if (!isSupported) {
|
if (!isSupported) {
|
||||||
await showError(t("scanner.notSupported"));
|
await showError(t("scanner.notSupported"));
|
||||||
@@ -62,10 +62,10 @@ export function useQRScanner() {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isSupported,
|
isSupported,
|
||||||
openScanner,
|
open,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import WalletCard from "./components/wallet-card.vue";
|
|||||||
|
|
||||||
const { vibrate } = useHaptics();
|
const { vibrate } = useHaptics();
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStore();
|
||||||
const { openScanner } = useQRScanner();
|
const { open } = useQRScanner();
|
||||||
|
|
||||||
async function handleRefresh(event: RefresherCustomEvent) {
|
async function handleRefresh(event: RefresherCustomEvent) {
|
||||||
vibrate();
|
vibrate();
|
||||||
@@ -23,7 +23,7 @@ async function handleRefresh(event: RefresherCustomEvent) {
|
|||||||
// 处理扫描二维码
|
// 处理扫描二维码
|
||||||
async function handleScan() {
|
async function handleScan() {
|
||||||
vibrate();
|
vibrate();
|
||||||
const result = await openScanner({
|
const result = await open({
|
||||||
title: "扫描二维码",
|
title: "扫描二维码",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user