This commit is contained in:
张成
2026-04-13 11:16:22 +08:00
parent 75149f994f
commit c73afd2325
13 changed files with 421 additions and 30 deletions

View File

@@ -3,6 +3,16 @@ import uiTool from '../utils/uiTool'
import { defaultMenus, filterMenusByIds } from '../config/menuConfig'
import userServer from '../api/system/userServer'
function readTenantLs() {
try {
const s = localStorage.getItem('currentTenant')
if (!s || s === 'undefined') return null
return JSON.parse(s)
} catch {
return null
}
}
export default {
namespaced: true,
state: {
@@ -10,7 +20,9 @@ export default {
avatorImgPath: '',
token: getToken(),
authorityMenus: [],
menuList: localStorage.getItem('menuList') ? JSON.parse(localStorage.getItem('menuList')) : []
menuList: localStorage.getItem('menuList') ? JSON.parse(localStorage.getItem('menuList')) : [],
/** 登录返回的租户信息:{ id, name, code, is_platform } */
currentTenant: readTenantLs()
},
mutations: {
setAvator(state, avatorPath) {
@@ -31,6 +43,14 @@ export default {
setMenuList(state, menus) {
state.menuList = menus
localStorage.setItem('menuList', JSON.stringify(menus))
},
setCurrentTenant(state, tenant) {
state.currentTenant = tenant && typeof tenant === 'object' ? tenant : null
if (state.currentTenant) {
localStorage.setItem('currentTenant', JSON.stringify(state.currentTenant))
} else {
localStorage.removeItem('currentTenant')
}
}
},
getters: {
@@ -162,6 +182,11 @@ export default {
commit('setUserName', name)
commit('setToken', token)
if (res.data.tenant) {
commit('setCurrentTenant', res.data.tenant)
} else {
commit('setCurrentTenant', null)
}
// 登录接口返回的 authorityMenus 是菜单 ID 数组字符串
console.log('登录返回的菜单 IDs:', authorityMenusIds)
@@ -205,6 +230,7 @@ export default {
commit('setToken', '')
commit('setAuthorityMenus', '[]')
commit('setMenuList', [])
commit('setCurrentTenant', null)
localStorage.removeItem('menuList')
window.location.reload()
}