fix 重新登录未加载管理员菜单

This commit is contained in:
bwcx_jzy 2023-04-14 11:56:13 +08:00
parent 72495297f0
commit 335c0dbbcd
No known key found for this signature in database
GPG Key ID: E187D6E9DDDE8C53
4 changed files with 17 additions and 14 deletions

View File

@ -13,6 +13,7 @@
3. 【server】优化 自动探测服务端登录验证码是否可用
4. 【all】优化 文件编辑后缀识别支持配置文件名或者正则表达式(感谢@MichelleChung
5. 【server】优化 支持自动执行触发器清理
6. 【server】优化 重新登录未加载管理员菜单(@A
------

View File

@ -289,12 +289,8 @@ export default {
dispatchLogin(data) {
// store action token
this.$store.dispatch("login", { token: data.token, longTermToken: data.longTermToken }).then(() => {
//
this.$store.dispatch("restLoadSystemMenus").then(() => {
//
//
this.$router.push({ path: "/" });
});
//
this.$router.push({ path: "/" });
});
},
},

View File

@ -3,7 +3,7 @@
* 存储所有打开的 tab 窗口并且记录当前激活的 tab
* 另外提供打开新 tab跳转 tab移除 tab 功能
*/
import { MANAGEMENT_ACTIVE_TAB_KEY, MANAGEMENT_TAB_LIST_KEY, MANAGEMENT_ACTIVE_MENU_KEY } from "@/utils/const";
import { MANAGEMENT_ACTIVE_MENU_KEY, MANAGEMENT_ACTIVE_TAB_KEY, MANAGEMENT_TAB_LIST_KEY } from "@/utils/const";
import { getSystemMenu } from "@/api/menu";
import routeMenuMap from "@/router/route-menu";
@ -37,9 +37,9 @@ const app = {
},
actions: {
// 加载系统菜单 action
loadManagementSystemMenus({ commit, state }) {
loadManagementSystemMenus({ commit, state }, rest) {
return new Promise((resolve, reject) => {
if (state.menus.length) {
if (state.menus.length && !rest) {
// 避免重复加载
resolve();
return;
@ -49,13 +49,12 @@ const app = {
.then((res) => {
res.data.forEach((element) => {
if (element.childs.length > 0) {
const childs = element.childs.map((child) => {
element.childs = element.childs.map((child) => {
return {
...child,
path: routeMenuMap[child.id],
};
});
element.childs = childs;
}
});
commit("setManagementMenus", res.data);

View File

@ -43,7 +43,7 @@ const user = {
if (res.code === 200) {
commit("setUserInfo", res.data);
localStorage.setItem(USER_INFO_KEY, JSON.stringify(res.data));
resolve();
resolve(res.data);
}
});
});
@ -62,9 +62,16 @@ const user = {
return new Promise((resolve) => {
commit("setToken", data);
//commit('setUserName', data.userName);
dispatch("refreshUserInfo");
dispatch("refreshUserInfo").then((userinfo) => {
if (userinfo?.systemUser) {
// 刷新管理员菜单
dispatch("loadManagementSystemMenus", true).then(() => {
//
});
}
});
// 加载系统菜单 这里需要等待 action 执行完毕返回 promise, 否则第一次登录可能会从 store 里面获取不到 menus 数据而报错
dispatch("loadSystemMenus").then(() => {
dispatch("restLoadSystemMenus").then(() => {
resolve();
});
});