smart-admin/smart-admin-web/src/lib/table-action.js
2020-01-11 09:10:29 +08:00

85 lines
1.5 KiB
JavaScript

// 处理table操作按钮
const tableAction = (h, array) => {
let btnArray = [];
let btnMore = [];
array.map((item, index) => {
if (index < 2) {
let btn = h(
'a',
{
props: {
type: !index ? 'primary' : 'info',
size: 'small',
to: item.to ? item.to : '',
target: item.target ? item.target : '_self',
ghost: true
},
style: {
marginLeft: '5px'
},
directives: item.directives,
on: {
click: item.action
}
},
item.title
);
btnArray.push(btn);
} else {
btnMore.push(
h(
'DropdownItem',
{
nativeOn: {
click: item.action
}
},
item.title
)
);
}
});
let dropdown = h(
'Dropdown',
{
props: {
transfer: true
}
},
[
h(
'a',
{
props: {
type: 'default',
size: 'small'
},
style: {
marginLeft: '5px'
}
},
[
h('span', '更多'),
h('Icon', {
props: {
type: 'ios-arrow-down'
}
})
]
),
h(
'DropdownMenu',
{
slot: 'list'
},
btnMore
)
]
);
if (array.length > 2) {
btnArray.push(dropdown);
}
return btnArray;
};
export default tableAction;