1- import { computed , ref , shallowRef } from 'vue' ;
1+ import { computed , nextTick , ref , shallowRef } from 'vue' ;
22import type { RouteRecordRaw } from 'vue-router' ;
33import { defineStore } from 'pinia' ;
44import { useBoolean } from '@sa/hooks' ;
@@ -9,7 +9,6 @@ import { createStaticRoutes, getAuthVueRoutes } from '@/router/routes';
99import { ROOT_ROUTE } from '@/router/routes/builtin' ;
1010import { getRouteName , getRoutePath } from '@/router/elegant/transform' ;
1111import { fetchGetConstantRoutes , fetchGetUserRoutes , fetchIsRouteExist } from '@/service/api' ;
12- import { useAppStore } from '../app' ;
1312import { useAuthStore } from '../auth' ;
1413import { useTabStore } from '../tab' ;
1514import {
@@ -25,7 +24,6 @@ import {
2524} from './shared' ;
2625
2726export const useRouteStore = defineStore ( SetupStoreId . Route , ( ) => {
28- const appStore = useAppStore ( ) ;
2927 const authStore = useAuthStore ( ) ;
3028 const tabStore = useTabStore ( ) ;
3129 const { bool : isInitConstantRoute , setBool : setIsInitConstantRoute } = useBoolean ( ) ;
@@ -97,78 +95,36 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
9795 /** Cache routes */
9896 const cacheRoutes = ref < RouteKey [ ] > ( [ ] ) ;
9997
100- /** All cache routes */
101- const allCacheRoutes = shallowRef < RouteKey [ ] > ( [ ] ) ;
102-
103- /**
104- * Get cache routes
105- *
106- * @param routes Vue routes
107- */
108- function getCacheRoutes ( routes : RouteRecordRaw [ ] ) {
109- const alls = getCacheRouteNames ( routes ) ;
110-
111- cacheRoutes . value = alls ;
112- allCacheRoutes . value = [ ...alls ] ;
113- }
114-
11598 /**
116- * Add cache routes
99+ * Exclude cache routes
117100 *
118- * @param routeKey
101+ * for reset route cache
119102 */
120- function addCacheRoutes ( routeKey : RouteKey ) {
121- if ( cacheRoutes . value . includes ( routeKey ) ) return ;
122-
123- cacheRoutes . value . push ( routeKey ) ;
124- }
103+ const excludeCacheRoutes = ref < RouteKey [ ] > ( [ ] ) ;
125104
126105 /**
127- * Remove cache routes
128- *
129- * @param routeKey
130- */
131- function removeCacheRoutes ( routeKey : RouteKey ) {
132- const index = cacheRoutes . value . findIndex ( item => item === routeKey ) ;
133-
134- if ( index === - 1 ) return ;
135-
136- cacheRoutes . value . splice ( index , 1 ) ;
137- }
138-
139- /**
140- * Is cached route
106+ * Get cache routes
141107 *
142- * @param routeKey
108+ * @param routes Vue routes
143109 */
144- function isCachedRoute ( routeKey : RouteKey ) {
145- return allCacheRoutes . value . includes ( routeKey ) ;
110+ function getCacheRoutes ( routes : RouteRecordRaw [ ] ) {
111+ cacheRoutes . value = getCacheRouteNames ( routes ) ;
146112 }
147113
148114 /**
149- * Re cache routes by route key
115+ * Reset route cache
150116 *
117+ * @default router.currentRoute.value.name current route name
151118 * @param routeKey
152119 */
153- async function reCacheRoutesByKey ( routeKey : RouteKey ) {
154- if ( ! isCachedRoute ( routeKey ) ) return ;
155-
156- removeCacheRoutes ( routeKey ) ;
120+ async function resetRouteCache ( routeKey ?: RouteKey ) {
121+ const routeName = routeKey || ( router . currentRoute . value . name as RouteKey ) ;
157122
158- await appStore . reloadPage ( ) ;
123+ excludeCacheRoutes . value . push ( routeName ) ;
159124
160- addCacheRoutes ( routeKey ) ;
161- }
125+ await nextTick ( ) ;
162126
163- /**
164- * Re cache routes by route keys
165- *
166- * @param routeKeys
167- */
168- async function reCacheRoutesByKeys ( routeKeys : RouteKey [ ] ) {
169- for await ( const key of routeKeys ) {
170- await reCacheRoutesByKey ( key ) ;
171- }
127+ excludeCacheRoutes . value = [ ] ;
172128 }
173129
174130 /** Global breadcrumbs */
@@ -361,8 +317,8 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
361317 searchMenus,
362318 updateGlobalMenusByLocale,
363319 cacheRoutes,
364- reCacheRoutesByKey ,
365- reCacheRoutesByKeys ,
320+ excludeCacheRoutes ,
321+ resetRouteCache ,
366322 breadcrumbs,
367323 initConstantRoute,
368324 isInitConstantRoute,
0 commit comments