144 lines
3.3 KiB
Vue
144 lines
3.3 KiB
Vue
<template>
|
|
<t-popup v-model="visible" placement="bottom" :z-index="props.zIndex" :overlay-props="props.overlayProps">
|
|
<div class="bottom-popup" :style="{ height: props.height, maxHeight: props.maxHeight }">
|
|
<div v-if="hasHeader" class="header">
|
|
<div class="button left">
|
|
<slot name="leftButton" :on-click="emitLeftButtonClick">
|
|
<t-button v-if="leftButtonText" variant="text" size="small" :disabled="props.leftButtonDisabled" @click="emitLeftButtonClick">
|
|
<span v-text="leftButtonText" />
|
|
</t-button>
|
|
</slot>
|
|
</div>
|
|
<div class="title text-bold">
|
|
<slot name="title">
|
|
<span v-text="title" />
|
|
</slot>
|
|
</div>
|
|
<div class="button right">
|
|
<slot name="rightButton" :on-click="emitRightButtonClick">
|
|
<t-button v-if="rightButtonText" theme="primary" variant="text" size="small" :disabled="props.rightButtonDisabled" @click="emitRightButtonClick">
|
|
<span v-text="rightButtonText" />
|
|
</t-button>
|
|
</slot>
|
|
</div>
|
|
</div>
|
|
<div class="body">
|
|
<slot />
|
|
</div>
|
|
</div>
|
|
</t-popup>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
defineOptions({
|
|
name: "BottomPopup"
|
|
});
|
|
|
|
export interface BottomPopupProps {
|
|
modelValue?: boolean;
|
|
leftButtonText?: string;
|
|
rightButtonText?: string;
|
|
/** 禁用左侧默认按钮。 */
|
|
leftButtonDisabled?: boolean;
|
|
/** 禁用右侧默认按钮。 */
|
|
rightButtonDisabled?: boolean;
|
|
height?: string | number;
|
|
/** 弹层最大高度,数字以 px 为单位。 */
|
|
maxHeight?: string | number;
|
|
title?: string;
|
|
zIndex?: number;
|
|
overlayProps?: Record<string, unknown>;
|
|
}
|
|
|
|
export interface BottomPopupSlots {
|
|
default?: () => unknown;
|
|
title?: () => unknown;
|
|
leftButton?: (props: { onClick: () => void }) => unknown;
|
|
rightButton?: (props: { onClick: () => void }) => unknown;
|
|
}
|
|
|
|
const props = withDefaults(defineProps<BottomPopupProps>(), {
|
|
modelValue: false,
|
|
leftButtonText: "取消",
|
|
rightButtonText: "确定",
|
|
height: "auto",
|
|
title: "",
|
|
maxHeight: "80vh",
|
|
zIndex: undefined,
|
|
overlayProps: undefined
|
|
});
|
|
|
|
const emit = defineEmits<{
|
|
"update:modelValue": [value: boolean];
|
|
leftButtonClick: [];
|
|
rightButtonClick: [];
|
|
}>();
|
|
|
|
const slots = useSlots() as BottomPopupSlots;
|
|
const visible = computed({
|
|
get: () => props.modelValue,
|
|
set: value => emit("update:modelValue", value)
|
|
});
|
|
const hasHeader = computed<boolean>(() => Boolean(
|
|
props.title
|
|
|| props.leftButtonText
|
|
|| props.rightButtonText
|
|
|| slots.title
|
|
|| slots.leftButton
|
|
|| slots.rightButton
|
|
));
|
|
|
|
function emitLeftButtonClick(): void {
|
|
emit("leftButtonClick");
|
|
}
|
|
|
|
function emitRightButtonClick(): void {
|
|
emit("rightButtonClick");
|
|
}
|
|
|
|
defineSlots<BottomPopupSlots>();
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.bottom-popup {
|
|
display: flex;
|
|
overflow: hidden;
|
|
padding-top: 1rem;
|
|
background: var(--td-bg-color-container, #fff);
|
|
border-radius: 1.25rem 1.25rem 0 0;
|
|
flex-direction: column;
|
|
|
|
.header {
|
|
flex: none;
|
|
padding: 0 1rem;
|
|
display: grid;
|
|
align-items: center;
|
|
grid-template-columns: 4rem 1fr 4rem;
|
|
}
|
|
|
|
.button {
|
|
min-width: 0;
|
|
display: flex;
|
|
|
|
&.right {
|
|
justify-content: flex-end;
|
|
}
|
|
}
|
|
|
|
.title {
|
|
overflow: hidden;
|
|
margin-top: -.25rem;
|
|
text-align: center;
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.body {
|
|
flex: 1;
|
|
padding: 0 0 var(--tui-safe-bottom, 0);
|
|
overflow: auto;
|
|
min-height: 0;
|
|
}
|
|
}
|
|
</style>
|