21 changed files with 275 additions and 345 deletions
@ -0,0 +1,21 @@ |
|||
import type { Plugin } from 'vite'; |
|||
|
|||
/** |
|||
* TODO |
|||
* Temporarily solve the Vite circular dependency problem, and wait for a better solution to fix it later. I don't know what problems this writing will bring. |
|||
* @returns |
|||
*/ |
|||
|
|||
export function configHmrPlugin(): Plugin { |
|||
return { |
|||
name: 'singleHMR', |
|||
handleHotUpdate({ modules, file }) { |
|||
if (file.match(/xml$/)) return []; |
|||
modules.forEach((m) => { |
|||
m.importedModules = new Set(); |
|||
m.importers = new Set(); |
|||
}); |
|||
return modules; |
|||
}, |
|||
}; |
|||
} |
|||
@ -1,63 +0,0 @@ |
|||
<!-- |
|||
* @Description: The reason is that tsx will report warnings under multi-level nesting. |
|||
--> |
|||
<template> |
|||
<div> |
|||
<RouterView> |
|||
<template #default="{ Component, route }"> |
|||
<transition |
|||
:name=" |
|||
getTransitionName({ |
|||
route, |
|||
openCache: openCache, |
|||
enableTransition: getEnableTransition, |
|||
cacheTabs: getCaches, |
|||
def: getBasicTransition, |
|||
}) |
|||
" |
|||
mode="out-in" |
|||
appear |
|||
> |
|||
<keep-alive v-if="openCache" :include="getCaches"> |
|||
<component :is="Component" v-bind="getKey(Component, route)" /> |
|||
</keep-alive> |
|||
<component v-else :is="Component" v-bind="getKey(Component, route)" /> |
|||
</transition> |
|||
</template> |
|||
</RouterView> |
|||
</div> |
|||
</template> |
|||
<script lang="ts"> |
|||
import { computed, defineComponent, unref } from 'vue'; |
|||
|
|||
import { useRootSetting } from '/@/hooks/setting/useRootSetting'; |
|||
import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; |
|||
|
|||
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; |
|||
import { useCache, getKey } from './useCache'; |
|||
import { getTransitionName } from './transition'; |
|||
|
|||
export default defineComponent({ |
|||
parentView: true, |
|||
setup() { |
|||
const { getCaches } = useCache(false); |
|||
|
|||
const { getShowMultipleTab } = useMultipleTabSetting(); |
|||
|
|||
const { getOpenKeepAlive } = useRootSetting(); |
|||
|
|||
const { getBasicTransition, getEnableTransition } = useTransitionSetting(); |
|||
|
|||
const openCache = computed(() => unref(getOpenKeepAlive) && unref(getShowMultipleTab)); |
|||
|
|||
return { |
|||
getCaches, |
|||
getBasicTransition, |
|||
openCache, |
|||
getEnableTransition, |
|||
getTransitionName, |
|||
getKey, |
|||
}; |
|||
}, |
|||
}); |
|||
</script> |
|||
@ -1,63 +0,0 @@ |
|||
import type { FunctionalComponent } from 'vue'; |
|||
import type { RouteLocation } from 'vue-router'; |
|||
import { computed, ref, unref, getCurrentInstance } from 'vue'; |
|||
import { useRootSetting } from '/@/hooks/setting/useRootSetting'; |
|||
|
|||
import { useRouter } from 'vue-router'; |
|||
import { useStore } from 'vuex'; |
|||
|
|||
const ParentLayoutName = 'ParentLayout'; |
|||
|
|||
const PAGE_LAYOUT_KEY = '__PAGE_LAYOUT__'; |
|||
|
|||
export function getKey(component: FunctionalComponent & { type: Indexable }, route: RouteLocation) { |
|||
return !!component?.type.parentView ? {} : { key: route.fullPath }; |
|||
} |
|||
|
|||
export function useCache(isPage: boolean) { |
|||
const { getters } = useStore(); |
|||
|
|||
const name = ref(''); |
|||
const { currentRoute } = useRouter(); |
|||
const instance = getCurrentInstance(); |
|||
const routeName = instance?.type.name; |
|||
if (routeName && ![ParentLayoutName].includes(routeName)) { |
|||
name.value = routeName; |
|||
} else { |
|||
const matched = currentRoute.value?.matched; |
|||
if (!matched) { |
|||
return; |
|||
} |
|||
const len = matched.length; |
|||
if (len < 2) return; |
|||
name.value = matched[len - 2].name as string; |
|||
} |
|||
|
|||
const { getOpenKeepAlive } = useRootSetting(); |
|||
|
|||
const getCaches = computed((): string[] => { |
|||
if (!unref(getOpenKeepAlive)) { |
|||
return []; |
|||
} |
|||
const cached = getters['app-tab/getCachedMapState']; |
|||
|
|||
if (isPage) { |
|||
// page Layout
|
|||
return cached.get(PAGE_LAYOUT_KEY) || []; |
|||
} |
|||
const cacheSet = new Set<string>(); |
|||
cacheSet.add(unref(name)); |
|||
|
|||
const list = cached.get(unref(name)); |
|||
|
|||
if (!list) { |
|||
return Array.from(cacheSet); |
|||
} |
|||
list.forEach((item) => { |
|||
cacheSet.add(item); |
|||
}); |
|||
|
|||
return Array.from(cacheSet); |
|||
}); |
|||
return { getCaches }; |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
import type { AppRouteRecordRaw } from '/@/router/types'; |
|||
import { t } from '/@/hooks/web/useI18n'; |
|||
import { REDIRECT_NAME, LAYOUT, EXCEPTION_COMPONENT } from '/@/router/constant'; |
|||
|
|||
// 404 on a page
|
|||
export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = { |
|||
path: '/:path(.*)*', |
|||
name: 'ErrorPage', |
|||
component: LAYOUT, |
|||
meta: { |
|||
title: 'ErrorPage', |
|||
hideBreadcrumb: true, |
|||
}, |
|||
children: [ |
|||
{ |
|||
path: '/:path(.*)*', |
|||
name: 'ErrorPage', |
|||
component: EXCEPTION_COMPONENT, |
|||
meta: { |
|||
title: 'ErrorPage', |
|||
hideBreadcrumb: true, |
|||
}, |
|||
}, |
|||
], |
|||
}; |
|||
|
|||
export const REDIRECT_ROUTE: AppRouteRecordRaw = { |
|||
path: '/redirect', |
|||
name: REDIRECT_NAME, |
|||
component: LAYOUT, |
|||
meta: { |
|||
title: REDIRECT_NAME, |
|||
hideBreadcrumb: true, |
|||
}, |
|||
children: [ |
|||
{ |
|||
path: '/redirect/:path(.*)', |
|||
name: REDIRECT_NAME, |
|||
component: () => import('/@/views/sys/redirect/index.vue'), |
|||
meta: { |
|||
title: REDIRECT_NAME, |
|||
hideBreadcrumb: true, |
|||
}, |
|||
}, |
|||
], |
|||
}; |
|||
|
|||
export const ERROR_LOG_ROUTE: AppRouteRecordRaw = { |
|||
path: '/error-log', |
|||
name: 'errorLog', |
|||
component: LAYOUT, |
|||
meta: { |
|||
title: 'ErrorLog', |
|||
hideBreadcrumb: true, |
|||
}, |
|||
children: [ |
|||
{ |
|||
path: 'list', |
|||
name: 'errorLogList', |
|||
component: () => import('/@/views/sys/error-log/index.vue'), |
|||
meta: { |
|||
title: t('routes.basic.errorLogList'), |
|||
hideBreadcrumb: true, |
|||
}, |
|||
}, |
|||
], |
|||
}; |
|||
Loading…
Reference in new issue