feat: 添加二维码扫描页面,优化用户界面和扫描功能

This commit is contained in:
2026-01-12 00:44:42 +07:00
parent 4902a155a1
commit 8a7af3783b
4 changed files with 57 additions and 12 deletions

View File

@@ -0,0 +1,49 @@
<script lang='ts' setup>
import { toastController } from "@ionic/vue";
const router = useRouter();
const scanner = useTemplateRef<InstanceType<typeof QrScanner>>("scanner");
function handleSuccess(value: string) {
toastController.create({
message: String(value),
duration: 2000,
position: "bottom",
color: "success",
}).then(toast => toast.present());
}
function handleError(error: Error) {
toastController.create({
message: `扫描失败: ${error.message}`,
duration: 2000,
position: "bottom",
color: "danger",
}).then(toast => toast.present());
}
function handleClose() {
if (window.history.length > 1) {
router.back();
}
else {
router.replace("/");
}
}
onMounted(() => {
scanner.value?.start();
});
onBeforeRouteLeave(() => {
scanner.value?.stop();
});
</script>
<template>
<ion-page>
<QrScanner ref="scanner" @success="handleSuccess" @error="handleError" @close="handleClose" />
</ion-page>
</template>
<style lang='css' scoped></style>

View File

@@ -12,9 +12,9 @@ import TradeSettings from "./components/trade-settings.vue";
import UserInfo from "./components/user-info.vue";
import WalletCard from "./components/wallet-card.vue";
const router = useRouter();
const { vibrate } = useHaptics();
const walletStore = useWalletStore();
const { open } = useQRScanner();
async function handleRefresh(event: RefresherCustomEvent) {
vibrate();
@@ -27,15 +27,7 @@ async function handleRefresh(event: RefresherCustomEvent) {
// 处理扫描二维码
async function handleScan() {
vibrate();
const result = await open({
title: "扫描二维码",
});
if (result) {
console.log("扫描结果:", result);
// TODO: 根据扫描结果进行相应处理
// 例如:跳转到对应页面、显示信息等
}
router.push("/scan_qr");
}
</script>