index.vue 2.6 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
            <a v-else @click="() => btn.click(row)" v-bind="btn.option">{{ btn.label }}</a>
13 14 15 16 17 18 19
            <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
                        <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"
                            />
29
                            <a v-else @click="() => btn.click(row)" v-bind="btn.option">{{ btn.label }}</a>
30
                        </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
    },
陈浩玮's avatar
陈浩玮 committed
53 54 55 56 57 58 59 60 61 62 63 64
    watch: {
        row() {
            this.init();
        },
    },
    data() {
        return {
            buttonsArr: [],
        };
    },
    created() {
        this.init();
65
        console.log(this.buttonsArr);
陈浩玮's avatar
陈浩玮 committed
66
    },
水落(YangLei)'s avatar
水落(YangLei) committed
67 68
    computed: {
        basicBtns() {
陈浩玮's avatar
陈浩玮 committed
69
            return this.buttonsArr.length > 3 ? this.buttonsArr.slice(0, 3) : this.buttonsArr;
水落(YangLei)'s avatar
水落(YangLei) committed
70 71
        },
        moreBtns() {
陈浩玮's avatar
陈浩玮 committed
72
            return this.buttonsArr.length > 3 ? this.buttonsArr.slice(3) : [];
水落(YangLei)'s avatar
水落(YangLei) committed
73 74
        },
    },
75 76 77 78 79
    methods: {
        getDelUrl(url, row) {
            if (isFunction(url)) return url(row);
            return url;
        },
陈浩玮's avatar
陈浩玮 committed
80
        init() {
81
            this.buttons.map(i => {
陈浩玮's avatar
陈浩玮 committed
82 83
                i.__hidden__ = i.isHidden && i.isHidden(this.row);
            });
84
            this.buttonsArr = this.buttons.filter(i => !i.__hidden__);
陈浩玮's avatar
陈浩玮 committed
85
        },
86
    },
水落(YangLei)'s avatar
水落(YangLei) committed
87 88
};
</script>