2019-03-07 05:26:03 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2019-03-08 05:48:55 +00:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2019-03-07 05:26:03 +00:00
|
|
|
import { getComponentFromProp } from '../_util/props-util';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
|
|
import emptyImg from './empty.svg';
|
2019-09-10 10:57:08 +00:00
|
|
|
import Base from '../base';
|
2019-03-07 05:26:03 +00:00
|
|
|
|
|
|
|
export const TransferLocale = () => {
|
|
|
|
return {
|
|
|
|
description: PropTypes.string,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const EmptyProps = () => {
|
|
|
|
return {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
image: PropTypes.any,
|
|
|
|
description: PropTypes.any,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const Empty = {
|
|
|
|
name: 'AEmpty',
|
|
|
|
props: {
|
|
|
|
...EmptyProps(),
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
renderEmpty(contentLocale) {
|
2019-05-28 03:37:38 +00:00
|
|
|
const { prefixCls: customizePrefixCls, ...restProps } = this.$props;
|
2019-03-08 05:48:55 +00:00
|
|
|
const prefixCls = ConfigConsumerProps.getPrefixCls('empty', customizePrefixCls);
|
2019-03-07 05:26:03 +00:00
|
|
|
const image = getComponentFromProp(this, 'image');
|
|
|
|
const description = getComponentFromProp(this, 'description');
|
|
|
|
|
|
|
|
const des = description || contentLocale.description;
|
|
|
|
const alt = typeof des === 'string' ? des : 'empty';
|
|
|
|
|
|
|
|
let imageNode = null;
|
|
|
|
if (!image) {
|
|
|
|
imageNode = <img alt={alt} src={emptyImg} />;
|
|
|
|
} else if (typeof image === 'string') {
|
|
|
|
imageNode = <img alt={alt} src={image} />;
|
|
|
|
} else {
|
|
|
|
imageNode = image;
|
|
|
|
}
|
|
|
|
return (
|
2019-09-10 10:57:08 +00:00
|
|
|
<div class={prefixCls} {...{ on: this.$listeners }}>
|
2019-03-07 05:26:03 +00:00
|
|
|
<div class={`${prefixCls}-image`}>{imageNode}</div>
|
|
|
|
<p class={`${prefixCls}-description`}>{des}</p>
|
2019-03-08 05:48:55 +00:00
|
|
|
{this.$slots.default && <div class={`${prefixCls}-footer`}>{this.$slots.default}</div>}
|
2019-03-07 05:26:03 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render() {
|
2019-05-28 03:37:38 +00:00
|
|
|
return <LocaleReceiver componentName="Empty" scopedSlots={{ default: this.renderEmpty }} />;
|
2019-03-07 05:26:03 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* istanbul ignore next */
|
|
|
|
Empty.install = function(Vue) {
|
2019-09-10 10:57:08 +00:00
|
|
|
Vue.use(Base);
|
2019-03-07 05:26:03 +00:00
|
|
|
Vue.component(Empty.name, Empty);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Empty;
|