HomeLease/pages/login/login.vue

551 lines
13 KiB
Vue
Raw Normal View History

2025-08-12 15:38:25 +08:00
<template>
<view class="login-container">
<view :style="{ top: getNavBarHeight() + 'rpx' }" class="goback" @click="goback">
<uni-icons :size="getTitleBarHeight()" type="left"></uni-icons>
</view>
2025-08-12 15:38:25 +08:00
<view class="logo-section">
<image :src="CommonEnum.LOGIN_SRC" class="logo-image"></image>
</view>
<view class="main-content">
<!-- 登录按钮 -->
<button :disabled="loginLoading" class="login-btn" @click="goToLogin">
2025-08-12 15:38:25 +08:00
<text class="btn-text">{{ loginLoading ? '登录中...' : '微信用户一键登录' }}</text>
</button>
2025-08-12 15:38:25 +08:00
</view>
<!-- 底部协议 -->
<view class="agreement-section">
<view class="agreement-checkbox" @click="toggleAgreement">
2025-08-18 09:42:48 +08:00
<view :class="{ checked: hasAgreed }" class="checkbox">
2025-08-12 15:38:25 +08:00
<text v-if="hasAgreed" class="checkmark"></text>
</view>
</view>
<text class="agreement-text">我已阅读并同意</text>
<text class="agreement-link" @click="showServiceTerms">服务协议</text>
<text class="agreement-text"></text>
<text class="agreement-link" @click="showPrivacyPolicy">隐私政策</text>
</view>
<!-- 服务条款弹窗 -->
<view v-if="showServiceTermsPopup" class="popup-overlay" @click="closeServiceTermsPopup">
<view class="popup-content" @click.stop>
<view class="popup-header">
<text class="popup-title">服务条款</text>
<text class="popup-close" @click="closeServiceTermsPopup">×</text>
</view>
2025-08-13 11:05:40 +08:00
<scroll-view
2025-08-18 09:42:48 +08:00
:scroll-top="scrollTop"
2025-08-13 11:05:40 +08:00
class="popup-body"
scroll-y="true"
show-scrollbar="true"
>
2025-08-12 15:38:25 +08:00
<view class="terms-content">
<rich-text :nodes="serviceTermsContent"></rich-text>
</view>
</scroll-view>
<view class="popup-footer">
<text class="popup-tip">请仔细阅读服务条款阅读完毕后点击同意</text>
<button class="popup-btn" @click="agreeServiceTerms">同意</button>
</view>
</view>
</view>
<!-- 隐私政策弹窗 -->
<view v-if="showPrivacyPolicyPopup" class="popup-overlay" @click="closePrivacyPolicyPopup">
<view class="popup-content" @click.stop>
<view class="popup-header">
<text class="popup-title">隐私政策</text>
<text class="popup-close" @click="closePrivacyPolicyPopup">×</text>
</view>
2025-08-13 11:05:40 +08:00
<scroll-view
2025-08-18 09:42:48 +08:00
:scroll-top="scrollTop"
2025-08-13 11:05:40 +08:00
class="popup-body"
scroll-y="true"
show-scrollbar="true"
>
2025-08-12 15:38:25 +08:00
<view class="terms-content">
<rich-text :nodes="privacyPolicyContent"></rich-text>
</view>
</scroll-view>
<view class="popup-footer">
<text class="popup-tip">请仔细阅读隐私政策阅读完毕后点击同意</text>
<button class="popup-btn" @click="agreePrivacyPolicy">同意</button>
</view>
</view>
</view>
</view>
</template>
<script>
2025-08-13 11:10:19 +08:00
import { wxLogin } from '@/api/auth/auth.js'
import { forceHideLoading, AutoLoadingManager } from '@/utils/request.js'
import { getServiceTerms, getPrivacyPolicy } from '@/api/article/article.js'
import { commonEnum } from '../../enum/commonEnum'
import { getNavBarHeight, getTitleBarHeight } from '../../utils/system'
2025-08-13 11:10:19 +08:00
export default {
data() {
return {
loginLoading: false,
hasAgreed: false,
hasReadServiceTerms: false,
hasReadPrivacyPolicy: false,
showServiceTermsPopup: false,
showPrivacyPolicyPopup: false,
serviceTermsContent: '',
privacyPolicyContent: '',
scrollTop: 0,
2025-08-21 15:07:36 +08:00
agentId: '', // 添加agentId字段
2025-08-13 11:10:19 +08:00
}
},
computed: {
CommonEnum() {
return commonEnum
2025-08-13 11:05:40 +08:00
},
2025-08-13 11:10:19 +08:00
},
2025-08-22 11:47:54 +08:00
onLoad: async function (options) {
if (options && options.q) {
const q = decodeURIComponent(options.q) // 解码二维码链接
console.log('解析后的链接:', q) // 示例: https://wx.ccttiot.com/cf/i/?agentId=63
// 提取agentId参数
const agentId = this.getUrlParam('agentId', q)
if (agentId) {
this.agentId = agentId // 存入实例属性
console.log('成功存入agentId:', this.agentId)
} else {
console.log('获取id失败')
}
}
2025-08-13 11:10:19 +08:00
},
2025-08-22 11:47:54 +08:00
2025-08-13 11:10:19 +08:00
onUnload() {
forceHideLoading()
if (this.pageLoading) {
this.pageLoading.destroy()
}
},
2025-08-13 11:10:19 +08:00
methods: {
throttle() {
return throttle
},
getTitleBarHeight,
getNavBarHeight,
goback() {
uni.navigateBack()
},
getUrlParam(key, url) {
const regex = new RegExp(`[?&]${key}=([^&#]*)`)
const match = url.match(regex)
return match ? decodeURIComponent(match[1]) : null
},
2025-08-13 11:10:19 +08:00
toggleAgreement() {
if (this.hasReadServiceTerms && this.hasReadPrivacyPolicy) {
this.hasAgreed = !this.hasAgreed
} else {
uni.showToast({
title: '请先阅读服务条款和隐私政策',
icon: 'none',
})
2025-08-13 11:05:40 +08:00
}
},
2025-08-13 11:10:19 +08:00
async showServiceTerms() {
try {
const res = await getServiceTerms()
if (res.code === 200 && res.data) {
let content = res.data.content || '暂无服务条款内容'
content = content.replace(/\n/g, '<br/>')
content = `<div style="word-wrap: break-word; word-break: break-all; line-height: 1.8; font-size: 28rpx; color: #333; padding: 0; margin: 0;">${content}</div>`
this.serviceTermsContent = content
this.showServiceTermsPopup = true
this.scrollTop = 0
2025-08-12 15:38:25 +08:00
} else {
uni.showToast({
title: '获取服务条款失败',
2025-08-13 11:05:40 +08:00
icon: 'none',
})
2025-08-12 15:38:25 +08:00
}
2025-08-13 11:10:19 +08:00
} catch (error) {
console.error('获取服务条款失败:', error)
uni.showToast({
title: '获取服务条款失败',
icon: 'none',
})
}
},
async showPrivacyPolicy() {
try {
const res = await getPrivacyPolicy()
if (res.code === 200 && res.data) {
let content = res.data.content || '暂无隐私政策内容'
content = content.replace(/\n/g, '<br/>')
content = `<div style="word-wrap: break-word; word-break: break-all; line-height: 1.8; font-size: 28rpx; color: #333; padding: 0; margin: 0;">${content}</div>`
this.privacyPolicyContent = content
this.showPrivacyPolicyPopup = true
this.scrollTop = 0
} else {
2025-08-12 15:38:25 +08:00
uni.showToast({
title: '获取隐私政策失败',
2025-08-13 11:05:40 +08:00
icon: 'none',
})
2025-08-12 15:38:25 +08:00
}
2025-08-13 11:10:19 +08:00
} catch (error) {
console.error('获取隐私政策失败:', error)
uni.showToast({
title: '获取隐私政策失败',
icon: 'none',
})
}
},
2025-08-12 15:38:25 +08:00
2025-08-13 11:10:19 +08:00
closeServiceTermsPopup() {
this.showServiceTermsPopup = false
},
2025-08-12 15:38:25 +08:00
2025-08-13 11:10:19 +08:00
closePrivacyPolicyPopup() {
this.showPrivacyPolicyPopup = false
},
2025-08-12 15:38:25 +08:00
2025-08-13 11:10:19 +08:00
async agreeServiceTerms() {
this.hasReadServiceTerms = true
this.closeServiceTermsPopup()
this.checkAgreementStatus()
2025-08-12 15:38:25 +08:00
2025-08-13 11:10:19 +08:00
if (!this.hasReadPrivacyPolicy) {
setTimeout(() => {
this.showPrivacyPolicy()
}, 500)
}
},
2025-08-13 11:05:40 +08:00
2025-08-13 11:10:19 +08:00
async agreePrivacyPolicy() {
this.hasReadPrivacyPolicy = true
this.closePrivacyPolicyPopup()
this.checkAgreementStatus()
2025-08-13 11:05:40 +08:00
2025-08-13 11:10:19 +08:00
if (!this.hasReadServiceTerms) {
setTimeout(() => {
this.showServiceTerms()
}, 500)
}
},
2025-08-13 11:05:40 +08:00
2025-08-13 11:10:19 +08:00
checkAgreementStatus() {
if (this.hasReadServiceTerms && this.hasReadPrivacyPolicy) {
this.hasAgreed = true
}
},
2025-08-13 11:05:40 +08:00
2025-08-13 11:10:19 +08:00
async showUnreadTerms() {
if (!this.hasReadServiceTerms) {
await this.showServiceTerms()
return
}
2025-08-13 11:05:40 +08:00
2025-08-13 11:10:19 +08:00
if (!this.hasReadPrivacyPolicy) {
await this.showPrivacyPolicy()
}
},
2025-08-13 11:05:40 +08:00
goToLogin() {
this.$uv.throttle(this.Login, 3000)
},
Login() {
console.log('开始登录流程')
2025-08-13 11:05:40 +08:00
// 显示加载状态
this.pageLoading?.show('登录中...')
uni.showModal({
title: '确认登录',
content: '我已阅读并同意服务协议和隐私政策',
confirmText: '确定登录',
cancelText: '取消',
success: async modalRes => {
if (modalRes.confirm) {
this.hasAgreed = true
try {
// 1. 获取微信登录code
const loginRes = await new Promise((resolve, reject) => {
uni.login({
success: resolve,
fail: reject,
})
})
2025-08-22 11:47:54 +08:00
if (!loginRes.code) {
throw new Error('获取登录code失败')
}
2025-08-13 11:10:19 +08:00
console.log('获取到登录code:', loginRes.code)
console.log('携带的agentId:', this.agentId)
2025-08-13 11:10:19 +08:00
// 2. 调用登录接口
const loginData = {
loginCode: loginRes.code,
agentId: this.agentId,
}
const res = await wxLogin(loginData)
if (res.code === 200) {
console.log('登录成功:', res)
uni.setStorageSync('token', res.token)
2025-08-13 11:10:19 +08:00
uni.showToast({
title: '登录成功',
icon: 'success',
duration: 1500,
complete: () => {
uni.switchTab({
url: '/pages/index/index',
})
},
2025-08-13 11:05:40 +08:00
})
} else {
throw new Error(res.msg || '登录失败')
}
} catch (error) {
console.error('登录流程出错:', error)
uni.showToast({
title: error.message || '登录失败',
icon: 'none',
2025-08-13 11:10:19 +08:00
})
} finally {
this.pageLoading?.hide()
forceHideLoading()
}
2025-08-13 11:10:19 +08:00
}
},
fail: err => {
console.error('弹窗操作失败:', err)
this.pageLoading?.hide()
2025-08-13 11:10:19 +08:00
},
})
},
},
}
2025-08-12 15:38:25 +08:00
</script>
2025-08-18 09:42:48 +08:00
<style lang="scss" scoped>
2025-08-13 11:10:19 +08:00
page {
position: relative;
2025-08-13 11:10:19 +08:00
background: #ffffff;
}
.goback {
color: #e80a0a;
position: absolute;
left: 20rpx;
}
2025-08-13 11:10:19 +08:00
.login-container {
padding-bottom: 40rpx;
max-width: 750rpx;
background: #ffffff;
}
.logo-section {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-bottom: 80rpx;
width: 100%;
margin-top: 330rpx;
//border:green 1px solid;
}
.logo-image {
width: 276rpx;
height: 276rpx;
}
2025-08-13 11:10:19 +08:00
.main-content {
padding: 0 53rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 654rpx;
//border: red 1px solid;
}
.login-btn {
width: 100%;
height: 98rpx;
background: #f15a04;
border-radius: 10rpx;
border: none;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
box-shadow: 0 4rpx 12rpx rgba(255, 107, 53, 0.3);
}
.login-btn:active {
transform: translateY(2rpx);
box-shadow: 0 2rpx 8rpx rgba(255, 107, 53, 0.3);
}
.login-btn:disabled {
background: #ccc;
box-shadow: none;
}
.btn-text {
font-size: 32rpx;
font-weight: 600;
color: #fff;
}
.agreement-section {
display: flex;
align-items: center;
justify-content: center;
gap: 8rpx;
padding: 30rpx;
margin-top: 40rpx;
flex-wrap: wrap;
}
.agreement-checkbox {
display: flex;
align-items: center;
}
.checkbox {
width: 28rpx;
height: 28rpx;
border: 2rpx solid #ff6b35;
border-radius: 6rpx;
display: flex;
align-items: center;
justify-content: center;
background: #fff;
transition: all 0.3s ease;
}
.checkbox.checked {
background: #ff6b35;
border-color: #ff6b35;
}
.checkmark {
color: #fff;
font-size: 18rpx;
font-weight: bold;
}
.agreement-text {
font-size: 24rpx;
color: #666;
}
.agreement-link {
font-size: 24rpx;
color: #ff6b35;
text-decoration: underline;
}
.popup-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
padding: 40rpx;
box-sizing: border-box;
}
.popup-content {
background: #fff;
border-radius: 20rpx;
overflow: hidden;
display: flex;
flex-direction: column;
width: 100%;
max-width: 680rpx;
height: 85vh;
max-height: 900rpx;
min-height: 600rpx;
margin: 0;
}
.popup-header {
padding: 30rpx;
border-bottom: 1rpx solid #eee;
display: flex;
align-items: center;
justify-content: space-between;
flex-shrink: 0;
}
.popup-title {
font-size: 32rpx;
font-weight: 500;
color: #333;
}
.popup-close {
font-size: 40rpx;
color: #999;
cursor: pointer;
padding: 10rpx;
}
.popup-body {
flex: 1;
2025-08-19 16:02:13 +08:00
2025-08-13 11:10:19 +08:00
overflow: hidden;
position: relative;
height: 0;
}
.terms-content {
2025-08-19 16:02:13 +08:00
padding: 20rpx;
2025-08-13 11:10:19 +08:00
line-height: 1.8;
font-size: 28rpx;
color: #333;
word-wrap: break-word;
word-break: break-all;
}
.popup-footer {
padding: 30rpx;
border-top: 1rpx solid #eee;
display: flex;
flex-direction: column;
align-items: center;
flex-shrink: 0;
}
.popup-tip {
font-size: 24rpx;
color: #999;
margin-bottom: 20rpx;
text-align: center;
}
.popup-btn {
width: 200rpx;
height: 70rpx;
2025-08-19 16:02:13 +08:00
background: #f15a04;
2025-08-13 11:10:19 +08:00
border-radius: 35rpx;
font-size: 28rpx;
color: #ffffff;
border: none;
}
2025-08-13 11:05:40 +08:00
</style>