添加登录滑块功能及a-modal添加背景

This commit is contained in:
yangjun 2025-07-29 14:59:03 +08:00
parent aa79f94ff9
commit e06ea16dcc
5 changed files with 195 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 KiB

View File

@ -23,6 +23,7 @@ enum Api {
GetPermCode = '/sys/permission/getPermCode',
//新加的获取图形验证码的接口
getInputCode = '/sys/randomImage',
randomCode = '/sys/randomInputCode',
//获取短信验证码的接口
getCaptcha = '/sys/sms',
//注册接口
@ -114,6 +115,10 @@ export function getCodeInfo(currdatetime) {
let url = Api.getInputCode + `/${currdatetime}`;
return defHttp.get({ url: url });
}
export function randomCode(currdatetime) {
let url = Api.randomCode + `/${currdatetime}`;
return defHttp.get({ url: url });
}
/**
* @description:
*/

View File

@ -47,6 +47,9 @@
.ant-modal-body {
padding: 0;
background: url(../resource/img/modalback.png);
background-repeat: no-repeat;
background-size: cover;
> .scrollbar > .scrollbar__bar.is-horizontal {
display: none;

View File

@ -53,7 +53,10 @@
</a-col>
</a-row>
</div>
<div class="aui-inputClear">
<div >
<huakuai @verifySuccess="checkInputCode"/>
</div>
<!-- <div class="aui-inputClear">
<a-row>
<a-col :span="2">
<span style="margin-top: 10px;display: block;"><img :src="icon3Img" alt="验证码" style="width: 20px;" /></span>
@ -70,7 +73,7 @@
</div>
</a-col>
</a-row>
</div>
</div> -->
</div>
</a-form>
</div>
@ -92,7 +95,7 @@
</div>
</template>
<script lang="ts" setup name="login-mini">
import { getCaptcha, getCodeInfo } from '/@/api/sys/user';
import { getCaptcha, getCodeInfo, randomCode } from '/@/api/sys/user';
import { computed, onMounted, reactive, ref, toRaw, unref } from 'vue';
import codeImg from '/@/assets/images/checkcode.png';
import { Rule } from '/@/components/Form';
@ -117,6 +120,7 @@
import CaptchaModal from '@/components/jeecg/captcha/CaptchaModal.vue';
import { useModal } from "@/components/Modal";
import { ExceptionEnum } from "@/enums/exceptionEnum";
import huakuai from './huakuai.vue';
const IconFont = createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/font_2316098_umqusozousr.js',
@ -178,12 +182,20 @@
formData.inputCode = '';
randCodeData.checkKey = 1629428467008;
getCodeInfo(randCodeData.checkKey).then((res) => {
randomCode(randCodeData.checkKey).then((res) => {
console.log("🚀 ~ handleChangeCheckCode ~ res:", res)
randCodeData.randCodeImage = res;
randCodeData.requestCodeSuccess = true;
formData.inputCode = res;
});
}
function checkInputCode(type){
console.log("🚀 ~ checkCode ~ checkCode:",type)
handleChangeCheckCode();
}
/**
* 切换登录方式
*/
@ -372,7 +384,7 @@
onMounted(() => {
//
handleChangeCheckCode();
// handleChangeCheckCode();
});
</script>

View File

@ -0,0 +1,170 @@
<template>
<!-- 滑动验证码容器 -->
<div class="slider-container" ref="containerRef">
<!-- 滑动遮罩层显示滑动进度 -->
<div class="slider-mask" :style="{ width: sliderMaskWidth }" />
<!-- 滑块按钮 -->
<div
class="slider"
ref="sliderRef"
@mousedown="handleDragStart"
:class="{ 'slider-success': verified }"
:style="{ left: sliderLeft }"
>
<!-- 滑块图标 -->
<Icon icon="ant-design:double-right-outlined" :size="20" />
</div>
<!-- 提示文本 -->
<div class="slider-text" :class="{ 'slider-text-success': verified }">
{{ verified ? "验证通过" : "将滑块拖动至右侧完成验证" }}
</div>
</div>
</template>
<script setup lang="ts">
import { ref, defineEmits, onUnmounted } from "vue"
const emit = defineEmits(["verifySuccess"])
// DOM
const containerRef = ref<HTMLElement | null>(null) //
const sliderRef = ref<HTMLElement | null>(null) //
//
const sliderLeft = ref("0px") //
const sliderMaskWidth = ref("0px") //
const verified = ref(false) //
//
let startX = 0 // X
let sliderLeft_temp = 0 //
/**
* 开始拖动处理
* @param e 鼠标事件对象
*/
const handleDragStart = (e: MouseEvent) => {
if (verified.value) return //
startX = e.clientX
sliderLeft_temp = parseInt(sliderLeft.value)
//
document.addEventListener("mousemove", handleDragMove)
document.addEventListener("mouseup", handleDragEnd)
}
/**
* 拖动过程处理
* @param e 鼠标事件对象
*/
const handleDragMove = (e: MouseEvent) => {
if (verified.value) return
const container = containerRef.value
if (!container) return
//
const diff = e.clientX - startX
const containerWidth = container.offsetWidth
const sliderWidth = sliderRef.value?.offsetWidth || 0
const maxLeft = containerWidth - sliderWidth
//
let newLeft = sliderLeft_temp + diff
if (newLeft < 0) newLeft = 0
if (newLeft > maxLeft) newLeft = maxLeft
//
sliderLeft.value = newLeft + "px"
sliderMaskWidth.value = newLeft + sliderWidth / 2 + "px"
//
if (newLeft === maxLeft) {
verified.value = true
emit("verifySuccess", true) //
handleDragEnd()
}
}
/**
* 结束拖动处理
*/
const handleDragEnd = () => {
if (!verified.value) {
//
sliderLeft.value = "0px"
sliderMaskWidth.value = "0px"
}
//
document.removeEventListener("mousemove", handleDragMove)
document.removeEventListener("mouseup", handleDragEnd)
}
//
onUnmounted(() => {
document.removeEventListener("mousemove", handleDragMove)
document.removeEventListener("mouseup", handleDragEnd)
})
</script>
<style scoped>
/* 滑动验证码容器样式 */
.slider-container {
position: relative;
width: 100%;
height: 42px;
background-color: #f5f5f5;
border: 1px solid #e4e7ed;
border-radius: 8px;
margin-top: 20px;
}
/* 滑动遮罩层样式 */
.slider-mask {
position: absolute;
top: 0;
left: 0;
height: 100%;
background-color: #d1e9fc;
border-radius: 8px;
transition: width 0.1s linear;
}
/* 滑块按钮样式 */
.slider {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 60px;
height: 42px;
background: #e1dede;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.2s;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
/* 验证成功时滑块样式 */
.slider-success {
background-color: #1ea0fa;
}
/* 提示文本样式 */
.slider-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
user-select: none;
font-weight: 400;
font-size: 12px;
color: #9cb3c5;
width: auto;
}
/* 验证成功时文本样式 */
.slider-text-success {
color: #1ea0fa;
}
</style>