- MasterDetail / MasterDetailPage: add `sub` prop and `#sub` slot. The three columns share one container and are placed by left/right, so the detail pane moves between columns without remounting and keeps its scroll position. - useMasterDetailPane: add subView / openSub / closeSub, keep the sub view in query and browser history alongside detail and view. - page-layout: sub pane reuses the in-pane navbar rules; the list navbar slides out on the third level instead of being hidden. - docs: demos for the third pane, the layered navbars and PaneTransition; restore transition durations in demo previews under prefers-reduced-motion, where VitePress zeroes them. Fix the missing `split` ref in the master-detail demo and the incorrect note about the back arrow.
74 lines
3.0 KiB
Markdown
74 lines
3.0 KiB
Markdown
# PaneTransition 栏内过渡
|
||
|
||
与路由无关的左右推入效果,用于栏位内部的视图切换。
|
||
|
||
## 与 PageTransition 的分工
|
||
|
||
两者效果同源,但职责完全不同:
|
||
|
||
| | PageTransition | PaneTransition |
|
||
| --- | --- | --- |
|
||
| 驱动方式 | 路由变化 | 业务状态变化 |
|
||
| 定位基准 | 视口(`fixed`) | 栏位(`absolute`) |
|
||
| 方向来源 | 路由层级自动判断 | 业务显式传入 |
|
||
| 典型场景 | 列表页 → 详情页 | 详情栏 → 编辑栏 |
|
||
|
||
`PageTransition` 内部绑定了 `useRoute()`、`<component :is="RoutePage" />` 和 `router.afterEach`,无法用于"路由不变、只换视图"的场合。这类场景用本组件。
|
||
|
||
## 基础用法
|
||
|
||
把需要切换的内容放进默认插槽,每个分支带唯一 `key`,用 `direction` 指定方向:
|
||
|
||
:::preview 三个方向 || 按钮切换视图,注意进入和返回时内容从哪一侧进出
|
||
|
||
demo-preview=../demos/pane-transition/basic.vue
|
||
|
||
:::
|
||
|
||
```vue
|
||
<template #detail>
|
||
<pane-transition :direction="direction">
|
||
<customer-edit v-if="editing" :key="`edit-${selectedId}`" :customer-id="selectedId" />
|
||
<customer-detail v-else-if="selectedId" :key="`detail-${selectedId}`" :customer-id="selectedId" />
|
||
<div v-else key="empty" class="tui-detail-empty">…</div>
|
||
</pane-transition>
|
||
</template>
|
||
```
|
||
|
||
```ts
|
||
const direction = ref<PaneDirection>("forward");
|
||
|
||
function openEdit(): void {
|
||
direction.value = "forward"; // 进入下一层
|
||
editing.value = true;
|
||
}
|
||
|
||
function onClose(): void {
|
||
direction.value = "back"; // 返回上一层
|
||
editing.value = false;
|
||
}
|
||
```
|
||
|
||
- `forward`:新内容从右侧推入,旧内容左移让位
|
||
- `back`:新内容从左侧覆盖回来,旧内容滑出右侧
|
||
- `none`:直接替换,不做动画
|
||
|
||
方向由业务决定,组件不猜。**同级换内容用 `none`**——列表里换一个客户、换一条记录,内容和布局都没变,只是数据换了,滑动会让人以为"进了下一层"。`useMasterDetailPane` 已经把这条处理好了:右栏已有内容时换项自动用 `none`,只有进编辑才用 `forward`。
|
||
|
||
用它搭多层界面时不用手写这一层:`MasterDetailPage` 的 `#detail` 和 `#sub` 槽已经接好了,
|
||
方向来自 `useMasterDetailPane` 的 `paneDirection`。
|
||
|
||
## 两个实现细节
|
||
|
||
**过渡期间旧视图是 `absolute`**,不占位。否则新旧两个视图会在栏位里上下排列,高度瞬间翻倍。
|
||
|
||
**样式是全局的**(非 scoped):过渡类由 Vue 加到插槽内容上,scoped 的属性选择器命中不了。类名带 `tui-pane-` 前缀隔离。
|
||
|
||
## 时长与曲线
|
||
|
||
默认 420ms,比 `PageTransition` 的 520ms 略快——栏位宽度更小,同样的曲线下观感更利落。
|
||
|
||
曲线取项目的 `--tui-bezier`(`timi-web` 定义在 `:root`,默认 `cubic-bezier(.19, 1, .22, 1)`),未引入时回落到同一个值。全库的位移、缩放过渡都用这一个变量,改一处即可统一调整。
|
||
|
||
需要改时长时,直接在自己的样式里重新声明对应类即可(时长写在 transition 里,没有暴露变量)。
|