- 新增全局 TabArea 组件及 tab-area.scss,替换 11 处页面内重复实现, 统一标签样式、排序入口与本地排序偏好 - 新增 51 个业务 SVG 图标,侧边栏/顶栏菜单支持图标展示, 调整收藏星标与展开箭头的间距、配色,避免图标重叠 - 顶部区域高度改为 ResizeObserver 实测,并输出 --app-header-height 变量, 移除 97/134 魔法数字与各页面 calc(100vh - N) 的高度计算 - TaskView 快捷区与标签行重构:Map 索引定位当前标签、v-memo 减少重渲染、 仅监听 route.fullPath 触发更新 - 打印组件连接初始化改为会话内只执行一次;路由树调试日志仅在开发环境输出 - 引入 unplugin-auto-import / unplugin-vue-components 依赖, 补充布局性能分析、菜单图标体系、顶部区域优化三份设计文档
109 lines
4.0 KiB
Vue
109 lines
4.0 KiB
Vue
<template>
|
||
<section class="app-main">
|
||
<div class="app-main__body">
|
||
<router-view v-slot="{ Component, route }">
|
||
<transition name="fade-transform" mode="out-in">
|
||
<!--
|
||
路由级缓存修复(方案P0):
|
||
1. keep-alive 始终存在(不能放 v-if 里:访问 Layout 外页面卸载 KeepAlive 会清空缓存)
|
||
2. include 仍用 cachedViews(路由 name 列表);将路由组件包装为 name=路由 name 的组件,
|
||
使 include 真正匹配(原 include 匹配「组件 name」与「路由 name」不一致 → 缓存从未生效)
|
||
3. :key 收窄为 route.name ?? route.path → 同页 query 变化不再触发整页销毁重建
|
||
4. transition 加 mode="out-in" → 新旧页面不再同时渲染
|
||
注:访问 Layout 外的页面(/404、/login、/redirect)会卸载整个 Layout 并清空路由缓存,
|
||
这是布局重建的自然行为(非缓存 bug),正常业务页面间切换不受影响。
|
||
-->
|
||
<keep-alive :include="pageCacheEnabled ? cachedViews : []" :max="pageCacheMax">
|
||
<component
|
||
:is="wrapRouteComponent(Component, route.name)"
|
||
:key="route.name ?? route.path"
|
||
class="app-router-page"
|
||
/>
|
||
</keep-alive>
|
||
</transition>
|
||
</router-view>
|
||
</div>
|
||
</section>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, defineComponent, h, markRaw } from 'vue'
|
||
import { useTagsViewStore } from '@/stores/modules/tagsView'
|
||
import { useExperimentalStore } from '@/stores/modules/experimental'
|
||
|
||
const tagsViewStore = useTagsViewStore()
|
||
const experimentalStore = useExperimentalStore()
|
||
const cachedViews = computed(() => tagsViewStore.cachedViews)
|
||
|
||
/** 页面缓存开关(实验性设置,默认开);关闭时路由级 keep-alive 不缓存任何页面 */
|
||
const pageCacheEnabled = computed(() => experimentalStore.pageCacheEnabled)
|
||
/** 路由级 keep-alive 最大缓存实例数(实验性设置,默认 8,LRU 淘汰最久未用) */
|
||
const pageCacheMax = computed(() => experimentalStore.pageCacheMax)
|
||
|
||
/** 已包装组件缓存(路由 name → 包装组件),避免每次渲染重建包装组件导致页面重新挂载 */
|
||
const routeWrapperCache = new Map<string, any>()
|
||
|
||
/**
|
||
* 将路由组件包装为 name=路由 name 的组件,使 keep-alive 的 :include(cachedViews=路由 name)
|
||
* 能正确匹配。路由页面组件(<script setup>)大多无组件 name,原 include 匹配失败导致缓存从未生效,
|
||
* 每次切换都销毁重建 + 重新请求(白屏闪烁)。
|
||
*/
|
||
function wrapRouteComponent(Component: any, routeName: string | symbol | undefined): any {
|
||
if (!routeName || typeof routeName !== 'string') return Component
|
||
let wrapped = routeWrapperCache.get(routeName)
|
||
if (!wrapped) {
|
||
wrapped = markRaw(
|
||
defineComponent({
|
||
name: routeName,
|
||
render: () => h(Component)
|
||
})
|
||
)
|
||
routeWrapperCache.set(routeName, wrapped)
|
||
}
|
||
return wrapped
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.app-main {
|
||
/* 90 = navbar + tags-view = 50 + 40;与 main-box 联动占满剩余视口高度 */
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
width: 100%;
|
||
position: relative;
|
||
overflow: hidden;
|
||
padding: 20px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.app-main__body {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 路由页根节点占满 app-main 剩余高度;具体布局由各页面根样式决定 */
|
||
.app-main__body :deep(.app-router-page) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
width: 100%;
|
||
}
|
||
|
||
/* 注:原 `.fixed-header + .app-main { padding-top: 90px }` 已移除。
|
||
顶部占位现在由 layout/index.vue 的 .fixed-header-spacer(实测高度)负责,
|
||
该选择器因中间隔着 spacer 从未命中,属于遗留死代码。 */
|
||
</style>
|
||
|
||
<style lang="scss">
|
||
// Global fix for el-popup-parent--hidden
|
||
.el-popup-parent--hidden {
|
||
.fixed-header {
|
||
padding-right: 15px;
|
||
}
|
||
}
|
||
</style>
|