-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2e0f47
commit a77843c
Showing
9 changed files
with
161 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,62 @@ | ||
import type { ElegantRoute, CustomRoute } from '@elegant-router/types'; | ||
import type { ElegantRoute, CustomRoute, SingleLevelRoute } from '@elegant-router/types'; | ||
import { autoRoutes } from '../elegant/routes'; | ||
import { layouts, views } from '../elegant/imports'; | ||
import { transformElegantRouteToVueRoute } from '../elegant/transform'; | ||
|
||
const constantRoutes: CustomRoute[] = [ | ||
{ | ||
name: 'root', | ||
path: '/', | ||
redirect: { | ||
name: 'home' | ||
} | ||
}, | ||
{ | ||
path: '/:pathMatch(.*)*', | ||
component: 'layout.blank', | ||
children: [ | ||
{ | ||
name: 'not-found', | ||
path: '', | ||
component: 'view.404' | ||
export function createRoutes() { | ||
const builtinRoutes: CustomRoute[] = [ | ||
{ | ||
name: 'root', | ||
path: '/', | ||
redirect: { | ||
name: 'home' | ||
}, | ||
meta: { | ||
title: 'root', | ||
constant: true | ||
} | ||
] | ||
} | ||
]; | ||
}, | ||
{ | ||
path: '/:pathMatch(.*)*', | ||
component: 'layout.blank', | ||
children: [ | ||
{ | ||
name: 'not-found', | ||
path: '', | ||
component: 'view.404', | ||
meta: { | ||
title: 'not-found', | ||
constant: true | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
|
||
const constantRoutes: ElegantRoute[] = [...builtinRoutes]; | ||
|
||
const authRoutes: ElegantRoute[] = []; | ||
|
||
autoRoutes.forEach(route => { | ||
const isConstant = Boolean(route.meta?.constant); | ||
|
||
const isSingleConstant = Boolean((route as SingleLevelRoute).children?.[0]?.meta?.constant); | ||
|
||
if (isConstant || isSingleConstant) { | ||
constantRoutes.push(route); | ||
} else { | ||
authRoutes.push(route); | ||
} | ||
}); | ||
|
||
const constantVueRoutes = transformElegantRouteToVueRoute(constantRoutes, layouts, views); | ||
|
||
const elegantRoutes: ElegantRoute[] = [...constantRoutes, ...autoRoutes]; | ||
const authVueRoutes = transformElegantRouteToVueRoute(authRoutes, layouts, views); | ||
|
||
export const routes = transformElegantRouteToVueRoute(elegantRoutes, layouts, views); | ||
return { | ||
constantRoutes, | ||
authRoutes, | ||
constantVueRoutes, | ||
authVueRoutes | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,68 @@ | ||
import { ref } from 'vue'; | ||
import type { RouteRecordRaw } from 'vue-router'; | ||
import { defineStore } from 'pinia'; | ||
import { useBoolean } from '@sa/hooks'; | ||
import { SetupStoreId } from '@/enum'; | ||
import { router } from '@/router'; | ||
import { createRoutes } from '@/router/routes'; | ||
|
||
export const useRouteStore = defineStore(SetupStoreId.Route, () => { | ||
// | ||
const { bool: isInitAuthRoute, setBool: setIsInitAuthRoute } = useBoolean(); | ||
|
||
/** | ||
* auth route mode | ||
* @description it recommends to use static mode in the development environment, and use dynamic mode in the production environment, | ||
* if use static mode in development environment, the auth routes will be auto generated by plugin "@elegant-router/vue" | ||
*/ | ||
const authRouteMode = ref(import.meta.env.VITE_AUTH_ROUTE_MODE); | ||
|
||
/** | ||
* home route key | ||
*/ | ||
const routeHome = ref(import.meta.env.VITE_ROUTE_HOME); | ||
|
||
/** | ||
* global menus | ||
*/ | ||
// const menus = ref<App.Global.Menu[]>([]); | ||
|
||
async function initAuthRoute() { | ||
if (authRouteMode.value === 'static') { | ||
await initStaticAuthRoute(); | ||
} else { | ||
await initDynamicAuthRoute(); | ||
} | ||
} | ||
|
||
/** | ||
* init static auth route | ||
*/ | ||
async function initStaticAuthRoute() { | ||
const { authVueRoutes } = createRoutes(); | ||
handleVueRoutes(authVueRoutes); | ||
} | ||
|
||
/** | ||
* init dynamic auth route | ||
*/ | ||
async function initDynamicAuthRoute() { | ||
// | ||
} | ||
|
||
function handleVueRoutes(routes: RouteRecordRaw[]) { | ||
addRoutesToVueRouter(routes); | ||
} | ||
|
||
function addRoutesToVueRouter(routes: RouteRecordRaw[]) { | ||
routes.forEach(route => { | ||
router.addRoute(route); | ||
}); | ||
} | ||
|
||
return { | ||
routeHome, | ||
initAuthRoute, | ||
isInitAuthRoute, | ||
setIsInitAuthRoute | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { ElegantRoute } from '@elegant-router/types'; | ||
|
||
export function getGlobalMenusByAuthRoutes(_routes: ElegantRoute[]) { | ||
const menus: App.Global.Menu[] = []; | ||
|
||
return menus; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters