feat: master-detail third pane
- 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.
This commit is contained in:
@@ -110,7 +110,7 @@ withDefaults(defineProps<{ customerId: string; embedded?: boolean }>(), {
|
||||
1. 内容区顶部内边距归零,两栏都从 `y=0` 开始
|
||||
2. 列表页 navbar 的 `.t-navbar__content` 收窄到 `--tui-master-width`
|
||||
3. 详情页 navbar 从 `fixed` 改成 `absolute`,浮在内容之上
|
||||
4. 详情页的返回按钮在分栏时隐藏——左栏就是列表,退回去没有意义
|
||||
4. 第三层时列表页 navbar 整条移出左侧,详情页和子页各占一条
|
||||
|
||||
第 3 步用 `absolute` 而不是 `static`:导航栏**不能占位**,否则内容只能在它下方滚动,穿不进毛玻璃层。内容区保留页面骨架的 `padding-top` 让位,滚动时自然会钻到导航栏底下。
|
||||
|
||||
@@ -181,6 +181,68 @@ const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, o
|
||||
没有编辑视图的模块不传 `edit`,`openEdit` 就会是空操作。需要自己控制关闭逻辑时,可以退回底层的 `useMasterDetail` 手动接 `onClose`。
|
||||
|
||||
新增/创建这类"从无到有"的流程通常仍走整页路由——右栏没有可依附的选中项,塞进去反而别扭。
|
||||
从详情里发起的创建(例如"给这单创建履约单")是另一回事,走下一节的第三层。
|
||||
|
||||
## 第三层:详情 + 子页
|
||||
|
||||
`detail-empty` 解决的是"一层都没有",`sub` 解决的是"从详情再往下跳"。
|
||||
|
||||
传 `sub` 并把子页放进 `#sub` 槽,布局从「列表 + 详情」变成「详情 + 子页」:
|
||||
列表整列滑出左侧,详情退到主栏的位置,右栏换成子页。
|
||||
|
||||
:::preview 详情 + 子页 || 一进来是第三层;点子页的返回,布局还原成「列表 + 详情」
|
||||
|
||||
demo-preview=../demos/master-detail-page/sub.vue
|
||||
|
||||
:::
|
||||
|
||||
```vue
|
||||
<master-detail :split="isWide" :detail-empty="!selectedId" :sub="!!subView">
|
||||
<template #master>…</template>
|
||||
<template #detail>
|
||||
<sales-order-detail :order-id="selectedId" />
|
||||
</template>
|
||||
<template #sub>
|
||||
<fulfillment-list :sales-order-id="selectedId" embedded />
|
||||
</template>
|
||||
</master-detail>
|
||||
```
|
||||
|
||||
三层的位置关系:
|
||||
|
||||
| 状态 | 主栏 | 右栏 |
|
||||
| --- | --- | --- |
|
||||
| 未选中 | 列表(占满) | 空 |
|
||||
| 选中 | 列表 | 详情 |
|
||||
| `sub` 为 true | 详情 | 子页 |
|
||||
|
||||
三列常驻在同一个容器里,靠 `left` / `right` 分配位置,**详情不会换父节点**——
|
||||
从右栏退到主栏时不会重新挂载,滚动位置和内部状态都保留。
|
||||
列表同理:它是整列滑出视口,不是销毁,返回时原样滑回来。
|
||||
|
||||
宽度都是 `100%` 与 `var(--tui-master-width)` 的 `calc` 表达式,
|
||||
浏览器能连续插值,过渡看起来就是"整条轨道往左挪一格"。
|
||||
|
||||
刻意不用 `transform` 平移整条轨道,理由和导航栏那节一样:会锁住栏内页面的 `fixed` 弹层。
|
||||
|
||||
第三层只在 `split` 为 true 时成立。窄屏没有右栏,`sub` 被忽略,
|
||||
子页应该走整页路由——`usePane().openSub()` 会返回 false,由详情页自己退回 `router.push`。
|
||||
|
||||
手写状态时,子页标识就是一段字符串,列表页自己解析:
|
||||
|
||||
```ts
|
||||
const subView = ref("");
|
||||
|
||||
function openSub(view: string): boolean {
|
||||
if (!isWide.value || !selectedId.value) {
|
||||
return false;
|
||||
}
|
||||
subView.value = view;
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
用 `useMasterDetailPane` 的话这些它都包了,把 `:sub="!!subView"` 接上即可。
|
||||
|
||||
### 切换动画
|
||||
|
||||
@@ -319,7 +381,7 @@ const editing = ref(route.query.view === "edit");
|
||||
|
||||
三个实现细节值得知道:
|
||||
|
||||
- **右栏不设 `display: none`**。那样宽度变化就没有过渡了。它保持 flex 分配、宽度压到 0,配 `overflow-x: hidden` 裁掉内容,主栏一过渡右栏自然被"挤"出来。
|
||||
- **右栏不设 `display: none`**。那样宽度变化就没有过渡了。它始终留在布局里,宽度收到 0 配 `overflow-x: hidden` 裁掉内容,主栏一过渡右栏自然被"挤"出来。
|
||||
- **展开时不做淡入**。宽度从 0 长出来本身就是"揭示",再叠一层 opacity 过渡,内容会看着迟迟不出现。淡入只写在 `is-collapsed` 里,只在收起方向生效。
|
||||
- **收起时内容比宽度先淡出**(120ms vs 320ms)。否则右栏被压到只剩几十像素时,文字会挤成竖排、导航按钮会卡在角上,看起来像残影。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user