2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import classNames from 'classnames';
|
2020-01-19 16:58:38 +08:00
|
|
|
import { getOptionProps, getListeners } from '../_util/props-util';
|
2019-04-10 09:08:29 +08:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2018-04-20 12:52:31 +08:00
|
|
|
|
|
|
|
export const BasicProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
hasSider: PropTypes.boolean,
|
2020-03-07 19:45:13 +08:00
|
|
|
tagName: PropTypes.string,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-20 12:52:31 +08:00
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
function generator({ suffixCls, tagName, name }) {
|
2019-01-12 11:33:27 +08:00
|
|
|
return BasicComponent => {
|
2018-04-20 12:52:31 +08:00
|
|
|
return {
|
|
|
|
name,
|
|
|
|
props: BasicComponent.props,
|
2019-04-10 09:08:29 +08:00
|
|
|
inject: {
|
2019-09-11 22:35:25 +08:00
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2019-04-10 09:08:29 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2019-04-10 09:08:29 +08:00
|
|
|
const { prefixCls: customizePrefixCls } = this.$props;
|
2019-09-11 22:35:25 +08:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-04-10 09:08:29 +08:00
|
|
|
const prefixCls = getPrefixCls(suffixCls, customizePrefixCls);
|
|
|
|
|
2018-04-20 12:52:31 +08:00
|
|
|
const basicComponentProps = {
|
|
|
|
props: {
|
|
|
|
prefixCls,
|
|
|
|
...getOptionProps(this),
|
2020-03-07 19:45:13 +08:00
|
|
|
tagName,
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
2020-01-19 16:58:38 +08:00
|
|
|
on: getListeners(this),
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
return <BasicComponent {...basicComponentProps}>{this.$slots.default}</BasicComponent>;
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
};
|
2018-04-20 12:52:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Basic = {
|
|
|
|
props: BasicProps,
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2020-03-07 19:45:13 +08:00
|
|
|
const { prefixCls, tagName: Tag, $slots } = this;
|
2018-04-20 12:52:31 +08:00
|
|
|
const divProps = {
|
|
|
|
class: prefixCls,
|
2020-01-19 16:58:38 +08:00
|
|
|
on: getListeners(this),
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
return <Tag {...divProps}>{$slots.default}</Tag>;
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-20 12:52:31 +08:00
|
|
|
|
|
|
|
const BasicLayout = {
|
|
|
|
props: BasicProps,
|
2019-01-12 11:33:27 +08:00
|
|
|
data() {
|
2018-04-20 12:52:31 +08:00
|
|
|
return {
|
|
|
|
siders: [],
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
provide() {
|
2018-04-20 12:52:31 +08:00
|
|
|
return {
|
|
|
|
siderHook: {
|
2019-01-12 11:33:27 +08:00
|
|
|
addSider: id => {
|
|
|
|
this.siders = [...this.siders, id];
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
removeSider: id => {
|
|
|
|
this.siders = this.siders.filter(currentId => currentId !== id);
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2020-03-07 19:45:13 +08:00
|
|
|
const { prefixCls, $slots, hasSider, tagName: Tag } = this;
|
2018-04-20 12:52:31 +08:00
|
|
|
const divCls = classNames(prefixCls, {
|
2020-03-07 19:45:13 +08:00
|
|
|
[`${prefixCls}-has-sider`]: typeof hasSider === 'boolean' ? hasSider : this.siders.length > 0,
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-04-20 12:52:31 +08:00
|
|
|
const divProps = {
|
|
|
|
class: divCls,
|
2020-01-19 16:58:38 +08:00
|
|
|
on: getListeners,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
return <Tag {...divProps}>{$slots.default}</Tag>;
|
2018-04-20 12:52:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-20 12:52:31 +08:00
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
const Layout = generator({
|
|
|
|
suffixCls: 'layout',
|
|
|
|
tagName: 'section',
|
|
|
|
name: 'ALayout',
|
|
|
|
})(BasicLayout);
|
2018-04-20 12:52:31 +08:00
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
const Header = generator({
|
|
|
|
suffixCls: 'layout-header',
|
|
|
|
tagName: 'header',
|
|
|
|
name: 'ALayoutHeader',
|
|
|
|
})(Basic);
|
2018-04-20 12:52:31 +08:00
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
const Footer = generator({
|
|
|
|
suffixCls: 'layout-footer',
|
|
|
|
tagName: 'footer',
|
|
|
|
name: 'ALayoutFooter',
|
|
|
|
})(Basic);
|
2018-04-20 12:52:31 +08:00
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
const Content = generator({
|
|
|
|
suffixCls: 'layout-content',
|
|
|
|
tagName: 'main',
|
|
|
|
name: 'ALayoutContent',
|
|
|
|
})(Basic);
|
2018-04-20 12:52:31 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
Layout.Header = Header;
|
|
|
|
Layout.Footer = Footer;
|
|
|
|
Layout.Content = Content;
|
2018-04-20 12:52:31 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default Layout;
|