2019-01-12 11:33:27 +08:00
|
|
|
import omit from 'omit.js';
|
|
|
|
import Tabs from '../tabs';
|
|
|
|
import Row from '../row';
|
|
|
|
import Col from '../col';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-01-18 21:34:23 +08:00
|
|
|
import {
|
|
|
|
getComponentFromProp,
|
|
|
|
getSlotOptions,
|
|
|
|
filterEmpty,
|
|
|
|
getListeners,
|
|
|
|
} from '../_util/props-util';
|
2019-01-12 11:33:27 +08:00
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
2019-03-13 21:32:14 +08:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2018-01-20 14:33:42 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const { TabPane } = Tabs;
|
2018-03-19 10:47:23 +08:00
|
|
|
export default {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ACard',
|
2018-03-19 10:47:23 +08:00
|
|
|
mixins: [BaseMixin],
|
|
|
|
props: {
|
2019-03-13 21:32:14 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2018-07-27 15:30:24 +08:00
|
|
|
title: PropTypes.any,
|
2018-03-19 10:47:23 +08:00
|
|
|
extra: PropTypes.any,
|
|
|
|
bordered: PropTypes.bool.def(true),
|
|
|
|
bodyStyle: PropTypes.object,
|
2018-09-05 21:28:54 +08:00
|
|
|
headStyle: PropTypes.object,
|
2018-03-19 10:47:23 +08:00
|
|
|
loading: PropTypes.bool.def(false),
|
|
|
|
hoverable: PropTypes.bool.def(false),
|
|
|
|
type: PropTypes.string,
|
2019-03-13 21:32:14 +08:00
|
|
|
size: PropTypes.oneOf(['default', 'small']),
|
2018-03-19 10:47:23 +08:00
|
|
|
actions: PropTypes.any,
|
|
|
|
tabList: PropTypes.array,
|
2020-03-07 19:45:13 +08:00
|
|
|
tabBarExtraContent: PropTypes.any,
|
2018-04-06 20:56:19 +08:00
|
|
|
activeTabKey: PropTypes.string,
|
|
|
|
defaultActiveTabKey: PropTypes.string,
|
2018-03-19 10:47:23 +08:00
|
|
|
},
|
2019-03-13 21:32:14 +08:00
|
|
|
inject: {
|
2019-09-11 22:35:25 +08:00
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2019-03-13 21:32:14 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
data() {
|
2018-03-19 10:47:23 +08:00
|
|
|
return {
|
|
|
|
widerPadding: false,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-19 10:47:23 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2020-03-07 19:45:13 +08:00
|
|
|
getAction(actions) {
|
|
|
|
const actionList = actions.map((action, index) => (
|
|
|
|
<li style={{ width: `${100 / actions.length}%` }} key={`action-${index}`}>
|
|
|
|
<span>{action}</span>
|
|
|
|
</li>
|
|
|
|
));
|
|
|
|
return actionList;
|
2018-01-20 14:33:42 +08:00
|
|
|
},
|
2020-03-07 19:45:13 +08:00
|
|
|
onTabChange(key) {
|
2019-01-12 11:33:27 +08:00
|
|
|
this.$emit('tabChange', key);
|
2018-03-19 10:47:23 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
isContainGrid(obj = []) {
|
|
|
|
let containGrid;
|
|
|
|
obj.forEach(element => {
|
|
|
|
if (element && getSlotOptions(element).__ANT_CARD_GRID) {
|
|
|
|
containGrid = true;
|
2018-03-19 10:47:23 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
return containGrid;
|
2018-01-20 14:33:42 +08:00
|
|
|
},
|
2018-03-19 10:47:23 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2018-03-19 10:47:23 +08:00
|
|
|
const {
|
2019-03-13 21:32:14 +08:00
|
|
|
prefixCls: customizePrefixCls,
|
2019-01-12 11:33:27 +08:00
|
|
|
headStyle = {},
|
|
|
|
bodyStyle = {},
|
|
|
|
loading,
|
|
|
|
bordered = true,
|
2019-03-13 21:32:14 +08:00
|
|
|
size = 'default',
|
2019-01-12 11:33:27 +08:00
|
|
|
type,
|
|
|
|
tabList,
|
|
|
|
hoverable,
|
|
|
|
activeTabKey,
|
|
|
|
defaultActiveTabKey,
|
|
|
|
} = this.$props;
|
2018-01-20 14:33:42 +08:00
|
|
|
|
2019-09-11 22:35:25 +08:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-13 21:32:14 +08:00
|
|
|
const prefixCls = getPrefixCls('card', customizePrefixCls);
|
|
|
|
|
2020-01-18 21:34:23 +08:00
|
|
|
const { $slots, $scopedSlots } = this;
|
2020-03-07 19:45:13 +08:00
|
|
|
const tabBarExtraContent = getComponentFromProp(this, 'tabBarExtraContent');
|
2018-03-19 10:47:23 +08:00
|
|
|
const classString = {
|
|
|
|
[`${prefixCls}`]: true,
|
|
|
|
[`${prefixCls}-loading`]: loading,
|
|
|
|
[`${prefixCls}-bordered`]: bordered,
|
|
|
|
[`${prefixCls}-hoverable`]: !!hoverable,
|
|
|
|
[`${prefixCls}-contain-grid`]: this.isContainGrid($slots.default),
|
|
|
|
[`${prefixCls}-contain-tabs`]: tabList && tabList.length,
|
2019-03-13 21:32:14 +08:00
|
|
|
[`${prefixCls}-${size}`]: size !== 'default',
|
2018-03-19 10:47:23 +08:00
|
|
|
[`${prefixCls}-type-${type}`]: !!type,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-01-20 14:33:42 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const loadingBlockStyle =
|
|
|
|
bodyStyle.padding === 0 || bodyStyle.padding === '0px' ? { padding: 24 } : undefined;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
2018-03-19 10:47:23 +08:00
|
|
|
const loadingBlock = (
|
2018-09-05 21:28:54 +08:00
|
|
|
<div class={`${prefixCls}-loading-content`} style={loadingBlockStyle}>
|
|
|
|
<Row gutter={8}>
|
|
|
|
<Col span={22}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={8}>
|
|
|
|
<Col span={8}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
<Col span={15}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={8}>
|
|
|
|
<Col span={6}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
<Col span={18}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={8}>
|
|
|
|
<Col span={13}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
<Col span={9}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row gutter={8}>
|
|
|
|
<Col span={4}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
<Col span={3}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
<Col span={16}>
|
|
|
|
<div class={`${prefixCls}-loading-block`} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2018-03-19 10:47:23 +08:00
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-01-20 14:33:42 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const hasActiveTabKey = activeTabKey !== undefined;
|
2018-04-06 20:56:19 +08:00
|
|
|
const tabsProps = {
|
|
|
|
props: {
|
|
|
|
size: 'large',
|
|
|
|
[hasActiveTabKey ? 'activeKey' : 'defaultActiveKey']: hasActiveTabKey
|
|
|
|
? activeTabKey
|
|
|
|
: defaultActiveTabKey,
|
2020-03-07 19:45:13 +08:00
|
|
|
tabBarExtraContent,
|
2018-04-06 20:56:19 +08:00
|
|
|
},
|
|
|
|
on: {
|
2020-03-07 19:45:13 +08:00
|
|
|
change: this.onTabChange,
|
2018-04-06 20:56:19 +08:00
|
|
|
},
|
|
|
|
class: `${prefixCls}-head-tabs`,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-06 20:56:19 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
let head;
|
|
|
|
const tabs =
|
|
|
|
tabList && tabList.length ? (
|
|
|
|
<Tabs {...tabsProps}>
|
|
|
|
{tabList.map(item => {
|
|
|
|
const { tab: temp, scopedSlots = {} } = item;
|
|
|
|
const name = scopedSlots.tab;
|
|
|
|
const tab =
|
|
|
|
temp !== undefined ? temp : $scopedSlots[name] ? $scopedSlots[name](item) : null;
|
|
|
|
return <TabPane tab={tab} key={item.key} disabled={item.disabled} />;
|
|
|
|
})}
|
|
|
|
</Tabs>
|
|
|
|
) : null;
|
|
|
|
const titleDom = getComponentFromProp(this, 'title');
|
|
|
|
const extraDom = getComponentFromProp(this, 'extra');
|
2018-03-19 10:47:23 +08:00
|
|
|
if (titleDom || extraDom || tabs) {
|
|
|
|
head = (
|
2018-09-05 21:28:54 +08:00
|
|
|
<div class={`${prefixCls}-head`} style={headStyle}>
|
2018-03-19 10:47:23 +08:00
|
|
|
<div class={`${prefixCls}-head-wrapper`}>
|
|
|
|
{titleDom && <div class={`${prefixCls}-head-title`}>{titleDom}</div>}
|
|
|
|
{extraDom && <div class={`${prefixCls}-extra`}>{extraDom}</div>}
|
2018-01-20 14:33:42 +08:00
|
|
|
</div>
|
2018-03-19 10:47:23 +08:00
|
|
|
{tabs}
|
2018-01-20 14:33:42 +08:00
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-03-19 10:47:23 +08:00
|
|
|
}
|
2018-03-02 16:54:22 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const children = $slots.default;
|
|
|
|
const cover = getComponentFromProp(this, 'cover');
|
|
|
|
const coverDom = cover ? <div class={`${prefixCls}-cover`}>{cover}</div> : null;
|
2018-03-19 10:47:23 +08:00
|
|
|
const body = (
|
|
|
|
<div class={`${prefixCls}-body`} style={bodyStyle}>
|
|
|
|
{loading ? loadingBlock : children}
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
|
|
|
const actions = filterEmpty(this.$slots.actions);
|
|
|
|
const actionDom =
|
|
|
|
actions && actions.length ? (
|
|
|
|
<ul class={`${prefixCls}-actions`}>{this.getAction(actions)}</ul>
|
|
|
|
) : null;
|
2018-03-19 10:47:23 +08:00
|
|
|
|
|
|
|
return (
|
2019-01-12 11:33:27 +08:00
|
|
|
<div
|
|
|
|
class={classString}
|
|
|
|
ref="cardContainerRef"
|
2020-01-18 21:34:23 +08:00
|
|
|
{...{ on: omit(getListeners(this), ['tabChange', 'tab-change']) }}
|
2019-01-12 11:33:27 +08:00
|
|
|
>
|
2018-03-19 10:47:23 +08:00
|
|
|
{head}
|
|
|
|
{coverDom}
|
|
|
|
{children ? body : null}
|
|
|
|
{actionDom}
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
);
|
2018-03-19 10:47:23 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|