feat: 接入三tab导航(首页/中奖记录/我的)、活动规则静态页、奖品详情弹窗;接口切换hnlylaw并透传authorization;缓存键统一Sft后缀;问卷ID切1005;注册增加收货地址;答题计时精确到0.01s及交互优化

This commit is contained in:
lcj
2026-10-30 09:47:31 +08:00
parent 305e22ddc5
commit ead48745c2
21 changed files with 1583 additions and 273 deletions
+151 -42
View File
@@ -1,14 +1,35 @@
<template>
<view>
<image src="https://aliyunoss.hn12301.net/learnlaw/xfsp_p_bj.jpg" style="width: 750rpx;" mode="widthFix"></image>
<view style="position: absolute;top: 1210rpx;width: 300rpx;left: 225rpx;height: 80rpx;" @click="goRegister"></view>
<view class="side-tab" style="top: 350rpx;" hover-class="side-tab-hover" @click="goRecords">答题记录</view>
<view class="side-tab" style="top: 430rpx;" hover-class="side-tab-hover" @click="goRules">活动规则</view>
<image src="https://aliyunoss.hn12301.net/learnlaw/xfhm_bj.jpg" style="width: 750rpx;" mode="widthFix"></image>
<image src="https://aliyunoss.hn12301.net/learnlaw/xfhm_ckjpxq.png"
style="width: 250rpx;position: absolute;top: 1210rpx;left: 250rpx;" mode="widthFix"
@click="showPrize = true"></image>
<image src="https://aliyunoss.hn12301.net/learnlaw/xfhm_dtcj.png"
style="width: 180rpx;position: absolute;top: 1420rpx;left: 160rpx;" mode="widthFix" @click="goRegister">
</image>
<image src="https://aliyunoss.hn12301.net/learnlaw/xfhm_fzxx.png"
style="width: 180rpx;position: absolute;top: 1420rpx;right: 50rpx;" mode="widthFix" @click="goStudy">
</image>
<view class="side-tab" style="top: 480rpx;" hover-class="side-tab-hover" @click="goRules">活动规则</view>
<!-- <view style="position: absolute;top: 1210rpx;width: 300rpx;left: 225rpx;height: 80rpx;" @click="goRegister"></view> -->
<!-- <view class="side-tab" style="top: 350rpx;" hover-class="side-tab-hover" @click="goRecords">答题记录</view>
<view class="side-tab" style="top: 430rpx;" hover-class="side-tab-hover" @click="goRules">活动规则</view> -->
<view class="blocked-mask" v-if="blocked">
<text class="blocked-tip">{{ blockTip }}</text>
<text class="blocked-sub">本活动仅支持手机微信访问</text>
</view>
<u-tabbar :list="tabbarList" :hideTabBar="true" activeColor="#FD5401" inactiveColor="#5D533D" :borderTop="false"
height="120rpx" iconSize="48"></u-tabbar>
<view class="prize-mask" v-if="showPrize" @click="showPrize = false"></view>
<view class="prize-popup" v-if="showPrize">
<scroll-view scroll-y class="prize-scroll">
<image src="https://aliyunoss.hn12301.net/learnlaw/xfhm_main_jp.jpg" mode="widthFix" style="width: 100%;"></image>
</scroll-view>
<view class="prize-close" @click="showPrize = false">
<text class="prize-close-text">✕</text>
</view>
</view>
</view>
</template>
@@ -20,7 +41,13 @@
data() {
return {
blocked: false,
blockTip: ''
blockTip: '',
showPrize: false,
tabbarList: [
{ pagePath: "/pages/index/index", iconPath: "/static/shouye.png", selectedIconPath: "/static/shouye_select.png", text: "首页" },
{ pagePath: "/pages/win-records/win-records", iconPath: "/static/zhongjiangjilu.png", selectedIconPath: "/static/zhongjiangjilu_select.png", text: "中奖记录" },
{ pagePath: "/pages/profile/profile", iconPath: "/static/wode.png", selectedIconPath: "/static/wode_select.png", text: "我的" }
]
}
},
onLoad() {
@@ -33,34 +60,39 @@
},
onShow() {
if (this.blocked) return
const openId = uni.getStorageSync('openId')
const isRegistered = uni.getStorageSync('isRegistered')
const userId = uni.getStorageSync('userId')
const openId = uni.getStorageSync('openIdSft')
const isRegistered = uni.getStorageSync('isRegisteredSft')
const userId = uni.getStorageSync('userIdSft')
if (openId && (!isRegistered || !userId)) {
this.loginWithOpenId(openId)
}
},
methods: {
goStudy() {
uni.navigateTo({
url: '/pages/study/preview'
})
},
initLogin() {
if (!this.isWechatBrowser()) {
this.block('请在微信中打开')
return
}
if (this.isPcWechat()) {
this.block('请使用手机微信打开')
return
}
let openId = uni.getStorageSync('openId')
// if (!this.isWechatBrowser()) {
// this.block('请在微信中打开')
// return
// }
// if (this.isPcWechat()) {
// this.block('请使用手机微信打开')
// return
// }
let openId = uni.getStorageSync('openIdSft')
if (openId) {
this.loginWithOpenId(openId)
return
}
const code = this.getCodeFromUrl()
if (code) {
this.exchangeOpenId(code)
} else {
this.wechatAuth()
}
// if (code) {
// this.exchangeOpenId(code)
// } else {
// this.wechatAuth()
// }
},
block(tip) {
this.blocked = true
@@ -82,29 +114,33 @@
window.history.replaceState({}, '', cleanUrl)
},
wechatAuth() {
const redirectUri = encodeURIComponent(window.location.href.split('?')[0].split('#')[0])
const base = window.location.href.split('#')[0].split('?')[0]
const redirectUri = encodeURIComponent(base + '#/pages/index/index')
const url =
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${redirectUri}&response_type=code&scope=${SCOPE}&state=STATE#wechat_redirect`
window.location.href = url
},
loginWithOpenId(openId) {
this.$u.api.wxOpenidLogin({ wenjuan_id: 1001, open_id: openId }).then(loginRes => {
this.$u.api.wxOpenidLogin({
wenjuan_id: 1005,
open_id: openId
}).then(loginRes => {
if (!loginRes.Data) {
uni.setStorageSync('isRegistered', false)
uni.setStorageSync('isRegisteredSft', false)
return
}
if (loginRes.code === 0 && loginRes.Data?.user_name && loginRes.Data?.user_phone) {
uni.setStorageSync('isRegistered', true)
uni.setStorageSync('userId', loginRes.Data.user_id)
uni.setStorageSync('userName', loginRes.Data.user_name)
uni.setStorageSync('userPhone', loginRes.Data.user_phone)
uni.setStorageSync('isRegisteredSft', true)
uni.setStorageSync('userIdSft', loginRes.Data.user_id)
uni.setStorageSync('userNameSft', loginRes.Data.user_name)
uni.setStorageSync('userPhoneSft', loginRes.Data.user_phone)
}
}).catch(err => {
console.error('登录请求失败', err)
})
},
goRegister() {
const isRegistered = uni.getStorageSync('isRegistered')
const isRegistered = uni.getStorageSync('isRegisteredSft')
if (isRegistered) {
uni.navigateTo({
url: '/pages/answer/answer'
@@ -115,7 +151,7 @@
url: '/pages/register/register'
})
},
goRecords() {
goRecords() {
uni.navigateTo({
url: '/pages/records/records'
})
@@ -129,17 +165,21 @@ goRecords() {
this.$u.api.getWxOpenId(code).then(res => {
if (res.code !== 0 || !res.Data || !res.Data.openid) return
const openId = res.Data.openid
uni.setStorageSync('openId', openId)
uni.setStorageSync('openIdSft', openId)
this.cleanUrlCode()
return this.$u.api.wxOpenidLogin({ wenjuan_id: 1001, open_id: openId })
return this.$u.api.wxOpenidLogin({
wenjuan_id: 1005,
open_id: openId
})
}).then(loginRes => {
if (loginRes && loginRes.code === 0 && loginRes.Data && loginRes.Data.user_name && loginRes.Data.user_phone) {
uni.setStorageSync('isRegistered', true)
uni.setStorageSync('userId', loginRes.Data.user_id || loginRes.Data.uesr_id)
uni.setStorageSync('userName', loginRes.Data.user_name)
uni.setStorageSync('userPhone', loginRes.Data.user_phone)
if (loginRes && loginRes.code === 0 && loginRes.Data && loginRes.Data.user_name && loginRes
.Data.user_phone) {
uni.setStorageSync('isRegisteredSft', true)
uni.setStorageSync('userIdSft', loginRes.Data.user_id || loginRes.Data.uesr_id)
uni.setStorageSync('userNameSft', loginRes.Data.user_name)
uni.setStorageSync('userPhoneSft', loginRes.Data.user_phone)
} else if (loginRes && !loginRes.Data) {
uni.setStorageSync('isRegistered', false)
uni.setStorageSync('isRegisteredSft', false)
}
}).catch(err => {
console.error('请求失败', err)
@@ -149,11 +189,33 @@ goRecords() {
}
</script>
<style>
page{
<style lang="scss">
page {
background-color: #7CC6EB;
}
::v-deep .u-tabbar__content {
background: linear-gradient(to bottom, #FFEBBC, #FFD67E) !important;
}
::v-deep .u-tabbar__content__item {
background: linear-gradient(to bottom, #FFEBBC, #FFD67E) !important;
}
::v-deep .u-tabbar {
.u-border-top {
border-top: none !important;
}
}
::v-deep .u-icon__img {
object-fit: contain !important;
}
::v-deep .u-tabbar__content__item {
padding: 16rpx 0 !important;
}
.blocked-mask {
position: fixed;
top: 0;
@@ -201,4 +263,51 @@ goRecords() {
.side-tab-hover {
opacity: 0.85;
}
.prize-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 1000;
}
.prize-popup {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 620rpx;
z-index: 1001;
display: flex;
flex-direction: column;
align-items: center;
}
.prize-scroll {
width: 620rpx;
max-height: 75vh;
background: #fff;
border-radius: 24rpx;
overflow: hidden;
}
.prize-close {
width: 64rpx;
height: 64rpx;
border-radius: 50%;
border: 2rpx solid rgba(255, 255, 255, 0.9);
display: flex;
align-items: center;
justify-content: center;
margin-top: 30rpx;
}
.prize-close-text {
font-size: 32rpx;
color: #fff;
line-height: 1;
}
</style>