index.vue 1.62 KB
Newer Older
水落(YangLei)'s avatar
水落(YangLei) committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<template>
    <a-table-column :title="title">
        <template #default="row">
            <template v-for="btn of basicBtns">
                <PopconfirmDelete
                    :url="`/api/v1/roles/${row.roleId}`"
                    :cb="refreshTable"
                    :key="btn.label"
                    v-if="btn.type === 'del'"
                />
                <a @click="() => btn?.click(row, btn)" :key="btn.label">{{ btn.label }}</a>
                <a-divider type="vertical" :key="btn.label + 'divider'" />
            </template>
            <template v-if="moreBtns.length">
                <a-popover>
                    <template slot="content">
                        <a v-for="btn of moreBtns" :key="btn.label" @click="() => btn?.click(row, btn)">
                            {{ btn.label }}
                        </a>
                    </template>
                    <a>...</a>
                </a-popover>
            </template>
        </template>
    </a-table-column>
</template>

<script>
export default {
    props: {
        title: {
            type: String,
            default: '操作',
        },
        buttons: {
            type: Array,
            default: () => [
                {
                    label: '查看',
                    onClick(row) {},
                    type: 'del',
                },
            ],
        },
    },
    computed: {
        basicBtns() {
            return this.buttons.length > 3 ? this.buttons.slice(0, 3) : this.buttons;
        },
        moreBtns() {
            return this.buttons.length > 3 ? this.buttons.slice(3) : [];
        },
    },
};
</script>