index.vue 1.63 KB
Newer Older
水落(YangLei)'s avatar
水落(YangLei) committed
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    <div>
        <span v-for="(btn, index) of basicBtns" :key="btn.label">
            <PopconfirmDelete
                :url="getDelUrl(btn.url, row)"
                v-if="btn.type === 'del'"
                :cb="btn.after"
                :title="btn.title"
            />
            <a v-else @click="() => btn.click(row)">{{ btn.label }}</a>
            <a-divider type="vertical" v-if="moreBtns.length || index !== basicBtns.length - 1" />
        </span>

        <template v-if="moreBtns.length">
            <a-popover>
                <template slot="content">
                    <a-space direction="vertical">
                        <a v-for="btn of moreBtns" :key="btn.label" @click="() => btn.click(row)">
水落(YangLei)'s avatar
水落(YangLei) committed
19 20
                            {{ btn.label }}
                        </a>
21 22 23 24
                    </a-space>
                </template>
                <a>...</a>
            </a-popover>
水落(YangLei)'s avatar
水落(YangLei) committed
25
        </template>
26
    </div>
水落(YangLei)'s avatar
水落(YangLei) committed
27 28 29
</template>

<script>
30 31 32
import { isFunction } from '@/utils';
import PopconfirmDelete from '@/components/popconfirm_delete/index.vue';

水落(YangLei)'s avatar
水落(YangLei) committed
33
export default {
34 35
    components: { PopconfirmDelete },

水落(YangLei)'s avatar
水落(YangLei) committed
36 37 38
    props: {
        buttons: {
            type: Array,
39
            default: () => [],
水落(YangLei)'s avatar
水落(YangLei) committed
40
        },
41
        row: Object,
水落(YangLei)'s avatar
水落(YangLei) committed
42 43 44 45 46 47 48 49 50
    },
    computed: {
        basicBtns() {
            return this.buttons.length > 3 ? this.buttons.slice(0, 3) : this.buttons;
        },
        moreBtns() {
            return this.buttons.length > 3 ? this.buttons.slice(3) : [];
        },
    },
51 52 53 54 55 56 57

    methods: {
        getDelUrl(url, row) {
            if (isFunction(url)) return url(row);
            return url;
        },
    },
水落(YangLei)'s avatar
水落(YangLei) committed
58 59
};
</script>