index.vue 2.11 KB
Newer Older
水落(YangLei)'s avatar
水落(YangLei) committed
1
<template>
2 3 4 5
    <div>
        <span v-for="(btn, index) of basicBtns" :key="btn.label">
            <PopconfirmDelete
                :url="getDelUrl(btn.url, row)"
6
                v-if="btn.type === 'confirm'"
7 8
                :cb="btn.after"
                :title="btn.title"
9 10
                :onOk="btn.onOk"
                :label="btn.label"
11 12 13 14 15 16 17 18 19
            />
            <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">
20 21 22 23 24 25 26 27 28 29 30
                        <span v-for="btn of moreBtns" :key="btn.label">
                            <PopconfirmDelete
                                :url="getDelUrl(btn.url, row)"
                                v-if="btn.type === 'confirm'"
                                :cb="btn.after"
                                :title="btn.title"
                                :onOk="btn.onOk"
                                :label="btn.label"
                            />
                            <a v-else @click="() => btn.click(row)">{{ btn.label }}</a>
                        </span>
31 32 33 34
                    </a-space>
                </template>
                <a>...</a>
            </a-popover>
水落(YangLei)'s avatar
水落(YangLei) committed
35
        </template>
36
    </div>
水落(YangLei)'s avatar
水落(YangLei) committed
37 38 39
</template>

<script>
40 41 42
import { isFunction } from '@/utils';
import PopconfirmDelete from '@/components/popconfirm_delete/index.vue';

水落(YangLei)'s avatar
水落(YangLei) committed
43
export default {
44 45
    components: { PopconfirmDelete },

水落(YangLei)'s avatar
水落(YangLei) committed
46 47 48
    props: {
        buttons: {
            type: Array,
49
            default: () => [],
水落(YangLei)'s avatar
水落(YangLei) committed
50
        },
51
        row: Object,
水落(YangLei)'s avatar
水落(YangLei) committed
52 53 54 55 56 57 58 59 60
    },
    computed: {
        basicBtns() {
            return this.buttons.length > 3 ? this.buttons.slice(0, 3) : this.buttons;
        },
        moreBtns() {
            return this.buttons.length > 3 ? this.buttons.slice(3) : [];
        },
    },
61 62 63 64 65 66 67

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