94 lines
3.4 KiB
TypeScript
94 lines
3.4 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { type AuthState } from '@/stores/interface'
|
|
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'
|
|
|
|
const CONTRAST_MODE_NAME = '比对式'
|
|
|
|
export const useAuthStore = defineStore(AUTH_STORE_KEY, {
|
|
state: (): AuthState => ({
|
|
authButtonList: {},
|
|
authMenuList: [],
|
|
routeName: '',
|
|
showMenuFlag: JSON.parse(localStorage.getItem('showMenuFlag') as string),
|
|
activateInfo: {} as Activate.ActivationCodePlaintext
|
|
}),
|
|
getters: {
|
|
authButtonListGet: state => state.authButtonList,
|
|
authMenuListGet: state => state.authMenuList,
|
|
showMenuListGet: state => getShowMenuList(state.authMenuList),
|
|
flatMenuListGet: state => getFlatMenuList(state.authMenuList),
|
|
breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList),
|
|
showMenuFlagGet: state => state.showMenuFlag,
|
|
activateInfoGet: state => state.activateInfo
|
|
},
|
|
actions: {
|
|
async getAuthButtonList() {
|
|
const { data } = await getAuthButtonListApi()
|
|
this.authButtonList = data
|
|
},
|
|
async getAuthMenuList() {
|
|
const modeStore = useModeStore()
|
|
const { data: menuData } = await getAuthMenuListApi()
|
|
|
|
const isContrastMode = modeStore.currentMode === CONTRAST_MODE_NAME
|
|
const filteredMenu = isContrastMode
|
|
? filterMenuByExcludedNames(menuData, ['testSource', 'testScript', 'controlSource'])
|
|
: filterMenuByExcludedNames(menuData, ['standardDevice'])
|
|
|
|
this.authMenuList = filterMenuByExcludedNames(filteredMenu, ['sntp'])
|
|
},
|
|
async setRouteName(name: string) {
|
|
this.routeName = name
|
|
},
|
|
async resetAuthStore() {
|
|
this.showMenuFlag = false
|
|
localStorage.removeItem('showMenuFlag')
|
|
},
|
|
async setShowMenu() {
|
|
this.showMenuFlag = true
|
|
localStorage.setItem('showMenuFlag', 'true')
|
|
},
|
|
changeModel() {
|
|
this.showMenuFlag = false
|
|
localStorage.removeItem('showMenuFlag')
|
|
},
|
|
async setActivateInfo() {
|
|
const licenseResult = await getLicense()
|
|
const licenseData = licenseResult.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
|
|
}
|
|
}
|
|
|
|
this.activateInfo = licenseData
|
|
}
|
|
}
|
|
})
|
|
|
|
function filterMenuByExcludedNames(menuList: Menu.MenuOptions[], excludedNames: string[]): Menu.MenuOptions[] {
|
|
return menuList.filter(menu => {
|
|
if (menu.children && menu.children.length > 0) {
|
|
menu.children = filterMenuByExcludedNames(menu.children, excludedNames)
|
|
}
|
|
|
|
return !excludedNames.includes(menu.name)
|
|
})
|
|
}
|