This commit is contained in:
zjf committed 2026-08-03 23:47:44 +08:00
1 parent 8fc5b51705
commit e1365d6850
2 files changed
+83 -16

No files matched your search

+71 -16
View File
@@ -1,10 +1,13 @@
<script setup lang="ts">
/**
* 门户壳「扫一扫」落地页(非 tabBar,进入即调起扫码)
* 扫码 / 结果处理与「我的」页同一套 useScanCode
* 门户壳扫一扫:
* 1)已登录 → 直接调起扫码
* 2)未登录 → 先自动登录(诗画/浙政钉),成功后再扫
* 3)取消扫码 / 失败 → 一次退回门户首页(returnUrl),避免连点两次
*/
import { onLoad } from "@dcloudio/uni-app"
import { hooks } from "@@/index"
import { ensureBizLogin } from "@@/utils/request"
const actModalShow = (_payload: { cancelId: string }) => {
uni.showToast({ title: "请到「我的」中核销活动码", icon: "none" })
@@ -13,16 +16,51 @@ const actModalShow = (_payload: { cancelId: string }) => {
const { scanCodeAction, processUrlScanResult, processBase64ScanResult } = hooks.useScanCode(actModalShow)
let returnUrl = ""
function readReturnUrl(options?: Record<string, string | undefined>): string {
const raw = (options?.returnUrl || "").trim()
if (raw) {
try {
return decodeURIComponent(raw)
} catch {
return raw
}
}
if (typeof window !== "undefined") {
const hash = window.location.hash || ""
const qi = hash.indexOf("?")
if (qi >= 0) {
const v = new URLSearchParams(hash.slice(qi + 1)).get("returnUrl")
if (v) {
try {
return decodeURIComponent(v)
} catch {
return v
}
}
}
}
return ""
}
/** 退回 zzdhome 首页;有 returnUrl 则整页跳,避免 navigateBack 无历史要按两次 */
function backToPortal() {
if (returnUrl && typeof window !== "undefined") {
window.location.replace(returnUrl)
return
}
uni.navigateBack({
fail: () => uni.switchTab({ url: "/pages/tabbar/my" }),
})
}
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)
uni.showToast({ title: "已取消扫码", icon: "none" })
setTimeout(() => backToPortal(), 300)
return
}
if (scanResult.startsWith("http")) {
@@ -33,24 +71,34 @@ const runScan = async () => {
} catch (e) {
console.warn("[portalScan] runScan", e)
uni.showToast({ title: "扫码异常", icon: "none" })
setTimeout(() => {
uni.navigateBack({
fail: () => uni.switchTab({ url: "/pages/tabbar/my" }),
})
}, 500)
setTimeout(() => backToPortal(), 400)
}
}
onLoad(() => {
setTimeout(() => {
onLoad((options?: Record<string, string | undefined>) => {
returnUrl = readReturnUrl(options)
setTimeout(async () => {
uni.showLoading({ title: "请稍候...", mask: true })
let ok = false
try {
ok = await ensureBizLogin()
} finally {
uni.hideLoading()
}
if (!ok) {
uni.showToast({ title: "请先登录后再扫码付款", icon: "none", duration: 2500 })
setTimeout(() => backToPortal(), 800)
return
}
void runScan()
}, 250)
}, 200)
})
</script>
<template>
<view class="wrap">
<text class="tip">正在打开扫一扫…</text>
<view class="back" @tap="backToPortal">返回首页</view>
</view>
</template>
@@ -58,12 +106,19 @@ onLoad(() => {
.wrap {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 24px;
background: #f5f5f5;
}
.tip {
font-size: 14px;
color: #666;
}
.back {
font-size: 14px;
color: #0094ff;
padding: 8px 16px;
}
</style>
+12
View File
@@ -374,6 +374,18 @@ async function loginBySh(): Promise<boolean> {
}
}
/**
* 门户扫一扫等:有有效 token 直接过;否则按环境自动登录(诗画/浙政钉)。
* 与「我的」里先登录再扫码一致,保证后续支付接口带用户身份。
*/
export async function ensureBizLogin(): Promise<boolean> {
const tokenStorage = uni.getStorageSync(TOKEN_KEY)
if (!isEmpty(tokenStorage) && !isTokenExpires(tokenStorage) && getTokenValue(tokenStorage)) {
return true
}
return await autoLogin()
}
// 请求函数
const request = (config: any) => {
return https.middleware(config)