vue-ant-patterns
Version:
vue-ant-patterns
313 lines (288 loc) • 11.1 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _vueTypes = require('ant-design-vue/lib/_util/vue-types');
var _vueTypes2 = _interopRequireDefault(_vueTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _antDesignVue = require('ant-design-vue');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var TabPane = _antDesignVue.Tabs.TabPane;
var DCard = {
name: 'DCard',
props: {
prefixCls: _vueTypes2['default'].string.def('depot-dcard'),
title: _vueTypes2['default'].any, // 卡片标题
backTitle: _vueTypes2['default'].string.def(''), // 卡片背面标题
bodyStyle: _vueTypes2['default'].object.def({
padding: '8px 16px 16px'
}), // 卡片内容样式
headStyle: _vueTypes2['default'].object.def({
borderBottom: 0,
padding: '16px 16px 0'
}), // 卡片标题样式
height: _vueTypes2['default'].string.def(''), // 卡片的高度
shadow: _vueTypes2['default'].bool.def(false), // 是否有阴影
borderRadius: _vueTypes2['default'].bool.def(true), // 有圆角
empty: _vueTypes2['default'].bool.def(false), // 空卡片
size: _vueTypes2['default'].string.def('default'),
hoverable: _vueTypes2['default'].bool.def(true), // 鼠标移过时可浮起
bordered: _vueTypes2['default'].bool.def(false), // 是否有边框
loading: _vueTypes2['default'].bool.def(false), // 显示预加载
rollingOver: _vueTypes2['default'].bool.def(false), // 翻转
tabList: _vueTypes2['default'].array, // 页签标题列表
activeTabKey: _vueTypes2['default'].string, // 当前激活页签的 key
defaultActiveTabKey: _vueTypes2['default'].string // 初始化选中页签的 key,如果没有设置 activeTabKey
},
data: function data() {
return {
sVisible: false, // 鼠标滑过显示
showBackCard: false // 是否显示卡片背面
};
},
methods: {
handleMouseOver: function handleMouseOver(e) {
this.sVisible = true;
},
handleMouseOut: function handleMouseOut(e) {
this.sVisible = false;
},
// 翻转卡片
showBackCardFun: function showBackCardFun(e) {
this.showBackCard = !this.showBackCard;
},
onHandleTabChange: function onHandleTabChange(key) {
this.$emit('tabChange', key);
}
},
render: function render() {
var _cx,
_props2,
_this = this,
_cx2,
_cx3,
_class;
var h = arguments[0];
var prefixCls = this.prefixCls,
$slots = this.$slots,
$scopedSlots = this.$scopedSlots,
$listeners = this.$listeners,
title = this.title,
backTitle = this.backTitle,
bodyStyle = this.bodyStyle,
headStyle = this.headStyle,
hoverable = this.hoverable,
bordered = this.bordered,
loading = this.loading,
shadow = this.shadow,
borderRadius = this.borderRadius,
empty = this.empty,
size = this.size,
height = this.height,
rollingOver = this.rollingOver,
tabList = this.tabList,
activeTabKey = this.activeTabKey,
defaultActiveTabKey = this.defaultActiveTabKey;
var content = $slots.content,
description = $slots.description,
extra = $slots.extra,
cover = $slots.cover,
actions = $slots.actions;
var children = $slots['default'];
// tab卡片
var hasActiveTabKey = activeTabKey !== undefined;
var tabsProps = {
props: (0, _defineProperty3['default'])({
size: 'large'
}, hasActiveTabKey ? 'activeKey' : 'defaultActiveKey', hasActiveTabKey ? activeTabKey : defaultActiveTabKey),
on: {
change: this.onHandleTabChange
},
'class': prefixCls + '-head-tabs'
};
var tabs = tabList && tabList.length ? h(
_antDesignVue.Tabs,
tabsProps,
[tabList.map(function (item) {
var temp = item.tab,
_item$scopedSlots = item.scopedSlots,
scopedSlots = _item$scopedSlots === undefined ? {} : _item$scopedSlots;
var name = scopedSlots.tab;
var tab = temp !== undefined ? temp : $scopedSlots[name] ? $scopedSlots[name](item) : null;
return h(TabPane, {
attrs: { tab: tab, disabled: item.disabled },
key: item.key });
})]
) : null;
var head = {
padding: '0 16px 0',
borderBottom: tabList && tabList.length > 0 ? '1px solid #e8e8e8' : 0
};
var newHeadStyle = size === 'small' ? (0, _extends3['default'])({}, headStyle, head) : (0, _extends3['default'])({}, headStyle); // 小卡片标题样式
var cardSizeClass = size === 'default' || actions !== undefined ? prefixCls + '-default' : size === 'small' ? prefixCls + '-small' : prefixCls + '-large';
// 正面卡片
var wrapProps = {
'class': (0, _classnames2['default'])((_cx = {}, (0, _defineProperty3['default'])(_cx, prefixCls + '-inner', 1), (0, _defineProperty3['default'])(_cx, prefixCls + '-empty', empty), (0, _defineProperty3['default'])(_cx, prefixCls + '-shadow', shadow), (0, _defineProperty3['default'])(_cx, prefixCls + '-borderRadius', borderRadius), (0, _defineProperty3['default'])(_cx, prefixCls + '-front', true), (0, _defineProperty3['default'])(_cx, prefixCls + '-loading', loading), (0, _defineProperty3['default'])(_cx, cardSizeClass, 1), (0, _defineProperty3['default'])(_cx, prefixCls + '-tabs-wrapper', tabList && tabList.length > 0), _cx)),
style: {
height: height
},
props: (_props2 = {
// ...newPropts,
bodyStyle: bodyStyle,
headStyle: newHeadStyle,
bordered: bordered,
title: !loading ? title : null,
hoverable: hoverable
}, (0, _defineProperty3['default'])(_props2, 'bordered', bordered), (0, _defineProperty3['default'])(_props2, 'size', size !== 'large' ? size : 'default'), (0, _defineProperty3['default'])(_props2, 'activeTabKey', activeTabKey), (0, _defineProperty3['default'])(_props2, 'defaultActiveTabKey', defaultActiveTabKey), _props2),
on: (0, _extends3['default'])({}, $listeners, {
mouseenter: function mouseenter(e) {
_this.handleMouseOver(e);
},
mouseleave: function mouseleave(e) {
_this.handleMouseOut(e);
}
})
};
// 背面卡片
var wrapPropsBack = {
'class': (0, _classnames2['default'])((_cx2 = {}, (0, _defineProperty3['default'])(_cx2, prefixCls + '-inner', 1), (0, _defineProperty3['default'])(_cx2, prefixCls + '-empty', empty), (0, _defineProperty3['default'])(_cx2, prefixCls + '-shadow', shadow), (0, _defineProperty3['default'])(_cx2, prefixCls + '-borderRadius', borderRadius), (0, _defineProperty3['default'])(_cx2, prefixCls + '-back', true), (0, _defineProperty3['default'])(_cx2, cardSizeClass, 1), _cx2)),
style: {
height: height
},
props: {
bodyStyle: bodyStyle,
headStyle: newHeadStyle,
bordered: bordered,
hoverable: hoverable,
size: size !== 'large' ? size : 'default',
title: backTitle
},
on: (0, _extends3['default'])({}, $listeners, {
mouseenter: function mouseenter(e) {
_this.handleMouseOver(e);
},
mouseleave: function mouseleave(e) {
_this.handleMouseOut(e);
}
})
};
// 内容
var mainProps = {
'class': prefixCls + '-content'
};
// 描述
var descriptionProps = {
'class': prefixCls + '-description'
};
// 右下角操作翻转卡片区域
var rollingOverProps = {
'class': (0, _classnames2['default'])((_cx3 = {}, (0, _defineProperty3['default'])(_cx3, 'right-bottom-operation', true), (0, _defineProperty3['default'])(_cx3, 'rightBottom-show', this.sVisible), _cx3)),
on: {
click: function click(e) {
_this.showBackCardFun(e);
}
}
};
var outerWrapper = {
'class': (_class = {}, (0, _defineProperty3['default'])(_class, prefixCls + '-container', true), (0, _defineProperty3['default'])(_class, prefixCls + '-showBackCard', this.showBackCard), _class)
};
var innerWrapper = {
'class': (0, _defineProperty3['default'])({}, prefixCls + '-container-inner', true)
};
var otherWrapper = {
'class': (0, _defineProperty3['default'])({}, prefixCls + '-container-other', true)
};
var loadingHeaderBlock = h(
'div',
{ 'class': prefixCls + '-loading-header' },
[h(
'a-row',
{
attrs: { gutter: 8 }
},
[h(
'a-col',
{
attrs: { span: 12 }
},
[h('div', { 'class': 'depot-dcard-loading-block' })]
), h(
'a-col',
{
attrs: { span: 3 },
style: 'float:right;' },
[h('div', { 'class': 'depot-dcard-loading-block' })]
)]
)]
);
var loadingBlock = h('div', { 'class': 'depot-dcard-loading-block' });
var loadingCover = h('div', { 'class': 'depot-dcard-loading-block', style: 'height: 140px' });
return h(
'div',
outerWrapper,
[h(
'div',
innerWrapper,
[h(
_antDesignVue.Card,
wrapProps,
[cover ? null : $slots.title || tabs ? h(
'template',
{ slot: 'title' },
[$slots.title || tabs]
) : null, cover ? null : h(
'template',
{ slot: 'extra' },
[!loading ? extra : loadingHeaderBlock]
), cover ? !loading ? h(
'template',
{ slot: 'cover' },
[h(
'div',
{ 'class': 'cover-box' },
[cover]
)]
) : loadingCover : null, description ? h(
'div',
descriptionProps,
[!loading ? description : loadingBlock]
) : null, h(
'div',
mainProps,
[content ? !loading ? content : loadingBlock : null]
), children ? h(
'div',
otherWrapper,
[children]
) : null, h(
'template',
{ slot: 'actions' },
[actions]
), rollingOver ? h('div', rollingOverProps) : null]
), rollingOver ? h(
_antDesignVue.Card,
wrapPropsBack,
[h(
'template',
{ slot: 'extra' },
[extra]
), h(
'div',
mainProps,
[$slots.backContent]
), rollingOver ? h('div', rollingOverProps) : null]
) : null]
)]
);
}
};
// DCard.install = (Vue) => {
// Vue.component(DCard.name, DCard);
// Vue.component(Person.name, Person);
// };
exports['default'] = DCard;