Files
RentWeAppFront/pages/login/login.vue

210 lines
4.7 KiB
Vue
Raw Normal View History

2025-11-14 11:39:33 +08:00
<template>
2025-11-17 17:30:29 +08:00
<view class="login-page">
<!-- 背景视频 -->
<video
class="bg-video"
src="/static/login.mp4"
autoplay
loop
muted
object-fit="cover"
controls="false"
show-center-play-btn="false"
show-play-btn="false"
show-fullscreen-btn="false"
show-mute-btn="false"
show-status-bar="false"
enable-progress-gesture="false"
/>
2025-11-14 11:39:33 +08:00
2025-11-17 17:30:29 +08:00
<!-- 遮罩层增强可读性 -->
<view class="overlay"></view>
<!-- 背景图 -->
<!-- <image class="bg-img" :src="currentBg" :class="{ fade: isFading }" mode="aspectFill"></image> -->
<!-- 内容层 -->
<view class="login-content">
<view class="title u-font-36 u-m-b-40">
2025-11-14 11:39:33 +08:00
微信授权登录
</view>
<button
2025-11-17 17:30:29 +08:00
class="login-btn"
2025-11-14 11:39:33 +08:00
open-type="getPhoneNumber"
@getphonenumber="onGetPhone"
>
使用微信手机号授权登录
</button>
2025-11-17 17:30:29 +08:00
<view class="privacy-tip u-m-t-30 u-text-center">
登录即同意
<text class="link" @click="goPrivacy('user')">用户协议</text>
<text class="link" @click="goPrivacy('privacy')">隐私政策</text>
</view>
2025-11-14 11:39:33 +08:00
</view>
2025-11-17 17:30:29 +08:00
</view>
2025-11-14 11:39:33 +08:00
</template>
<script>
export default {
2025-11-17 17:30:29 +08:00
data() {
return {
bgImages: [
'/static/loginbg1.jpg',
'/static/loginbg2.jpg'
],
currentIndex: 0,
currentBg: '/static/loginbg1.jpg',
timer: null
}
},
onLoad() {
this.startBgTimer();
},
onUnload() {
clearInterval(this.timer);
},
2025-11-14 11:39:33 +08:00
methods: {
2025-11-17 17:30:29 +08:00
startBgTimer() {
this.timer = setInterval(() => {
this.currentIndex = (this.currentIndex + 1) % this.bgImages.length;
this.currentBg = this.bgImages[this.currentIndex];
}, 2000); // 每 4 秒切换一次
},
2025-11-14 11:39:33 +08:00
onGetPhone(e) {
2025-11-17 17:30:29 +08:00
const { code } = e.detail;
2025-11-14 11:39:33 +08:00
if (!code) {
2025-11-17 17:30:29 +08:00
this.$mytip.toast("授权失败");
return;
2025-11-14 11:39:33 +08:00
}
2025-11-17 17:30:29 +08:00
this.doLogin(code);
2025-11-14 11:39:33 +08:00
},
async doLogin(code) {
2025-11-17 17:30:29 +08:00
uni.showLoading({ title: "登录中...", mask: true });
2025-11-14 11:39:33 +08:00
try {
2025-11-17 17:30:29 +08:00
const authRes = await this.$u.get(`/api/weChatAuth?code=${code}`);
2025-11-14 11:39:33 +08:00
if (!authRes.hasPhone) {
2025-11-17 17:30:29 +08:00
this.showPhoneSelector(authRes.phoneList, authRes.openid);
return;
2025-11-14 11:39:33 +08:00
}
2025-11-17 17:30:29 +08:00
await this.loginWithOpenId(authRes.openid);
2025-11-14 11:39:33 +08:00
} catch (err) {
2025-11-17 17:30:29 +08:00
this.$mytip.toast("登录失败");
uni.switchTab({ url: '/pages/index/index' });
2025-11-14 11:39:33 +08:00
}
},
showPhoneSelector(phoneList, openid) {
2025-11-17 17:30:29 +08:00
this.$emit("choosePhone", { phoneList, openid });
2025-11-14 11:39:33 +08:00
},
async loginWithOpenId(openid) {
2025-11-17 17:30:29 +08:00
const loginRes = await this.$u.post('/api/weChatLoginByOpenId', { openid });
this.$u.vuex('vuex_token', loginRes.token);
this.$u.vuex('vuex_user', loginRes.loginUser);
uni.hideLoading();
uni.switchTab({ url: '/pages/index/index' });
},
goPrivacy(type) {
const url = type === 'user'
? '/pages/privacy/userAgreement'
: '/pages/privacy/privacyPolicy';
uni.navigateTo({ url });
}
}
}
</script>
<style lang="scss" scoped>
.login-page {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
.bg-video {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: -1;
}
.overlay {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
background: rgba(0,0,0,0.3);
z-index:0;
}
.bg-img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
filter: brightness(0.7) blur(2px);
opacity: 1;
transition: opacity 0.5s ease;
}
.bg-img.fade {
opacity: 0;
}
.login-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80%;
max-width: 400rpx;
display: flex;
flex-direction: column;
align-items: center;
z-index: 1;
animation: floatBtn 2s ease-in-out infinite alternate;
2025-11-14 11:39:33 +08:00
2025-11-17 17:30:29 +08:00
.title {
color: #fff;
font-weight: bold;
text-align: center;
}
2025-11-14 11:39:33 +08:00
2025-11-17 17:30:29 +08:00
.login-btn {
width: 100%;
height: 80rpx;
line-height: 80rpx;
font-size: 28rpx;
color: #fff;
border-radius: 40rpx;
background: linear-gradient(90deg, #4CAF50, #07c160);
box-shadow: 0 6rpx 12rpx rgba(0,0,0,0.25);
text-align: center;
margin-top: 20rpx;
}
.privacy-tip {
font-size: 24rpx;
color: #fff;
margin-top: 20rpx;
text-align: center;
.link {
color: #ffd700;
text-decoration: underline;
margin: 0 4rpx;
}
2025-11-14 11:39:33 +08:00
}
}
}
2025-11-17 17:30:29 +08:00
@keyframes floatBtn {
0% { transform: translate(-50%, -50%) translateY(0); }
100% { transform: translate(-50%, -50%) translateY(-10rpx); }
}
</style>