layout.ts 539 B

123456789101112131415161718192021222324252627282930
  1. import { defineStore } from 'pinia';
  2. import type { Component } from 'vue';
  3. export interface MenuItem {
  4. key: string;
  5. label: string;
  6. icon: Component;
  7. path: string;
  8. }
  9. export interface LayoutConfig {
  10. menuItems: MenuItem[];
  11. }
  12. export const useLayoutStore = defineStore('layout', {
  13. state: () => ({
  14. menuItems: [] as MenuItem[],
  15. collapsed: false
  16. }),
  17. actions: {
  18. init(config: LayoutConfig) {
  19. this.menuItems = config.menuItems;
  20. },
  21. toggleCollapsed() {
  22. this.collapsed = !this.collapsed;
  23. }
  24. }
  25. });