Files
llpreheat/pages/index/index.vue
T

313 lines
8.6 KiB
Vue

<template>
<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>
<script>
const APP_ID = 'wx71c218bd9ff0e2da'
const SCOPE = 'snsapi_base'
export default {
data() {
return {
blocked: false,
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() {
// if (new Date().getTime() < new Date('2026/09/02 10:00:00')) {
// uni.redirectTo({
// url:'/pages/jqqd/jqqd'
// })
// }
this.initLogin()
},
onShow() {
if (this.blocked) return
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('openIdSft')
if (openId) {
this.loginWithOpenId(openId)
return
}
const code = this.getCodeFromUrl()
// if (code) {
// this.exchangeOpenId(code)
// } else {
// this.wechatAuth()
// }
},
block(tip) {
this.blocked = true
this.blockTip = tip
},
isWechatBrowser() {
return /MicroMessenger/i.test(navigator.userAgent)
},
isPcWechat() {
return /MicroMessenger/i.test(navigator.userAgent) && /WindowsWechat|MacWechat/i.test(navigator.userAgent)
},
getCodeFromUrl() {
const match = window.location.href.match(/[?&]code=([^&#]+)/)
return match ? match[1] : null
},
cleanUrlCode() {
const cleanUrl = window.location.href.replace(/[?&]code=[^&#]*(&|#|$)/, (m, p1) => p1 === '&' ? '?' : (
p1 === '#' ? '#' : ''))
window.history.replaceState({}, '', cleanUrl)
},
wechatAuth() {
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: 1005,
open_id: openId
}).then(loginRes => {
if (!loginRes.Data) {
uni.setStorageSync('isRegisteredSft', false)
return
}
if (loginRes.code === 0 && loginRes.Data?.user_name && 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('isRegisteredSft')
if (isRegistered) {
uni.navigateTo({
url: '/pages/answer/answer'
})
return
}
uni.navigateTo({
url: '/pages/register/register'
})
},
goRecords() {
uni.navigateTo({
url: '/pages/records/records'
})
},
goRules() {
uni.navigateTo({
url: '/pages/rules/rules'
})
},
exchangeOpenId(code) {
this.$u.api.getWxOpenId(code).then(res => {
if (res.code !== 0 || !res.Data || !res.Data.openid) return
const openId = res.Data.openid
uni.setStorageSync('openIdSft', openId)
this.cleanUrlCode()
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('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('isRegisteredSft', false)
}
}).catch(err => {
console.error('请求失败', err)
})
}
}
}
</script>
<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;
left: 0;
right: 0;
bottom: 0;
z-index: 999;
background-color: #7CC6EB;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.blocked-tip {
font-size: 36rpx;
font-weight: 600;
color: #fff;
}
.blocked-sub {
font-size: 26rpx;
color: rgba(255, 255, 255, 0.85);
margin-top: 16rpx;
}
.side-tab {
position: absolute;
right: 0;
width: 160rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 30rpx 0 0 30rpx;
background: linear-gradient(135deg, #FD5401, #FF8A3D);
color: #fff;
font-size: 24rpx;
font-weight: 600;
letter-spacing: 2rpx;
border-left: 6rpx solid rgba(255, 255, 255, 0.65);
box-shadow: 0 6rpx 16rpx rgba(253, 84, 1, 0.35);
}
.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>