2025-10-14 19:00:47 +08:00
|
|
|
|
import { defineStore } from 'pinia'
|
2025-10-27 16:27:12 +08:00
|
|
|
|
import { type AuthState } from '@/stores/interface'
|
2025-10-14 19:00:47 +08:00
|
|
|
|
import { getAuthButtonListApi, getAuthMenuListApi } from '@/api/user/login'
|
|
|
|
|
|
import { getAllBreadcrumbList, getFlatMenuList, getShowMenuList } from '@/utils'
|
|
|
|
|
|
import { AUTH_STORE_KEY } from '@/stores/constant'
|
|
|
|
|
|
import { useModeStore } from '@/stores/modules/mode'
|
|
|
|
|
|
import { getLicense } from '@/api/activate'
|
|
|
|
|
|
import type { Activate } from '@/api/activate/interface'
|
2025-07-21 13:47:56 +08:00
|
|
|
|
|
2025-10-27 16:27:12 +08:00
|
|
|
|
export const useAuthStore = defineStore(AUTH_STORE_KEY, {
|
2025-10-14 19:00:47 +08:00
|
|
|
|
state: (): AuthState => ({
|
|
|
|
|
|
// 按钮权限列表
|
|
|
|
|
|
authButtonList: {},
|
|
|
|
|
|
// 菜单权限列表
|
|
|
|
|
|
authMenuList: [],
|
|
|
|
|
|
// 当前页面的 router name,用来做按钮权限筛选
|
|
|
|
|
|
routeName: '',
|
|
|
|
|
|
//登录不显示菜单栏和导航栏,点击进入测试的时候显示
|
|
|
|
|
|
showMenuFlag: JSON.parse(localStorage.getItem('showMenuFlag') as string),
|
2025-10-27 16:27:12 +08:00
|
|
|
|
activateInfo: {} as Activate.ActivationCodePlaintext
|
2025-10-14 19:00:47 +08:00
|
|
|
|
}),
|
|
|
|
|
|
getters: {
|
|
|
|
|
|
// 按钮权限列表
|
|
|
|
|
|
authButtonListGet: state => state.authButtonList,
|
|
|
|
|
|
// 菜单权限列表 ==> 这里的菜单没有经过任何处理
|
|
|
|
|
|
authMenuListGet: state => state.authMenuList,
|
|
|
|
|
|
// 菜单权限列表 ==> 左侧菜单栏渲染,需要剔除 isHide == true
|
|
|
|
|
|
showMenuListGet: state => getShowMenuList(state.authMenuList),
|
|
|
|
|
|
// 菜单权限列表 ==> 扁平化之后的一维数组菜单,主要用来添加动态路由
|
|
|
|
|
|
flatMenuListGet: state => getFlatMenuList(state.authMenuList),
|
|
|
|
|
|
// 递归处理后的所有面包屑导航列表
|
|
|
|
|
|
breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList),
|
|
|
|
|
|
//是否显示菜单和导航栏
|
|
|
|
|
|
showMenuFlagGet: state => state.showMenuFlag,
|
|
|
|
|
|
// 获取激活信息
|
|
|
|
|
|
activateInfoGet: state => state.activateInfo
|
2024-08-23 13:19:20 +08:00
|
|
|
|
},
|
2025-10-14 19:00:47 +08:00
|
|
|
|
actions: {
|
|
|
|
|
|
// Get AuthButtonList
|
|
|
|
|
|
async getAuthButtonList() {
|
|
|
|
|
|
const { data } = await getAuthButtonListApi()
|
|
|
|
|
|
this.authButtonList = data
|
|
|
|
|
|
},
|
|
|
|
|
|
// Get AuthMenuList
|
|
|
|
|
|
async getAuthMenuList() {
|
|
|
|
|
|
const modeStore = useModeStore()
|
|
|
|
|
|
|
|
|
|
|
|
const { data: menuData } = await getAuthMenuListApi()
|
|
|
|
|
|
// 根据不同模式过滤菜单
|
|
|
|
|
|
const filteredMenu =
|
|
|
|
|
|
modeStore.currentMode === '比对式'
|
|
|
|
|
|
? filterMenuByExcludedNames(menuData, ['testSource', 'testScript', 'controlSource'])
|
|
|
|
|
|
: filterMenuByExcludedNames(menuData, ['standardDevice'])
|
2025-07-21 13:47:56 +08:00
|
|
|
|
|
2025-10-14 19:00:47 +08:00
|
|
|
|
this.authMenuList = filteredMenu
|
|
|
|
|
|
},
|
|
|
|
|
|
// Set RouteName
|
|
|
|
|
|
async setRouteName(name: string) {
|
|
|
|
|
|
this.routeName = name
|
|
|
|
|
|
},
|
|
|
|
|
|
//重置权限
|
|
|
|
|
|
async resetAuthStore() {
|
|
|
|
|
|
this.showMenuFlag = false
|
|
|
|
|
|
localStorage.removeItem('showMenuFlag')
|
|
|
|
|
|
},
|
|
|
|
|
|
//修改判断菜单栏/导航栏显示条件
|
|
|
|
|
|
async setShowMenu() {
|
|
|
|
|
|
this.showMenuFlag = true
|
|
|
|
|
|
localStorage.setItem('showMenuFlag', 'true')
|
|
|
|
|
|
},
|
|
|
|
|
|
//更改模式
|
2025-10-27 16:27:12 +08:00
|
|
|
|
changeModel() {
|
2025-10-14 19:00:47 +08:00
|
|
|
|
this.showMenuFlag = false
|
|
|
|
|
|
localStorage.removeItem('showMenuFlag')
|
|
|
|
|
|
},
|
|
|
|
|
|
async setActivateInfo() {
|
|
|
|
|
|
const license_result = await getLicense()
|
2025-10-22 11:40:57 +08:00
|
|
|
|
const licenseData = license_result.data as Activate.ActivationCodePlaintext
|
|
|
|
|
|
if (!licenseData.simulate) {
|
|
|
|
|
|
licenseData.simulate = {
|
|
|
|
|
|
permanently: 0
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!licenseData.digital) {
|
|
|
|
|
|
licenseData.digital = {
|
|
|
|
|
|
permanently: 0
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!licenseData.contrast) {
|
|
|
|
|
|
licenseData.contrast = {
|
|
|
|
|
|
permanently: 0
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-14 19:00:47 +08:00
|
|
|
|
this.activateInfo = licenseData
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2025-07-21 13:47:56 +08:00
|
|
|
|
|
2025-08-08 13:18:01 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 通用菜单过滤函数
|
|
|
|
|
|
* @param menuList 菜单列表
|
|
|
|
|
|
* @param excludedNames 需要排除的菜单名称数组
|
|
|
|
|
|
* @returns 过滤后的菜单列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
function filterMenuByExcludedNames(menuList: any[], excludedNames: string[]): any[] {
|
2025-10-14 19:00:47 +08:00
|
|
|
|
return menuList.filter(menu => {
|
|
|
|
|
|
// 如果当前项有 children,递归处理子项
|
|
|
|
|
|
if (menu.children && menu.children.length > 0) {
|
|
|
|
|
|
menu.children = filterMenuByExcludedNames(menu.children, excludedNames)
|
|
|
|
|
|
}
|
|
|
|
|
|
// 过滤掉在排除列表中的菜单项
|
|
|
|
|
|
return !excludedNames.includes(menu.name)
|
|
|
|
|
|
})
|
2025-07-21 13:47:56 +08:00
|
|
|
|
}
|