mirror of
https://gitee.com/fantastic-admin/basic.git
synced 2024-11-29 18:48:31 +08:00
refactor: 修改全局loading消失时机
This commit is contained in:
parent
76c66f9bc9
commit
a5b3c5660d
@ -111,7 +111,7 @@ const enableAppSetting = import.meta.env.VITE_APP_SETTING === 'true'
|
||||
<Topbar />
|
||||
<div class="main">
|
||||
<RouterView v-slot="{ Component, route }">
|
||||
<Transition name="slide-right" mode="out-in" appear>
|
||||
<Transition name="slide-right" mode="out-in">
|
||||
<KeepAlive :include="keepAliveStore.list">
|
||||
<component :is="Component" v-show="!isLink" :key="route.fullPath" />
|
||||
</KeepAlive>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import { loadingFadeOut } from 'virtual:app-loading'
|
||||
import setupGuards from './guards'
|
||||
|
||||
// 路由相关数据
|
||||
@ -13,4 +14,8 @@ const router = createRouter({
|
||||
|
||||
setupGuards(router)
|
||||
|
||||
router.isReady().then(() => {
|
||||
loadingFadeOut()
|
||||
})
|
||||
|
||||
export default router
|
||||
|
7
src/types/shims.d.ts
vendored
7
src/types/shims.d.ts
vendored
@ -3,6 +3,13 @@ declare interface Window {
|
||||
mozDevicePixelRatio: any
|
||||
}
|
||||
|
||||
declare module 'virtual:app-loading' {
|
||||
const loadingFadeOut: () => void
|
||||
export {
|
||||
loadingFadeOut,
|
||||
}
|
||||
}
|
||||
|
||||
declare const __SYSTEM_INFO__: {
|
||||
pkg: {
|
||||
version: Recordable<string>
|
||||
|
@ -124,34 +124,44 @@ export default function createVitePlugins(viteEnv, isBuild = false) {
|
||||
}
|
||||
})(),
|
||||
|
||||
{
|
||||
name: 'vite-plugin-loading',
|
||||
enforce: 'pre',
|
||||
transformIndexHtml: {
|
||||
handler: async html => html.replace(/<\/body>/, `${
|
||||
`<div data-app-loading>${await fs.readFileSync(path.resolve(process.cwd(), 'loading.html'), 'utf8')}</div>`
|
||||
}</body>`),
|
||||
order: 'pre',
|
||||
},
|
||||
transform: (code, id) => {
|
||||
if (/src\/main.ts$/.test(id)) {
|
||||
code = code.concat(`
|
||||
const loadingEl = document.querySelector('[data-app-loading]')
|
||||
if (loadingEl) {
|
||||
loadingEl.style['pointer-events'] = 'none'
|
||||
loadingEl.style.visibility = 'hidden'
|
||||
loadingEl.style.opacity = 0
|
||||
loadingEl.style.transition = 'all 0.5s ease-out'
|
||||
loadingEl.addEventListener('transitionend', () => loadingEl.remove(), { once: true })
|
||||
}
|
||||
`)
|
||||
return {
|
||||
code,
|
||||
map: null,
|
||||
(function () {
|
||||
const virtualModuleId = 'virtual:app-loading'
|
||||
const resolvedVirtualModuleId = `\0${virtualModuleId}`
|
||||
return {
|
||||
name: 'vite-plugin-loading',
|
||||
resolveId(id) {
|
||||
if (id === virtualModuleId) {
|
||||
return resolvedVirtualModuleId
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
load(id) {
|
||||
if (id === resolvedVirtualModuleId) {
|
||||
return {
|
||||
code: `
|
||||
export function loadingFadeOut() {
|
||||
const loadingEl = document.querySelector('[data-app-loading]')
|
||||
if (loadingEl) {
|
||||
loadingEl.style['pointer-events'] = 'none'
|
||||
loadingEl.style.visibility = 'hidden'
|
||||
loadingEl.style.opacity = 0
|
||||
loadingEl.style.transition = 'all 0.5s ease-out'
|
||||
loadingEl.addEventListener('transitionend', () => loadingEl.remove(), { once: true })
|
||||
}
|
||||
}
|
||||
`,
|
||||
map: null,
|
||||
}
|
||||
}
|
||||
},
|
||||
enforce: 'pre',
|
||||
transformIndexHtml: {
|
||||
handler: async html => html.replace(/<\/body>/, `${
|
||||
`<div data-app-loading>${await fs.readFileSync(path.resolve(process.cwd(), 'loading.html'), 'utf8')}</div>`
|
||||
}</body>`),
|
||||
order: 'pre',
|
||||
},
|
||||
}
|
||||
})(),
|
||||
|
||||
// https://github.com/unplugin/unplugin-turbo-console
|
||||
TurboConsole(),
|
||||
|
Loading…
Reference in New Issue
Block a user