mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-08-10 14:58:41 +00:00
74 lines
1.6 KiB
Vue
74 lines
1.6 KiB
Vue
<script lang="ts">
|
|
import { defineComponent, h, PropType, vShow, withDirectives } from 'vue';
|
|
|
|
import { TMagicButton, TMagicTooltip } from '@tmagic/design';
|
|
|
|
import { disabled, formatActionText as formatter } from './actionHelpers';
|
|
import { ColumnActionConfig } from './schema';
|
|
|
|
export default defineComponent({
|
|
name: 'MTableActionButton',
|
|
|
|
props: {
|
|
action: {
|
|
type: Object as PropType<ColumnActionConfig>,
|
|
required: true,
|
|
},
|
|
row: {
|
|
type: null as unknown as PropType<any>,
|
|
required: true,
|
|
},
|
|
index: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
btnClass: {
|
|
type: String,
|
|
default: 'action-btn',
|
|
},
|
|
visible: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
},
|
|
|
|
emits: ['click'],
|
|
|
|
setup(props, { emit }) {
|
|
const onClick = () => emit('click', props.action, props.row, props.index);
|
|
|
|
return () => {
|
|
const button = withDirectives(
|
|
h(
|
|
TMagicButton,
|
|
{
|
|
class: props.btnClass,
|
|
link: true,
|
|
size: 'small',
|
|
type: props.action.buttonType || 'primary',
|
|
icon: props.action.icon,
|
|
disabled: disabled(props.action.disabled, props.row),
|
|
onClick,
|
|
},
|
|
() => h('span', { innerHTML: formatter(props.action.text, props.row) }),
|
|
),
|
|
[[vShow, props.visible]],
|
|
);
|
|
|
|
if (!props.action.tooltip) {
|
|
return button;
|
|
}
|
|
|
|
return h(
|
|
TMagicTooltip,
|
|
{
|
|
placement: props.action.tooltipPlacement || 'top',
|
|
content: props.action.tooltip,
|
|
},
|
|
() => button,
|
|
);
|
|
};
|
|
},
|
|
});
|
|
</script>
|