Skip to content

Commit fd49f40

Browse files
authored
feat: Add <keep-alive> (#83)
1 parent 88b0c25 commit fd49f40

File tree

28 files changed

+233
-225
lines changed

28 files changed

+233
-225
lines changed

build/vite/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
1313
import { VitePWA } from 'vite-plugin-pwa'
1414
import Sitemap from 'vite-plugin-sitemap'
1515
import VueDevTools from 'vite-plugin-vue-devtools'
16-
import Layouts from 'vite-plugin-vue-layouts'
1716
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
1817
import { createViteVConsole } from './vconsole'
1918

@@ -28,11 +27,6 @@ export function createVitePlugins() {
2827

2928
vue(),
3029

31-
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
32-
Layouts({
33-
pagesDirs: 'src/pages/**',
34-
}),
35-
3630
// https://github.com/jbaubree/vite-plugin-sitemap
3731
Sitemap(),
3832

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"vite-plugin-sitemap": "^0.5.3",
7474
"vite-plugin-vconsole": "^2.1.1",
7575
"vite-plugin-vue-devtools": "^7.0.25",
76-
"vite-plugin-vue-layouts": "^0.11.0",
7776
"vitest": "^1.4.0",
7877
"vue-tsc": "^2.0.7"
7978
},

pnpm-lock.yaml

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { storeToRefs } from 'pinia'
33
import useAppStore from '@/stores/modules/app'
4+
import useRouteCache from '@/stores/modules/routeCache'
45
import useRouteTransitionNameStore from '@/stores/modules/routeTransitionName'
56
import useAutoThemeSwitcher from '@/hooks/useAutoThemeSwitcher'
67
@@ -30,9 +31,12 @@ const { mode } = storeToRefs(appStore)
3031
3132
const routeTransitionNameStore = useRouteTransitionNameStore()
3233
const { routeTransitionName } = storeToRefs(routeTransitionNameStore)
33-
3434
const { initializeThemeSwitcher } = useAutoThemeSwitcher(appStore)
3535
36+
const keepAliveRouteNames = computed(() => {
37+
return useRouteCache().routeCaches as string[]
38+
})
39+
3640
onMounted(() => {
3741
initializeThemeSwitcher()
3842
})
@@ -43,21 +47,11 @@ onMounted(() => {
4347
<NavBar />
4448
<router-view v-slot="{ Component, route }">
4549
<transition :name="routeTransitionName">
46-
<div :key="route.name" class="app-wrapper">
47-
<component :is="Component" />
48-
</div>
50+
<keep-alive :include="keepAliveRouteNames">
51+
<component :is="Component" :key="route.name" />
52+
</keep-alive>
4953
</transition>
5054
</router-view>
55+
<TabBar />
5156
</VanConfigProvider>
5257
</template>
53-
54-
<style scoped>
55-
.app-wrapper {
56-
width: 100%;
57-
height: 100%;
58-
padding-top: 46px;
59-
overflow-y: auto;
60-
position: absolute;
61-
left: 0;
62-
}
63-
</style>

src/components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {}
88
declare module 'vue' {
99
export interface GlobalComponents {
1010
Chart: typeof import('./components/Chart/index.vue')['default']
11+
Container: typeof import('./components/Container.vue')['default']
1112
NavBar: typeof import('./components/NavBar.vue')['default']
1213
RouterLink: typeof import('vue-router')['RouterLink']
1314
RouterView: typeof import('vue-router')['RouterView']
@@ -24,6 +25,7 @@ declare module 'vue' {
2425
VanPopup: typeof import('vant/es')['Popup']
2526
VanRadio: typeof import('vant/es')['Radio']
2627
VanSpace: typeof import('vant/es')['Space']
28+
VanStepper: typeof import('vant/es')['Stepper']
2729
VanSwitch: typeof import('vant/es')['Switch']
2830
VanTabbar: typeof import('vant/es')['Tabbar']
2931
VanTabbarItem: typeof import('vant/es')['TabbarItem']

src/components/Container.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
defineProps({
3+
paddingX: {
4+
type: Number,
5+
default: 16,
6+
},
7+
})
8+
</script>
9+
10+
<template>
11+
<main
12+
class="absolute left-0 h-full w-full overflow-y-auto pt-46"
13+
:style="`padding-left: ${paddingX}px; padding-right: ${paddingX}px`"
14+
>
15+
<slot />
16+
</main>
17+
</template>

src/components/TabBar.vue

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
<script setup lang="ts">
2-
const { t } = useI18n()
3-
const active = ref(0)
4-
</script>
5-
6-
<template>
7-
<van-tabbar v-model="active" route>
8-
<van-tabbar-item replace to="/">
9-
{{ t('layouts.home') }}
10-
<template #icon>
11-
<div class="i-carbon:home" />
12-
</template>
13-
</van-tabbar-item>
14-
<van-tabbar-item replace to="/profile">
15-
{{ t('layouts.profile') }}
16-
<template #icon>
17-
<div class="i-carbon:user" />
18-
</template>
19-
</van-tabbar-item>
20-
</van-tabbar>
21-
</template>
1+
<script setup lang="ts">
2+
const { t } = useI18n()
3+
const active = ref(0)
4+
const route = useRoute()
5+
6+
const display = computed(() => {
7+
if (route.meta.level && route.meta.level !== 2)
8+
return true
9+
return false
10+
})
11+
</script>
12+
13+
<template>
14+
<van-tabbar v-show="display" v-model="active" route>
15+
<van-tabbar-item replace to="/">
16+
{{ t('layouts.home') }}
17+
<template #icon>
18+
<div class="i-carbon:home" />
19+
</template>
20+
</van-tabbar-item>
21+
<van-tabbar-item replace to="/profile">
22+
{{ t('layouts.profile') }}
23+
<template #icon>
24+
<div class="i-carbon:user" />
25+
</template>
26+
</van-tabbar-item>
27+
</van-tabbar>
28+
</template>

src/layouts/404.vue

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/layouts/README.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/layouts/default.vue

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)