add app-shell, master-detail, pane-transition

This commit is contained in:
Timi
2026-11-02 21:46:30 +08:00
parent 107a3086ba
commit 8f6b8c1eff
32 changed files with 2631 additions and 55 deletions
+138
View File
@@ -0,0 +1,138 @@
<template>
<div class="demo">
<div class="bar">
<button
v-for="item in modeList"
:key="item.value"
type="button"
class="chip"
:class="{ on: mode === item.value }"
@click="mode = item.value"
>
<span v-text="item.text" />
</button>
</div>
<div class="frame">
<app-shell
v-model="active"
:items="tabList"
:mode="mode"
logo-text="糕"
>
<div class="page">
<header class="navbar">
<span v-text="activeText" />
</header>
<main class="content">
<p class="mode" v-text="`当前形态:${mode}`" />
<p class="desc" v-text="descText" />
</main>
</div>
</app-shell>
</div>
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from "vue";
import { AppShell, type AppShellMode } from "timi-tdesign-mobile";
const modeList: Array<{ value: AppShellMode; text: string }> = [
{ value: "phone", text: "手机" },
{ value: "tablet", text: "竖屏平板" },
{ value: "wide", text: "横屏平板" }
];
const tabList = [
{ value: "/customers", icon: "usergroup", text: "客户", badge: 12 },
{ value: "/product", icon: "layers", text: "产品" },
{ value: "/store", icon: "shop-3", text: "门店" },
{ value: "/management", icon: "setting-1", text: "管理" }
];
const mode = ref<AppShellMode>("wide");
const active = ref("/customers");
const activeText = computed(() => tabList.find(item => item.value === active.value)?.text || "");
const descText = computed(() => (mode.value === "wide"
? "横屏平板使用左侧导航栏,一级导航始终可见。"
: "手机与竖屏平板保留底部标签栏,把纵向空间留给内容。"));
</script>
<style scoped lang="less">
.demo {
.bar {
gap: .5rem;
display: flex;
margin-bottom: .75rem;
}
.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: 340px;
overflow: hidden;
border-radius: .75rem;
border: 1px solid var(--td-component-border);
:deep(.tui-app-shell) {
height: 100%;
}
}
.page {
height: 100%;
display: flex;
flex-direction: column;
background: var(--td-bg-color-page);
.navbar {
height: 3rem;
flex: none;
display: grid;
color: var(--td-text-color-primary);
font-size: .9375rem;
font-weight: 600;
place-items: center;
background: var(--td-bg-color-container);
border-bottom: 1px solid var(--td-component-border);
}
.content {
flex: 1;
padding: 1rem;
min-height: 0;
overflow-y: auto;
}
.mode {
margin: 0 0 .5rem;
color: var(--td-text-color-primary);
font-size: .875rem;
font-weight: 600;
}
.desc {
margin: 0;
color: var(--td-text-color-secondary);
font-size: .8125rem;
line-height: 1.7;
}
}
}
</style>
+149
View File
@@ -0,0 +1,149 @@
<template>
<div class="demo">
<div class="bar">
<button
v-for="item in splitList"
:key="String(item.value)"
type="button"
class="chip"
:class="{ on: split === item.value }"
@click="split = item.value"
>
<span v-text="item.text" />
</button>
</div>
<div class="frame">
<master-detail-page :split="split" :master-width="220" :selected="!!selectedId">
<template #master>
<t-pull-down-refresh class="list" :value="false">
<button
v-for="item in customerList"
:key="item.id"
type="button"
class="item"
:class="{ on: selectedId === item.id }"
@click="selectedId = item.id"
>
<span class="name" v-text="item.name" />
<span class="phone" v-text="item.phone" />
</button>
</t-pull-down-refresh>
</template>
<template #detail>
<div class="detail">
<h3 class="title" v-text="current?.name" />
<p class="row" v-text="`联系电话:${current?.phone}`" />
<p class="row" v-text="`护理次数:${current?.visits} 次`" />
<p class="row" v-text="`最近护理:${current?.last}`" />
</div>
</template>
</master-detail-page>
</div>
</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, last: "10-26" },
{ id: "c2", name: "陈国强", phone: "139 0088 1234", visits: 8, last: "10-21" },
{ id: "c3", name: "王丽华", phone: "137 0011 5678", visits: 12, last: "10-18" },
{ id: "c4", name: "张桂芳", phone: "135 6620 8899", visits: 26, last: "10-15" }
];
const splitList: Array<{ value: boolean | "auto"; text: string }> = [
{ value: "auto", text: "跟随布局" },
{ value: true, text: "强制分栏" },
{ value: false, text: "强制单栏" }
];
const selectedId = ref("c1");
const current = computed(() => customerList.find(item => item.id === selectedId.value));
</script>
<style scoped lang="less">
.demo {
.bar {
gap: .5rem;
display: flex;
margin-bottom: .75rem;
}
.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;
overflow: hidden;
border-radius: .75rem;
border: 1px solid var(--td-component-border);
background: var(--td-bg-color-page);
}
.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;
}
}
.detail {
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;
}
}
}
</style>
+144
View File
@@ -0,0 +1,144 @@
<template>
<div class="demo">
<div class="bar">
<button
v-for="item in splitList"
:key="String(item.value)"
type="button"
class="chip"
:class="{ on: split === item.value }"
@click="split = item.value"
>
<span v-text="item.text" />
</button>
</div>
<div class="frame">
<master-detail :split="split" :master-width="240" empty-text="从左侧选择一位客户">
<template #master>
<button
v-for="item in customerList"
:key="item.id"
type="button"
class="item"
:class="{ on: selected === item.id }"
@click="selected = item.id"
>
<span class="name" v-text="item.name" />
<span class="phone" v-text="item.phone" />
</button>
</template>
<template #detail>
<div v-if="current" class="detail">
<h3 class="title" v-text="current.name" />
<p class="row" v-text="`联系电话:${current.phone}`" />
<p class="row" v-text="`护理次数:${current.visits} 次`" />
<p class="row" v-text="`最近护理:${current.last}`" />
</div>
</template>
</master-detail>
</div>
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from "vue";
import { MasterDetail } from "timi-tdesign-mobile";
const splitList: Array<{ value: boolean | "auto"; text: string }> = [
{ value: "auto", text: "跟随布局" },
{ value: true, text: "强制分栏" },
{ value: false, text: "强制单栏" }
];
const customerList = [
{ id: "c1", name: "林秀兰", phone: "138 0012 3456", visits: 18, last: "10-26" },
{ id: "c2", name: "陈国强", phone: "139 0088 1234", visits: 8, last: "10-21" },
{ id: "c3", name: "王丽华", phone: "137 0011 5678", visits: 12, last: "10-18" },
{ id: "c4", name: "张桂芳", phone: "135 6620 8899", visits: 26, last: "10-15" }
];
const split = ref<boolean | "auto">(true);
const selected = ref("c1");
const current = computed(() => customerList.find(item => item.id === selected.value));
</script>
<style scoped lang="less">
.demo {
.bar {
gap: .5rem;
display: flex;
margin-bottom: .75rem;
}
.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;
overflow: hidden;
border-radius: .75rem;
border: 1px solid var(--td-component-border);
background: var(--td-bg-color-page);
}
.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;
}
}
.detail {
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;
}
}
}
</style>