Skip to content

Commit

Permalink
feat: page component (vbenjs#4087)
Browse files Browse the repository at this point in the history
* feat: page component

* chore: basic page

* chore: add demos

* chore: add header-sticky support

* chore: update web-ele

* chore: rename slot name

---------

Co-authored-by: Vben <ann.vben@gmail.com>
  • Loading branch information
likui628 and anncwb authored Aug 11, 2024
1 parent b464b87 commit 3015912
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 16 deletions.
12 changes: 5 additions & 7 deletions apps/web-ele/src/views/demos/element/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import {
ElButton,
ElCard,
Expand Down Expand Up @@ -39,13 +41,9 @@ function notify(type: NotificationType) {
</script>

<template>
<div class="p-5">
<Page title="Element Plus组件使用演示">
<template #header> 支持多语言,主题功能集成切换等 </template>
<div class="card-box p-5">
<h1 class="text-xl font-semibold">Element Plus组件使用演示</h1>
<div class="text-foreground/80 mt-2">支持多语言,主题功能集成切换等</div>
</div>

<div class="card-box mt-5 p-5">
<div class="mb-3">
<span class="text-lg font-semibold">按钮</span>
</div>
Expand Down Expand Up @@ -92,5 +90,5 @@ function notify(type: NotificationType) {
<ElButton type="success" @click="notify('success')"> 成功 </ElButton>
</div>
</div>
</div>
</Page>
</template>
13 changes: 5 additions & 8 deletions apps/web-naive/src/views/demos/naive/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import type { NotificationType } from 'naive-ui';
import { Page } from '@vben/common-ui';
import { type NotificationType } from 'naive-ui';
import { NButton, NCard, NSpace, useMessage, useNotification } from 'naive-ui';
const notification = useNotification();
Expand Down Expand Up @@ -33,13 +34,9 @@ function notify(type: NotificationType) {
</script>

<template>
<div class="p-5">
<Page title="naive组件使用演示">
<template #header> 支持多语言,主题功能集成切换等 </template>
<div class="card-box p-5">
<h1 class="text-xl font-semibold">naive组件使用演示</h1>
<div class="text-foreground/80 mt-2">支持多语言,主题功能集成切换等</div>
</div>

<div class="card-box mt-5 p-5">
<div class="mb-3">
<span class="text-lg font-semibold">按钮</span>
</div>
Expand Down Expand Up @@ -87,5 +84,5 @@ function notify(type: NotificationType) {
<NButton type="primary" @click="notify('info')"> 加载中 </NButton>
</div>
</div>
</div>
</Page>
</template>
9 changes: 8 additions & 1 deletion apps/web-naive/src/views/demos/table/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
import { ref } from 'vue';
import { Page } from '@vben/common-ui';
import { NDataTable } from 'naive-ui';
const columns = ref([
Expand All @@ -25,7 +27,12 @@ const data = [
</script>

<template>
<NDataTable :columns="columns" :data="data" />
<Page title="NDataTable">
<template #header>
表单页用于向用户收集或验证信息,基础表单常见于数据项较少的表单场景。
</template>
<NDataTable :columns="columns" :data="data" />
</Page>
</template>

<style scoped></style>
1 change: 1 addition & 0 deletions packages/effects/common-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './authentication';
export * from './dashboard';
export * from './ellipsis-text';
export * from './fallback';
export * from './page';
export { useToast } from '@vben-core/shadcn-ui';
1 change: 1 addition & 0 deletions packages/effects/common-ui/src/page/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Page } from './page.vue';
13 changes: 13 additions & 0 deletions packages/effects/common-ui/src/page/page-footer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script setup lang="ts">
defineOptions({
name: 'PageFooter',
});
</script>

<template>
<div
class="bg-card align-center absolute bottom-0 left-0 right-0 flex px-6 py-4"
>
<slot></slot>
</div>
</template>
20 changes: 20 additions & 0 deletions packages/effects/common-ui/src/page/page-header.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
import type { PageHeaderProps } from './page.ts';
defineOptions({
name: 'PageHeader',
});
const props = defineProps<PageHeaderProps>();
</script>

<template>
<div class="bg-card px-6 py-4">
<div class="flex justify-between text-lg font-bold">
{{ props.title }}
</div>
<div class="pt-3">
<slot></slot>
</div>
</div>
</template>
11 changes: 11 additions & 0 deletions packages/effects/common-ui/src/page/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface PageHeaderProps {
title?: string;
}

interface Props extends PageHeaderProps {
headerSticky?: boolean;
showFooter?: boolean;
showHeader?: boolean;
}

export type { PageHeaderProps, Props };
34 changes: 34 additions & 0 deletions packages/effects/common-ui/src/page/page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script setup lang="ts">
import type { Props } from './page.ts';
import PageFooter from './page-footer.vue';
import PageHeader from './page-header.vue';
defineOptions({
name: 'Page',
});
const props = withDefaults(defineProps<Props>(), {
showFooter: false,
showHeader: true,
title: '',
});
</script>

<template>
<div class="relative h-full">
<PageHeader v-if="props.showHeader" :title="props.title">
<template #default>
<slot name="header"></slot>
</template>
</PageHeader>
<div class="m-4 overflow-hidden">
<slot></slot>
</div>
<PageFooter v-if="props.showFooter">
<template #default>
<slot name="footer"></slot>
</template>
</PageFooter>
</div>
</template>

0 comments on commit 3015912

Please sign in to comment.