getPrem.js 1.34 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 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
import { Button, Popconfirm } from "antd";

export default function getPrem(name, type, text, clickfn, pop) {
  let { buttonPerm } = { buttonPerm: [] }; //单独运行

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

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

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

  if (pop) {
    return (
      <Popconfirm
        disabled={!ifs}
        okText="确认"
        cancelText="取消"
        placement="bottomRight"
        title={pop.title}
        onConfirm={() => {
          if (!ifs) {
            return;
          }
          pop.onConfirm();
        }}
      >
        <Button
          size="small"
          type={type?.type || "default"}
          disabled={!ifs}
          danger
          style={{ userSelect: "none" }}
          onClick={() => {
            clickfn ? clickfn() : null;
          }}
        >
          {text}
        </Button>
      </Popconfirm>
    );
  } else {
    return (
      <Button
        size="small"
        type={type?.type || "primary"}
        disabled={!ifs}
        style={{ userSelect: "none" }}
        onClick={() => {
          clickfn ? clickfn() : null;
        }}
      >
        {text}
      </Button>
    );
  }
}