import { defineStore } from 'pinia' export interface MenuItem { id: number pid: number link: string icon: string text: string group?: boolean show?: boolean children?: MenuItem[] } export interface MenuInfoState { menu: MenuItem[] buttons: string[] } export const useMenuStore = defineStore('useMenuStore', { state: (): MenuInfoState => { return { menu: [], buttons: [], } }, actions: { init(payload) { this.menu = [ { id: 0, pid: -1, link: '', icon: '', text: '', group: true, show: true, children: menuAdaptor(payload.menus), }, ] this.buttons = payload.buttons }, clear() { this.menu = [] this.buttons = [] }, }, }) function menuAdaptor(menu): MenuItem[] { return menu.map((v) => { let { children } = v const { id, parentResID, name, icon, link, show, target } = v if (children && children.length) { children = menuAdaptor(v.children) } return { id, pid: parentResID, text: name, icon, link: `/activeRule${link}`, children, show, target, } }) }