- 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.
250 lines
6.1 KiB
Vue
250 lines
6.1 KiB
Vue
<template>
|
||
<div class="demo">
|
||
<div class="bar">
|
||
<span class="hint" v-text="hint" />
|
||
<button type="button" class="chip" @click="reset">
|
||
<span>回到空栏</span>
|
||
</button>
|
||
</div>
|
||
<div class="frame">
|
||
<!-- `--tui-master-width` 要和 master-width 一致,否则列表页导航栏的宽度对不上 -->
|
||
<div class="tui-page-layout tui-navbar" style="--tui-master-width: 220px">
|
||
<t-navbar fixed :z-index="20" title="交易订单" left-arrow />
|
||
<master-detail-page
|
||
:split="true"
|
||
:selected="!!selectedId"
|
||
:master-width="220"
|
||
:sub="!!subView"
|
||
>
|
||
<template #master>
|
||
<div class="list">
|
||
<button
|
||
v-for="item in orderList"
|
||
:key="item.id"
|
||
type="button"
|
||
class="item"
|
||
:class="{ on: selectedId === item.id }"
|
||
@click="openDetail(item.id)"
|
||
>
|
||
<span class="no" v-text="item.no" />
|
||
<span class="amount" v-text="item.amount" />
|
||
</button>
|
||
</div>
|
||
</template>
|
||
<template #detail>
|
||
<!-- 整页结构直接塞进右栏:导航栏会退化成栏内头部 -->
|
||
<div class="tui-page-layout tui-navbar pane">
|
||
<t-navbar fixed :z-index="20" title="订单详情" left-arrow @left-click="openDetail('')" />
|
||
<main class="tui-page-content scroll column">
|
||
<div class="body">
|
||
<div class="headline" v-text="current?.no" />
|
||
<p class="row" v-text="`成交金额:${current?.amount}`" />
|
||
<p class="row" v-text="`客户:${current?.customer}`" />
|
||
<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>
|
||
</main>
|
||
</div>
|
||
</template>
|
||
<template #sub>
|
||
<!-- key 跟着子页走,PaneTransition 才认得出是两个视图在切换 -->
|
||
<div v-if="subView" :key="subView" class="tui-page-layout tui-navbar pane">
|
||
<t-navbar fixed :z-index="20" :title="subTitle" left-arrow @left-click="closeSub" />
|
||
<main class="tui-page-content scroll column">
|
||
<div class="body">
|
||
<p v-for="line in subLines" :key="line" class="row" v-text="line" />
|
||
</div>
|
||
</main>
|
||
</div>
|
||
</template>
|
||
</master-detail-page>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { computed, ref } from "vue";
|
||
import { MasterDetailPage } from "timi-tdesign-mobile";
|
||
|
||
const orderList = [
|
||
{ id: "o1", no: "SO-20261108-004", amount: "¥ 1,280.00", customer: "林秀兰" },
|
||
{ id: "o2", no: "SO-20261105-012", amount: "¥ 680.00", customer: "陈国强" },
|
||
{ id: "o3", no: "SO-20261030-008", amount: "¥ 2,150.00", customer: "王丽华" }
|
||
];
|
||
|
||
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"
|
||
]
|
||
},
|
||
create: {
|
||
title: "创建履约单",
|
||
lines: [
|
||
"来源订单:SO-20261108-004",
|
||
"客户:林秀兰",
|
||
"履约时间:2026-11-11 15:00"
|
||
]
|
||
}
|
||
};
|
||
|
||
const selectedId = ref("o1");
|
||
// 默认停在第三层:三条导航栏的位置关系一进来就能看到
|
||
const subView = ref("fulfillments");
|
||
|
||
const current = computed(() => orderList.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 (!selectedId.value) {
|
||
return "空栏:导航栏满宽";
|
||
}
|
||
return subView.value ? "第三层:列表导航栏已让位" : "第二层:导航栏收窄到主栏宽";
|
||
});
|
||
|
||
function openDetail(id: string): void {
|
||
selectedId.value = id;
|
||
subView.value = "";
|
||
}
|
||
|
||
function openSub(view: string): void {
|
||
if (selectedId.value) {
|
||
subView.value = view;
|
||
}
|
||
}
|
||
|
||
function closeSub(): void {
|
||
subView.value = "";
|
||
}
|
||
|
||
function reset(): void {
|
||
selectedId.value = "";
|
||
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;
|
||
}
|
||
|
||
.frame {
|
||
height: 340px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
border-radius: .75rem;
|
||
border: 1px solid var(--td-component-border);
|
||
background: var(--td-bg-color-page);
|
||
|
||
// 真实页面里 .tui-page-layout 是路由页,高度由 PageTransition 给;
|
||
// demo 里用 100vh 会撑爆卡片,压成卡片高度
|
||
:deep(.tui-page-layout) {
|
||
height: 100%;
|
||
min-height: 0;
|
||
}
|
||
}
|
||
|
||
.list {
|
||
height: 100%;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.item {
|
||
gap: .125rem;
|
||
width: 100%;
|
||
display: flex;
|
||
padding: .625rem .75rem;
|
||
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);
|
||
}
|
||
|
||
.no {
|
||
color: var(--td-text-color-primary);
|
||
font-size: .8125rem;
|
||
}
|
||
|
||
.amount {
|
||
color: var(--td-text-color-secondary);
|
||
font-size: .75rem;
|
||
}
|
||
}
|
||
|
||
.pane {
|
||
|
||
.body {
|
||
padding: 1rem;
|
||
}
|
||
|
||
.headline {
|
||
margin-bottom: .75rem;
|
||
color: var(--td-text-color-primary);
|
||
font-size: .9375rem;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.row {
|
||
margin: 0 0 .5rem;
|
||
color: var(--td-text-color-secondary);
|
||
font-size: .8125rem;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
}
|
||
}
|
||
</style>
|