index.vue 1.58 KB
Newer Older
1
<template>
2 3
    <a-popconfirm :title="title" ok-text="确认" cancel-text="取消" @confirm="confirm">
        <a>{{ label }}</a>
4 5 6 7 8
    </a-popconfirm>
</template>

<script>
import { EMPTY_FUN } from '@/utils';
陈浩玮's avatar
陈浩玮 committed
9
import { delReq, getReq, postReq, putReq } from '@/utils';
10 11 12

export default {
    props: {
陈浩玮's avatar
陈浩玮 committed
13
        url: [String, Object],
水落(YangLei)'s avatar
水落(YangLei) committed
14
        cb: {
15 16 17
            type: Function,
            default: EMPTY_FUN,
        },
18 19 20 21
        title: {
            type: String,
            default: '确认是否删除',
        },
22 23 24 25 26 27 28 29
        onOk: {
            type: Function,
            default: EMPTY_FUN,
        },
        label: {
            type: String,
            default: '删除',
        },
30
    },
水落(YangLei)'s avatar
水落(YangLei) committed
31
    methods: {
32
        async confirm() {
陈浩玮's avatar
陈浩玮 committed
33
            if (typeof this.url === 'string') {
34 35
                await delReq(this.url);
            }
陈浩玮's avatar
陈浩玮 committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
            if (typeof this.url === 'object') {
                switch (this.url.method) {
                    case 'get':
                        await getReq(this.url.url, this.url?.data);
                        break;
                    case 'post':
                        await postReq(this.url.url, this.url?.data);
                        break;
                    case 'put':
                        await putReq(this.url.url, this.url?.data);
                        break;
                    case 'del':
                        await delReq(this.url.url, this.url?.data);
                        break;
                }
            }
52 53 54
            if (this.onOk) {
                await this.onOk();
            }
55
            this?.cb();
水落(YangLei)'s avatar
水落(YangLei) committed
56 57
        },
    },
58 59
};
</script>