officialAccount/pages/login/code.vue

563 lines
12 KiB
Vue
Raw Normal View History

2025-05-28 17:36:42 +08:00
<template>
<view class="login-container">
2025-06-19 17:03:31 +08:00
<image class="photo-imge" src="https://www.focusnu.com/media/directive/login/bgc.png" />
<image class="back-imge" src="https://www.focusnu.com/media/directive/login/back.png" @click="goback" />
<view class="under-container-title">
<view class="code-title">
请输入验证码
2025-05-28 17:36:42 +08:00
</view>
2025-06-19 17:03:31 +08:00
<view class="code-number">
验证码已发送到
<view class="code-font">
{{ mobile }}
</view>
2025-05-28 17:36:42 +08:00
</view>
2025-06-19 17:03:31 +08:00
</view>
<view class="captcha-container">
<u-message-input active-color="#333333" inactive-color="rgb(175,179,189)" width="150" :focus="true" mode="bottomLine" @finish="finshinput" ></u-message-input>
</view>
<view class="under-view" style="z-index: 1;">
2025-06-03 17:29:22 +08:00
2025-06-19 17:03:31 +08:00
<view class="right-blue" v-if="!countdown" @click="getcode">
重新发送
</view>
<view class="right-white" v-if="countdown">
<text style="color: #0096FF;">{{countdown}}</text>后重新发送
</view>
<view class="right-black" @click="isFadingOut=true">
收不到验证码?
2025-05-28 17:36:42 +08:00
</view>
</view>
2025-06-19 17:03:31 +08:00
<!-- </view> -->
2025-05-28 17:36:42 +08:00
<!-- 遮罩 -->
2025-06-19 17:03:31 +08:00
<!-- <transition name="fade"> -->
2025-05-28 17:36:42 +08:00
<view v-if="isFadingOut" class="overlay" @click="closeModal" :style="{ backgroundColor: maskColor }" />
2025-06-19 17:03:31 +08:00
<!-- </transition>
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
<!-- 底部弹窗 -->
2025-06-19 17:03:31 +08:00
<!-- <transition name="slide-up"> -->
2025-05-28 17:36:42 +08:00
<view v-if="isFadingOut" class="modal">
<view class="modal-title">收不到验证码</view>
<view class="model-p">
<view class="text-view" style="font-weight: 600;">手机号可正常使用:</view>
<view class="text-view">1 是否输错手机号</view>
<view class="text-view">2 手机是否设置短信拦截/欠费/信号不好</view>
<view class="text-view">3 手机内存是否满了</view>
<view class="text-view">4 手机卡是否为物联卡而非SIM卡</view>
</view>
</view>
2025-06-19 17:03:31 +08:00
<!-- </transition> -->
2025-05-28 17:36:42 +08:00
</view>
</template>
<script setup>
import {
nextTick,
reactive,
ref,
2025-06-03 17:29:22 +08:00
onUnmounted
2025-05-28 17:36:42 +08:00
} from 'vue';
import {
onLoad
} from '@dcloudio/uni-app';
2025-06-03 17:29:22 +08:00
import {
smsCode,
2025-06-19 17:03:31 +08:00
checkPhoneCode,
getMessage
2025-06-03 17:29:22 +08:00
} from "@/api/loginApi.js"
const mobile = ref("")
const hkcode = ref("")
2025-05-28 17:36:42 +08:00
const captcha = ref(['', '', '', '']); // 用来存储4个小方块的验证码输入
2025-06-03 17:29:22 +08:00
const focusedIndex = ref(-1); // 当前聚焦的小方块索引
2025-05-28 17:36:42 +08:00
const isFadingOut = ref(false);
// 遮罩色rgba 可调透明度
const maskColor = ref('rgba(0, 0, 0, 0.5)')
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
function closeModal() {
isFadingOut.value = false
}
2025-06-19 17:03:31 +08:00
const aaaa = () =>{
console.log("?????")
}
2025-06-03 17:29:22 +08:00
function filterToSingleDigit(number) {
if (typeof number === 'number') {
return number % 10; // 只保留个位数
2025-05-28 17:36:42 +08:00
}
2025-06-03 17:29:22 +08:00
return number; // 如果不是 number原样返回
}
2025-06-19 17:03:31 +08:00
const finshinput = (res) => {
// console.log("res",res)
submitCaptcha(res);
}
2025-06-03 17:29:22 +08:00
// 输入框输入时的处理函数
const handleInput = (index, event) => {
2025-06-19 17:03:31 +08:00
const val = event.detail.value || '';
captcha.value[index] = val
2025-06-03 17:29:22 +08:00
if (val.length == 4) {
// 1. 转成字符串,并补足前导 0 到 4 位
const codeStr = event.detail.value.toString().padStart(4, '0') // "0123"
captcha.value = codeStr.split('')
focusedIndex.value = 3
nextTick(() => {
2025-05-28 17:36:42 +08:00
submitCaptcha()
2025-06-03 17:29:22 +08:00
})
} else if (val.length == 2) {
captcha.value[index] = filterToSingleDigit(captcha.value[index])
if (captcha.value[index]) {
if (index < 3) {
focusedIndex.value = index + 1; // 输入后自动聚焦到下一个小方块
2025-06-20 17:32:20 +08:00
// console.log("cccccccccc")
2025-06-03 17:29:22 +08:00
}
2025-05-28 17:36:42 +08:00
}
2025-06-03 17:29:22 +08:00
let isFour = true;
captcha.value.forEach(number => {
if (!number) {
isFour = false;
}
})
nextTick(() => {
if (isFour) {
submitCaptcha()
}
})
} else {
if (captcha.value[index]) {
if (index < 3) {
focusedIndex.value = index + 1; // 输入后自动聚焦到下一个小方块
}
}
let isFour = true;
captcha.value.forEach(number => {
if (!number) {
isFour = false;
}
})
nextTick(() => {
if (isFour) {
submitCaptcha()
}
})
}
2025-05-28 17:36:42 +08:00
};
// 处理删除键
const handleKeydown = (index, event) => {
if (event.key === 'Backspace' && !captcha.value[index]) {
if (index > 0) {
focusedIndex.value = index - 1; // 如果当前小方块为空,则聚焦到前一个小方块
}
}
};
2025-06-03 17:29:22 +08:00
const rightCode = ref("")
2025-05-28 17:36:42 +08:00
// 提交验证码
2025-06-19 17:03:31 +08:00
const submitCaptcha = (res0) => {
const code = res0
2025-05-28 17:36:42 +08:00
if (code.length === 4) {
2025-06-19 17:03:31 +08:00
let openid = uni.getStorageSync('openid')
2025-06-03 17:29:22 +08:00
if (rightCode.value != code) {
rightCode.value = code;
checkPhoneCode({
mobile: mobile.value,
2025-06-19 17:03:31 +08:00
openId: openid,
2025-06-03 17:29:22 +08:00
smscode: code
}).then(res => {
if (res.success) {
2025-06-19 17:03:31 +08:00
getMessage(openid).then(res => {
2025-06-20 17:32:20 +08:00
// uni.setStorageSync('tel', res.result.tel);
// uni.setStorageSync('token', res.result.token);
// uni.setStorageSync('serverUrl', res.result.serverUrl);
// uni.redirectTo({
// url: `/pages/login/threeselectone`
// });
if(uni.getStorageSync('special')){
uni.setStorageSync('tel', res.result.tel);
uni.setStorageSync('token', res.result.token);
uni.setStorageSync('serverUrl', res.result.serverUrl);
uni.redirectTo({
url: `/pages/login/special`
});
}else{
uni.setStorageSync('tel', res.result.tel);
uni.setStorageSync('token', res.result.token);
uni.setStorageSync('serverUrl', res.result.serverUrl);
uni.redirectTo({
url: `/pages/login/threeselectone`
});
}
2025-06-19 17:03:31 +08:00
})
2025-06-20 17:32:20 +08:00
2025-06-03 17:29:22 +08:00
} else {
uni.showToast({
title: '验证码错误',
icon: 'none', // 不显示图标(提示信息)
duration: 2000 // 显示时长(毫秒)
})
}
})
}
2025-05-28 17:36:42 +08:00
// 执行验证码提交的逻辑
} else {
console.log('验证码未输入完整');
}
};
2025-06-03 17:29:22 +08:00
const getcode = () => {
smsCode({
mobile: mobile.value,
hkcode: hkcode.value,
2025-06-19 17:03:31 +08:00
smsmode: 1
2025-06-03 17:29:22 +08:00
}).then(res => {
if (res.success) {
uni.showToast({
title: '发送成功',
icon: 'none', // 不显示图标(提示信息)
duration: 2000 // 显示时长(毫秒)
})
focusedIndex.value = 0;
// 倒计时逻辑
countdown.value = 60;
timerId = setInterval(() => {
if (countdown.value > 0) {
countdown.value--;
} else {
clearInterval(timerId);
timerId = null;
}
}, 1000);
} else {
uni.showToast({
title: res.message,
icon: 'none', // 不显示图标(提示信息)
duration: 2000 // 显示时长(毫秒)
})
}
})
2025-05-28 17:36:42 +08:00
}
2025-06-19 17:03:31 +08:00
const goback = () => {
uni.navigateBack()
}
2025-05-28 17:36:42 +08:00
// 新增:倒计时相关
2025-06-03 17:29:22 +08:00
const countdown = ref(0);
2025-05-28 17:36:42 +08:00
let timerId = null;
// 页面卸载时清除定时器
onUnmounted(() => {
2025-06-03 17:29:22 +08:00
if (timerId) {
clearInterval(timerId);
}
2025-05-28 17:36:42 +08:00
});
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
onLoad((options) => {
2025-06-03 17:29:22 +08:00
mobile.value = options.mobile;
hkcode.value = options.hkcode;
2025-05-28 17:36:42 +08:00
getcode()
});
</script>
<style lang="scss" scoped>
.login-container {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: rgb(239, 241, 252);
position: relative;
.title {
2025-06-19 17:03:31 +08:00
margin-top: 180rpx;
2025-05-28 17:36:42 +08:00
align-items: center;
.title-imge {
width: 100rpx;
height: 105rpx;
margin-left: 100rpx;
}
.title-font {
font-size: 35rpx;
font-weight: 600;
margin-left: 105rpx;
margin-top: 10rpx;
}
}
.photo-imge {
position: absolute;
2025-06-19 17:03:31 +08:00
top: 200rpx;
2025-05-28 17:36:42 +08:00
left: 0;
width: 100%;
2025-06-19 17:03:31 +08:00
height: 1300rpx;
2025-05-28 17:36:42 +08:00
}
.old-imge {
position: absolute;
right: 30rpx;
top: 400rpx;
width: 400rpx;
height: 400rpx;
}
.under-container {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 45vh;
background-color: #fff;
border-top-left-radius: 50rpx;
border-top-right-radius: 50rpx;
box-shadow: 10rpx 10rpx 20rpx rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
color: #5A607F;
.radio-circle {
position: relative;
margin-top: 2rpx;
width: 40rpx;
height: 40rpx;
border-radius: 50%;
border: 2rpx solid #C0C5D9;
background-color: transparent;
}
.radio-circle-target {
position: relative;
margin-top: 2rpx;
width: 40rpx;
height: 40rpx;
border-radius: 50%;
border: 2rpx solid #C0C5D9;
background-color: transparent;
}
.radio-circle-target::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 30rpx;
height: 30rpx;
background-color: #00C9FF;
border-radius: 50%;
}
}
}
.under-container-title {
2025-06-19 17:03:31 +08:00
margin-top: 270rpx;
2025-05-28 17:36:42 +08:00
margin-bottom: 20rpx;
font-size: 25rpx;
font-weight: 500;
width: 100%;
.code-title {
margin-left: 80rpx;
2025-06-19 17:03:31 +08:00
font-size: 40rpx;
color: #333333;
font-weight: 600;
2025-05-28 17:36:42 +08:00
margin-bottom: 20rpx;
}
.code-number {
margin-left: 80rpx;
2025-06-19 17:03:31 +08:00
font-size: 25rpx;
2025-05-28 17:36:42 +08:00
margin-bottom: 20rpx;
2025-06-19 17:03:31 +08:00
display: flex;
align-items: center;
2025-05-28 17:36:42 +08:00
}
}
.captcha-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20rpx;
2025-06-19 17:03:31 +08:00
margin-bottom: 20rpx;
2025-05-28 17:36:42 +08:00
}
.captcha-box {
display: flex;
justify-content: space-between;
margin-bottom: 20rpx;
}
.captcha-item {
display: flex;
justify-content: center;
align-items: center;
}
.captcha-input {
width: 110rpx;
height: 110rpx;
2025-06-19 17:03:31 +08:00
border-bottom: 5rpx solid #333333;
// border-radius: 30rpx;
2025-05-28 17:36:42 +08:00
font-size: 50rpx;
font-weight: 700;
text-align: center;
margin-right: 40rpx;
outline: none;
}
.captcha-input:focus {
border-color: #00C9FF;
}
2025-06-03 17:29:22 +08:00
.right-blue {
2025-06-19 17:03:31 +08:00
2025-05-28 17:36:42 +08:00
color: #0083FF;
2025-06-19 17:03:31 +08:00
margin-left: 70rpx;
2025-05-28 17:36:42 +08:00
}
2025-06-03 17:29:22 +08:00
.right-white {
color: rgb(194, 198, 211);
2025-06-19 17:03:31 +08:00
margin-left: 70rpx;
2025-05-28 17:36:42 +08:00
}
2025-06-03 17:29:22 +08:00
.right-black {
2025-05-28 17:36:42 +08:00
// float: right;
2025-06-19 17:03:31 +08:00
margin-right: 110rpx;
color: #00A2FF;
2025-05-28 17:36:42 +08:00
}
2025-06-03 17:29:22 +08:00
.under-view {
2025-05-28 17:36:42 +08:00
width: 100%;
margin-top: 10rpx;
display: flex;
justify-content: space-between;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
/* 遮罩 */
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 998;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
/* 弹窗 */
.modal {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #fff;
z-index: 999;
border-top-left-radius: 50rpx;
border-top-right-radius: 50rpx;
width: 100%;
height: 500rpx;
display: flex;
flex-direction: column;
align-items: center;
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.modal-title {
font-size: 32rpx;
font-weight: 700;
margin: 50rpx 0;
margin-bottom: 30rpx;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.model-p {
padding: 0 50rpx;
width: 100%;
font-size: 30rpx;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.model-down {
display: flex;
width: 100%;
justify-content: space-between;
padding: 0 50rpx;
margin-top: 40rpx;
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.model-white {
border-radius: 50rpx;
width: 300rpx;
height: 95rpx;
border: 5rpx solid rgb(0, 141, 255);
color: rgb(0, 141, 255);
font-size: 35rpx;
display: flex;
justify-content: center;
align-items: center;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.model-blue {
border-radius: 50rpx;
width: 300rpx;
height: 95rpx;
background: linear-gradient(to right, #00C9FF, #0076FF);
color: #fff;
font-size: 35rpx;
display: flex;
justify-content: center;
align-items: center;
}
}
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
/* 动画:遮罩淡入淡出 */
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.fade-enter-to,
.fade-leave-from {
opacity: 1;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
/* 动画:弹窗上滑 */
.slide-up-enter-active,
.slide-up-leave-active {
transition: transform 0.3s;
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.slide-up-enter-from,
.slide-up-leave-to {
transform: translateY(100%);
}
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
.slide-up-enter-to,
.slide-up-leave-from {
transform: translateY(0);
}
2025-06-03 17:29:22 +08:00
.text-view {
2025-05-28 17:36:42 +08:00
margin-bottom: 20rpx;
}
2025-06-19 17:03:31 +08:00
.back-imge {
position: absolute;
top: 100rpx;
left: 30rpx;
width: 50rpx;
height: 50rpx;
}
.code-font {
font-weight: 600;
font-size: 30rpx;
margin-left: 15rpx;
}
2025-05-28 17:36:42 +08:00
</style>