Merge pull request #194 from taisha/main
fix(components): refresh cached routes
This commit is contained in:
commit
c3d0b74c75
@ -5,18 +5,27 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAppStore } from '@/store';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useAppStore, useRouteStore } from '@/store';
|
||||
import { useLoading } from '@/hooks';
|
||||
|
||||
defineOptions({ name: 'ReloadButton' });
|
||||
|
||||
const app = useAppStore();
|
||||
const routeStore = useRouteStore();
|
||||
const route = useRoute();
|
||||
const { loading, startLoading, endLoading } = useLoading();
|
||||
|
||||
function handleRefresh() {
|
||||
const isCached = routeStore.cacheRoutes.includes(String(route.name));
|
||||
if (isCached) {
|
||||
routeStore.removeCacheRoute(route.name as AuthRoute.AllRouteKey);
|
||||
}
|
||||
startLoading();
|
||||
app.reloadPage();
|
||||
setTimeout(() => {
|
||||
if (isCached) {
|
||||
routeStore.addCacheRoute(route.name as AuthRoute.AllRouteKey);
|
||||
}
|
||||
endLoading();
|
||||
}, 1000);
|
||||
}
|
||||
|
@ -146,6 +146,22 @@ export const useRouteStore = defineStore('route-store', {
|
||||
} else {
|
||||
await this.initStaticRoute();
|
||||
}
|
||||
},
|
||||
|
||||
/** 从缓存路由中去除某个路由 */
|
||||
removeCacheRoute(name: AuthRoute.AllRouteKey) {
|
||||
const index = this.cacheRoutes.indexOf(name);
|
||||
if (index > -1) {
|
||||
this.cacheRoutes.splice(index, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/** 添加某个缓存路由 */
|
||||
addCacheRoute(name: AuthRoute.AllRouteKey) {
|
||||
const index = this.cacheRoutes.indexOf(name);
|
||||
if (index === -1) {
|
||||
this.cacheRoutes.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user