Skip to content

Commit

Permalink
fix: PageContainer fixedHeader no work
Browse files Browse the repository at this point in the history
  • Loading branch information
sendya committed Apr 24, 2022
1 parent 02af260 commit 6933724
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 113 deletions.
141 changes: 54 additions & 87 deletions packages/pro-layout/examples/layouts/BasicLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,103 +68,70 @@
</pro-layout>
</template>

<script lang="ts">
import { computed, defineComponent, reactive, ref, watchEffect, onMounted } from 'vue';
<script setup lang="ts">
import { computed, reactive, ref, watchEffect, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { message, Button, Input, Switch, Select, Avatar, Space, Badge, Menu } from 'ant-design-vue';
import { getMenuData, clearMenuItem, WaterMark, FooterToolbar } from '@ant-design-vue/pro-layout';
import type { RouteContextProps } from '@ant-design-vue/pro-layout';
import { getMenuData, clearMenuItem, type RouteContextProps } from '@ant-design-vue/pro-layout';
const i18n = (t: string) => t;
export default defineComponent({
name: 'BasicLayout',
components: {
FooterToolbar,
WaterMark,
const watermarkContent = ref('Pro Layout');
const loading = ref(false);
const router = useRouter();
const { menuData } = getMenuData(clearMenuItem(router.getRoutes()));
[Button.name]: Button,
[Input.name]: Input,
[Input.Search.name]: Input.Search,
[Switch.name]: Switch,
[Select.name]: Select,
['a-slect-option']: Select.Option,
[Space.name]: Space,
[Badge.name]: Badge,
[Avatar.name]: Avatar,
[Menu.Item.name]: Menu.Item,
},
setup() {
const loading = ref(false);
const watermarkContent = ref('Pro Layout');
const router = useRouter();
const { menuData } = getMenuData(clearMenuItem(router.getRoutes()));
const baseState = reactive<Omit<RouteContextProps, 'menuData'>>({
selectedKeys: [],
openKeys: [],
// default
collapsed: false,
});
const state = reactive({
menuData,
splitMenus: false,
// title: 'ProLayout',
// logo: 'https://alicdn.antdv.com/v2/assets/logo.1ef800a8.svg',
navTheme: 'light',
layout: 'side',
fixSiderbar: false,
fixedHeader: true,
});
const breadcrumb = computed(() =>
router.currentRoute.value.matched.concat().map((item) => {
return {
path: item.path,
breadcrumbName: item.meta.title || '',
};
})
);
const baseState = reactive<Omit<RouteContextProps, 'menuData'>>({
selectedKeys: [],
openKeys: [],
// default
collapsed: false,
});
const handleCollapsed = (collapsed?: boolean) => {
console.log('collapsed', collapsed);
baseState.collapsed = collapsed;
const state = reactive({
menuData,
splitMenus: false,
// title: 'ProLayout',
// logo: 'https://alicdn.antdv.com/v2/assets/logo.1ef800a8.svg',
navTheme: 'light',
layout: 'mix',
fixSiderbar: true,
fixedHeader: true,
});
const breadcrumb = computed(() =>
router.currentRoute.value.matched.concat().map((item) => {
return {
path: item.path,
breadcrumbName: item.meta.title || '',
};
watchEffect(() => {
if (router.currentRoute) {
const matched = router.currentRoute.value.matched.concat();
baseState.selectedKeys = matched.filter((r) => r.name !== 'index').map((r) => r.path);
baseState.openKeys = matched.filter((r) => r.path !== router.currentRoute.value.path).map((r) => r.path);
}
});
})
);
function handlePageLoadingClick() {
loading.value = true;
setTimeout(() => {
loading.value = false;
}, 2000);
}
onMounted(() => {
setTimeout(() => {
watermarkContent.value = 'New Mark';
}, 2000);
});
watchEffect(() => {
if (router.currentRoute) {
const matched = router.currentRoute.value.matched.concat();
baseState.selectedKeys = matched.filter((r) => r.name !== 'index').map((r) => r.path);
baseState.openKeys = matched.filter((r) => r.path !== router.currentRoute.value.path).map((r) => r.path);
}
});
return {
i18n,
watermarkContent,
baseState,
state,
loading,
breadcrumb,
const handleCollapsed = (collapsed?: boolean) => {
baseState.collapsed = collapsed;
};
const handlePageLoadingClick = () => {
loading.value = true;
setTimeout(() => {
loading.value = false;
}, 2000);
};
handlePageLoadingClick,
handleCollapsed,
handleSearch: () => {
message.info('search..');
},
};
},
onMounted(() => {
setTimeout(() => {
watermarkContent.value = 'New Mark';
}, 2000);
});
const handleSearch = () => {
message.info('search..');
};
</script>
29 changes: 11 additions & 18 deletions packages/pro-layout/examples/views/MyPage.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<PageContainer :title="$route.meta.title">
<PageContainer fixed-header :title="(route.meta.title as string)">
<template #tags>
<a-tag>tag1</a-tag>
<a-tag color="pink">tag2</a-tag>
<Tag>tag1</Tag>
<Tag color="pink">tag2</Tag>
</template>
<a-result
<Result
status="404"
:style="{
height: '100%',
Expand All @@ -14,24 +14,17 @@
sub-title="Sorry, you are not authorized to access this page."
>
<template #extra>
<a-button type="primary">Back Home</a-button>
<Button type="primary">Back Home</Button>
</template>
</a-result>
</Result>
</PageContainer>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
<script setup lang="ts">
import { Button, Tag, Result } from 'ant-design-vue';
import { PageContainer } from '@ant-design-vue/pro-layout';
export default defineComponent({
components: {
[Button.name]: Button,
[Tag.name]: Tag,
[Result.name]: Result,
},
setup() {
return {};
},
});
import { useRoute } from 'vue-router';
const route = useRoute();
</script>
2 changes: 1 addition & 1 deletion packages/pro-layout/examples/views/TestPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<page-container title="Page 1" sub-title="is a sub-title.">
<page-container fixed-header title="Page 1" sub-title="is a sub-title.">
<template #content>
<div>
container.content
Expand Down
2 changes: 1 addition & 1 deletion packages/pro-layout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ant-design-vue/pro-layout",
"version": "3.2.1",
"version": "3.2.2",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
Expand Down
4 changes: 4 additions & 0 deletions packages/pro-layout/src/BasicLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ const ProLayout = defineComponent({
'disableMobile',
'fixSiderbar',
'fixedHeader',
'headerHeight',
// 'hasSideMenu',
// 'hasHeader',
// 'hasFooter',
Expand All @@ -238,6 +239,7 @@ const ProLayout = defineComponent({
breadcrumb,
flatMenuData,
hasSide,
hasHeader: true,
flatMenu: hasFlatMenu,
});
provide(routeContextInjectKey, routeContext);
Expand Down Expand Up @@ -292,6 +294,8 @@ const ProLayout = defineComponent({
)
);

routeContext.hasHeader = !!headerDom.value;

const contentClassName = computed(() => {
return {
[`${baseClassName.value}-content`]: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/pro-layout/src/components/PageContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const ProPageHeader: FunctionalComponent<PageContainerProps & { prefixedClassNam
extraContent,
prefixedClassName,
prefixCls,
fixedHeader: _,
...restProps
} = props;
const value = useRouteContext();
Expand Down Expand Up @@ -215,7 +216,7 @@ const ProPageHeader: FunctionalComponent<PageContainerProps & { prefixedClassNam
<div class={`${prefixedClassName}-wrap`}>
<PageHeader
{...restProps}
{...value}
// {...value}
title={pageHeaderTitle}
breadcrumb={breadcrumb}
footer={renderFooter({
Expand Down Expand Up @@ -279,7 +280,6 @@ const PageContainer = defineComponent({
return () => {
const { fixedHeader } = props;
const footer = getSlot(slots, props, 'footer');

return (
<div class={classNames.value}>
{fixedHeader && headerDom.value ? (
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

0 comments on commit 6933724

Please sign in to comment.