- 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.
288 lines
6.7 KiB
Vue
288 lines
6.7 KiB
Vue
<template>
|
||
<div class="demo">
|
||
<div class="bar">
|
||
<span class="hint" v-text="hint" />
|
||
<button type="button" class="chip" :class="{ on: split }" @click="split = !split">
|
||
<span v-text="split ? '分栏' : '单栏'" />
|
||
</button>
|
||
</div>
|
||
<div class="frame">
|
||
<master-detail-page
|
||
:split="split"
|
||
:selected="!!selectedId"
|
||
:master-width="220"
|
||
:sub="!!subView"
|
||
>
|
||
<template #master>
|
||
<div class="list">
|
||
<button
|
||
v-for="item in customerList"
|
||
:key="item.id"
|
||
type="button"
|
||
class="item"
|
||
:class="{ on: selectedId === item.id }"
|
||
@click="openDetail(item.id)"
|
||
>
|
||
<span class="name" v-text="item.name" />
|
||
<span class="phone" v-text="item.phone" />
|
||
</button>
|
||
</div>
|
||
</template>
|
||
<template #detail>
|
||
<div class="pane">
|
||
<h3 class="title" v-text="current?.name" />
|
||
<p class="row" v-text="`联系电话:${current?.phone}`" />
|
||
<p class="row" v-text="`护理次数:${current?.visits} 次`" />
|
||
<div class="actions">
|
||
<button type="button" class="action" @click="openSub('fulfillments')">
|
||
<span>查看履约记录</span>
|
||
</button>
|
||
<button type="button" class="action" @click="openSub('create')">
|
||
<span>创建履约单</span>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<template #sub>
|
||
<!-- key 跟着子页走,PaneTransition 才认得出是两个视图在切换 -->
|
||
<div v-if="subView" :key="subView" class="pane">
|
||
<div class="pane-head">
|
||
<button type="button" class="back" @click="closeSub">
|
||
<span>返回</span>
|
||
</button>
|
||
<strong class="sub-title" v-text="subTitle" />
|
||
</div>
|
||
<p v-for="line in subLines" :key="line" class="row" v-text="line" />
|
||
</div>
|
||
</template>
|
||
</master-detail-page>
|
||
</div>
|
||
<ol class="steps">
|
||
<li v-for="step in steps" :key="step" v-text="step" />
|
||
</ol>
|
||
</div>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { computed, ref } from "vue";
|
||
import { MasterDetailPage } from "timi-tdesign-mobile";
|
||
|
||
const customerList = [
|
||
{ id: "c1", name: "林秀兰", phone: "138 0012 3456", visits: 18 },
|
||
{ id: "c2", name: "陈国强", phone: "139 0088 1234", visits: 8 },
|
||
{ id: "c3", name: "王丽华", phone: "137 0011 5678", visits: 12 },
|
||
{ id: "c4", name: "张桂芳", phone: "135 6620 8899", visits: 26 }
|
||
];
|
||
|
||
const steps = [
|
||
"点列表项:列表 + 详情",
|
||
"点详情里的按钮:详情退到主栏,右栏换成子页(列表整列滑出左侧)",
|
||
"点子页的返回:还原成列表 + 详情,列表的滚动位置还在"
|
||
];
|
||
|
||
/** 子页内容,真实项目里由 #sub 槽里的组件自己渲染。 */
|
||
const subPages: Record<string, { title: string; lines: string[] }> = {
|
||
fulfillments: {
|
||
title: "履约记录",
|
||
lines: [
|
||
"FV-20261110-001 · 已核销 · 09:12",
|
||
"FV-20261103-006 · 已核销 · 14:40",
|
||
"FV-20261028-012 · 待核销 · 10:05",
|
||
"FV-20261020-003 · 已核销 · 16:22"
|
||
]
|
||
},
|
||
create: {
|
||
title: "创建履约单",
|
||
lines: [
|
||
"来源订单:SO-20261108-004",
|
||
"客户:林秀兰",
|
||
"产品:护理套餐 A × 1",
|
||
"履约时间:2026-11-11 15:00"
|
||
]
|
||
}
|
||
};
|
||
|
||
const split = ref(true);
|
||
const selectedId = ref("c1");
|
||
// 默认就停在第三层:一进来看到的就是「详情 + 子页」
|
||
const subView = ref("fulfillments");
|
||
|
||
const current = computed(() => customerList.find(item => item.id === selectedId.value));
|
||
const subPage = computed(() => subPages[subView.value]);
|
||
const subTitle = computed(() => subPage.value?.title ?? "");
|
||
const subLines = computed(() => subPage.value?.lines ?? []);
|
||
const hint = computed(() => {
|
||
if (!split.value) {
|
||
return "单栏下只显示一层,sub 不生效";
|
||
}
|
||
if (!selectedId.value) {
|
||
return "先点一条,再在详情里打开子页";
|
||
}
|
||
return subView.value ? "第三层:详情 + 子页" : "第二层:列表 + 详情";
|
||
});
|
||
|
||
function openDetail(id: string): void {
|
||
selectedId.value = id;
|
||
// 换一项时子页属于上一条,跟着收掉
|
||
subView.value = "";
|
||
}
|
||
|
||
function openSub(view: string): void {
|
||
if (!split.value || !selectedId.value) {
|
||
return;
|
||
}
|
||
subView.value = view;
|
||
}
|
||
|
||
function closeSub(): void {
|
||
subView.value = "";
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="less">
|
||
.demo {
|
||
.bar {
|
||
gap: .5rem;
|
||
display: flex;
|
||
align-items: center;
|
||
margin-bottom: .75rem;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.hint {
|
||
color: var(--td-text-color-secondary);
|
||
font-size: .8125rem;
|
||
}
|
||
|
||
.chip {
|
||
padding: .375rem .875rem;
|
||
color: var(--td-text-color-secondary);
|
||
font-size: .8125rem;
|
||
background: var(--td-bg-color-container);
|
||
border-radius: 99rem;
|
||
border: 1px solid var(--td-component-border);
|
||
cursor: pointer;
|
||
|
||
&.on {
|
||
color: var(--td-brand-color);
|
||
border-color: var(--td-brand-color);
|
||
background: var(--td-brand-color-1);
|
||
}
|
||
}
|
||
|
||
.frame {
|
||
height: 320px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
border-radius: .75rem;
|
||
border: 1px solid var(--td-component-border);
|
||
background: var(--td-bg-color-page);
|
||
|
||
// 组件自带 tui-page-content,真实页面里它绝对定位铺满内容区,
|
||
// demo 里补上同样的定位上下文,否则三栏没有高度可分配
|
||
:deep(.tui-master-detail-page) {
|
||
inset: 0;
|
||
position: absolute;
|
||
}
|
||
}
|
||
|
||
.list {
|
||
height: 100%;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.item {
|
||
gap: .125rem;
|
||
width: 100%;
|
||
display: flex;
|
||
padding: .625rem .875rem;
|
||
text-align: left;
|
||
align-items: flex-start;
|
||
flex-direction: column;
|
||
background: none;
|
||
border-radius: .5rem;
|
||
border: 0;
|
||
cursor: pointer;
|
||
|
||
&.on {
|
||
background: var(--td-brand-color-1);
|
||
}
|
||
|
||
.name {
|
||
color: var(--td-text-color-primary);
|
||
font-size: .875rem;
|
||
}
|
||
|
||
.phone {
|
||
color: var(--td-text-color-secondary);
|
||
font-size: .75rem;
|
||
}
|
||
}
|
||
|
||
.pane {
|
||
padding: 1rem;
|
||
|
||
.title {
|
||
margin: 0 0 .75rem;
|
||
color: var(--td-text-color-primary);
|
||
font-size: 1rem;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.row {
|
||
margin: 0 0 .5rem;
|
||
color: var(--td-text-color-secondary);
|
||
font-size: .8125rem;
|
||
line-height: 1.6;
|
||
}
|
||
}
|
||
|
||
.pane-head {
|
||
gap: .5rem;
|
||
display: flex;
|
||
margin-bottom: .75rem;
|
||
align-items: center;
|
||
|
||
.back {
|
||
padding: .25rem .625rem;
|
||
color: var(--td-brand-color);
|
||
font-size: .75rem;
|
||
background: none;
|
||
border-radius: 99rem;
|
||
border: 1px solid var(--td-brand-color);
|
||
cursor: pointer;
|
||
}
|
||
|
||
.sub-title {
|
||
color: var(--td-text-color-primary);
|
||
font-size: .9375rem;
|
||
}
|
||
}
|
||
|
||
.actions {
|
||
gap: .5rem;
|
||
display: flex;
|
||
margin-top: 1rem;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.action {
|
||
padding: .375rem .75rem;
|
||
color: var(--td-brand-color);
|
||
font-size: .8125rem;
|
||
background: var(--td-brand-color-1);
|
||
border-radius: .5rem;
|
||
border: 0;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.steps {
|
||
margin: .75rem 0 0;
|
||
padding-left: 1.125rem;
|
||
color: var(--td-text-color-placeholder);
|
||
font-size: .75rem;
|
||
line-height: 1.8;
|
||
}
|
||
}
|
||
</style>
|