|
@@ -0,0 +1,62 @@
|
|
|
+// @ts-ignore
|
|
|
+import {fetchMenusApi} from "@/api/login";
|
|
|
+import {Ref, ref} from "vue";
|
|
|
+import {isDev} from "@/utils/public";
|
|
|
+
|
|
|
+declare type RoutesType = {
|
|
|
+ id: number;
|
|
|
+ path: string;
|
|
|
+ completeRoute: string;
|
|
|
+ metaTitle: string;
|
|
|
+ metaIcon: string | null;
|
|
|
+ parent: number;
|
|
|
+ hideTabs: null;
|
|
|
+ hideMenu: null;
|
|
|
+ redirect: null;
|
|
|
+ meta: {
|
|
|
+ icon: string | null;
|
|
|
+ title: string;
|
|
|
+ };
|
|
|
+ children: RoutesType[] | null;
|
|
|
+}
|
|
|
+
|
|
|
+declare type MenusData = {
|
|
|
+ flatRoutes: {
|
|
|
+ id: null | string;
|
|
|
+ path: null | string;
|
|
|
+ completeRoute: string;
|
|
|
+ metaTitle: string;
|
|
|
+ metaIcon: null | string;
|
|
|
+ parent: null | string;
|
|
|
+ hideTabs: null | string;
|
|
|
+ hideMenu: null | string;
|
|
|
+ redirect: null | string;
|
|
|
+ meta: null | string;
|
|
|
+ children: null | string;
|
|
|
+ }[],
|
|
|
+ paths: string[],
|
|
|
+ routes: RoutesType[]
|
|
|
+}
|
|
|
+
|
|
|
+export const menusData: Ref<MenusData> = ref({
|
|
|
+ routes: [],
|
|
|
+ flatRoutes: [],
|
|
|
+ paths: [],
|
|
|
+})
|
|
|
+
|
|
|
+let once = false
|
|
|
+
|
|
|
+export const initStoreData = async () => {
|
|
|
+ if (once) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ await fetchMenusApi().then((res: MenusData) => {
|
|
|
+ isDev && console.log(res)
|
|
|
+ menusData.value = res
|
|
|
+ }).catch(() => {
|
|
|
+
|
|
|
+ }).finally(() => {
|
|
|
+ once = true
|
|
|
+ })
|
|
|
+ return once
|
|
|
+}
|