index.vue 1.68 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') {
水落(YangLei)'s avatar
水落(YangLei) committed
34 35 36 37 38
                try {
                    await delReq(this.url);
                } catch (error) {
                    return;
                }
39
            }
陈浩玮's avatar
陈浩玮 committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
            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;
                }
            }
56 57 58
            if (this.onOk) {
                await this.onOk();
            }
59
            this?.cb();
水落(YangLei)'s avatar
水落(YangLei) committed
60 61
        },
    },
62 63
};
</script>