index.jsx 2.12 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4
import React, { useState } from 'react';
import { Button, Popconfirm } from 'antd';

const Deletecheck = props => {
wuhao's avatar
wuhao committed
5
    const { name, type, text, clickfn, pop, btnType } = props;
wuhao's avatar
wuhao committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    //点击删除按钮,若需要调取接口进行校验,需要传btnType,且值为deleteCheck

    const [title, ct] = useState(btnType == "deleteCheck" ? "" : pop?.title),
        [visible, cv] = useState(false);
    let { buttonPerm } = { buttonPerm: [] };//单独运行

    let res = buttonPerm && buttonPerm.length > 0 ? buttonPerm.filter((it) => { return it.typeName == name }) : [];
    if (res.length == 1) {
        res = res[0]
    } else {
        res = {}
    }

    let ifs = name === false ? false : true;

    if (type == "ifs") {
        return ifs
    }


    return pop ? <Popconfirm
        disabled={!ifs}
        okText="确认"
        cancelText="取消"
        placement="bottomRight"
        title={title}
        onConfirm={() => {
            if (!ifs) {
                return
            }
            pop.onConfirm();
            cv(false);
        }}
        visible={visible}
        onCancel={() => {
            cv(false)
        }}
    >
        <Button
            size='small'
            type={type?.type || 'default'}
            disabled={!ifs}
            danger
            style={{ userSelect: "none" }}
            onClick={() => {
                if (btnType == "deleteCheck") {
                    clickfn().then(res => {
                        if (res.code == "0000") {
                            ct(res?.data?.msg)
                            cv(true)
                        }
                    })
                } else {
                    clickfn ? clickfn() : null;
                    cv(true)
                }
            }}
        >
            {text}
        </Button>
    </Popconfirm>
        :
        <Button
            size='small'
            type={type?.type || 'primary'}
            disabled={!ifs}
            style={{ userSelect: "none" }}
            onClick={() => {
                clickfn ? clickfn() : null
            }}
        >
            {text}
        </Button>

}

export default Deletecheck;