add弹窗登录
This commit is contained in:
@@ -265,6 +265,7 @@
|
|||||||
<!-- 支付组件 -->
|
<!-- 支付组件 -->
|
||||||
<Payment v-model="showPayment" :data="featureData" :id="queryId" type="query" @close="showPayment = false" />
|
<Payment v-model="showPayment" :data="featureData" :id="queryId" type="query" @close="showPayment = false" />
|
||||||
<BindPhoneDialog @bind-success="handleBindSuccess" />
|
<BindPhoneDialog @bind-success="handleBindSuccess" />
|
||||||
|
<LoginDialog @login-success="handleLoginSuccess" />
|
||||||
|
|
||||||
<!-- 历史查询按钮 - 仅推广查询显示 -->
|
<!-- 历史查询按钮 - 仅推广查询显示 -->
|
||||||
<div v-if="props.type === 'promotion'" @click="toHistory"
|
<div v-if="props.type === 'promotion'" @click="toHistory"
|
||||||
@@ -285,6 +286,7 @@ import { showConfirmDialog } from "vant";
|
|||||||
|
|
||||||
import Payment from "@/components/Payment.vue";
|
import Payment from "@/components/Payment.vue";
|
||||||
import BindPhoneDialog from "@/components/BindPhoneDialog.vue";
|
import BindPhoneDialog from "@/components/BindPhoneDialog.vue";
|
||||||
|
import LoginDialog from "@/components/LoginDialog.vue";
|
||||||
import SectionTitle from "@/components/SectionTitle.vue";
|
import SectionTitle from "@/components/SectionTitle.vue";
|
||||||
|
|
||||||
// Props
|
// Props
|
||||||
@@ -504,19 +506,27 @@ function handleBindSuccess() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理登录成功的回调
|
||||||
|
function handleLoginSuccess() {
|
||||||
|
if (pendingPayment.value) {
|
||||||
|
pendingPayment.value = false;
|
||||||
|
submitRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 处理输入框点击事件
|
// 处理输入框点击事件
|
||||||
const handleInputClick = async () => {
|
const handleInputClick = async () => {
|
||||||
if (!isLoggedIn.value) {
|
if (!isLoggedIn.value) {
|
||||||
// 非微信浏览器环境:未登录用户提示跳转到登录页
|
// 非微信浏览器环境:未登录用户提示打开登录弹窗
|
||||||
if (!isWeChat.value) {
|
if (!isWeChat.value) {
|
||||||
try {
|
try {
|
||||||
await showConfirmDialog({
|
await showConfirmDialog({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
message: '您需要登录后才能进行查询,是否前往登录?',
|
message: '您需要登录后才能进行查询,是否立即登录?',
|
||||||
confirmButtonText: '前往登录',
|
confirmButtonText: '立即登录',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
});
|
});
|
||||||
router.push('/login');
|
dialogStore.openLogin();
|
||||||
} catch {
|
} catch {
|
||||||
// 用户点击取消,什么都不做
|
// 用户点击取消,什么都不做
|
||||||
}
|
}
|
||||||
@@ -532,7 +542,7 @@ const handleInputClick = async () => {
|
|||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
// 非微信浏览器环境:检查登录状态
|
// 非微信浏览器环境:检查登录状态
|
||||||
if (!isWeChat.value && !isLoggedIn.value) {
|
if (!isWeChat.value && !isLoggedIn.value) {
|
||||||
router.push('/login');
|
dialogStore.openLogin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
321
src/components/LoginDialog.vue
Normal file
321
src/components/LoginDialog.vue
Normal file
@@ -0,0 +1,321 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, computed, nextTick } from 'vue'
|
||||||
|
import { showToast } from 'vant'
|
||||||
|
import ClickCaptcha from '@/components/ClickCaptcha.vue'
|
||||||
|
import { useDialogStore } from '@/stores/dialogStore'
|
||||||
|
import { useUserStore } from '@/stores/userStore'
|
||||||
|
|
||||||
|
const emit = defineEmits(['login-success'])
|
||||||
|
const dialogStore = useDialogStore()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
const phoneNumber = ref('')
|
||||||
|
const verificationCode = ref('')
|
||||||
|
const password = ref('')
|
||||||
|
const isPasswordLogin = ref(false)
|
||||||
|
const isAgreed = ref(false)
|
||||||
|
const isCountingDown = ref(false)
|
||||||
|
const countdown = ref(60)
|
||||||
|
let timer = null
|
||||||
|
|
||||||
|
// 验证组件状态
|
||||||
|
const showCaptcha = ref(false)
|
||||||
|
const captchaVerified = ref(false)
|
||||||
|
|
||||||
|
// 聚焦状态变量
|
||||||
|
const phoneFocused = ref(false)
|
||||||
|
const codeFocused = ref(false)
|
||||||
|
const passwordFocused = ref(false)
|
||||||
|
|
||||||
|
const isPhoneNumberValid = computed(() => {
|
||||||
|
return /^1[3-9]\d{9}$/.test(phoneNumber.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const canLogin = computed(() => {
|
||||||
|
if (!isPhoneNumberValid.value) return false
|
||||||
|
if (isPasswordLogin.value) {
|
||||||
|
return password.value.length >= 6
|
||||||
|
} else {
|
||||||
|
return verificationCode.value.length === 6
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function sendVerificationCode() {
|
||||||
|
if (isCountingDown.value || !isPhoneNumberValid.value) return
|
||||||
|
if (!isPhoneNumberValid.value) {
|
||||||
|
showToast({ message: "请输入有效的手机号" });
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { data, error } = await useApiFetch('auth/sendSms')
|
||||||
|
.post({ mobile: phoneNumber.value, actionType: 'login' })
|
||||||
|
.json()
|
||||||
|
|
||||||
|
if (data.value && !error.value) {
|
||||||
|
if (data.value.code === 200) {
|
||||||
|
showToast({ message: "获取成功" });
|
||||||
|
startCountdown()
|
||||||
|
// 聚焦到验证码输入框
|
||||||
|
nextTick(() => {
|
||||||
|
const verificationCodeInput = document.getElementById('verificationCode');
|
||||||
|
if (verificationCodeInput) {
|
||||||
|
verificationCodeInput.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
showToast(data.value.msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startCountdown() {
|
||||||
|
isCountingDown.value = true
|
||||||
|
countdown.value = 60
|
||||||
|
timer = setInterval(() => {
|
||||||
|
if (countdown.value > 0) {
|
||||||
|
countdown.value--
|
||||||
|
} else {
|
||||||
|
clearInterval(timer)
|
||||||
|
isCountingDown.value = false
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleLogin() {
|
||||||
|
if (!isPhoneNumberValid.value) {
|
||||||
|
showToast({ message: "请输入有效的手机号" });
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (isPasswordLogin.value) {
|
||||||
|
if (password.value.length < 6) {
|
||||||
|
showToast({ message: "密码长度不能小于6位" });
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (verificationCode.value.length !== 6) {
|
||||||
|
showToast({ message: "请输入有效的验证码" });
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isAgreed.value) {
|
||||||
|
showToast({ message: "请先同意用户协议" });
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 显示验证组件
|
||||||
|
showCaptcha.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证成功回调
|
||||||
|
function handleCaptchaSuccess() {
|
||||||
|
captchaVerified.value = true
|
||||||
|
showCaptcha.value = false
|
||||||
|
// 执行实际的登录逻辑
|
||||||
|
performLogin()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证关闭回调
|
||||||
|
function handleCaptchaClose() {
|
||||||
|
showCaptcha.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行实际的登录逻辑
|
||||||
|
async function performLogin() {
|
||||||
|
const { data, error } = await useApiFetch('/user/mobileCodeLogin')
|
||||||
|
.post({ mobile: phoneNumber.value, code: verificationCode.value })
|
||||||
|
.json()
|
||||||
|
|
||||||
|
if (data.value && !error.value) {
|
||||||
|
if (data.value.code === 200) {
|
||||||
|
localStorage.setItem('token', data.value.data.accessToken)
|
||||||
|
localStorage.setItem('refreshAfter', data.value.data.refreshAfter)
|
||||||
|
localStorage.setItem('accessExpire', data.value.data.accessExpire)
|
||||||
|
|
||||||
|
// 更新用户信息
|
||||||
|
await userStore.fetchUserInfo()
|
||||||
|
|
||||||
|
showToast({ message: "登录成功" });
|
||||||
|
closeDialog();
|
||||||
|
emit('login-success');
|
||||||
|
} else {
|
||||||
|
showToast(data.value.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeDialog() {
|
||||||
|
dialogStore.closeLogin();
|
||||||
|
// 重置表单
|
||||||
|
phoneNumber.value = '';
|
||||||
|
verificationCode.value = '';
|
||||||
|
password.value = '';
|
||||||
|
isPasswordLogin.value = false;
|
||||||
|
isAgreed.value = false;
|
||||||
|
isCountingDown.value = false;
|
||||||
|
countdown.value = 60;
|
||||||
|
if (timer) {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toUserAgreement() {
|
||||||
|
closeDialog();
|
||||||
|
router.push(`/userAgreement`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toPrivacyPolicy() {
|
||||||
|
closeDialog();
|
||||||
|
router.push(`/privacyPolicy`);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<van-popup v-model:show="dialogStore.showLogin" round position="bottom" @close="closeDialog"
|
||||||
|
:style="{ maxHeight: '90vh' }">
|
||||||
|
<div class="login-dialog">
|
||||||
|
<div class="title-bar">
|
||||||
|
<div class="text-base sm:text-lg font-bold">登录</div>
|
||||||
|
<van-icon name="cross" class="close-icon" @click="closeDialog" />
|
||||||
|
</div>
|
||||||
|
<div class="px-8">
|
||||||
|
<div class="mb-8 pt-8 text-left">
|
||||||
|
<div class="flex flex-col items-center">
|
||||||
|
<img class="h-16 w-16 rounded-full shadow" src="/logo.jpg" alt="Logo" />
|
||||||
|
<div class="text-3xl mt-4 text-slate-700 font-bold">
|
||||||
|
天远数据
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-5">
|
||||||
|
<!-- 手机号输入 -->
|
||||||
|
<div :class="[
|
||||||
|
'input-container bg-blue-300/20',
|
||||||
|
phoneFocused ? 'focused' : '',
|
||||||
|
]">
|
||||||
|
<input v-model="phoneNumber" class="input-field" type="tel" placeholder="请输入手机号"
|
||||||
|
maxlength="11" @focus="phoneFocused = true" @blur="phoneFocused = false" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 验证码输入 -->
|
||||||
|
<div v-if="!isPasswordLogin" class="flex items-center justify-between">
|
||||||
|
<div :class="[
|
||||||
|
'input-container bg-blue-300/20',
|
||||||
|
codeFocused ? 'focused' : '',
|
||||||
|
]">
|
||||||
|
<input v-model="verificationCode" id="verificationCode" class="input-field"
|
||||||
|
placeholder="请输入验证码" maxlength="6" @focus="codeFocused = true"
|
||||||
|
@blur="codeFocused = false" />
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
class="ml-2 px-4 py-2 text-sm font-bold flex-shrink-0 rounded-lg transition duration-300"
|
||||||
|
:class="isCountingDown || !isPhoneNumberValid
|
||||||
|
? 'cursor-not-allowed bg-gray-300 text-gray-500'
|
||||||
|
: 'bg-blue-500 text-white hover:bg-blue-600'
|
||||||
|
" @click="sendVerificationCode">
|
||||||
|
{{
|
||||||
|
isCountingDown
|
||||||
|
? `${countdown}s重新获取`
|
||||||
|
: "获取验证码"
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 密码输入 -->
|
||||||
|
<div v-else :class="[
|
||||||
|
'input-container bg-blue-300/20',
|
||||||
|
passwordFocused ? 'focused' : '',
|
||||||
|
]">
|
||||||
|
<input v-model="password" class="input-field" type="password" placeholder="请输入密码"
|
||||||
|
@focus="passwordFocused = true" @blur="passwordFocused = false" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 登录方式切换 -->
|
||||||
|
<div class="flex justify-end items-center">
|
||||||
|
<div class="text-sm text-blue-500 cursor-pointer" @click="isPasswordLogin = !isPasswordLogin">
|
||||||
|
{{ isPasswordLogin ? '验证码登录' : '密码登录' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 协议同意框 -->
|
||||||
|
<div class="flex items-start space-x-2">
|
||||||
|
<input type="checkbox" v-model="isAgreed" class="mt-1" />
|
||||||
|
<span class="text-xs text-gray-400 leading-tight">
|
||||||
|
登录即代表您已阅读并同意
|
||||||
|
<a class="cursor-pointer text-blue-400" @click="toUserAgreement">
|
||||||
|
《用户协议》
|
||||||
|
</a>
|
||||||
|
和
|
||||||
|
<a class="cursor-pointer text-blue-400" @click="toPrivacyPolicy">
|
||||||
|
《隐私政策》
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="mt-10 w-full py-3 text-lg font-bold text-white bg-blue-500 rounded-full transition duration-300"
|
||||||
|
:class="{ 'opacity-50 cursor-not-allowed': !canLogin }" @click="handleLogin">
|
||||||
|
登 录
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</van-popup>
|
||||||
|
|
||||||
|
<!-- 点击验证组件 -->
|
||||||
|
<ClickCaptcha :visible="showCaptcha" @success="handleCaptchaSuccess" @close="handleCaptchaClose" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.login-dialog {
|
||||||
|
background: url("@/assets/images/login_bg.png") no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
background-size: cover;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-bar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 12px 16px;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-icon {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #666;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-container {
|
||||||
|
border: 2px solid rgba(125, 211, 252, 0);
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
transition: all 0.3s;
|
||||||
|
height: 3rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-container.focused {
|
||||||
|
border: 2px solid rgba(59, 130, 246, 0.5);
|
||||||
|
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-field {
|
||||||
|
background-color: transparent;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0 1rem;
|
||||||
|
color: #333;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-field::placeholder {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement-checkbox {
|
||||||
|
accent-color: #3b82f6;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -4,6 +4,7 @@ import { ref } from 'vue'
|
|||||||
export const useDialogStore = defineStore('dialog', () => {
|
export const useDialogStore = defineStore('dialog', () => {
|
||||||
const showBindPhone = ref(false)
|
const showBindPhone = ref(false)
|
||||||
const showRealNameAuth = ref(false)
|
const showRealNameAuth = ref(false)
|
||||||
|
const showLogin = ref(false)
|
||||||
|
|
||||||
function openBindPhone() {
|
function openBindPhone() {
|
||||||
showBindPhone.value = true
|
showBindPhone.value = true
|
||||||
@@ -21,6 +22,14 @@ export const useDialogStore = defineStore('dialog', () => {
|
|||||||
showRealNameAuth.value = false
|
showRealNameAuth.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openLogin() {
|
||||||
|
showLogin.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeLogin() {
|
||||||
|
showLogin.value = false
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showBindPhone,
|
showBindPhone,
|
||||||
openBindPhone,
|
openBindPhone,
|
||||||
@@ -28,5 +37,8 @@ export const useDialogStore = defineStore('dialog', () => {
|
|||||||
showRealNameAuth,
|
showRealNameAuth,
|
||||||
openRealNameAuth,
|
openRealNameAuth,
|
||||||
closeRealNameAuth,
|
closeRealNameAuth,
|
||||||
|
showLogin,
|
||||||
|
openLogin,
|
||||||
|
closeLogin,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ import { ref, onMounted, onBeforeMount } from "vue";
|
|||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { useUserStore } from '@/stores/userStore';
|
import { useUserStore } from '@/stores/userStore';
|
||||||
|
import { useDialogStore } from '@/stores/dialogStore';
|
||||||
import InquireForm from "@/components/InquireForm.vue";
|
import InquireForm from "@/components/InquireForm.vue";
|
||||||
|
import LoginDialog from "@/components/LoginDialog.vue";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
const dialogStore = useDialogStore();
|
||||||
const { mobile: userStoreMobile } = storeToRefs(userStore);
|
const { mobile: userStoreMobile } = storeToRefs(userStore);
|
||||||
|
|
||||||
const linkIdentifier = ref("");
|
const linkIdentifier = ref("");
|
||||||
@@ -59,4 +62,5 @@ async function getProduct() {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<InquireForm :type="'promotion'" :feature="feature" :link-identifier="linkIdentifier" :feature-data="featureData" />
|
<InquireForm :type="'promotion'" :feature="feature" :link-identifier="linkIdentifier" :feature-data="featureData" />
|
||||||
|
<LoginDialog />
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user