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:
@@ -37,13 +37,117 @@ demo-preview=../demos/master-detail-page/basic.vue
|
||||
一个模块如果有「列表 → 详情」或「列表 → 详情 → 编辑」两层及以上结构,就用它。
|
||||
只有一个页面的模块(例如排行榜、选择页)保持原样即可,套上去没有右栏可放。
|
||||
|
||||
## 第三层:详情 + 子页
|
||||
|
||||
从详情再往下跳时,常见做法是整页跳走,回来还得重新找回那一条。
|
||||
传 `sub` 并把子页交给 `#sub` 槽,布局会变成「详情 + 子页」,订单这类主体留在主栏里:
|
||||
|
||||
:::preview 详情 + 子页 || 从详情打开子页,观察列表滑出、详情退到主栏、返回时逐级还原
|
||||
|
||||
demo-preview=../demos/master-detail-page/sub.vue
|
||||
|
||||
:::
|
||||
|
||||
```vue
|
||||
<master-detail-page :split="isWide" :selected="!!selectedId" :sub="!!subView">
|
||||
<template #master><!-- 列表 --></template>
|
||||
<template #detail><order-detail :order-id="selectedId" /></template>
|
||||
<template #sub>
|
||||
<recycle-rule-detail v-if="subKind === 'recycle-rule'" :rule-id="subArg" />
|
||||
<fulfillment-list v-else-if="subKind === 'fulfillments'" embedded />
|
||||
</template>
|
||||
</master-detail-page>
|
||||
```
|
||||
|
||||
三层的位置关系:
|
||||
|
||||
| 状态 | 主栏 | 右栏 |
|
||||
| --- | --- | --- |
|
||||
| 未选中 | 列表(占满) | 空 |
|
||||
| 选中 | 列表 | 详情 |
|
||||
| `sub` 为 true | 详情 | 子页 |
|
||||
|
||||
三层共用同一个容器,靠 `left` / `right` 分配位置,**详情不会换父节点**——
|
||||
所以从右栏退到主栏时不会重新挂载,滚动位置和内部状态都还在。
|
||||
列表整列滑出视口而不是销毁,返回时同理。
|
||||
|
||||
第三层只在分栏形态下成立:`split` 为 false 时 `sub` 被忽略,
|
||||
子页要走整页路由,由详情页自己判断(`usePane().openSub()` 会返回 false)。
|
||||
|
||||
### 谁来决定子页
|
||||
|
||||
详情页发起,列表页编排:
|
||||
|
||||
```ts
|
||||
// 详情页:接不住就退回整页跳转
|
||||
function toRecycleRule(id: string): void {
|
||||
if (pane?.openSub(`recycle-rule:${id}`)) {
|
||||
return;
|
||||
}
|
||||
void router.push({ name: "RecycleRuleDetail", params: { id } });
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
// 列表页:`kind:arg` 由自己解析,`#sub` 槽按 kind 渲染
|
||||
const { selectedId, subView } = useMasterDetailPane({
|
||||
path: "/management/sales-orders",
|
||||
detail: id => `/management/sales-orders/${id}`
|
||||
});
|
||||
```
|
||||
|
||||
子页标识是一段字符串,写进 query 的 `sub` 字段,刷新和分享链接都能还原。
|
||||
子页里的返回调 `usePane().close()`,会关掉最上面一层;`pane.close(true)` 表示
|
||||
子页里改过数据,回到详情时宿主会重新拉一次。
|
||||
|
||||
子页内部不要再套一层 `MasterDetailPage` 分栏——右栏本来就不宽,
|
||||
需要列表就用单栏形态(`split` 传 false)。
|
||||
|
||||
### 子页之间的切换动画
|
||||
|
||||
`#sub` 槽外面包着 `PaneTransition`,方向就是 `direction`:
|
||||
|
||||
- **进入第三层**:子页从右侧推入,和右栏展开同时进行
|
||||
- **退出第三层**:子页滑出右侧,右栏同步收缩
|
||||
- **子页互切**(履约记录 → 创建履约单):新内容推入、旧内容左移让位
|
||||
|
||||
子页内容带一个跟着子页标识走的 `:key` 才能触发过渡:
|
||||
|
||||
```vue
|
||||
<template #sub>
|
||||
<fulfillment-list v-if="subKind === 'fulfillments'" key="fulfillments" />
|
||||
<fulfillment-create v-else-if="subKind === 'create'" key="fulfillment-create" />
|
||||
</template>
|
||||
```
|
||||
|
||||
注意第二层时 `#sub` 里什么都不要渲染(用 `v-if` 收掉),否则会留下一个空视图,
|
||||
进入第三层时它要陪着播一次 leave。
|
||||
|
||||
### 三层时的导航栏
|
||||
|
||||
栏内页面照常写 `<t-navbar>`,不用隐藏:列表页的导航栏在第三层整条滑出,
|
||||
详情页的导航栏变成主栏头部,子页的导航栏变成右栏头部,三者位置天然对齐。
|
||||
|
||||
:::preview 三层的导航栏 || 详情栏和子页栏都放了完整的整页结构,观察三条导航栏怎么分配位置
|
||||
|
||||
demo-preview=../demos/master-detail-page/sub-navbar.vue
|
||||
|
||||
:::
|
||||
|
||||
有一个前提:页面根节点(`.tui-page-layout`)上的 `--tui-master-width`
|
||||
必须和传给组件的 `master-width` 一致,否则列表页导航栏的宽度对不上主栏:
|
||||
|
||||
```vue
|
||||
<div class="tui-page-layout tui-navbar" style="--tui-master-width: 420px">
|
||||
```
|
||||
|
||||
## 状态从哪来
|
||||
|
||||
选中项、编辑态、切换方向、关闭逻辑、转屏、query 同步都由 `useMasterDetailPane` 管,
|
||||
列表页把它返回的字段接到模板上:
|
||||
|
||||
```ts
|
||||
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
const { selectedId, editing, subView, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
useMasterDetailPane({
|
||||
path: "/management/customers",
|
||||
detail: id => `/management/customers/${id}`,
|
||||
@@ -51,12 +155,13 @@ const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, o
|
||||
});
|
||||
```
|
||||
|
||||
- `selectedId` / `editing` / `paneDirection` → 传给组件
|
||||
- `selectedId` / `editing` / `subView` / `paneDirection` → 传给组件
|
||||
- `isWide` → 传给 `split`
|
||||
- 列表项点击 → `openDetail(item.id)`
|
||||
- 详情里的「编辑」按钮 → `@edit="openEdit"`
|
||||
|
||||
没有编辑视图的模块不传 `edit`,`openEdit` 是空操作,`editing` 恒为 false。
|
||||
没有子页的模块不传 `#sub`,`subView` 恒为空,`openSub()` 返回 false。
|
||||
|
||||
## 右栏里的页面要改什么
|
||||
|
||||
@@ -93,15 +198,16 @@ await router.replace("/management/customers");
|
||||
```
|
||||
|
||||
导航栏照常写,**不用隐藏**:分栏时它会退化成右栏内的头部,编辑按钮原样保留。
|
||||
返回箭头在分栏时由组件自动隐藏。
|
||||
返回箭头也照常显示,点击时由 `pane.close()` 决定退到哪一层(有子页先关子页)。
|
||||
|
||||
## 返回手势
|
||||
|
||||
栏内层级默认会进浏览器历史:选中一项和进入编辑各推一条,所以浏览器返回手势、
|
||||
物理返回键会先在栏内逐级回退,空栏时再返回才离开列表页:
|
||||
栏内层级默认会进浏览器历史:选中一项、进入编辑、打开子页各推一条,
|
||||
所以浏览器返回手势、物理返回键会先在栏内逐级回退,空栏时再返回才离开列表页:
|
||||
|
||||
| 当前 | 返回一次 | 再返回 |
|
||||
| --- | --- | --- |
|
||||
| 子页 | 同一条的详情 | 空栏,主栏占满 |
|
||||
| 编辑 | 同一条的详情 | 空栏,主栏占满 |
|
||||
| 详情 | 空栏,主栏占满 | 离开列表页 |
|
||||
| 空栏 | 离开列表页 | — |
|
||||
|
||||
Reference in New Issue
Block a user