|
@@ -4,7 +4,7 @@ import { Menu_User_List } from '@/api/role/index'
|
|
import { User_Info } from '@/api/user/index'
|
|
import { User_Info } from '@/api/user/index'
|
|
import { isEmptyObject } from '@/utils/common'
|
|
import { isEmptyObject } from '@/utils/common'
|
|
import { User_Dept_List, User_Post_List } from '@/api/user/index'
|
|
import { User_Dept_List, User_Post_List } from '@/api/user/index'
|
|
-import { getAllBreadcrumbList, hanlderMenuList } from '@/utils/common'
|
|
|
|
|
|
+import { flatMenuListGet, AddRouterMeta } from '@/utils/common'
|
|
|
|
|
|
export const GlobalStore = defineStore({
|
|
export const GlobalStore = defineStore({
|
|
id: 'GlobalState',
|
|
id: 'GlobalState',
|
|
@@ -16,9 +16,10 @@ export const GlobalStore = defineStore({
|
|
UserDeptList: [],
|
|
UserDeptList: [],
|
|
UserPostList: [],
|
|
UserPostList: [],
|
|
User_tokey: localStorage.getItem('User_tokey') || '',
|
|
User_tokey: localStorage.getItem('User_tokey') || '',
|
|
- MenuList: [],
|
|
|
|
path: '',
|
|
path: '',
|
|
- allBreadcrumbList: null
|
|
|
|
|
|
+ MenuList: [],
|
|
|
|
+ allBreadcrumbList: [],
|
|
|
|
+ flatMenu: []
|
|
}),
|
|
}),
|
|
getters: {
|
|
getters: {
|
|
GET_User_tokey: state => state.User_tokey,
|
|
GET_User_tokey: state => state.User_tokey,
|
|
@@ -26,7 +27,8 @@ export const GlobalStore = defineStore({
|
|
GET_isCollapse: state => state.isCollapse,
|
|
GET_isCollapse: state => state.isCollapse,
|
|
GET_Breadcrumb: state => state.breadcrumb,
|
|
GET_Breadcrumb: state => state.breadcrumb,
|
|
GET_User_Info: state => state.userInfo,
|
|
GET_User_Info: state => state.userInfo,
|
|
- GET_Menu_List: state => state.MenuList
|
|
|
|
|
|
+ GET_Menu_List: state => state.MenuList,
|
|
|
|
+ GET_Flat_Menu: state => state.flatMenu
|
|
},
|
|
},
|
|
actions: {
|
|
actions: {
|
|
SET_User_Tokey(payload: string) {
|
|
SET_User_Tokey(payload: string) {
|
|
@@ -43,12 +45,15 @@ export const GlobalStore = defineStore({
|
|
})
|
|
})
|
|
this.breadcrumb = map
|
|
this.breadcrumb = map
|
|
},
|
|
},
|
|
- // SET_User_Info(payload: any) {
|
|
|
|
- // this.userInfo = payload
|
|
|
|
- // },
|
|
|
|
|
|
+ SET_User_Info(payload: any) {
|
|
|
|
+ this.userInfo = payload
|
|
|
|
+ },
|
|
SET_Path(payload: string) {
|
|
SET_Path(payload: string) {
|
|
this.path = payload
|
|
this.path = payload
|
|
},
|
|
},
|
|
|
|
+ SET_Flat_Menu(payload: any) {
|
|
|
|
+ this.flatMenu = payload
|
|
|
|
+ },
|
|
async SET_User_Dept_List() {
|
|
async SET_User_Dept_List() {
|
|
const res: any = await User_Dept_List()
|
|
const res: any = await User_Dept_List()
|
|
this.UserDeptList = res.Data
|
|
this.UserDeptList = res.Data
|
|
@@ -59,20 +64,19 @@ export const GlobalStore = defineStore({
|
|
},
|
|
},
|
|
async SET_UserInfo() {
|
|
async SET_UserInfo() {
|
|
// 如果以及有用户数据,则不请求
|
|
// 如果以及有用户数据,则不请求
|
|
- if (!isEmptyObject(this.GET_User_Info)) return
|
|
|
|
|
|
+ if (isEmptyObject(this.GET_User_Info)) return
|
|
const res: any = await User_Info({ User_tokey: this.GET_User_tokey })
|
|
const res: any = await User_Info({ User_tokey: this.GET_User_tokey })
|
|
if (res.Code === 200) {
|
|
if (res.Code === 200) {
|
|
- this.userInfo = res.Data
|
|
|
|
|
|
+ this.SET_User_Info(res.Data)
|
|
localStorage.setItem('User_info', JSON.stringify(res.Data))
|
|
localStorage.setItem('User_info', JSON.stringify(res.Data))
|
|
}
|
|
}
|
|
},
|
|
},
|
|
async SET_Menu_User_List() {
|
|
async SET_Menu_User_List() {
|
|
const res: any = await Menu_User_List({ User_tokey: this.GET_User_tokey })
|
|
const res: any = await Menu_User_List({ User_tokey: this.GET_User_tokey })
|
|
if (res.Code === 200) {
|
|
if (res.Code === 200) {
|
|
- this.MenuList = res.Data.Data
|
|
|
|
- hanlderMenuList(res.Data.Data)
|
|
|
|
- this.allBreadcrumbList = getAllBreadcrumbList(res.Data.Data)
|
|
|
|
- // console.log(this.allBreadcrumbList)
|
|
|
|
|
|
+ this.MenuList = res.Data.Data // 保存所有菜单
|
|
|
|
+ this.allBreadcrumbList = AddRouterMeta(res.Data.Data) // 扩展菜单属性
|
|
|
|
+ this.SET_Flat_Menu(flatMenuListGet(this.allBreadcrumbList)) // 接收扁平化菜单
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|