暂去掉验证码登录
This commit is contained in:
1 parent
4cb85e2dea
commit
a9f2d0a67f
1 file changed
+58
-51
@@ -1,5 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-form size="large" class="login-content-form" ref="loginFormRef" :rules="loginRules" :model="state.ruleForm" @keyup.enter="handleVerify">
|
<el-form
|
||||||
|
size="large"
|
||||||
|
class="login-content-form"
|
||||||
|
ref="loginFormRef"
|
||||||
|
:rules="loginRules"
|
||||||
|
:model="state.ruleForm"
|
||||||
|
@keyup.enter="handleVerify"
|
||||||
|
>
|
||||||
<el-form-item class="login-animation1" prop="username">
|
<el-form-item class="login-animation1" prop="username">
|
||||||
<el-input
|
<el-input
|
||||||
text
|
text
|
||||||
@@ -56,22 +63,22 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item class="mt-4 login-animation4">
|
<el-form-item class="mt-4 login-animation4">
|
||||||
<el-button type="primary" class="rounded-lg login-content-submit" v-waves @click="handleVerify" :loading="loading">
|
<el-button type="primary" class="rounded-lg login-content-submit" v-waves @click="handleVerify" :loading="loading">
|
||||||
<span class="font-semibold tracking-wide">{{ $t('password.accountBtnText') }}</span>
|
<span class="font-semibold tracking-wide">{{ $t("password.accountBtnText") }}</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<div class="relative flex items-center justify-between">
|
<div class="relative flex items-center justify-between">
|
||||||
<div class="ml-auto text-sm">
|
<div class="ml-auto text-sm">
|
||||||
<a href="#" class="text-blue-500" @click="emit('change', LoginTypeEnum.MOBILE)">
|
<!-- <a href="#" class="text-blue-500" @click="emit('change', LoginTypeEnum.MOBILE)">
|
||||||
{{ $t('password.mobileLogin') }}
|
{{ $t("password.mobileLogin") }}
|
||||||
</a>
|
</a> -->
|
||||||
<a href="#" v-if="autoRegisterEnable" class="ml-2 text-blue-500" @click="emit('change', LoginTypeEnum.REGISTER)">
|
<a href="#" v-if="autoRegisterEnable" class="ml-2 text-blue-500" @click="emit('change', LoginTypeEnum.REGISTER)">
|
||||||
{{ $t('password.createAccount') }}
|
{{ $t("password.createAccount") }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="font12 mt30 login-animation4 login-msg text-slate-400">{{ $t('browserMsgText') }}</div>
|
<div class="font12 mt30 login-animation4 login-msg text-slate-400">{{ $t("browserMsgText") }}</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
<Verify
|
<Verify
|
||||||
@success="verifySuccess"
|
@success="verifySuccess"
|
||||||
@@ -84,92 +91,92 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts" name="password">
|
<script setup lang="ts" name="password">
|
||||||
import { defineAsyncComponent, reactive, ref } from 'vue';
|
import { defineAsyncComponent, reactive, ref } from "vue"
|
||||||
import { useUserInfo } from '/@/stores/userInfo';
|
import { useUserInfo } from "/@/stores/userInfo"
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from "vue-i18n"
|
||||||
import { generateUUID } from '/@/utils/other';
|
import { generateUUID } from "/@/utils/other"
|
||||||
import { LoginErrorEnum, LoginTypeEnum } from '/@/api/login';
|
import { LoginErrorEnum, LoginTypeEnum } from "/@/api/login"
|
||||||
|
|
||||||
// 使用国际化插件
|
// 使用国际化插件
|
||||||
const { t } = useI18n();
|
const { t } = useI18n()
|
||||||
|
|
||||||
// 动态加载滑块验证码组件
|
// 动态加载滑块验证码组件
|
||||||
const Verify = defineAsyncComponent(() => import('/@/components/Verifition/Verify.vue'));
|
const Verify = defineAsyncComponent(() => import("/@/components/Verifition/Verify.vue"))
|
||||||
|
|
||||||
// 定义变量内容
|
// 定义变量内容
|
||||||
const autoRegisterEnable = ref(import.meta.env.VITE_REGISTER_ENABLE === 'true');
|
const autoRegisterEnable = ref(import.meta.env.VITE_REGISTER_ENABLE === "true")
|
||||||
const emit = defineEmits(['signInSuccess', 'change']); // 声明事件名称
|
const emit = defineEmits(["signInSuccess", "change"]) // 声明事件名称
|
||||||
const loginFormRef = ref(); // 定义LoginForm表单引用
|
const loginFormRef = ref() // 定义LoginForm表单引用
|
||||||
const loading = ref(false); // 定义是否正在登录中
|
const loading = ref(false) // 定义是否正在登录中
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
isShowPassword: false, // 是否显示密码
|
isShowPassword: false, // 是否显示密码
|
||||||
ruleForm: {
|
ruleForm: {
|
||||||
// 表单数据
|
// 表单数据
|
||||||
username: '', // 用户名
|
username: "", // 用户名
|
||||||
password: '', // 密码
|
password: "", // 密码
|
||||||
code: '', // 验证码
|
code: "", // 验证码
|
||||||
randomStr: 'blockPuzzle', // 验证码随机数
|
randomStr: "blockPuzzle", // 验证码随机数
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|
||||||
const loginRules = reactive({
|
const loginRules = reactive({
|
||||||
username: [{ required: true, trigger: 'blur', message: t('password.accountPlaceholder1') }], // 用户名校验规则
|
username: [{ required: true, trigger: "blur", message: t("password.accountPlaceholder1") }], // 用户名校验规则
|
||||||
password: [{ required: true, trigger: 'blur', message: t('password.accountPlaceholder2') }], // 密码校验规则
|
password: [{ required: true, trigger: "blur", message: t("password.accountPlaceholder2") }], // 密码校验规则
|
||||||
code: [{ required: true, trigger: 'blur', message: t('verify.imageCode') }],
|
code: [{ required: true, trigger: "blur", message: t("verify.imageCode") }],
|
||||||
});
|
})
|
||||||
|
|
||||||
const verifyref = ref<InstanceType<typeof Verify>>(null); // 定义verify组件引用
|
const verifyref = ref<InstanceType<typeof Verify>>(null) // 定义verify组件引用
|
||||||
// 是否开启验证码
|
// 是否开启验证码
|
||||||
const verifyEnable = ref(import.meta.env.VITE_VERIFY_ENABLE === 'true');
|
const verifyEnable = ref(import.meta.env.VITE_VERIFY_ENABLE === "true")
|
||||||
const verifyImageEnable = ref(import.meta.env.VITE_VERIFY_IMAGE_ENABLE === 'true');
|
const verifyImageEnable = ref(import.meta.env.VITE_VERIFY_IMAGE_ENABLE === "true")
|
||||||
const imgSrc = ref('');
|
const imgSrc = ref("")
|
||||||
|
|
||||||
// 调用图形证码进行校验
|
// 调用图形证码进行校验
|
||||||
const getVerifyImageCode = () => {
|
const getVerifyImageCode = () => {
|
||||||
state.ruleForm.randomStr = generateUUID();
|
state.ruleForm.randomStr = generateUUID()
|
||||||
imgSrc.value = `${import.meta.env.VITE_API_URL}${import.meta.env.VITE_IS_MICRO == 'false' ? '/admin' : '/auth'}/code/image?randomStr=${
|
imgSrc.value = `${import.meta.env.VITE_API_URL}${import.meta.env.VITE_IS_MICRO == "false" ? "/admin" : "/auth"}/code/image?randomStr=${
|
||||||
state.ruleForm.randomStr
|
state.ruleForm.randomStr
|
||||||
}`;
|
}`
|
||||||
};
|
}
|
||||||
|
|
||||||
// 调用滑块验证码进行校验
|
// 调用滑块验证码进行校验
|
||||||
const handleVerify = async () => {
|
const handleVerify = async () => {
|
||||||
const valid = await loginFormRef.value.validate().catch(() => {}); // 表单校验
|
const valid = await loginFormRef.value.validate().catch(() => {}) // 表单校验
|
||||||
|
|
||||||
if (valid && verifyEnable.value) {
|
if (valid && verifyEnable.value) {
|
||||||
verifyref.value.show(); // 显示验证组件
|
verifyref.value.show() // 显示验证组件
|
||||||
} else if (valid) {
|
} else if (valid) {
|
||||||
onSignIn(); // 调用登录方法
|
onSignIn() // 调用登录方法
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// 滑块验证码校验成功调用后台登录接口
|
// 滑块验证码校验成功调用后台登录接口
|
||||||
const verifySuccess = (params: any) => {
|
const verifySuccess = (params: any) => {
|
||||||
state.ruleForm.code = params.captchaVerification; // 获取验证码
|
state.ruleForm.code = params.captchaVerification // 获取验证码
|
||||||
onSignIn(); // 调用登录方法
|
onSignIn() // 调用登录方法
|
||||||
};
|
}
|
||||||
|
|
||||||
// 账号密码登录
|
// 账号密码登录
|
||||||
const onSignIn = async () => {
|
const onSignIn = async () => {
|
||||||
loading.value = true; // 正在登录中
|
loading.value = true // 正在登录中
|
||||||
try {
|
try {
|
||||||
await useUserInfo().login(state.ruleForm); // 调用登录方法
|
await useUserInfo().login(state.ruleForm) // 调用登录方法
|
||||||
emit('signInSuccess'); // 触发事件
|
emit("signInSuccess") // 触发事件
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err?.data === LoginErrorEnum.CREDENTIALS_EXPIRED) {
|
if (err?.data === LoginErrorEnum.CREDENTIALS_EXPIRED) {
|
||||||
emit('change', LoginTypeEnum.EXPIRE, state.ruleForm.username); // 触发修改密码
|
emit("change", LoginTypeEnum.EXPIRE, state.ruleForm.username) // 触发修改密码
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false; // 登录结束
|
loading.value = false // 登录结束
|
||||||
if (verifyImageEnable.value) {
|
if (verifyImageEnable.value) {
|
||||||
getVerifyImageCode();
|
getVerifyImageCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (verifyImageEnable.value) {
|
if (verifyImageEnable.value) {
|
||||||
getVerifyImageCode();
|
getVerifyImageCode()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
</script>
|
</script>
|
||||||
Reference in new issue
Block a user