Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve page component #5013

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/.vitepress/config/zh.mts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ function sidebarComponents(): DefaultTheme.SidebarItem[] {
},
],
},
{
collapsed: false,
text: '布局组件',
items: [
{
link: 'layout-ui/page',
text: 'Page 页面',
},
],
},
{
collapsed: false,
text: '通用组件',
Expand Down
4 changes: 4 additions & 0 deletions docs/src/components/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

:::

## 布局组件

布局组件一般在页面内容区域用作顶层容器组件,提供一些统一的布局样式和基本功能。

## 通用组件

通用组件是一些常用的组件,比如弹窗、抽屉、表单等。大部分基于 `Tailwind CSS` 实现,可适用于不同 UI 组件库的应用。
43 changes: 43 additions & 0 deletions docs/src/components/layout-ui/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
outline: deep
---

# Page 常规页面组件

提供一个常规页面布局的组件,包括头部、内容区域、底部三个部分。

::: info 写在前面

本组件是一个基本布局组件。如果有更多的通用页面布局需求(比如双列布局等),可以根据实际需求自行封装。

:::

## 基础用法

将`Page`作为你的业务页面的根组件即可。

### Props

| 属性名 | 描述 | 类型 | 默认值 |
| ----------------- | ------------------------ | --------- | ------- |
| title | 页面标题 | `string` | - |
| description | 页面描述(标题下的内容) | `string` | - |
| contentClass | 内容区域的class | `string` | - |
| autoContentHeight | 自动调整内容区域的高度 | `boolean` | `false` |
| fixedHeader | 固定头部 | `boolean` | `false` |

::: tip 注意

如果`title`、`description`、`extra`三者均未提供有效内容(通过`props`或者`slots`均可),则页面头部区域不会渲染。
mynetfan marked this conversation as resolved.
Show resolved Hide resolved

:::

### Slots

| 插槽名称 | 描述 |
| ----------- | ------------ |
| default | 页面内容 |
| title | 页面标题 |
| description | 页面描述 |
| extra | 页面头部右侧 |
| footer | 页面底部 |
2 changes: 1 addition & 1 deletion packages/@core/ui-kit/layout-ui/src/vben-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ function handleHeaderToggle() {

<div
ref="contentRef"
class="flex flex-1 flex-col overflow-hidden transition-all duration-300 ease-in"
class="flex flex-1 flex-col transition-all duration-300 ease-in"
>
<div
:class="[
Expand Down
1 change: 1 addition & 0 deletions packages/effects/common-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@vben-core/form-ui": "workspace:*",
"@vben-core/popup-ui": "workspace:*",
"@vben-core/preferences": "workspace:*",
"@vben-core/shadcn-ui": "workspace:*",
"@vben-core/shared": "workspace:*",
"@vben/constants": "workspace:*",
Expand Down
27 changes: 26 additions & 1 deletion packages/effects/common-ui/src/components/page/page.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<script setup lang="ts">
import { computed, nextTick, onMounted, ref, useTemplateRef } from 'vue';
import {
computed,
nextTick,
onMounted,
ref,
type StyleValue,
useTemplateRef,
} from 'vue';

import { preferences } from '@vben-core/preferences';

interface Props {
title?: string;
Expand All @@ -9,6 +18,8 @@ interface Props {
* 根据content可见高度自适应
*/
autoContentHeight?: boolean;
/** 头部固定 */
fixedHeader?: boolean;
}

defineOptions({
Expand All @@ -20,6 +31,7 @@ const {
description = '',
autoContentHeight = false,
title = '',
fixedHeader = false,
} = defineProps<Props>();

const headerHeight = ref(0);
Expand All @@ -29,6 +41,18 @@ const shouldAutoHeight = ref(false);
const headerRef = useTemplateRef<HTMLDivElement>('headerRef');
const footerRef = useTemplateRef<HTMLDivElement>('footerRef');

const headerStyle = computed<StyleValue>(() => {
return fixedHeader
? {
position: 'sticky',
zIndex: 200,
top:
preferences.header.mode === 'fixed' ? 'var(--vben-header-height)' : 0,
borderBottom: '1px solid hsl(240 5.9% 90%)',
}
: undefined;
});

const contentStyle = computed(() => {
if (autoContentHeight) {
return {
Expand Down Expand Up @@ -69,6 +93,7 @@ onMounted(() => {
$slots.extra
"
ref="headerRef"
:style="headerStyle"
class="bg-card relative px-6 py-4"
>
<slot name="title">
Expand Down
1 change: 1 addition & 0 deletions playground/src/views/examples/modal/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function openFormModal() {
<template>
<Page
description="弹窗组件常用于在不离开当前页面的情况下,显示额外的信息、表单或操作提示,更多api请查看组件文档。"
fixed-header
title="弹窗组件示例"
>
<template #extra>
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading