提交 0cec9ddf authored 作者: 刘旭's avatar 刘旭

修复登录权限bug,登录失败刷新验证码功能

上级 fd14c361
......@@ -4,7 +4,6 @@ import { LoginParm } from "@/services/types/user/userModel";
export default function useBaseLogin() {
//表单的ref属性
const loginFormRef = ref<InstanceType<typeof ElForm>>();
//表单绑定的数据
const loginModel = reactive<LoginParm>({
username: '',
......@@ -32,6 +31,6 @@ export default function useBaseLogin() {
return {
loginModel,
rules,
loginFormRef
loginFormRef,
}
}
\ No newline at end of file
import { ref, onMounted } from 'vue'
import { getImagApi } from '@/services/api/user/userAPI';
import { ElNotification } from 'element-plus';
import {debounce} from '@/utils/debounce_throttle'
import { debounce } from '@/utils/debounce_throttle'
export default function useImage() {
//定义图片src
......@@ -13,20 +13,23 @@ export default function useImage() {
await getImagApi().then(res => {
return res.data.data as string;
}).then(data => {
imgSrc.value = data;
setTimeout(() => {
imgSrc.value = data;
}, 1000);
}).catch((err) => {
ElNotification({
title:'获取验证码失败',
message:err.message,
type:'error',
title: '获取验证码失败',
message: err.message,
type: 'error',
})
})
},1000)
}, 1000)
onMounted(() => {
getImage()
})
return {
imgSrc,
getImage
getImage,
}
}
\ No newline at end of file
import { ref,getCurrentInstance } from "vue";
import { ref, getCurrentInstance, nextTick } from "vue";
import { LoginParm } from "@/services/types/user/userModel";
import { store } from "@/store";
import { ElNotification } from 'element-plus';
import router from '@/router/index'
export default function useLogin(loginModel: LoginParm) {
const { proxy } = getCurrentInstance() as any;
const flag: any = ref(0)
//登录提交
const login = async () => {
//表单验证
......@@ -15,27 +17,29 @@ export default function useLogin(loginModel: LoginParm) {
loginState.value = false
if (res.code == 200) {
ElNotification({
title:'登录成功',
message:'欢迎回来',
type:'success',
title: '登录成功',
message: '欢迎回来',
type: 'success',
})
//跳转到首页
setTimeout(()=> {
setTimeout(() => {
router.push({ path: '/' })
},1500)
}, 1500)
} else {
ElNotification({
title:'登陆失败',
message:res.msg,
type:'error',
})
flag.value++
// ElNotification({
// title: '登陆失败',
// message: res.msg,
// type: 'error',
// })
}
}).catch((err) => {
loginState.value = false
// console.log(imgSrc.value, 'lll');
ElNotification({
title:'登录失败',
message:err.message,
type:'error',
title: '登录失败',
message: err.message,
type: 'error',
})
})
}
......@@ -45,6 +49,7 @@ export default function useLogin(loginModel: LoginParm) {
const loginState = ref(false)
return {
login,
flag,
loginState
}
}
\ No newline at end of file
......@@ -2,8 +2,10 @@ import { getMenuListApi } from "@/services/api/menu/menuAPI";
import { RouteRecordRaw } from "vue-router";
import { ActionContext } from "vuex";
import { RootState } from "..";
import { ElNotification } from "element-plus";
import Layout from "@/layout/index.vue";
import { store } from "@/store";
const modules = import.meta.glob("../../views/**/*.vue");
//定义state
export type MenuState = {
......@@ -51,15 +53,27 @@ export const actions = {
return new Promise((resolve, reject) => {
getMenuListApi()
.then((res) => {
let accessedRoutes;
if (res.code == 200) {
//动态生成路由
accessedRoutes = filterAsyncRoutes(res.data, router);
//设置到menuList
commit("setMenuList", accessedRoutes);
if (res.data.length === 0) {
ElNotification({
title: '获取权限失败',
message: '该账号没有后台权限,请联系管理员授权',
type: 'error',
})
sessionStorage.clear()
return window.location.href = "/#/login";
}
else {
let accessedRoutes;
if (res.code == 200) {
//动态生成路由
accessedRoutes = filterAsyncRoutes(res.data, router);
//设置到menuList
commit("setMenuList", accessedRoutes);
}
//返回
resolve(accessedRoutes);
}
//返回
resolve(accessedRoutes);
console.log('getMenuList', res);
})
.catch((error) => {
reject(error);
......
......@@ -47,6 +47,7 @@
</div>
</template>
<script setup lang="ts">
import { watch, ref } from "vue";
import useImage from "@/services/business/login/useImage";
import useBaseLogin from "@/services/business/login/useBaseLogin";
import useLogin from "@/services/business/login/useLogin";
......@@ -57,7 +58,9 @@ const { loginModel, rules, loginFormRef } = useBaseLogin();
const { imgSrc, getImage } = useImage();
//登录
const { login, loginState } = useLogin(loginModel);
const { login, loginState, flag } = useLogin(loginModel);
watch(flag, () => getImage(), { deep: true })
</script>
<style scoped lang="scss">
.logincontainer {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论