mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2025-04-24 23:47:17 +08:00
fix: 登陆失败时验证码不重新加载&修改角色状态时出现undefined
This commit is contained in:
parent
fb7ca82260
commit
36a21a3126
@ -1,11 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import {
|
||||||
|
onBeforeMount,
|
||||||
|
onBeforeUnmount,
|
||||||
|
onMounted,
|
||||||
|
reactive,
|
||||||
ref,
|
ref,
|
||||||
toRaw,
|
toRaw,
|
||||||
reactive,
|
|
||||||
onMounted,
|
|
||||||
onBeforeUnmount,
|
|
||||||
onBeforeMount,
|
|
||||||
watch
|
watch
|
||||||
} from "vue";
|
} from "vue";
|
||||||
import Motion from "./utils/motion";
|
import Motion from "./utils/motion";
|
||||||
@ -22,16 +22,17 @@ import type { FormInstance } from "element-plus";
|
|||||||
import { operates, thirdParty } from "./utils/enums";
|
import { operates, thirdParty } from "./utils/enums";
|
||||||
import { useLayout } from "@/layout/hooks/useLayout";
|
import { useLayout } from "@/layout/hooks/useLayout";
|
||||||
import { rsaEncrypt } from "@/utils/crypt";
|
import { rsaEncrypt } from "@/utils/crypt";
|
||||||
import { initRouter, getTopMenu } from "@/router/utils";
|
import { getTopMenu, initRouter } from "@/router/utils";
|
||||||
import { bg, avatar, illustration } from "./utils/static";
|
import { avatar, bg, illustration } from "./utils/static";
|
||||||
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
||||||
import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
|
import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
|
||||||
import {
|
import {
|
||||||
saveIsRememberMe,
|
|
||||||
getIsRememberMe,
|
getIsRememberMe,
|
||||||
savePassword,
|
|
||||||
getPassword,
|
getPassword,
|
||||||
removePassword
|
removePassword,
|
||||||
|
saveIsRememberMe,
|
||||||
|
savePassword,
|
||||||
|
setTokenFromBackend
|
||||||
} from "@/utils/auth";
|
} from "@/utils/auth";
|
||||||
|
|
||||||
import dayIcon from "@/assets/svg/day.svg?component";
|
import dayIcon from "@/assets/svg/day.svg?component";
|
||||||
@ -39,8 +40,7 @@ import darkIcon from "@/assets/svg/dark.svg?component";
|
|||||||
import Lock from "@iconify-icons/ri/lock-fill";
|
import Lock from "@iconify-icons/ri/lock-fill";
|
||||||
import User from "@iconify-icons/ri/user-3-fill";
|
import User from "@iconify-icons/ri/user-3-fill";
|
||||||
import * as CommonAPI from "@/api/common/login";
|
import * as CommonAPI from "@/api/common/login";
|
||||||
import { setTokenFromBackend } from "../../utils/auth";
|
import { useUserStoreHook } from "@/store/modules/user";
|
||||||
import { useUserStoreHook } from "../../store/modules/user";
|
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "Login"
|
name: "Login"
|
||||||
@ -97,6 +97,8 @@ const onLogin = async (formEl: FormInstance | undefined) => {
|
|||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
//如果登陆失败则重新获取验证码
|
||||||
|
getCaptchaCode();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@ -113,10 +115,12 @@ function onkeypress({ code }: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getCaptchaCode() {
|
async function getCaptchaCode() {
|
||||||
await CommonAPI.getCaptchaCode().then(res => {
|
if (isCaptchaOn.value) {
|
||||||
captchaCodeBase64.value = `data:image/gif;base64,${res.data.captchaCodeImg}`;
|
await CommonAPI.getCaptchaCode().then(res => {
|
||||||
ruleForm.captchaCodeKey = res.data.captchaCodeKey;
|
captchaCodeBase64.value = `data:image/gif;base64,${res.data.captchaCodeImg}`;
|
||||||
});
|
ruleForm.captchaCodeKey = res.data.captchaCodeKey;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(isRememberMe, newVal => {
|
watch(isRememberMe, newVal => {
|
||||||
@ -132,9 +136,7 @@ onBeforeMount(async () => {
|
|||||||
useUserStoreHook().SET_DICTIONARY(res.data.dictionary);
|
useUserStoreHook().SET_DICTIONARY(res.data.dictionary);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isCaptchaOn.value) {
|
await getCaptchaCode();
|
||||||
getCaptchaCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
isRememberMe.value = getIsRememberMe();
|
isRememberMe.value = getIsRememberMe();
|
||||||
if (isRememberMe.value) {
|
if (isRememberMe.value) {
|
||||||
@ -158,9 +160,9 @@ onBeforeUnmount(() => {
|
|||||||
<!-- 主题 -->
|
<!-- 主题 -->
|
||||||
<el-switch
|
<el-switch
|
||||||
v-model="dataTheme"
|
v-model="dataTheme"
|
||||||
inline-prompt
|
|
||||||
:active-icon="dayIcon"
|
:active-icon="dayIcon"
|
||||||
:inactive-icon="darkIcon"
|
:inactive-icon="darkIcon"
|
||||||
|
inline-prompt
|
||||||
@change="dataThemeChange"
|
@change="dataThemeChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -175,7 +177,7 @@ onBeforeUnmount(() => {
|
|||||||
<avatar class="avatar" />
|
<avatar class="avatar" />
|
||||||
<Motion>
|
<Motion>
|
||||||
<h2 class="outline-none">
|
<h2 class="outline-none">
|
||||||
<TypeIt :values="[title]" :cursor="false" :speed="150" />
|
<TypeIt :cursor="false" :speed="150" :values="[title]" />
|
||||||
</h2>
|
</h2>
|
||||||
</Motion>
|
</Motion>
|
||||||
|
|
||||||
@ -198,10 +200,10 @@ onBeforeUnmount(() => {
|
|||||||
prop="username"
|
prop="username"
|
||||||
>
|
>
|
||||||
<el-input
|
<el-input
|
||||||
clearable
|
|
||||||
v-model="ruleForm.username"
|
v-model="ruleForm.username"
|
||||||
placeholder="账号"
|
|
||||||
:prefix-icon="useRenderIcon(User)"
|
:prefix-icon="useRenderIcon(User)"
|
||||||
|
clearable
|
||||||
|
placeholder="账号"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</Motion>
|
</Motion>
|
||||||
@ -209,11 +211,11 @@ onBeforeUnmount(() => {
|
|||||||
<Motion :delay="150">
|
<Motion :delay="150">
|
||||||
<el-form-item prop="password">
|
<el-form-item prop="password">
|
||||||
<el-input
|
<el-input
|
||||||
clearable
|
|
||||||
show-password
|
|
||||||
v-model="ruleForm.password"
|
v-model="ruleForm.password"
|
||||||
placeholder="密码"
|
|
||||||
:prefix-icon="useRenderIcon(Lock)"
|
:prefix-icon="useRenderIcon(Lock)"
|
||||||
|
clearable
|
||||||
|
placeholder="密码"
|
||||||
|
show-password
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</Motion>
|
</Motion>
|
||||||
@ -221,19 +223,19 @@ onBeforeUnmount(() => {
|
|||||||
<Motion :delay="200">
|
<Motion :delay="200">
|
||||||
<el-form-item v-if="isCaptchaOn" prop="captchaCode">
|
<el-form-item v-if="isCaptchaOn" prop="captchaCode">
|
||||||
<el-input
|
<el-input
|
||||||
clearable
|
|
||||||
v-model="ruleForm.captchaCode"
|
v-model="ruleForm.captchaCode"
|
||||||
placeholder="验证码"
|
|
||||||
:prefix-icon="useRenderIcon('ri:shield-keyhole-line')"
|
:prefix-icon="useRenderIcon('ri:shield-keyhole-line')"
|
||||||
|
clearable
|
||||||
|
placeholder="验证码"
|
||||||
>
|
>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
<el-image
|
<el-image
|
||||||
|
:src="captchaCodeBase64"
|
||||||
style="
|
style="
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
width: 120px;
|
width: 120px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
"
|
"
|
||||||
:src="captchaCodeBase64"
|
|
||||||
@click="getCaptchaCode"
|
@click="getCaptchaCode"
|
||||||
>
|
>
|
||||||
<template #error>
|
<template #error>
|
||||||
@ -248,16 +250,16 @@ onBeforeUnmount(() => {
|
|||||||
<Motion :delay="250">
|
<Motion :delay="250">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<div class="w-full h-[20px] flex justify-between items-center">
|
<div class="w-full h-[20px] flex justify-between items-center">
|
||||||
<el-checkbox v-model="isRememberMe"> 记住密码 </el-checkbox>
|
<el-checkbox v-model="isRememberMe"> 记住密码</el-checkbox>
|
||||||
<el-button link type="primary" @click="currentPage = 4">
|
<el-button link type="primary" @click="currentPage = 4">
|
||||||
忘记密码
|
忘记密码
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-button
|
<el-button
|
||||||
|
:loading="loading"
|
||||||
class="w-full mt-4"
|
class="w-full mt-4"
|
||||||
size="default"
|
size="default"
|
||||||
type="primary"
|
type="primary"
|
||||||
:loading="loading"
|
|
||||||
@click="onLogin(ruleFormRef)"
|
@click="onLogin(ruleFormRef)"
|
||||||
>
|
>
|
||||||
登录
|
登录
|
||||||
@ -295,8 +297,8 @@ onBeforeUnmount(() => {
|
|||||||
>
|
>
|
||||||
<IconifyIconOnline
|
<IconifyIconOnline
|
||||||
:icon="`ri:${item.icon}-fill`"
|
:icon="`ri:${item.icon}-fill`"
|
||||||
width="20"
|
|
||||||
class="text-gray-500 cursor-pointer hover:text-blue-400"
|
class="text-gray-500 cursor-pointer hover:text-blue-400"
|
||||||
|
width="20"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@ -328,8 +330,8 @@ onBeforeUnmount(() => {
|
|||||||
rel="external nofollow"
|
rel="external nofollow"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
type="primary"
|
type="primary"
|
||||||
>闽ICP备2022018106号-2</el-link
|
>闽ICP备2022018106号-2
|
||||||
>
|
</el-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,7 @@ import { getMenuListApi, MenuDTO } from "@/api/system/menu";
|
|||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
import { usePublicHooks } from "../../hooks";
|
import { usePublicHooks } from "../../hooks";
|
||||||
import { type PaginationProps } from "@pureadmin/table";
|
import { type PaginationProps } from "@pureadmin/table";
|
||||||
import { reactive, ref, onMounted, toRaw } from "vue";
|
import { onMounted, reactive, ref, toRaw } from "vue";
|
||||||
import { toTree } from "@/utils/tree";
|
import { toTree } from "@/utils/tree";
|
||||||
|
|
||||||
export function useRole() {
|
export function useRole() {
|
||||||
@ -97,7 +97,7 @@ export function useRole() {
|
|||||||
`确认要<strong>${
|
`确认要<strong>${
|
||||||
row.status === 0 ? "停用" : "启用"
|
row.status === 0 ? "停用" : "启用"
|
||||||
}</strong><strong style='color:var(--el-color-primary)'>${
|
}</strong><strong style='color:var(--el-color-primary)'>${
|
||||||
row.name
|
row.roleName
|
||||||
}</strong>吗?`,
|
}</strong>吗?`,
|
||||||
"系统提示",
|
"系统提示",
|
||||||
{
|
{
|
||||||
@ -124,7 +124,7 @@ export function useRole() {
|
|||||||
loading: false
|
loading: false
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
message(`已${row.status === 0 ? "停用" : "启用"}${row.name}`, {
|
message(`已${row.status === 0 ? "停用" : "启用"}${row.roleName}`, {
|
||||||
type: "success"
|
type: "success"
|
||||||
});
|
});
|
||||||
}, 300);
|
}, 300);
|
||||||
@ -170,6 +170,7 @@ export function useRole() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const menuTree = ref<MenuDTO[]>([]);
|
const menuTree = ref<MenuDTO[]>([]);
|
||||||
|
|
||||||
/** 菜单权限 */
|
/** 菜单权限 */
|
||||||
async function getMenuTree() {
|
async function getMenuTree() {
|
||||||
if (menuTree.value?.length) {
|
if (menuTree.value?.length) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user