306 lines
7.6 KiB
Vue
306 lines
7.6 KiB
Vue
<template>
|
||
<view>
|
||
<image src="https://aliyunoss.hn12301.net/learnlaw/xfswj_bj1.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/xfswj_dtcj.png"
|
||
style="width: 340rpx;position: absolute;top: 1250rpx;left: 25rpx;" mode="widthFix" @click="goRegister">
|
||
</image>
|
||
<image src="https://aliyunoss.hn12301.net/learnlaw/xfswj_fzxx.png"
|
||
style="width: 340rpx;position: absolute;top: 1250rpx;right: 25rpx;" mode="widthFix" @click="goStudy">
|
||
</image>
|
||
<view class="side-tab" style="top: 480rpx;" hover-class="side-tab-hover" @click="goRules">活动规则</view>
|
||
<view class="back-home" @click="goHome">
|
||
<text class="back-home-icon">‹</text>
|
||
</view>
|
||
<view class="blocked-mask" v-if="blocked">
|
||
<text class="blocked-tip">{{ blockTip }}</text>
|
||
<text class="blocked-sub">本活动仅支持手机微信访问</text>
|
||
</view>
|
||
<sw-tabbar current="index"></sw-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>
|
||
import swTabbar from '@/components/sw-tabbar/sw-tabbar.vue'
|
||
|
||
const APP_ID = 'wx71c218bd9ff0e2da'
|
||
const SCOPE = 'snsapi_base'
|
||
|
||
export default {
|
||
components: {
|
||
swTabbar
|
||
},
|
||
data() {
|
||
return {
|
||
blocked: false,
|
||
blockTip: '',
|
||
showPrize: false
|
||
}
|
||
},
|
||
onLoad() {
|
||
this.initLogin()
|
||
},
|
||
onShow() {
|
||
if (this.blocked) return
|
||
const openId = uni.getStorageSync('openIdSw')
|
||
const isRegistered = uni.getStorageSync('isRegisteredSw')
|
||
const userId = uni.getStorageSync('userIdSw')
|
||
if (openId && (!isRegistered || !userId)) {
|
||
this.loginWithOpenId(openId)
|
||
}
|
||
},
|
||
methods: {
|
||
goHome() {
|
||
uni.reLaunch({
|
||
url: '/pages/home/home'
|
||
})
|
||
},
|
||
goStudy() {
|
||
uni.navigateTo({
|
||
url: '/pages/sw-study/sw-study'
|
||
})
|
||
},
|
||
initLogin() {
|
||
if (!this.isWechatBrowser()) {
|
||
this.block('请在微信中打开')
|
||
return
|
||
}
|
||
if (this.isPcWechat()) {
|
||
this.block('请使用手机微信打开')
|
||
return
|
||
}
|
||
let openId = uni.getStorageSync('openIdSw')
|
||
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/sw-index/sw-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: 1006,
|
||
open_id: openId
|
||
}).then(loginRes => {
|
||
if (!loginRes.Data) {
|
||
uni.setStorageSync('isRegisteredSw', false)
|
||
return
|
||
}
|
||
if (loginRes.code === 0 && loginRes.Data?.user_name && loginRes.Data?.user_phone) {
|
||
uni.setStorageSync('isRegisteredSw', true)
|
||
uni.setStorageSync('userIdSw', loginRes.Data.user_id)
|
||
uni.setStorageSync('userNameSw', loginRes.Data.user_name)
|
||
uni.setStorageSync('userPhoneSw', loginRes.Data.user_phone)
|
||
}
|
||
}).catch(err => {
|
||
console.error('登录请求失败', err)
|
||
})
|
||
},
|
||
goRegister() {
|
||
const isRegistered = uni.getStorageSync('isRegisteredSw')
|
||
if (isRegistered) {
|
||
uni.navigateTo({
|
||
url: '/pages/sw-answer/sw-answer'
|
||
})
|
||
return
|
||
}
|
||
uni.navigateTo({
|
||
url: '/pages/sw-register/sw-register'
|
||
})
|
||
},
|
||
goRules() {
|
||
uni.navigateTo({
|
||
url: '/pages/sw-rules/sw-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('openIdSw', openId)
|
||
this.cleanUrlCode()
|
||
return this.$u.api.wxOpenidLogin({
|
||
wenjuan_id: 1006,
|
||
open_id: openId
|
||
})
|
||
}).then(loginRes => {
|
||
if (loginRes && loginRes.code === 0 && loginRes.Data && loginRes.Data.user_name && loginRes
|
||
.Data.user_phone) {
|
||
uni.setStorageSync('isRegisteredSw', true)
|
||
uni.setStorageSync('userIdSw', loginRes.Data.user_id || loginRes.Data.uesr_id)
|
||
uni.setStorageSync('userNameSw', loginRes.Data.user_name)
|
||
uni.setStorageSync('userPhoneSw', loginRes.Data.user_phone)
|
||
} else if (loginRes && !loginRes.Data) {
|
||
uni.setStorageSync('isRegisteredSw', false)
|
||
}
|
||
}).catch(err => {
|
||
console.error('请求失败', err)
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
page {
|
||
background-color: #7CC6EB;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.back-home {
|
||
position: fixed;
|
||
left: 20rpx;
|
||
top: 80rpx;
|
||
width: 64rpx;
|
||
height: 64rpx;
|
||
border-radius: 50%;
|
||
background: rgba(0, 0, 0, 0.25);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
z-index: 998;
|
||
}
|
||
|
||
.back-home-icon {
|
||
font-size: 44rpx;
|
||
color: #fff;
|
||
line-height: 1;
|
||
margin-top: -6rpx;
|
||
}
|
||
|
||
.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>
|