Files
hhrs/pages/index/index.vue
T
jacobxu666andClaude Fable 5 69a42cd6fc feat:付款码仅放行云闪付免密登录——验证码/未登录点付款码给引导提示
- 免密登录记 loginWay=ysf、验证码登录记 loginWay=sms,纳入账号缓存清理键(换账号不残留)
- 详情页付款码桥就绪后校验登录方式,非 ysf 按登录态弹对应引导,不拉起容器付款码

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-10-26 17:36:00 +08:00

403 lines
13 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<!-- xuchao: 2026-10 首页按 UI 设计稿改版 —— 底部双 Tab 为自定义组件(切图含文字),页面留 tabbar 高度的底衬 -->
<view class="page">
<!-- 顶部头图(整张烘焙切图) -->
<image class="hero" src="/static/hhrs2_hero.png" mode="widthFix"></image>
<!-- 金刚区:图标文字已烘焙进切图,不再代码渲染文字 -->
<view class="kong">
<image class="kong-item" src="/static/hhrs2_kong_venue.png" mode="aspectFit" @click="goPage('/pages/venue/venue')"></image>
<image class="kong-item" src="/static/hhrs2_kong_shop.png" mode="aspectFit" @click="goPage('/pages/discount/discount')"></image>
<image class="kong-item" src="/static/hhrs2_kong_rights.png" mode="aspectFit" @click="goRights()"></image>
<image class="kong-item" src="/static/hhrs2_kong_winner.png" mode="aspectFit" @click="goPage('/pages/winners/winners')"></image>
</view>
<!-- 可领权益包 -->
<view class="card">
<view class="card-head">
<view class="head-left">
<view class="bar"></view>
<text class="head-title">可领权益包</text>
</view>
<text class="head-right">数量有限 先到先得</text>
</view>
<text class="pack-sub">本期已产生10,000份千元权益包·实时公证开奖</text>
<!-- 查询按钮整图切图(含渐变底/礼盒图标/文案),点击打开中奖查询半屏弹层 -->
<image class="btn-query" src="/static/hhrs2_btn_query.png" mode="widthFix" @click="openQuery()"></image>
<!-- 指南轮播:两张图 3 秒自动轮播,图片下方指示点标当前张 -->
<swiper class="guides" :autoplay="true" :interval="3000" :duration="400" circular
indicator-dots indicator-color="rgba(232,84,47,0.25)" indicator-active-color="#E8542F">
<swiper-item @click="goPage('/pages/guide/join')">
<image class="guide-img" src="/static/hhrs2_guide_join.png" mode="aspectFill"></image>
</swiper-item>
<swiper-item @click="goPage('/pages/guide/use')">
<image class="guide-img" src="/static/hhrs2_guide_use.png" mode="aspectFill"></image>
</swiper-item>
</swiper>
</view>
<!-- 怀化社保卡折扣商户:按后台分类取前 4 类,每类前 8 家(2 行 4 列),logo 用商铺 image 字段 -->
<view class="card">
<view class="card-head">
<view class="head-left">
<view class="bar"></view>
<text class="head-title">怀化社保卡折扣商户</text>
</view>
<view class="head-link" @click="goPage('/pages/discount/discount')">
<text>查看全部商户</text>
<view class="chev"></view>
</view>
</view>
<view class="cat" v-for="grp in storeGroups" :key="grp.name">
<view class="cat-head">
<view class="bar bar-sm"></view>
<text class="cat-name">{{ grp.name }}</text>
</view>
<view class="mer-row">
<view class="mer-item" v-for="s in grp.stores" :key="s.shopId" @click="goStore(s)">
<image class="mer-logo" :src="s.image" mode="aspectFill"></image>
<text class="mer-name">{{ s.name }}</text>
</view>
</view>
</view>
</view>
<hhrs-tabbar current="home"></hhrs-tabbar>
<!-- xuchao: 「查询我的中奖结果」半屏弹层 -->
<hhrs-winner-sheet :visible="queryVisible" @close="queryVisible = false"></hhrs-winner-sheet>
</view>
</template>
<script>
import account from '@/common/account.js'
import HhrsTabbar from '@/components/hhrs-tabbar/hhrs-tabbar.vue'
import HhrsWinnerSheet from '@/components/hhrs-winner-sheet/hhrs-winner-sheet.vue'
export default {
components: { HhrsTabbar, HhrsWinnerSheet },
data() {
return {
storeGroups: [],
queryVisible: false,
// xuchao: 云闪付免密登录是否仍在进行中 —— 返回前不放行任何依赖身份的跳转
tokenLoginPending: false,
tokenLoginTimer: null
}
},
onLoad(options) {
// xuchao: 云闪付入口带 token 进来 —— 直接免密换取会话,不经过手机号验证码
if (options.token) {
this.handleTokenLogin(options.token)
}
// xuchao: 登录页 redirect=query 回跳时自动弹出中奖查询层
if (options.openQuery) {
this.queryVisible = true
}
this.getLocation()
this.loadStores()
},
// xuchao: 离开首页时收尾,避免看门狗与遮罩残留
onUnload() {
this.finishTokenLogin()
},
methods: {
// xuchao: 首页商户板块按分类面板数量降序取前 4 类,每类取列表里前 8 家(2 行 4 列),与设计稿分组宫格一致
loadStores() {
this.$u.api.getStoreList({ pageNo: 1, pageSize: 60, typeId: 2 }).then(res => {
if (res.errcode !== 0 || !res.data) return
const cats = (res.data.categories || []).filter(c => c.value).slice(0, 4)
const list = res.data.list || []
this.storeGroups = cats.map(c => {
const matched = list.filter(s => s.category === c.value)
// xuchao: 每行 4 个,截成整行数(最少 1 行、最多 2 行),避免最后半行残缺
const rows = Math.max(1, Math.min(2, Math.floor(matched.length / 4)))
return { name: c.value, stores: matched.slice(0, rows * 4) }
}).filter(g => g.stores.length)
})
},
// xuchao: 云闪付入口 token 自动登录(免密换人)
handleTokenLogin(token) {
// xuchao: 云闪付入口是"免密换人",本机上一个账号的会话与权益缓存必须先丢弃:
// 一是请求不能再带旧 accessToken(后端"会话优先"会把旧账号数据返给新用户),
// 二是权益页只在 onLoad 取一次账号快照、不会自我纠正,所以清缓存必须赶在
// 发请求之前 —— 解码返回前的窗口期里最多读到"未登录",绝不会读到别人的数据
account.clearAccountCache()
this.tokenLoginPending = true
uni.showLoading({ title: '登录中', mask: true })
// xuchao: 兜底看门狗,网络异常时不让遮罩卡死(只收遮罩,不改变登录结果)
this.tokenLoginTimer = setTimeout(() => {
this.finishTokenLogin()
}, 10000)
this.$u.api.tokenDecode({ token }).then(res => {
this.finishTokenLogin()
if (res.errcode === 0 && res.data && res.data.mobile) {
uni.setStorageSync('phone', res.data.mobile)
// xuchao: 后端已为云闪付入口签发会员会话,存下 accessToken,后续接口才认得这个用户。
// 只认"非空字符串":后端字段缺失/为 null 时会被序列化成 {},直接存进缓存
// 就会变成 Bearer [object Object],把所有鉴权接口全打挂
const issued = typeof res.data.accessToken === 'string' ? res.data.accessToken : ''
if (issued) uni.setStorageSync('token', issued)
// xuchao: 标记本次会话为云闪付免密登录——商户详情付款码按此放行
uni.setStorageSync('loginWay', 'ysf')
this.$u.api.getEligibility({ phone: res.data.mobile, identityNo: res.data.idNo || '', name: res.data.name || '' }).then(eRes => {
if (eRes.errcode === 0) {
uni.setStorageSync('isAuth', eRes.data.isAuth)
uni.setStorageSync('hasWin', eRes.data.hasWin)
uni.setStorageSync('cardNumber', eRes.data.cardNumber)
uni.setStorageSync('expiresTime', eRes.data.expiresTime)
}
})
// xuchao: 清除地址栏 token,防止分享泄露
this.clearUrlToken()
} else {
this.degradeToPhoneLogin()
}
}).catch(() => {
this.finishTokenLogin()
this.degradeToPhoneLogin()
})
},
// xuchao: 免密登录收尾(收起遮罩、撤看门狗),成功/失败/超时/离开页面都会走到
finishTokenLogin() {
if (!this.tokenLoginPending) return
this.tokenLoginPending = false
clearTimeout(this.tokenLoginTimer)
this.tokenLoginTimer = null
uni.hideLoading()
},
// xuchao: 解码失败兜底,提示并跳手机号登录
degradeToPhoneLogin() {
uni.showToast({ title: '登录凭证已失效,请使用手机号登录', icon: 'none' })
setTimeout(() => {
uni.navigateTo({ url: '/pages/index/login' })
}, 800)
},
// xuchao: 从 URL hash 中移除 token 参数
clearUrlToken() {
try {
const hash = window.location.hash || ''
const qIndex = hash.indexOf('?')
if (qIndex === -1) return
const params = new URLSearchParams(hash.substring(qIndex + 1))
if (!params.has('token')) return
params.delete('token')
const rest = params.toString()
const base = hash.substring(0, qIndex)
window.history.replaceState(null, '', rest ? `${base}?${rest}` : base)
} catch (e) {}
},
getLocation() {
import('@/common/location.js').then(module => {
module.default.getLocation().then(({ lng, lat }) => {
console.log('定位成功:', lng, lat)
}).catch(err => {
console.log('定位失败:', err)
})
})
},
goPage(url) {
uni.navigateTo({ url })
},
// xuchao: 「查询我的中奖结果」入口:免密登录中不放行,未登录先去登录并回跳,否则开弹层
openQuery() {
if (this.tokenLoginPending) {
uni.showToast({ title: '正在登录,请稍候', icon: 'none' })
return
}
const phone = uni.getStorageSync('phone')
if (!phone) {
uni.navigateTo({ url: '/pages/index/login?redirect=query' })
return
}
this.queryVisible = true
},
goStore(s) {
// xuchao: 与商户折扣页同款跳转——品牌详情页
uni.navigateTo({ url: '/pages/shop/detail?id=' + s.shopId })
},
goRights() {
// xuchao: 免密登录还没返回时不放行,避免带着空/旧身份进权益页
if (this.tokenLoginPending) {
uni.showToast({ title: '正在登录,请稍候', icon: 'none' })
return
}
const phone = uni.getStorageSync('phone')
if (!phone) {
uni.navigateTo({ url: '/pages/index/login?redirect=rights' })
return
}
const isAuth = uni.getStorageSync('isAuth')
const hasWin = uni.getStorageSync('hasWin')
// xuchao: 最近发起过认证流程(含取消)时忽略旧认证缓存,一律回认证页
const authFlowStarted = uni.getStorageSync('authFlowStarted')
let status = 'auth'
if (isAuth && !authFlowStarted) {
status = hasWin ? 'info' : 'noWin'
}
uni.navigateTo({ url: `/pages/rights/rights?status=${status}` })
}
}
}
</script>
<style>
/* xuchao: 改版后首页底色取设计稿暖米色;底部为自定义 tabbar(128rpx+安全区)留底衬 */
.page {
min-height: 100vh;
background-color: #FDECE2;
padding-bottom: calc(156rpx + env(safe-area-inset-bottom));
}
.hero {
width: 100%;
display: block;
}
/* 金刚区(整图切图 110rpx,含文字);与卡1间距由 80 减半为 40(16+卡 margin-top 24) */
.kong {
display: flex;
justify-content: space-around;
align-items: center;
padding: 10rpx 0 16rpx;
}
.kong-item {
width: 110rpx;
height: 110rpx;
}
/* 白卡通用(设计稿实测:外边距 29、左右内边距 17,内容宽 658 与切图基准一致) */
.card {
background: #FFFFFF;
border-radius: 28rpx;
margin: 24rpx 29rpx 0;
padding: 24rpx 17rpx;
}
.card-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.head-left {
display: flex;
align-items: center;
}
.bar {
width: 8rpx;
height: 34rpx;
border-radius: 4rpx;
background: linear-gradient(180deg, #F6613C, #E01818);
margin-right: 14rpx;
}
.head-title {
font-size: 34rpx;
font-weight: bold;
color: #333333;
}
.head-right {
font-size: 24rpx;
color: #BCAB9A;
}
.head-link {
display: flex;
align-items: center;
font-size: 26rpx;
font-weight: 600;
color: #E0342B;
}
.chev {
width: 12rpx;
height: 12rpx;
border-top: 3rpx solid #E0342B;
border-right: 3rpx solid #E0342B;
transform: rotate(45deg);
margin-left: 8rpx;
}
/* 可领权益包(切图 @1500 基准,显示 px÷2:按钮 658×102、指南卡 571×141) */
.pack-sub {
display: block;
margin-top: 22rpx;
font-size: 26rpx;
color: #E05A38;
}
.btn-query {
display: block;
width: 100%;
margin-top: 26rpx;
}
/* xuchao: 指南轮播 swiper —— 图 648x200(切图 1297x400÷2),指示点浮于图片内侧 */
.guides {
margin-top: 26rpx;
height: 200rpx;
}
/* xuchao: uni-app H5 把页面样式编成 scoped,swiper 内部元素无 data-v 属性,必须 /deep/ 穿透;
容器高=图高时 bottom 即点距图底距离,3px ≈ 原默认位置(压出图外3px)上移 6px 且完全在图内 */
.guides /deep/ .uni-swiper-dots-horizontal {
bottom: 3px !important;
}
.guide-img {
display: block;
width: 648rpx;
height: 200rpx;
border-radius: 24rpx;
margin: 0 auto;
}
/* 折扣商户 */
.cat {
margin-top: 28rpx;
}
.cat-head {
display: flex;
align-items: center;
}
.bar-sm {
width: 6rpx;
height: 26rpx;
border-radius: 3rpx;
margin-right: 12rpx;
/* xuchao: 折扣商户二级标题标记色,按 UI 要求统一琥珀金 */
background: #E79A30;
}
.cat-name {
font-size: 30rpx;
font-weight: bold;
color: #333333;
}
.mer-row {
display: flex;
flex-wrap: wrap;
margin-top: 24rpx;
}
.mer-item {
width: 25%;
box-sizing: border-box;
padding: 0 8rpx;
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 30rpx;
}
.mer-logo {
width: 96rpx;
height: 96rpx;
border-radius: 16rpx;
background: #F5F5F5;
}
.mer-name {
width: 100%;
text-align: center;
font-size: 22rpx;
color: #4A3A2E;
margin-top: 12rpx;
line-height: 30rpx;
height: 60rpx;
/* xuchao: 设计稿店名可折两行,固定两行高度保证宫格对齐 */
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
</style>