Commit ad17111d authored by Sendya's avatar Sendya

fix: GlobalFooter props check err

parent 4d1d8485
...@@ -231,6 +231,28 @@ const layoutConf = reactive({ ...@@ -231,6 +231,28 @@ const layoutConf = reactive({
</template> </template>
``` ```
#### Custom footer with slot
```vue
<GlobalFooter>
<template #links>
<a>链接1</a>
<a>链接2</a>
<a>链接3</a>
<a>链接4</a>
</template>
<template #copyright>
<span>Pro Layout &copy; 2021 Sendya.</span>
</template>
</GlobalFooter>
```
#### Custom footer with props
```vue
<GlobalFooter :links="[{ title: 'Link 1', href: '#' }, { title: 'Link 2', href: '#' }]" copyright="Pro Layout &copy; 2021 Sendya." />
```
### Use WaterMark ### Use WaterMark
```vue ```vue
<router-view v-slot="{ Component }"> <router-view v-slot="{ Component }">
......
{ {
"name": "@ant-design-vue/pro-layout", "name": "@ant-design-vue/pro-layout",
"version": "3.1.6", "version": "3.1.7",
"license": "MIT", "license": "MIT",
"files": [ "files": [
"dist" "dist"
......
...@@ -2,6 +2,7 @@ import './index.less'; ...@@ -2,6 +2,7 @@ import './index.less';
import { WithFalse } from '../typings'; import { WithFalse } from '../typings';
import { defineComponent, PropType, SetupContext, VNodeChild } from 'vue'; import { defineComponent, PropType, SetupContext, VNodeChild } from 'vue';
import { getPropsSlot } from '../utils';
export type Links = WithFalse< export type Links = WithFalse<
{ {
...@@ -18,6 +19,25 @@ export interface GlobalFooterProps { ...@@ -18,6 +19,25 @@ export interface GlobalFooterProps {
prefixCls?: string; prefixCls?: string;
} }
const hasLinks = (props: GlobalFooterProps, slots: Record<string, any>) => {
if (
props.links === null ||
props.links === false ||
(Array.isArray(props.links) && props.links.length <= 0) ||
slots.links === undefined
) {
return false;
}
return true;
};
const hasCopyright = (props: GlobalFooterProps, slots: Record<string, any>) => {
if (props.copyright === null || props.copyright === false || slots.copyright === undefined) {
return false;
}
return true;
};
export default defineComponent({ export default defineComponent({
name: 'GlobalFooter', name: 'GlobalFooter',
props: { props: {
...@@ -32,37 +52,38 @@ export default defineComponent({ ...@@ -32,37 +52,38 @@ export default defineComponent({
}, },
}, },
setup(props: GlobalFooterProps, { slots }: SetupContext) { setup(props: GlobalFooterProps, { slots }: SetupContext) {
if ( if (hasLinks(props, slots) && hasCopyright(props, slots)) {
(props.links == null ||
props.links === false ||
(Array.isArray(props.links) && props.links.length === 0)) &&
(props.copyright == null || props.copyright === false)
) {
console.warn('[pro-layout]: GlobalFooter required `links` or `copyright`'); console.warn('[pro-layout]: GlobalFooter required `links` or `copyright`');
return () => null; return () => null;
} }
const baseClassName = `${props.prefixCls}-global-footer`; const baseClassName = `${props.prefixCls}-global-footer`;
const copyright = props.copyright || (slots.copyright && slots.copyright());
return () => ( return () => {
<footer class={baseClassName}> const links = getPropsSlot(slots, props, 'links');
{props.links && ( const copyright = getPropsSlot(slots, props, 'copyright');
<div class={`${baseClassName}-links`}>
{props.links.map(link => ( return (
<a <footer class={baseClassName}>
key={link.key} {links && (
title={link.key} <div class={`${baseClassName}-links`}>
target={link.blankTarget ? '_blank' : '_self'} {(props.links &&
href={link.href} props.links.map(link => (
> <a
{link.title} key={link.key}
</a> title={link.key}
))} target={link.blankTarget ? '_blank' : '_self'}
</div> href={link.href}
)} >
{props.copyright && <div class={`${baseClassName}-copyright`}>{copyright}</div>} {link.title}
</footer> </a>
); ))) ||
links}
</div>
)}
{copyright && <div class={`${baseClassName}-copyright`}>{copyright}</div>}
</footer>
);
};
}, },
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment