import omit from 'omit.js'; import {defineComponent, getCurrentInstance} from 'vue'; import {filterEmpty, getComponentFromProp, getListenersFromInstance, getSlotOptions} from '../_util/props-util'; import PropTypes from '../_util/vue-types'; import {useConfigProvider} from '../config-provider'; import Col from '../grid/col'; import Row from '../grid/row'; import Tabs from '../tabs'; const {TabPane} = Tabs; export default defineComponent({ name: 'ACard', props: { prefixCls: PropTypes.string, title: PropTypes.any, extra: PropTypes.any, bordered: PropTypes.bool.def(true), bodyStyle: PropTypes.object, headStyle: PropTypes.object, loading: PropTypes.bool.def(false), hoverable: PropTypes.bool.def(false), type: PropTypes.string, size: PropTypes.oneOf(['default', 'small']), actions: PropTypes.any, tabList: PropTypes.array, tabBarExtraContent: PropTypes.any, activeTabKey: PropTypes.string, defaultActiveTabKey: PropTypes.string }, data() { return { widerPadding: false }; }, setup(props, {emit}) { const getAction = (actions) => { const actionList = actions.map((action, index) => (
  • {action}
  • )); return actionList; }; const onTabChange = (key) => { emit('tabChange', key); }; const isContainGrid = (obj = []) => { let containGrid; obj.forEach(element => { if (element && getSlotOptions(element).__ANT_CARD_GRID) { containGrid = true; } }); return containGrid; }; return { getAction, onTabChange, isContainGrid, configProvider: useConfigProvider() }; }, render(ctx) { const instance = getCurrentInstance(); const { prefixCls: customizePrefixCls, headStyle = {}, bodyStyle = {}, loading, bordered = true, size = 'default', type, tabList, hoverable, activeTabKey, defaultActiveTabKey } = ctx.$props; const getPrefixCls = ctx.configProvider.getPrefixCls; const prefixCls = getPrefixCls('card', customizePrefixCls); const tabBarExtraContent = getComponentFromProp(instance, 'tabBarExtraContent'); const classString = { [`${prefixCls}`]: true, [`${prefixCls}-loading`]: loading, [`${prefixCls}-bordered`]: bordered, [`${prefixCls}-hoverable`]: !!hoverable, [`${prefixCls}-contain-grid`]: ctx.isContainGrid(this.$slots.default()), [`${prefixCls}-contain-tabs`]: tabList && tabList.length, [`${prefixCls}-${size}`]: size !== 'default', [`${prefixCls}-type-${type}`]: !!type }; const loadingBlockStyle = bodyStyle.padding === 0 || bodyStyle.padding === '0px' ? {padding: 24} : undefined; const loadingBlock = (
    ); const hasActiveTabKey = activeTabKey !== undefined; const tabsProps = { size: 'large', [hasActiveTabKey ? 'activeKey' : 'defaultActiveKey']: hasActiveTabKey ? activeTabKey : defaultActiveTabKey, tabBarExtraContent, onChange: ctx.onTabChange, class: `${prefixCls}-head-tabs` }; let head; const tabs = tabList && tabList.length ? ( {tabList.map(item => { const {tab: temp, slots = {}} = item; const name = slots.tab; const tab = temp !== undefined ? temp : ctx.$slots[name] ? ctx.$slots[name](item) : null; return ; })} ) : null; const titleDom = getComponentFromProp(instance, 'title'); const extraDom = getComponentFromProp(instance, 'extra'); if (titleDom || extraDom || tabs) { head = (
    {titleDom &&
    {titleDom}
    } {extraDom &&
    {extraDom}
    }
    {tabs}
    ); } const children = ctx.$slots.default(); const cover = getComponentFromProp(instance, 'cover'); const coverDom = cover ?
    {cover}
    : null; const body = (
    {loading ? loadingBlock : children}
    ); const actions = filterEmpty(ctx.$slots.actions); const actionDom = actions && actions.length ? (
      {ctx.getAction(actions)}
    ) : null; return (
    {head} {coverDom} {children ? body : null} {actionDom}
    ); } }) as any;