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:
@@ -80,7 +80,7 @@ export {
|
||||
};
|
||||
|
||||
export { createLayoutContext, provideLayout, useLayout } from "./app-shell";
|
||||
export { useExpandToMaster, useMasterDetail, useMasterDetailPane, usePane } from "../composables/use-master-detail";
|
||||
export { useExpandToMaster, useMasterDetail, useMasterDetailPane, usePane, providePane } from "../composables/use-master-detail";
|
||||
export type { ExpandToMasterOptions, PaneContext, PaneDirection, UseMasterDetailOptions, UseMasterDetailPaneOptions, UseMasterDetailPaneReturn, UseMasterDetailReturn } from "../composables/use-master-detail";
|
||||
|
||||
export type {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
:top-inset="topInset"
|
||||
:detail-empty="!selected"
|
||||
:sub="sub"
|
||||
:sub-mode="subMode"
|
||||
>
|
||||
<template #master>
|
||||
<div class="tui-master-wrap">
|
||||
@@ -54,7 +55,8 @@ const props = withDefaults(defineProps<MasterDetailPageProps>(), {
|
||||
direction: "forward",
|
||||
masterWidth: 380,
|
||||
topInset: "",
|
||||
sub: false
|
||||
sub: false,
|
||||
subMode: "shift"
|
||||
});
|
||||
|
||||
defineSlots<{
|
||||
|
||||
@@ -19,9 +19,16 @@ export interface MasterDetailPageProps {
|
||||
/**
|
||||
* 是否进入第三层:主栏换成详情内容,右栏显示 `#sub` 槽。
|
||||
*
|
||||
* 三层依次是:列表 → 详情 → 子页。进入时列表整列滑出左侧、详情退到主栏,
|
||||
* 返回时反向还原成「列表 + 详情」。只有分栏形态下有效,
|
||||
* 三层依次是:列表 → 详情 → 子页。只有分栏形态下有效,
|
||||
* 窄屏请让子页走整页路由(`usePane().openSub()` 会返回 false)。
|
||||
*/
|
||||
sub?: boolean;
|
||||
/**
|
||||
* 第三层的呈现方式,默认 `shift`。
|
||||
*
|
||||
* - `shift`:列表整列滑出、详情退到主栏,适合同一条记录继续往下钻;
|
||||
* - `cover`:主栏不动、子页盖住详情栏,适合从详情跳进另一个模块的页面,
|
||||
* 列表要一直留在眼前(详情原地保活,返回时滚动位置和状态都在)。
|
||||
*/
|
||||
subMode?: "shift" | "cover";
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
:class="{
|
||||
split: isSplit,
|
||||
'is-collapsed': isSplit && detailEmpty,
|
||||
'has-sub': isSplit && showSub
|
||||
'has-sub': isSplit && showSub,
|
||||
'is-sub-cover': isSplit && showSub && subMode === 'cover'
|
||||
}"
|
||||
:style="rootStyle"
|
||||
>
|
||||
@@ -44,7 +45,8 @@ const props = withDefaults(defineProps<MasterDetailProps>(), {
|
||||
emptyText: "",
|
||||
topInset: "",
|
||||
detailEmpty: false,
|
||||
sub: false
|
||||
sub: false,
|
||||
subMode: "shift"
|
||||
});
|
||||
|
||||
defineSlots<{
|
||||
@@ -231,6 +233,35 @@ const rootStyle = computed<StyleValue>(() => ({
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三层的 cover 形态:右栏换人,主栏不动。
|
||||
*
|
||||
* shift 是"整条轨道左移",用户已经不看列表了;cover 针对的相反——
|
||||
* 从详情跳进别的模块,列表本身要一直留在眼前。
|
||||
* 详情不参与位移,只原地淡出(保活,返回时滚动位置和内部状态都还在),
|
||||
* 子页像换班一样滑进右栏。
|
||||
*/
|
||||
&.has-sub.is-sub-cover {
|
||||
|
||||
.master {
|
||||
left: 0;
|
||||
right: calc(100% - var(--tui-master-width));
|
||||
border-right-color: var(--td-component-border, rgba(0, 0, 0, .08));
|
||||
}
|
||||
|
||||
.detail {
|
||||
left: var(--tui-master-width);
|
||||
right: 0;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.sub {
|
||||
left: var(--tui-master-width);
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -31,4 +31,15 @@ export interface MasterDetailProps {
|
||||
* 只有分栏形态下有效,窄屏请让子页走整页路由。
|
||||
*/
|
||||
sub?: boolean;
|
||||
/**
|
||||
* 第三层的呈现方式,默认 `shift`。
|
||||
*
|
||||
* - `shift`:整条轨道左移,列表滑出、详情退到主栏。适合同一条记录继续往下钻,
|
||||
* 用户已经不需要再看列表了。
|
||||
* - `cover`:主栏不动,子页直接盖住详情栏(详情原地保活,返回时滚动位置和内部状态都在)。
|
||||
* 适合从详情跳进**另一个模块**的页面——列表本身是用户要一直看的东西。
|
||||
*
|
||||
* 两种方式共用同一套 `sub` / `subView` 状态,切换只影响布局,不影响层级和历史的处理。
|
||||
*/
|
||||
subMode?: "shift" | "cover";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user