officialAccount/pages/login/code.vue

524 lines
11 KiB
Vue
Raw Normal View History

2025-05-28 17:36:42 +08:00
<template>
<view class="login-container">
<view class="title">
<image class="title-imge" src="/static/index/nu.png" />
<view class="title-font">
<view class="">您好</view>
<view class="">欢迎使用护理单元~</view>
</view>
</view>
<image class="photo-imge" src="/static/index/bgc.png" />
<image class="old-imge" src="/static/index/old.png" />
<view class="under-container">
<view class="under-container-title">
<view class="code-title">
请输入验证码
</view>
<view class="code-number">
2025-06-03 17:29:22 +08:00
验证码已发送至{{ mobile }}
2025-05-28 17:36:42 +08:00
</view>
</view>
<view class="captcha-container">
<view class="captcha-box">
<view v-for="(digit, index) in captcha" :key="index" class="captcha-item">
2025-06-03 17:29:22 +08:00
<input v-model="captcha[index]" class="captcha-input" type="number" maxlength="4"
:placeholder="index < 3 ? '' : ' '" @input="handleInput(index, $event)"
2025-05-28 17:36:42 +08:00
@keydown="handleKeydown(index, $event)" :focus="focusedIndex === index" />
</view>
</view>
</view>
<view class="under-view">
2025-06-03 17:29:22 +08:00
<view class="right-blue" v-show="!countdown" @click="getcode">
2025-05-28 17:36:42 +08:00
重新发送
</view>
<view class="right-white" v-show="countdown">
{{countdown}}S后重新发送
</view>
<view class="right-black" @click="isFadingOut=true">
收不到验证码
</view>
</view>
</view>
<!-- 遮罩 -->
<transition name="fade">
<view v-if="isFadingOut" class="overlay" @click="closeModal" :style="{ backgroundColor: maskColor }" />
</transition>
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
<!-- 底部弹窗 -->
<transition name="slide-up">
<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>
</transition>
</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,
checkPhoneCode
} 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-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原样返回
}
// 输入框输入时的处理函数
const handleInput = (index, event) => {
const val = event.detail.value || ''
console.log("??????", event)
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-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
// 提交验证码
const submitCaptcha = () => {
const code = captcha.value.join('');
if (code.length === 4) {
console.log('提交验证码:', code);
2025-06-03 17:29:22 +08:00
if (rightCode.value != code) {
rightCode.value = code;
checkPhoneCode({
mobile: mobile.value,
openId : uni.getStorageSync('openid').openid,
smscode: code
}).then(res => {
if (res.success) {
uni.redirectTo({
url: `/pages/index/index`
});
} 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,
smsmode:1
}).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-03 17:29:22 +08:00
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()
2025-06-03 17:29:22 +08:00
2025-05-28 17:36:42 +08:00
});
</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 {
margin-top: 70rpx;
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;
top: 120rpx;
left: 0;
width: 100%;
height: 1100rpx;
}
.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 {
margin-top: 50rpx;
margin-bottom: 20rpx;
font-size: 25rpx;
font-weight: 500;
width: 100%;
.code-title {
margin-left: 80rpx;
font-size: 35rpx;
color: black;
font-weight: 500;
margin-bottom: 20rpx;
}
.code-number {
margin-left: 80rpx;
font-size: 28rpx;
margin-bottom: 20rpx;
}
}
.captcha-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20rpx;
}
.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;
border: 3rpx solid #C0C5D9;
border-radius: 30rpx;
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-05-28 17:36:42 +08:00
// float: right;
color: #0083FF;
margin-left: 60rpx;
}
2025-06-03 17:29:22 +08:00
.right-white {
color: rgb(194, 198, 211);
2025-05-28 17:36:42 +08:00
margin-left: 60rpx;
}
2025-06-03 17:29:22 +08:00
.right-black {
2025-05-28 17:36:42 +08:00
// float: right;
// color: #0083FF;
margin-right: 80rpx;
color: black;
}
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;
}
</style>