refactor(mhzc): 短信登录页滑块验证改为图形验证码(原代码注释保留)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
liulujian 2026-04-15 15:55:37 +08:00
parent eef27d2aeb
commit 8a91713bab

View File

@ -26,28 +26,27 @@
{{ countDown === 0 ? '发送验证码' : `${countDown}秒后可重发` }} {{ countDown === 0 ? '发送验证码' : `${countDown}秒后可重发` }}
</t-button> </t-button>
</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" v-if="iscxhk"> <div class="drag" ref="dragDiv" v-if="iscxhk">...</div>
<div class="drag_bg"></div> <div class="drag" ref="dragDiv" v-else>...</div>
<div class="drag_text">{{ confirmWords }}</div> </t-form-item>
<div -->
ref="moveDiv"
@mousedown="mouseDown($event)" <!-- 新增图形验证码 -->
:class="{ handler_ok_bg: confirmSuccess }" <t-form-item name="captchaCode">
class="handler handler_bg" <div class="captcha-wrapper">
style="position: absolute; top: 0; left: 0" <img
></div> v-if="captchaImage"
</div> :src="captchaImage"
<div class="drag" ref="dragDiv" v-else> @click="refreshCaptcha"
<div class="drag_bg"></div> class="captcha-img"
<div class="drag_text">{{ confirmWords }}</div> alt="验证码"
<div />
ref="moveDiv" <t-button :disabled="countDown > 0" @click="refreshCaptcha" size="small" style="padding: 0 8px;">
@mousedown="mouseDown($event)" 刷新
:class="{ handler_ok_bg: confirmSuccess }" </t-button>
class="handler handler_bg"
style="position: absolute; top: 0; left: 0"
></div>
</div> </div>
</t-form-item> </t-form-item>
</div> </div>
@ -67,7 +66,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,loginBySMS,sendMsg } from '@/pages/index/api/login'; // import { getVerify, loginBySMS, sendMsg } from '@/pages/index/api/login'; //
import { getCaptcha, loginBySMS, sendMsg } from '@/pages/index/api/login';
const FORM_RULES = { const FORM_RULES = {
sjhm: [{ required: true, message: '手机号必填', type: 'error' }], sjhm: [{ required: true, message: '手机号必填', type: 'error' }],
@ -80,14 +80,23 @@ 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',
// isCounting: false,
// iscxhk: false,
// === end ===
//
captchaUuid: '',
captchaImage: '',
FORM_RULES, FORM_RULES,
loginForm: { loginForm: {
loginType: 'password', loginType: 'password',
@ -100,8 +109,6 @@ export default {
}, },
countDown: 0, countDown: 0,
intervalTimer: null, intervalTimer: null,
isCounting: false, //
iscxhk:false,
}; };
}, },
beforeDestroy() { beforeDestroy() {
@ -143,18 +150,8 @@ export default {
}) })
.catch((error) => { .catch((error) => {
console.log('22222'); console.log('22222');
// this.stopAndResetTimer();
// if (this.isCounting) { return;
// this.stopAndResetTimer();
// this.reSetSlider();
// }
if (this.isCounting) {
this.stopAndResetTimer();
}
return;
// if (error === 1004003) {
// this.reSetSlider();
// }
}); });
}, },
handleCounter() { handleCounter() {
@ -165,9 +162,9 @@ handleCounter() {
}); });
return; return;
} }
if (!this.confirmSuccess) { if (!this.captchaUuid) {
MessagePlugin.info({ MessagePlugin.info({
content: '请先完成滑块验证', content: '请先获取验证码',
duration: 1000, duration: 1000,
}); });
return; return;
@ -210,94 +207,38 @@ handleCounter() {
// //
stopAndResetTimer() { stopAndResetTimer() {
clearInterval(this.intervalTimer); clearInterval(this.intervalTimer);
this.iscxhk = !this.iscxhk;
this.intervalTimer = null; this.intervalTimer = null;
this.countDown = 0; this.countDown = 0;
this.isCounting = false;
//
this.reSetSlider();
}, },
// === 便 ===
// mousedown // mousedown
mouseDown(e) { // mouseDown(e) { ... },
if (!this.confirmSuccess) { // successFunction() { ... },
e.preventDefault && e.preventDefault(); // // removeMouseListeners() { ... },
this.mouseMoveState = true; // mouseMoveFn(e) { ... },
this.beginClientX = e.clientX; // moseUpFn(e) { ... },
} // reSet() { ... },
}, // reSetSlider() { ... },
// // addMouseListeners() { ... },
successFunction() { // === end ===
getVerify().then((res) => {
this.loginForm.captchaVerification = res.data; //
this.confirmSuccess = true; refreshCaptcha() {
this.confirmWords = '验证通过'; getCaptcha().then((res) => {
this.captchaUuid = res.data.uuid;
this.captchaImage = res.data.imageBase64;
this.loginForm.captchaVerification = res.data.uuid;
}); });
this.removeMouseListeners();
},
//
removeMouseListeners() {
if (window.addEventListener) {
document.getElementsByTagName('html')[0].removeEventListener('mousemove', this.mouseMoveFn);
document.getElementsByTagName('html')[0].removeEventListener('mouseup', this.moseUpFn);
} else {
document.getElementsByTagName('html')[0].removeEventListener('mouseup', () => {});
}
document.getElementsByClassName('drag_text')[0].style.color = '#fff';
document.getElementsByClassName('handler')[0].style.left = `${this.maxWidth}px`;
document.getElementsByClassName('drag_bg')[0].style.width = `${this.maxWidth}px`;
},
// mousemove
mouseMoveFn(e) {
if (this.mouseMoveState) {
const width = e.clientX - this.beginClientX;
if (width > 0 && width <= this.maxWidth) {
document.getElementsByClassName('handler')[0].style.left = `${width}px`;
document.getElementsByClassName('drag_bg')[0].style.width = `${width}px`;
} else if (width > this.maxWidth) {
this.successFunction();
}
}
},
// mouseup
moseUpFn(e) {
this.mouseMoveState = false;
const width = e.clientX - this.beginClientX;
if (width < this.maxWidth) {
document.getElementsByClassName('handler')[0].style.left = `${0}px`;
document.getElementsByClassName('drag_bg')[0].style.width = `${0}px`;
}
},
reSet() {
this.formData.sfzhm = '';
this.formData.xm = '';
this.reSetSlider();
},
reSetSlider() {
this.confirmSuccess = false;
this.mouseMoveState = false;
this.confirmWords = '请按住滑块,拖动到最右边';
document.getElementsByClassName('handler')[0].style.left = `${0}px`;
document.getElementsByClassName('drag_bg')[0].style.width = `${0}px`;
document.getElementsByClassName('drag_text')[0].style.color = 'black';
//
this.addMouseListeners();
},
//
addMouseListeners() {
document.getElementsByTagName('html')[0].addEventListener('mousemove', this.mouseMoveFn);
document.getElementsByTagName('html')[0].addEventListener('mouseup', this.moseUpFn);
}, },
}, },
mounted() { mounted() {
// // === ===
this.maxWidth = this.$refs.dragDiv.clientWidth - this.$refs.moveDiv.clientWidth; // this.maxWidth = this.$refs.dragDiv.clientWidth - this.$refs.moveDiv.clientWidth;
// // this.addMouseListeners();
this.addMouseListeners();
//
this.refreshCaptcha();
}, },
}; };
</script> </script>
@ -363,4 +304,29 @@ stopAndResetTimer() {
.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;
}
</style> </style>