Files
pj_h5_cloud/src/pages/user/portalScan.vue
T
2026-08-03 23:32:38 +08:00

70 lines
1.6 KiB
Vue

<script setup lang="ts">
/**
* 门户壳「扫一扫」落地页(非 tabBar,进入即调起扫码)
* 扫码 / 结果处理与「我的」页同一套 useScanCode
*/
import { onLoad } from "@dcloudio/uni-app"
import { hooks } from "@@/index"
const actModalShow = (_payload: { cancelId: string }) => {
uni.showToast({ title: "请到「我的」中核销活动码", icon: "none" })
uni.switchTab({ url: "/pages/tabbar/my" })
}
const { scanCodeAction, processUrlScanResult, processBase64ScanResult } = hooks.useScanCode(actModalShow)
const runScan = async () => {
try {
const scanResult = await scanCodeAction()
if (!scanResult) {
uni.showToast({ title: "扫码取消或失败", icon: "none" })
setTimeout(() => {
uni.navigateBack({
fail: () => uni.switchTab({ url: "/pages/tabbar/my" }),
})
}, 400)
return
}
if (scanResult.startsWith("http")) {
processUrlScanResult(scanResult.replace("/#", ""))
} else {
processBase64ScanResult(scanResult)
}
} catch (e) {
console.warn("[portalScan] runScan", e)
uni.showToast({ title: "扫码异常", icon: "none" })
setTimeout(() => {
uni.navigateBack({
fail: () => uni.switchTab({ url: "/pages/tabbar/my" }),
})
}, 500)
}
}
onLoad(() => {
setTimeout(() => {
void runScan()
}, 250)
})
</script>
<template>
<view class="wrap">
<text class="tip">正在打开扫一扫…</text>
</view>
</template>
<style scoped>
.wrap {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f5f5f5;
}
.tip {
font-size: 14px;
color: #666;
}
</style>