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:
@@ -5,6 +5,7 @@
|
||||
:master-width="masterWidth"
|
||||
:top-inset="topInset"
|
||||
:detail-empty="!selected"
|
||||
:sub="sub"
|
||||
>
|
||||
<template #master>
|
||||
<div class="tui-master-wrap">
|
||||
@@ -22,6 +23,16 @@
|
||||
<slot name="detail" />
|
||||
</pane-transition>
|
||||
</template>
|
||||
<template #sub>
|
||||
<!--
|
||||
常驻而不是 v-if:退出第三层时子页要能播 leave 滑出右侧。
|
||||
进入时子页从右侧推入,和右栏展开同时进行;
|
||||
子页互切靠 slot 内容自己的 :key 触发。
|
||||
-->
|
||||
<pane-transition :direction="direction">
|
||||
<slot name="sub" />
|
||||
</pane-transition>
|
||||
</template>
|
||||
</master-detail>
|
||||
</main>
|
||||
</template>
|
||||
@@ -42,12 +53,14 @@ const props = withDefaults(defineProps<MasterDetailPageProps>(), {
|
||||
selected: false,
|
||||
direction: "forward",
|
||||
masterWidth: 380,
|
||||
topInset: ""
|
||||
topInset: "",
|
||||
sub: false
|
||||
});
|
||||
|
||||
defineSlots<{
|
||||
master?: () => unknown;
|
||||
detail?: () => unknown;
|
||||
sub?: () => unknown;
|
||||
}>();
|
||||
|
||||
const layout = useLayout({ tablet: true });
|
||||
|
||||
@@ -16,4 +16,12 @@ export interface MasterDetailPageProps {
|
||||
masterWidth?: number | string;
|
||||
/** 主栏顶部让出的高度,通常不需要传。 */
|
||||
topInset?: string;
|
||||
/**
|
||||
* 是否进入第三层:主栏换成详情内容,右栏显示 `#sub` 槽。
|
||||
*
|
||||
* 三层依次是:列表 → 详情 → 子页。进入时列表整列滑出左侧、详情退到主栏,
|
||||
* 返回时反向还原成「列表 + 详情」。只有分栏形态下有效,
|
||||
* 窄屏请让子页走整页路由(`usePane().openSub()` 会返回 false)。
|
||||
*/
|
||||
sub?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<template>
|
||||
<div
|
||||
class="tui-master-detail"
|
||||
:class="{ split: isSplit, 'is-collapsed': isSplit && detailEmpty }"
|
||||
:class="{
|
||||
split: isSplit,
|
||||
'is-collapsed': isSplit && detailEmpty,
|
||||
'has-sub': isSplit && showSub
|
||||
}"
|
||||
:style="rootStyle"
|
||||
>
|
||||
<section class="master">
|
||||
@@ -14,6 +18,13 @@
|
||||
</div>
|
||||
</slot>
|
||||
</section>
|
||||
<!--
|
||||
子页层常驻:宽度收到 0 藏在右侧边界外。
|
||||
用 v-if 新建的话,进入时没有起始值可供过渡,子页会直接"蹦"出来。
|
||||
-->
|
||||
<section v-if="isSplit" class="sub">
|
||||
<slot name="sub" />
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -32,12 +43,14 @@ const props = withDefaults(defineProps<MasterDetailProps>(), {
|
||||
split: "auto",
|
||||
emptyText: "",
|
||||
topInset: "",
|
||||
detailEmpty: false
|
||||
detailEmpty: false,
|
||||
sub: false
|
||||
});
|
||||
|
||||
defineSlots<{
|
||||
master?: () => unknown;
|
||||
detail?: () => unknown;
|
||||
sub?: () => unknown;
|
||||
}>();
|
||||
|
||||
// ---------- 分栏判定 ----------
|
||||
@@ -47,6 +60,9 @@ const layout = useLayout({ tablet: true });
|
||||
/** split 为 auto 时跟随 AppShell 的横屏状态,显式传入布尔值时以业务为准。 */
|
||||
const isSplit = computed(() => (props.split === "auto" ? layout.isWide.value : props.split));
|
||||
|
||||
/** 第三层只在有详情时成立:空栏上叠不了子页。 */
|
||||
const showSub = computed(() => props.sub && !props.detailEmpty);
|
||||
|
||||
// ---------- 尺寸 ----------
|
||||
|
||||
const rootStyle = computed<StyleValue>(() => ({
|
||||
@@ -59,6 +75,7 @@ const rootStyle = computed<StyleValue>(() => ({
|
||||
|
||||
<style scoped lang="less">
|
||||
@easing: var(--tui-bezier, cubic-bezier(.19, 1, .22, 1));
|
||||
@duration: var(--tui-split-duration, 320ms);
|
||||
|
||||
.tui-master-detail {
|
||||
flex: 1;
|
||||
@@ -82,38 +99,58 @@ const rootStyle = computed<StyleValue>(() => ({
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分栏:三层常驻在同一个容器里,用 left/right 分配位置。
|
||||
*
|
||||
* 用绝对定位而不是 flex 宽度,是因为详情要在两层之间换位置:
|
||||
* 选中时它占右栏,进入子页时它退到主栏、右栏让给子页。
|
||||
* 换父容器会让整棵子树重建(重新请求、丢滚动位置),改 left/right 只是挪动同一个元素。
|
||||
*
|
||||
* 刻意不用 transform 平移:那会把栏内页面的 fixed 弹层锁进栏位。
|
||||
*/
|
||||
&.split {
|
||||
display: block;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
.master {
|
||||
flex: none;
|
||||
width: var(--tui-master-width);
|
||||
.master,
|
||||
.detail,
|
||||
.sub {
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
// 宽度过渡期间列表会被压窄,内容可能横向溢出,裁掉避免压到详情栏上
|
||||
overflow-x: hidden;
|
||||
border-right: 1px solid var(--td-component-border, rgba(0, 0, 0, .08));
|
||||
// 时长和曲线都来自 page-layout.less 的变量,列表页导航栏用同一组,
|
||||
// 两边必须同拍,否则列表跳、导航滑。
|
||||
transition: width var(--tui-split-duration, 320ms) @easing, border-color .2s linear;
|
||||
}
|
||||
|
||||
.detail {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
position: relative;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
padding-top: var(--tui-master-top-inset, 0px);
|
||||
background: var(--tui-master-detail-background, var(--td-bg-color-page));
|
||||
-webkit-overflow-scrolling: touch;
|
||||
// 展开方向不加 opacity 过渡:
|
||||
// 宽度从 0 长出来本身就是"揭示",再叠一层淡入会让内容看着迟迟不出现。
|
||||
// 收起方向的淡出定义在 .is-collapsed 里,只在收起时生效。
|
||||
// 时长和曲线都来自 page-layout.less 的变量,列表页导航栏用同一组,
|
||||
// 两边必须同拍,否则列表跳、导航滑。
|
||||
transition: left @duration @easing, right @duration @easing, opacity .12s ease-out;
|
||||
}
|
||||
|
||||
// 未选中:主栏占满,另外两层收在右侧边界外
|
||||
.master {
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.detail,
|
||||
.sub {
|
||||
left: 100%;
|
||||
right: 0;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情栏里放的整页组件自动适配栏位:贴合高度、建立定位上下文。
|
||||
* 导航栏不隐藏,而是由 page-layout.less 退化成栏内头部,
|
||||
* 这样编辑等操作仍然可用。
|
||||
*/
|
||||
.detail,
|
||||
.sub {
|
||||
|
||||
/**
|
||||
* 详情栏里放的整页组件自动适配栏位:贴合高度、建立定位上下文。
|
||||
* 导航栏不隐藏,而是由 page-layout.less 退化成栏内头部,
|
||||
* 这样编辑等操作仍然可用。
|
||||
*/
|
||||
:deep(.tui-page-layout) {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
@@ -121,31 +158,68 @@ const rootStyle = computed<StyleValue>(() => ({
|
||||
}
|
||||
}
|
||||
|
||||
.detail {
|
||||
background: var(--tui-master-detail-background, var(--td-bg-color-page));
|
||||
}
|
||||
|
||||
// 选中:主栏收缩到 master-width,详情从右侧展开
|
||||
&:not(.is-collapsed) {
|
||||
|
||||
.master {
|
||||
right: calc(100% - var(--tui-master-width));
|
||||
border-right: 1px solid var(--td-component-border, rgba(0, 0, 0, .08));
|
||||
}
|
||||
|
||||
.detail,
|
||||
.sub {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.detail {
|
||||
left: var(--tui-master-width);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 未选中详情:主栏占满,右栏收起。
|
||||
*
|
||||
* 详情栏不设 display: none——那样宽度变化就没有过渡了。
|
||||
* 保持 flex 分配、把宽度压到 0,配合 overflow-x: hidden 裁掉内容,
|
||||
* 主栏宽度一过渡,右栏自然被"挤"出来。
|
||||
* 收起方向:内容比宽度先淡出。
|
||||
* 否则右栏被压到只剩几十像素时,文字会挤成竖排、按钮会卡在角上,
|
||||
* 看起来像残影而不是"被推走"。
|
||||
*/
|
||||
&.is-collapsed {
|
||||
|
||||
.master {
|
||||
width: 100%;
|
||||
border-right-color: transparent;
|
||||
}
|
||||
|
||||
.detail {
|
||||
// 收起方向:内容比宽度先淡出。
|
||||
// 否则右栏被压到只剩几十像素时,文字会挤成竖排、按钮会卡在角上,
|
||||
// 看起来像残影而不是"被推走"。
|
||||
//
|
||||
// transition 只写在这里:展开时 class 被移除,属性回到默认的瞬间切换,
|
||||
// 内容第一帧就是可见的。
|
||||
opacity: 0;
|
||||
.detail,
|
||||
.sub {
|
||||
overflow-y: hidden;
|
||||
pointer-events: none;
|
||||
transition: opacity .12s ease-out;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三层:列表整列滑出左侧,详情退到主栏,子页接管右栏。
|
||||
*
|
||||
* 三列宽度都是流式表达式(100% 与 px 的 calc),浏览器能连续插值,
|
||||
* 看起来就是"整条轨道往左挪一格"。列表宽度始终是 master-width,
|
||||
* 只是位置变了,所以里面的滚动位置和展开状态都还在。
|
||||
*/
|
||||
&.has-sub {
|
||||
|
||||
.master {
|
||||
left: calc(-1 * var(--tui-master-width));
|
||||
right: 100%;
|
||||
}
|
||||
|
||||
.detail {
|
||||
left: 0;
|
||||
right: calc(100% - var(--tui-master-width));
|
||||
}
|
||||
|
||||
.sub {
|
||||
left: var(--tui-master-width);
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,13 @@ export interface MasterDetailProps {
|
||||
* 只有卡片式列表适合打开——多列宽表格从满宽压到 master-width 会挤成一团。
|
||||
*/
|
||||
detailEmpty?: boolean;
|
||||
/**
|
||||
* 是否进入第三层,默认 false。
|
||||
*
|
||||
* 三层依次是:列表 → 详情 → 子页。此时列表整列滑出左侧,详情退到主栏位置,
|
||||
* 右栏交给 `sub` 槽,形成「详情 + 子页」的两栏;返回时回到「列表 + 详情」。
|
||||
*
|
||||
* 只有分栏形态下有效,窄屏请让子页走整页路由。
|
||||
*/
|
||||
sub?: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user