refactor(mhzc): 登录页滑块验证改为图形验证码(原代码注释保留)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0f2efb0b66
commit
eef27d2aeb
@ -33,6 +33,8 @@
|
|||||||
</template>
|
</template>
|
||||||
</t-input>
|
</t-input>
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
|
<!-- 滑块验证区域(已注释,保留以便回滚) -->
|
||||||
|
<!--
|
||||||
<t-form-item name="captchaVerification" user-select:none>
|
<t-form-item name="captchaVerification" user-select:none>
|
||||||
<div class="drag" ref="dragDiv">
|
<div class="drag" ref="dragDiv">
|
||||||
<div class="drag_bg"></div>
|
<div class="drag_bg"></div>
|
||||||
@ -46,6 +48,28 @@
|
|||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- 新增:图形验证码 -->
|
||||||
|
<t-form-item name="captchaCode">
|
||||||
|
<div class="captcha-wrapper">
|
||||||
|
<img
|
||||||
|
v-if="captchaImage"
|
||||||
|
:src="captchaImage"
|
||||||
|
@click="refreshCaptcha"
|
||||||
|
class="captcha-img"
|
||||||
|
alt="验证码"
|
||||||
|
/>
|
||||||
|
<t-input
|
||||||
|
v-model="loginForm.captchaCode"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
maxlength="4"
|
||||||
|
style="width: 120px"
|
||||||
|
@enterkey="onSubmit"
|
||||||
|
/>
|
||||||
|
<span class="captcha-refresh" @click="refreshCaptcha">刷新</span>
|
||||||
|
</div>
|
||||||
|
</t-form-item>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 短信验证码登录 -->
|
<!-- 短信验证码登录 -->
|
||||||
@ -65,7 +89,8 @@
|
|||||||
import { removePassword, removeRememberMe, removeUsername } from '@/utils/auth';
|
import { removePassword, removeRememberMe, removeUsername } from '@/utils/auth';
|
||||||
import { UserIcon, LockOnIcon } from 'tdesign-icons-vue';
|
import { UserIcon, LockOnIcon } from 'tdesign-icons-vue';
|
||||||
import { MessagePlugin } from 'tdesign-vue';
|
import { MessagePlugin } from 'tdesign-vue';
|
||||||
import { getVerify } from '@/pages/index/api/login';
|
// import { getVerify } from '@/pages/index/api/login'; // 滑块验证已注释
|
||||||
|
import { getCaptcha } from '@/pages/index/api/login';
|
||||||
|
|
||||||
const FORM_RULES = {
|
const FORM_RULES = {
|
||||||
mobile: [{ required: true, message: '手机号必填', type: 'error' }],
|
mobile: [{ required: true, message: '手机号必填', type: 'error' }],
|
||||||
@ -80,14 +105,22 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
beginClientX: 0 /* 距离屏幕左端距离 */,
|
// === 滑块验证相关数据(已注释,保留以便回滚) ===
|
||||||
mouseMoveState: false /* 触发拖动状态 判断 */,
|
// beginClientX: 0,
|
||||||
maxWidth: '' /* 拖动最大宽度,依据滑块宽度算出来的 */,
|
// mouseMoveState: false,
|
||||||
confirmWords: '请按住滑块,拖动到最右边' /* 滑块文字 */,
|
// maxWidth: '',
|
||||||
confirmSuccess: false /* 验证成功判断 */,
|
// confirmWords: '请按住滑块,拖动到最右边',
|
||||||
width: 350,
|
// confirmSuccess: false,
|
||||||
height: 42,
|
// width: 350,
|
||||||
textSize: '18px',
|
// height: 42,
|
||||||
|
// textSize: '18px',
|
||||||
|
// === 滑块验证相关数据 end ===
|
||||||
|
|
||||||
|
// 图形验证码相关
|
||||||
|
captchaUuid: '',
|
||||||
|
captchaImage: '',
|
||||||
|
captchaCode: '',
|
||||||
|
|
||||||
FORM_RULES,
|
FORM_RULES,
|
||||||
loginForm: {
|
loginForm: {
|
||||||
loginType: 'password',
|
loginType: 'password',
|
||||||
@ -122,9 +155,16 @@ export default {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.confirmSuccess) {
|
if (!this.captchaUuid) {
|
||||||
MessagePlugin.info({
|
MessagePlugin.info({
|
||||||
content: '请先完成滑块验证',
|
content: '请先获取验证码',
|
||||||
|
duration: 1000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.loginForm.captchaCode || this.loginForm.captchaCode.length !== 4) {
|
||||||
|
MessagePlugin.info({
|
||||||
|
content: '请输入4位验证码',
|
||||||
duration: 1000,
|
duration: 1000,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -212,75 +252,89 @@ export default {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
// === 滑块验证方法(已注释,保留以便回滚) ===
|
||||||
// mousedown 事件
|
// mousedown 事件
|
||||||
mouseDown(e) {
|
// mouseDown(e) {
|
||||||
if (!this.confirmSuccess) {
|
// if (!this.confirmSuccess) {
|
||||||
e.preventDefault && e.preventDefault(); // 阻止文字选中等 浏览器默认事件
|
// e.preventDefault && e.preventDefault();
|
||||||
this.mouseMoveState = true;
|
// this.mouseMoveState = true;
|
||||||
this.beginClientX = e.clientX;
|
// this.beginClientX = e.clientX;
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
// 验证成功函数
|
// 验证成功函数
|
||||||
successFunction() {
|
// successFunction() {
|
||||||
getVerify().then((res) => {
|
// getVerify().then((res) => {
|
||||||
this.loginForm.captchaVerification = res.data;
|
// this.loginForm.captchaVerification = res.data;
|
||||||
this.confirmSuccess = true;
|
// this.confirmSuccess = true;
|
||||||
this.confirmWords = '验证通过';
|
// this.confirmWords = '验证通过';
|
||||||
});
|
// });
|
||||||
if (window.addEventListener) {
|
// if (window.addEventListener) {
|
||||||
document.getElementsByTagName('html')[0].removeEventListener('mousemove', this.mouseMoveFn);
|
// document.getElementsByTagName('html')[0].removeEventListener('mousemove', this.mouseMoveFn);
|
||||||
document.getElementsByTagName('html')[0].removeEventListener('mouseup', this.moseUpFn);
|
// document.getElementsByTagName('html')[0].removeEventListener('mouseup', this.moseUpFn);
|
||||||
} else {
|
// } else {
|
||||||
document.getElementsByTagName('html')[0].removeEventListener('mouseup', () => {});
|
// document.getElementsByTagName('html')[0].removeEventListener('mouseup', () => {});
|
||||||
}
|
// }
|
||||||
document.getElementsByClassName('drag_text')[0].style.color = '#fff';
|
// document.getElementsByClassName('drag_text')[0].style.color = '#fff';
|
||||||
document.getElementsByClassName('handler')[0].style.left = `${this.maxWidth}px`;
|
// document.getElementsByClassName('handler')[0].style.left = `${this.maxWidth}px`;
|
||||||
document.getElementsByClassName('drag_bg')[0].style.width = `${this.maxWidth}px`;
|
// document.getElementsByClassName('drag_bg')[0].style.width = `${this.maxWidth}px`;
|
||||||
},
|
// },
|
||||||
// mousemove事件
|
// mousemove事件
|
||||||
mouseMoveFn(e) {
|
// mouseMoveFn(e) {
|
||||||
if (this.mouseMoveState) {
|
// if (this.mouseMoveState) {
|
||||||
const width = e.clientX - this.beginClientX;
|
// const width = e.clientX - this.beginClientX;
|
||||||
if (width > 0 && width <= this.maxWidth) {
|
// if (width > 0 && width <= this.maxWidth) {
|
||||||
document.getElementsByClassName('handler')[0].style.left = `${width}px`;
|
// document.getElementsByClassName('handler')[0].style.left = `${width}px`;
|
||||||
document.getElementsByClassName('drag_bg')[0].style.width = `${width}px`;
|
// document.getElementsByClassName('drag_bg')[0].style.width = `${width}px`;
|
||||||
} else if (width > this.maxWidth) {
|
// } else if (width > this.maxWidth) {
|
||||||
this.successFunction();
|
// this.successFunction();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
// mouseup事件
|
// mouseup事件
|
||||||
moseUpFn(e) {
|
// moseUpFn(e) {
|
||||||
this.mouseMoveState = false;
|
// this.mouseMoveState = false;
|
||||||
const width = e.clientX - this.beginClientX;
|
// const width = e.clientX - this.beginClientX;
|
||||||
if (width < this.maxWidth) {
|
// if (width < this.maxWidth) {
|
||||||
document.getElementsByClassName('handler')[0].style.left = `${0}px`;
|
// document.getElementsByClassName('handler')[0].style.left = `${0}px`;
|
||||||
document.getElementsByClassName('drag_bg')[0].style.width = `${0}px`;
|
// document.getElementsByClassName('drag_bg')[0].style.width = `${0}px`;
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
reSet() {
|
// reSet() {
|
||||||
this.formData.sfzhm = '';
|
// this.formData.sfzhm = '';
|
||||||
this.formData.xm = '';
|
// this.formData.xm = '';
|
||||||
this.reSetSlider();
|
// this.reSetSlider();
|
||||||
},
|
// },
|
||||||
reSetSlider() {
|
// reSetSlider() {
|
||||||
this.confirmSuccess = false;
|
// this.confirmSuccess = false;
|
||||||
this.mouseMoveState = false;
|
// this.mouseMoveState = false;
|
||||||
this.cxBtnDisabled = true;
|
// this.cxBtnDisabled = true;
|
||||||
this.confirmWords = '请按住滑块,拖动到最右边';
|
// this.confirmWords = '请按住滑块,拖动到最右边';
|
||||||
document.getElementsByClassName('handler')[0].style.left = `${0}px`;
|
// document.getElementsByClassName('handler')[0].style.left = `${0}px`;
|
||||||
document.getElementsByClassName('drag_bg')[0].style.width = `${0}px`;
|
// document.getElementsByClassName('drag_bg')[0].style.width = `${0}px`;
|
||||||
document.getElementsByClassName('drag_text')[0].style.color = 'black';
|
// document.getElementsByClassName('drag_text')[0].style.color = 'black';
|
||||||
document.getElementsByTagName('html')[0].addEventListener('mousemove', this.mouseMoveFn);
|
// document.getElementsByTagName('html')[0].addEventListener('mousemove', this.mouseMoveFn);
|
||||||
document.getElementsByTagName('html')[0].addEventListener('mouseup', this.moseUpFn);
|
// document.getElementsByTagName('html')[0].addEventListener('mouseup', this.moseUpFn);
|
||||||
|
// },
|
||||||
|
// === 滑块验证方法 end ===
|
||||||
|
|
||||||
|
// 新增:刷新验证码
|
||||||
|
refreshCaptcha() {
|
||||||
|
getCaptcha().then((res) => {
|
||||||
|
this.captchaUuid = res.data.uuid;
|
||||||
|
this.captchaImage = res.data.imageBase64;
|
||||||
|
this.loginForm.captchaVerification = res.data.uuid;
|
||||||
|
this.loginForm.captchaCode = '';
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
// 计算滑块滑动最大值
|
// === 滑块初始化(已注释) ===
|
||||||
this.maxWidth = this.$refs.dragDiv.clientWidth - this.$refs.moveDiv.clientWidth;
|
// this.maxWidth = this.$refs.dragDiv.clientWidth - this.$refs.moveDiv.clientWidth;
|
||||||
// 添加监听事件
|
// document.getElementsByTagName('html')[0].addEventListener('mousemove', this.mouseMoveFn);
|
||||||
document.getElementsByTagName('html')[0].addEventListener('mousemove', this.mouseMoveFn);
|
// document.getElementsByTagName('html')[0].addEventListener('mouseup', this.moseUpFn);
|
||||||
document.getElementsByTagName('html')[0].addEventListener('mouseup', this.moseUpFn);
|
|
||||||
|
// 新增:初始化图形验证码
|
||||||
|
this.refreshCaptcha();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -346,4 +400,38 @@ export default {
|
|||||||
.btn-container {
|
.btn-container {
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* === 滑块验证样式(已注释,保留以便回滚) ===
|
||||||
|
.drag { ... }
|
||||||
|
.handler { ... }
|
||||||
|
.handler_bg { ... }
|
||||||
|
.handler_ok_bg { ... }
|
||||||
|
.drag_bg { ... }
|
||||||
|
.drag_text { ... }
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 新增:图形验证码样式 */
|
||||||
|
.captcha-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
width: 350px;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
.captcha-img {
|
||||||
|
width: 120px;
|
||||||
|
height: 40px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
.captcha-refresh {
|
||||||
|
color: #0052d9;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.captcha-refresh:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user