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';
|
2020-06-05 01:04:34 +00:00
|
|
|
import { getComponent } from '../_util/props-util';
|
2019-03-07 05:26:03 +00:00
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2020-03-07 11:45:13 +00:00
|
|
|
import DefaultEmptyImg from './empty';
|
|
|
|
import SimpleEmptyImg from './simple';
|
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,
|
2020-03-07 11:45:13 +00:00
|
|
|
imageStyle: PropTypes.object,
|
2019-03-07 05:26:03 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const Empty = {
|
|
|
|
name: 'AEmpty',
|
|
|
|
props: {
|
|
|
|
...EmptyProps(),
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
renderEmpty(contentLocale) {
|
2020-03-07 11:45:13 +00:00
|
|
|
const { prefixCls: customizePrefixCls, imageStyle } = this.$props;
|
2019-03-08 05:48:55 +00:00
|
|
|
const prefixCls = ConfigConsumerProps.getPrefixCls('empty', customizePrefixCls);
|
2020-06-05 01:04:34 +00:00
|
|
|
const image = getComponent(this, 'image') || <DefaultEmptyImg />;
|
|
|
|
const description = getComponent(this, 'description');
|
2019-03-07 05:26:03 +00:00
|
|
|
|
2020-03-07 11:45:13 +00:00
|
|
|
const des = typeof description !== 'undefined' ? description : contentLocale.description;
|
2019-03-07 05:26:03 +00:00
|
|
|
const alt = typeof des === 'string' ? des : 'empty';
|
2020-03-07 11:45:13 +00:00
|
|
|
const cls = { [prefixCls]: true };
|
2019-03-07 05:26:03 +00:00
|
|
|
let imageNode = null;
|
2020-03-07 11:45:13 +00:00
|
|
|
if (typeof image === 'string') {
|
2019-03-07 05:26:03 +00:00
|
|
|
imageNode = <img alt={alt} src={image} />;
|
2020-03-07 11:45:13 +00:00
|
|
|
} else if (typeof image === 'object' && image.PRESENTED_IMAGE_SIMPLE) {
|
|
|
|
const Image = image;
|
|
|
|
imageNode = <Image />;
|
|
|
|
cls[`${prefixCls}-normal`] = true;
|
2019-03-07 05:26:03 +00:00
|
|
|
} else {
|
|
|
|
imageNode = image;
|
|
|
|
}
|
|
|
|
return (
|
2020-06-05 01:04:34 +00:00
|
|
|
<div class={cls}>
|
2020-03-07 11:45:13 +00:00
|
|
|
<div class={`${prefixCls}-image`} style={imageStyle}>
|
|
|
|
{imageNode}
|
|
|
|
</div>
|
|
|
|
{des && <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
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-03-07 11:45:13 +00:00
|
|
|
Empty.PRESENTED_IMAGE_DEFAULT = DefaultEmptyImg;
|
|
|
|
Empty.PRESENTED_IMAGE_SIMPLE = SimpleEmptyImg;
|
|
|
|
|
2019-03-07 05:26:03 +00:00
|
|
|
/* istanbul ignore next */
|
2020-06-05 01:04:34 +00:00
|
|
|
Empty.install = function(app) {
|
|
|
|
app.component(Empty.name, Empty);
|
2019-03-07 05:26:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Empty;
|