add app-shell, master-detail, pane-transition
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import view from "./index.vue";
|
||||
import { WebToolkit } from "timi-web";
|
||||
|
||||
export const MasterDetail = WebToolkit.withInstall(view);
|
||||
export default MasterDetail;
|
||||
|
||||
export type { MasterDetailProps } from "./type";
|
||||
@@ -0,0 +1,153 @@
|
||||
<template>
|
||||
<div
|
||||
class="tui-master-detail"
|
||||
:class="{ split: isSplit, 'is-collapsed': isSplit && detailEmpty }"
|
||||
:style="rootStyle"
|
||||
>
|
||||
<section class="master">
|
||||
<slot name="master" />
|
||||
</section>
|
||||
<section v-if="isSplit" class="detail">
|
||||
<slot name="detail">
|
||||
<div v-if="emptyText && !detailEmpty" class="empty">
|
||||
<center-tips :content="emptyText" />
|
||||
</div>
|
||||
</slot>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, type StyleValue } from "vue";
|
||||
import { CenterTips } from "timi-web";
|
||||
import { useLayout } from "../../composables/use-layout";
|
||||
import type { MasterDetailProps } from "./type";
|
||||
|
||||
defineOptions({
|
||||
name: "MasterDetail"
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<MasterDetailProps>(), {
|
||||
masterWidth: 380,
|
||||
split: "auto",
|
||||
emptyText: "",
|
||||
topInset: "",
|
||||
detailEmpty: false
|
||||
});
|
||||
|
||||
defineSlots<{
|
||||
master?: () => unknown;
|
||||
detail?: () => unknown;
|
||||
}>();
|
||||
|
||||
// ---------- 分栏判定 ----------
|
||||
|
||||
const layout = useLayout({ tablet: true });
|
||||
|
||||
/** split 为 auto 时跟随 AppShell 的横屏状态,显式传入布尔值时以业务为准。 */
|
||||
const isSplit = computed(() => (props.split === "auto" ? layout.isWide.value : props.split));
|
||||
|
||||
// ---------- 尺寸 ----------
|
||||
|
||||
const rootStyle = computed<StyleValue>(() => ({
|
||||
"--tui-master-width": typeof props.masterWidth === "number"
|
||||
? `${props.masterWidth}px`
|
||||
: props.masterWidth,
|
||||
...(props.topInset ? { "--tui-master-top-inset": props.topInset } : {})
|
||||
}));
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@easing: var(--tui-bezier, cubic-bezier(.19, 1, .22, 1));
|
||||
|
||||
.tui-master-detail {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
|
||||
.master {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
position: relative;
|
||||
overflow-y: auto;
|
||||
padding-top: var(--tui-master-top-inset, 0px);
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.empty {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
&.split {
|
||||
|
||||
.master {
|
||||
flex: none;
|
||||
width: var(--tui-master-width);
|
||||
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 退化成栏内头部,
|
||||
* 这样编辑等操作仍然可用。
|
||||
*/
|
||||
:deep(.tui-page-layout) {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 未选中详情:主栏占满,右栏收起。
|
||||
*
|
||||
* 详情栏不设 display: none——那样宽度变化就没有过渡了。
|
||||
* 保持 flex 分配、把宽度压到 0,配合 overflow-x: hidden 裁掉内容,
|
||||
* 主栏宽度一过渡,右栏自然被"挤"出来。
|
||||
*/
|
||||
&.is-collapsed {
|
||||
|
||||
.master {
|
||||
width: 100%;
|
||||
border-right-color: transparent;
|
||||
}
|
||||
|
||||
.detail {
|
||||
// 收起方向:内容比宽度先淡出。
|
||||
// 否则右栏被压到只剩几十像素时,文字会挤成竖排、按钮会卡在角上,
|
||||
// 看起来像残影而不是"被推走"。
|
||||
//
|
||||
// transition 只写在这里:展开时 class 被移除,属性回到默认的瞬间切换,
|
||||
// 内容第一帧就是可见的。
|
||||
opacity: 0;
|
||||
overflow-y: hidden;
|
||||
pointer-events: none;
|
||||
transition: opacity .12s ease-out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,25 @@
|
||||
/** MasterDetail 组件属性。 */
|
||||
export interface MasterDetailProps {
|
||||
/** 主栏宽度,数字以 px 为单位,默认 380。 */
|
||||
masterWidth?: number | string;
|
||||
/** 是否分栏;auto 时跟随 AppShell 的横屏状态,默认 auto。 */
|
||||
split?: boolean | "auto";
|
||||
/** 分栏且详情为空时显示的文案。 */
|
||||
emptyText?: string;
|
||||
/**
|
||||
* 两栏顶部的内边距,通常填导航栏高度。
|
||||
*
|
||||
* 加在两栏自己的滚动容器上,内容滚动时才能穿到 fixed 导航栏的毛玻璃层下面;
|
||||
* 加在外层容器上只会把内容整体下移,滚不动。
|
||||
*/
|
||||
topInset?: string;
|
||||
/**
|
||||
* 详情栏当前是否为空,默认 false。
|
||||
*
|
||||
* 传 true 时主栏占满宽度、详情栏收起,选中后主栏收缩到 master-width、右栏展开。
|
||||
* 适合"先看列表、选中再展开"的平板场景:空白右栏不占位,列表也不用挤在 380 的窄条里。
|
||||
*
|
||||
* 只有卡片式列表适合打开——多列宽表格从满宽压到 master-width 会挤成一团。
|
||||
*/
|
||||
detailEmpty?: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user