导航栏/菜单栏显示逻辑修改
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<el-form ref="loginFormRef" :model="loginForm" :rules="loginRules" size="large">
|
||||
<el-form
|
||||
ref="loginFormRef"
|
||||
:model="loginForm"
|
||||
:rules="loginRules"
|
||||
size="large"
|
||||
>
|
||||
<el-form-item prop="username">
|
||||
<el-input v-model="loginForm.username" placeholder="用户名:admin / user">
|
||||
<template #prefix>
|
||||
@@ -10,7 +15,13 @@
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input v-model="loginForm.password" type="password" placeholder="密码:123456" show-password autocomplete="new-password">
|
||||
<el-input
|
||||
v-model="loginForm.password"
|
||||
type="password"
|
||||
placeholder="密码:123456"
|
||||
show-password
|
||||
autocomplete="new-password"
|
||||
>
|
||||
<template #prefix>
|
||||
<el-icon class="el-input__icon">
|
||||
<lock />
|
||||
@@ -20,8 +31,22 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="login-btn">
|
||||
<el-button :icon="CircleClose" round size="large" @click="resetForm(loginFormRef)"> 重置 </el-button>
|
||||
<el-button :icon="UserFilled" round size="large" type="primary" :loading="loading" @click="login(loginFormRef)">
|
||||
<el-button
|
||||
:icon="CircleClose"
|
||||
round
|
||||
size="large"
|
||||
@click="resetForm(loginFormRef)"
|
||||
>
|
||||
重置
|
||||
</el-button>
|
||||
<el-button
|
||||
:icon="UserFilled"
|
||||
round
|
||||
size="large"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="login(loginFormRef)"
|
||||
>
|
||||
登录
|
||||
</el-button>
|
||||
</div>
|
||||
@@ -40,9 +65,10 @@ import { useTabsStore } from "@/stores/modules/tabs";
|
||||
import { useKeepAliveStore } from "@/stores/modules/keepAlive";
|
||||
import { initDynamicRouter } from "@/routers/modules/dynamicRouter";
|
||||
import { CircleClose, UserFilled } from "@element-plus/icons-vue";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import type { ElForm } from "element-plus";
|
||||
import md5 from "md5";
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const tabsStore = useTabsStore();
|
||||
@@ -52,24 +78,27 @@ type FormInstance = InstanceType<typeof ElForm>;
|
||||
const loginFormRef = ref<FormInstance>();
|
||||
const loginRules = reactive({
|
||||
username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
|
||||
password: [{ required: true, message: "请输入密码", trigger: "blur" }]
|
||||
password: [{ required: true, message: "请输入密码", trigger: "blur" }],
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const loginForm = reactive<Login.ReqLoginForm>({
|
||||
username: "",
|
||||
password: ""
|
||||
password: "",
|
||||
});
|
||||
|
||||
// login
|
||||
const login = (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return;
|
||||
formEl.validate(async valid => {
|
||||
formEl.validate(async (valid) => {
|
||||
if (!valid) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
// 1.执行登录接口
|
||||
const { data } = await loginApi({ ...loginForm, password: md5(loginForm.password) });
|
||||
const { data } = await loginApi({
|
||||
...loginForm,
|
||||
password: md5(loginForm.password),
|
||||
});
|
||||
userStore.setToken(data.accessToken);
|
||||
|
||||
// 2.添加动态路由
|
||||
@@ -81,11 +110,13 @@ const login = (formEl: FormInstance | undefined) => {
|
||||
|
||||
// 4.跳转到首页
|
||||
router.push(HOME_URL);
|
||||
// 5.登录默认不显示菜单和导航栏
|
||||
authStore.resetAuthStore();
|
||||
ElNotification({
|
||||
title: getTimeState(),
|
||||
message: "登录成功",
|
||||
type: "success",
|
||||
duration: 3000
|
||||
duration: 3000,
|
||||
});
|
||||
} finally {
|
||||
loading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user