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-01-19 08:58:38 +00:00
|
|
|
import { getComponentFromProp, getListeners } 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-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,
|
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-03-07 11:45:13 +00:00
|
|
|
const image = getComponentFromProp(this, 'image') || <DefaultEmptyImg />;
|
2019-03-07 05:26:03 +00:00
|
|
|
const description = getComponentFromProp(this, 'description');
|
|
|
|
|
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-03-07 11:45:13 +00:00
|
|
|
<div class={cls} {...{ on: getListeners(this) }}>
|
|
|
|
<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 */
|
|
|
|
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;
|