-
立即注册
+
@@ -100,9 +185,12 @@ export default {
return {
title: process.env.VUE_APP_TITLE,
codeUrl: '',
+ loginType: 'password', // 登录类型:password 或 sms
loginForm: {
username: 'admin',
password: 'admin123',
+ mobile: '',
+ smsCode: '',
rememberMe: false,
code: '',
uuid: '',
@@ -122,6 +210,25 @@ export default {
message: '请输入您的密码',
},
],
+ mobile: [
+ {
+ required: true,
+ trigger: 'blur',
+ message: '请输入手机号',
+ },
+ {
+ pattern: /^1[3-9]\d{9}$/,
+ message: '请输入正确的手机号',
+ trigger: 'blur',
+ },
+ ],
+ smsCode: [
+ {
+ required: true,
+ trigger: 'blur',
+ message: '请输入验证码',
+ },
+ ],
code: [
{
required: true,
@@ -136,6 +243,8 @@ export default {
// 注册开关
register: false,
redirect: undefined,
+ // 短信验证码倒计时
+ smsCountdown: 0,
}
},
watch: {
@@ -151,6 +260,40 @@ export default {
this.getCookie()
},
methods: {
+ // 切换登录类型
+ switchLoginType(type) {
+ this.loginType = type
+ // 清空表单验证
+ this.$nextTick(() => {
+ this.$refs.loginForm.clearValidate()
+ })
+ },
+ // 发送短信验证码
+ sendSmsCode() {
+ if (!this.loginForm.mobile) {
+ this.$message.warning('请先输入手机号')
+ return
+ }
+ if (!/^1[3-9]\d{9}$/.test(this.loginForm.mobile)) {
+ this.$message.warning('请输入正确的手机号')
+ return
+ }
+
+ // 这里应该调用发送短信验证码的API
+ // 模拟发送成功
+ this.$message.success('验证码已发送')
+ this.startCountdown()
+ },
+ // 开始倒计时
+ startCountdown() {
+ this.smsCountdown = 60
+ const timer = setInterval(() => {
+ this.smsCountdown--
+ if (this.smsCountdown <= 0) {
+ clearInterval(timer)
+ }
+ }, 1000)
+ },
getCode() {
getCodeImg().then((res) => {
this.captchaEnabled =
@@ -180,23 +323,42 @@ export default {
this.$refs.loginForm.validate((valid) => {
if (valid) {
this.loading = true
- if (this.loginForm.rememberMe) {
- Cookies.set('username', this.loginForm.username, {
- expires: 30,
- })
- Cookies.set(
- 'password',
- encrypt(this.loginForm.password),
- { expires: 30 },
- )
- Cookies.set('rememberMe', this.loginForm.rememberMe, {
- expires: 30,
- })
+
+ // 根据登录类型处理不同的登录逻辑
+ if (this.loginType === 'password') {
+ // 密码登录逻辑
+ if (this.loginForm.rememberMe) {
+ Cookies.set('username', this.loginForm.username, {
+ expires: 30,
+ })
+ Cookies.set(
+ 'password',
+ encrypt(this.loginForm.password),
+ { expires: 30 },
+ )
+ Cookies.set(
+ 'rememberMe',
+ this.loginForm.rememberMe,
+ {
+ expires: 30,
+ },
+ )
+ } else {
+ Cookies.remove('username')
+ Cookies.remove('password')
+ Cookies.remove('rememberMe')
+ }
} else {
- Cookies.remove('username')
- Cookies.remove('password')
- Cookies.remove('rememberMe')
+ // 短信验证码登录逻辑
+ // 这里可以添加短信验证码登录的特殊处理
+ console.log(
+ '短信验证码登录',
+ this.loginForm.mobile,
+ this.loginForm.smsCode,
+ )
}
+
+ // 调用登录接口
this.$store
.dispatch('Login', this.loginForm)
.then(() => {
@@ -206,7 +368,10 @@ export default {
})
.catch(() => {
this.loading = false
- if (this.captchaEnabled) {
+ if (
+ this.captchaEnabled &&
+ this.loginType === 'password'
+ ) {
this.getCode()
}
})
@@ -218,65 +383,365 @@ export default {
diff --git a/src/views/login_old.vue b/src/views/login_old.vue
new file mode 100644
index 0000000..4687b2b
--- /dev/null
+++ b/src/views/login_old.vue
@@ -0,0 +1,282 @@
+
+
+
+ {{ title }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
![]()
+
+
+ 记住密码
+
+
+ 登 录
+ 登 录 中...
+
+
+ 立即注册
+
+
+
+
+
+
+
+
+
+
+