feat(master-detail): add cover sub-mode and providePane
- MasterDetail / MasterDetailPage: add `sub-mode` ("shift" | "cover", default
"shift", so existing callers are unaffected). `cover` leaves the master pane
untouched and puts the sub pane over the detail column: the case where the
list must stay visible while drilling into another module. The detail pane
fades out in place instead of sliding into the master column, so it stays
mounted and keeps its scroll position and internal state.
- use-master-detail: export `providePane(context)` and return `close` from
useMasterDetailPane. A page can now hand a derived pane context to its whole
subtree, which is how a host rewrites sub view ids (prefixing them with the
owning record). The alternative - a wrapper component - breaks the
`.detail > .tui-page-layout` selectors in page-layout.less and sends the
in-pane navbar back to `position: fixed`.
- docs: cover vs shift, and how to prefix sub view ids without a wrapper.
This commit is contained in:
@@ -74,6 +74,30 @@ demo-preview=../demos/master-detail-page/sub.vue
|
||||
第三层只在分栏形态下成立:`split` 为 false 时 `sub` 被忽略,
|
||||
子页要走整页路由,由详情页自己判断(`usePane().openSub()` 会返回 false)。
|
||||
|
||||
### 列表要留着的时候:`sub-mode="cover"`
|
||||
|
||||
上面那种是「同一条记录继续往下钻」,列表可以不要了。但如果从详情跳进的是**另一个模块**
|
||||
的页面,用户还得对着列表核对,`shift` 把列表推走就错了。
|
||||
|
||||
传 `sub-mode="cover"`:主栏不动、子页直接盖住详情栏,详情原地保活(返回时滚动位置和状态都在)。
|
||||
|
||||
```vue
|
||||
<master-detail-page :split="isWide" :selected="!!selectedId" :sub="!!subView" sub-mode="cover">
|
||||
<template #master><!-- 资金流水列表 --></template>
|
||||
<template #detail><fund-record-detail :record-id="selectedId" /></template>
|
||||
<template #sub><sales-order-detail :order-id="orderPane.orderId" /></template>
|
||||
</master-detail-page>
|
||||
```
|
||||
|
||||
| 状态 | 主栏 | 右栏 |
|
||||
| --- | --- | --- |
|
||||
| 选中 | 列表 | 详情 |
|
||||
| `sub` 为 true | 列表(不动) | 子页 |
|
||||
|
||||
两种模式共用同一套 `sub` / `subView` 状态,层级、历史和 `pane.close()` 的行为完全一致,
|
||||
只影响布局。子页里再换一层(订单详情 → 取消订单)仍然是给 `#sub` 里的内容换 `:key`,
|
||||
外层 `PaneTransition` 自动接上。
|
||||
|
||||
### 谁来决定子页
|
||||
|
||||
详情页发起,列表页编排:
|
||||
@@ -100,6 +124,18 @@ const { selectedId, subView } = useMasterDetailPane({
|
||||
子页里的返回调 `usePane().close()`,会关掉最上面一层;`pane.close(true)` 表示
|
||||
子页里改过数据,回到详情时宿主会重新拉一次。
|
||||
|
||||
宿主需要给子页标识补前缀(例如标明"叠在哪一单上")时,用 `providePane` 在页面最外层
|
||||
换一套派生上下文,别在中间塞容器组件——那会切断栏内骨架的直系选择器:
|
||||
|
||||
```ts
|
||||
const { selectedId, subView, openSub, close } = useMasterDetailPane({ … });
|
||||
|
||||
providePane({
|
||||
close: saved => close(saved),
|
||||
openSub: view => openSub(buildView(orderPane.value.orderId, view))
|
||||
});
|
||||
```
|
||||
|
||||
子页内部不要再套一层 `MasterDetailPage` 分栏——右栏本来就不宽,
|
||||
需要列表就用单栏形态(`split` 传 false)。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user