index.jsx 4.09 KB
Newer Older
wuhao's avatar
wuhao committed
1
import { Row, Col, Card, Grid, Button } from "antd";
wuhao's avatar
wuhao committed
2 3
import Mcard from "./mcard";
import Mtable from "./mtable";
wuhao's avatar
wuhao committed
4 5 6
import getPrem from "@/utils/getPrem"; //权限判断fn
import { ExportOutlined } from "@ant-design/icons";

wuhao's avatar
wuhao committed
7 8
const { useBreakpoint } = Grid;

wuhao's avatar
wuhao committed
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
function isString(obj) {
  return obj.constructor === String ? true : false;
}

// const tableprops = {
//   ...props,
//   addconfig: {
//       premkey: "sysDepartment_save",
//       disabled:true,
//       btnprops:{},
//       onClick: () => {
//           alert(0)
//       },
//   },
//   exportconfig:{
//       premkey: "sysDepartment_save",
//       btnprops:{
//       },
//       onClick: () => {
//           alert(1)
//       },
//   },
//   pageextra: activeTabKey == "1" ? "add" : "none",
//   tabList: [
//       {
//           tab: "未完成",
//           key: "1"
//       }, {
//           tab: "已完成",
//           key: "2"
//       }
//   ],
//   activeTabKey,
//   onTabChange
// }

wuhao's avatar
wuhao committed
45 46 47
export default (props) => {
  const screens = useBreakpoint();

wuhao's avatar
wuhao committed
48
  const actionbtn = {
wuhao's avatar
wuhao committed
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
    add: (
      <Button
        key={"add"}
        disabled={
          props?.addconfig?.disabled ||
          !getPrem(props?.addconfig?.premkey ?? "", "ifs")
        }
        type="primary"
        {...props?.addconfig?.btnprops}
        onClick={() => {
          props?.addconfig?.onClick?.();
        }}
      >
        新增
      </Button>
    ),
    export: (
      <Button
        key={"add"}
        disabled={
          props?.exportconfig?.disabled ||
          !getPrem(props?.exportconfig?.premkey ?? "", "ifs")
        }
        type="danger"
        icon={<ExportOutlined />}
        {...props?.exportconfig?.btnprops}
        onClick={() => {
          props?.exportconfig?.onClick?.();
        }}
      >
        导出
      </Button>
    ),
  };
wuhao's avatar
wuhao committed
83 84 85 86

  //右上角 pageextra 类型 1.reactDom 2.string 以逗号隔开 为none时不显示
  const renderextra = () => {
    if (props.pageextra && !isString(props.pageextra)) {
wuhao's avatar
wuhao committed
87
      return props.pageextra;
wuhao's avatar
wuhao committed
88
    } else if (props.pageextra === "none") {
wuhao's avatar
wuhao committed
89
      return <div style={{ height: 32, width: 64 }}></div>;
wuhao's avatar
wuhao committed
90
    } else if (props.pageextra) {
wuhao's avatar
wuhao committed
91 92
      let strarr = props.pageextra ? props.pageextra.split(",") : ["add"];
      return strarr.map((it, i) => {
wuhao's avatar
wuhao committed
93 94 95 96 97 98
        return (
          <div style={{ marginRight: i == strarr.length - 1 ? 0 : 6 }}>
            {actionbtn[it]}
          </div>
        );
      });
wuhao's avatar
wuhao committed
99
    }
wuhao's avatar
wuhao committed
100
  };
wuhao's avatar
wuhao committed
101 102 103 104 105 106 107 108 109 110 111
  // screens.xs ? (
  //   <div
  //     style={{ display: "flex", flexDirection: "column", height: "100%" }}
  //   >
  //     {props.children && (
  //       <div style={{ marginBottom: 12 }}>{props.children}</div>
  //     )}
  //     <div>
  //       <Mcard {...props} pageextra={renderextra()}/>
  //     </div>
  //   </div>
wuhao's avatar
wuhao committed
112
  // ) :
wuhao's avatar
wuhao committed
113

wuhao's avatar
wuhao committed
114 115
  return (
    <div className="diycard">
wuhao's avatar
wuhao committed
116
      {props.withCard === false ? (
wuhao's avatar
wuhao committed
117
        <div style={{ display: "flex", width: "100%" }}>
wuhao's avatar
wuhao committed
118
          {(props.childposition == "left" || !props.childposition) &&
wuhao's avatar
wuhao committed
119
            props.children}
wuhao's avatar
wuhao committed
120 121 122 123 124 125 126 127 128 129 130
          <div style={{ flex: 1, width: "100%" }}>
            {props.childposition == "top" && props.children}
            <Mtable {...props} />
          </div>
          {(props.childposition == "right" || !props.childposition) &&
            props.children}
        </div>
      ) : (
        <Card
          bordered={props.bordered === false ? false : true}
          style={{ height: "100%" }}
wuhao's avatar
wuhao committed
131 132
          title={props?.route?.name ? props.route.name : props.pagetitle}
          extra={<div className="center">{renderextra()}</div>}
wuhao's avatar
wuhao committed
133 134 135 136 137
          activeTabKey={props.activeTabKey}
          tabList={props.tabList}
          onTabChange={props.onTabChange}
        >
          <div style={{ display: "flex", width: "100%" }}>
wuhao's avatar
wuhao committed
138 139
            {(props.childposition == "left" || !props.childposition) &&
              props.children}
wuhao's avatar
wuhao committed
140
            <div style={{ flex: 1, overflow:"hidden" }}>
wuhao's avatar
wuhao committed
141 142 143 144 145 146 147 148 149 150 151
              {props.childposition == "top" && props.children}
              <Mtable {...props} />
            </div>
            {(props.childposition == "right" || !props.childposition) &&
              props.children}
          </div>
        </Card>
      )}
    </div>
  );
};