feat(projects): 增加页面重载功能

This commit is contained in:
Coffee-crocodile 2022-08-12 13:25:33 +08:00
parent 34f0951364
commit 254712c7a8
6 changed files with 43 additions and 16 deletions

View File

@ -11,7 +11,7 @@
<Breadcrumb /> <Breadcrumb />
</div> </div>
<div class="flex-y-center h-full"> <div class="flex-y-center h-full">
<Refresh /> <Reload />
<Search /> <Search />
<Notices /> <Notices />
<Github /> <Github />
@ -23,7 +23,11 @@
</n-layout-header> </n-layout-header>
<div class="p-16px"> <div class="p-16px">
<n-layout-content> <n-layout-content>
<router-view></router-view> <router-view v-slot="{ Component }">
<transition name="fade-slide" appear mode="out-in">
<component :is="Component" v-if="appStore.loadFlag" />
</transition>
</router-view>
</n-layout-content> </n-layout-content>
</div> </div>
<n-layout-footer position="absolute" bordered class="flex-center bg-white h-40px"> <n-layout-footer position="absolute" bordered class="flex-center bg-white h-40px">
@ -47,7 +51,7 @@ import {
Notices, Notices,
UserCenter, UserCenter,
Search, Search,
Refresh, Reload,
} from '../components'; } from '../components';
const appStore = useAppStore(); const appStore = useAppStore();

View File

@ -1,7 +1,7 @@
<template> <template>
<n-tooltip placement="bottom" trigger="hover"> <n-tooltip placement="bottom" trigger="hover">
<template #trigger> <template #trigger>
<HeaderButton @click="handleRefresh"><e-icon icon="icon-park-outline:refresh" /></HeaderButton> <HeaderButton @click="handleReload"><e-icon icon="icon-park-outline:refresh" /></HeaderButton>
</template> </template>
<span>刷新页面</span> <span>刷新页面</span>
</n-tooltip> </n-tooltip>
@ -9,8 +9,11 @@
<script setup lang="ts"> <script setup lang="ts">
import HeaderButton from '../common/HeaderButton.vue'; import HeaderButton from '../common/HeaderButton.vue';
const handleRefresh = () => { import { useAppStore } from '@/store';
window.open('https://github.com/chen-see'); const appStore = useAppStore();
const handleReload = () => {
appStore.reloadPage();
}; };
</script> </script>

View File

@ -12,7 +12,7 @@ import Github from './header/Github.vue';
import Notices from './header/Notices.vue'; import Notices from './header/Notices.vue';
import UserCenter from './header/UserCenter.vue'; import UserCenter from './header/UserCenter.vue';
import Search from './header/Search.vue'; import Search from './header/Search.vue';
import Refresh from './header/Refresh.vue'; import Reload from './header/Reload.vue';
export { export {
Breadcrumb, Breadcrumb,
@ -26,5 +26,5 @@ export {
Notices, Notices,
UserCenter, UserCenter,
Search, Search,
Refresh, Reload,
}; };

View File

@ -1,24 +1,27 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { nextTick } from 'vue';
import { darkTheme, GlobalTheme } from 'naive-ui'; import { darkTheme, GlobalTheme } from 'naive-ui';
interface AppStatus { interface AppStatus {
title: string;
footerText: string;
collapsed: boolean; collapsed: boolean;
fullScreen: boolean; fullScreen: boolean;
darkMode: boolean; darkMode: boolean;
darkTheme: GlobalTheme | null; darkTheme: GlobalTheme | null;
title: string; loadFlag: boolean;
footerText: string;
} }
export const useAppStore = defineStore('app-store', { export const useAppStore = defineStore('app-store', {
state: (): AppStatus => { state: (): AppStatus => {
return { return {
title: import.meta.env.VITE_APP_TITLE,
footerText: '哲学的基本问题是思维和存在的关系问题',
collapsed: false, collapsed: false,
fullScreen: false, fullScreen: false,
darkMode: false, darkMode: false,
darkTheme: null, darkTheme: null,
title: import.meta.env.VITE_APP_TITLE, loadFlag: true,
footerText: '哲学的基本问题是思维和存在的关系问题',
}; };
}, },
actions: { actions: {
@ -45,5 +48,21 @@ export const useAppStore = defineStore('app-store', {
this.darkTheme = null; this.darkTheme = null;
} }
}, },
/**
* @description:
* @param {number} delay -
* @return {*}
*/
async reloadPage(delay = 100) {
this.loadFlag = false;
await nextTick();
if (delay) {
setTimeout(() => {
this.loadFlag = true;
}, delay);
} else {
this.loadFlag = true;
}
},
}, },
}); });

View File

@ -1,6 +1,5 @@
<template> <template>
<div text-center c-yellow>I prove that you have made the ju mp test2.</div> <div text-center c-yellow>I prove that you have made the ju mp test2. {{ userStore.name }}</div>
{{ userStore.name }}
</template> </template>
<script setup lang="ts"> <script setup lang="ts">

View File

@ -1,6 +1,8 @@
<template> <template>
<div text-center c-red>I prove that you have made the jump test3.</div> <div text-center c-red>
<n-button strong secondary type="success" @click="testMsg">testMsg</n-button> I prove that you have made the jump test3.
<n-button strong secondary type="success" @click="testMsg">testMsg</n-button>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">