index.jsx 4.53 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable react/jsx-key */
import React, { useMemo } from 'react';
import { Card, Tabs } from 'antd';
import Mtable from './mtable';
import PremButton from '../PremButton'; //权限判断fn
import { ExportOutlined } from '@ant-design/icons';
import { useMatch } from '@umijs/max';

function isString(obj) {
  return obj.constructor === String ? true : false;
}

export default (props) => {
wuhao's avatar
wuhao committed
15 16
  let { childposition } = props;
  childposition = childposition ?? 'left';
wuhao's avatar
wuhao committed
17
  const actionbtn = {
TZW's avatar
TZW committed
18
    add: <PremButton {...props?.addconfig}>{props?.addconfig?.name || '新增'}</PremButton>,
wuhao's avatar
wuhao committed
19 20 21 22 23 24 25 26 27 28 29 30 31
    export: (
      <PremButton
        {...props?.exportconfig}
        btn={{
          ...props.exportconfig,
          icon: <ExportOutlined />,
        }}
      >
        导出
      </PremButton>
    ),
  };

TZW's avatar
TZW committed
32
  //右上角  extra 类型 1.reactDom 2.string 以逗号隔开 为none时不显示
wuhao's avatar
wuhao committed
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
  const renderextra = () => {
    if (props.pageextra && !isString(props.pageextra)) {
      if (typeof props?.pageextra == 'function') {
        return props.pageextra?.();
      } else {
        return props.pageextra;
      }
    } else if (props.pageextra === 'none') {
      return <div style={{ height: 28, width: 64 }} />;
    } else if (props.pageextra) {
      let strarr = props.pageextra ? props.pageextra.split(',') : ['add'];
      return strarr.map((it, i) => {
        return (
          <div key={i} style={{ marginRight: i == strarr.length - 1 ? 0 : 6 }}>
            {actionbtn[it]}
          </div>
        );
      });
    }
  };
  const match = useMatch({ path: '/welcome' });
  const items = useMemo(() => {
    if (props.nocardtab && props.tabList) {
      return props.tabList.map((it) => {
        return {
          label: it.tab,
          key: it.key,
          children: (
            <>
              <div style={{ display: 'flex', width: '100%' }}>
wuhao's avatar
wuhao committed
63 64 65 66 67 68 69 70 71
                {(childposition == 'left' || !childposition) && props.children}
                <div
                  style={{
                    flex: 1,
                    overflow: 'hidden',
                    paddingLeft: `${childposition == 'left' && props.children ? '15px' : '0'}`,
                  }}
                >
                  {childposition == 'top' && props.children}
wuhao's avatar
wuhao committed
72 73
                  <Mtable {...props} activeTabKey={null} />
                </div>
wuhao's avatar
wuhao committed
74
                {(childposition == 'right' || !childposition) && props.children}
wuhao's avatar
wuhao committed
75
              </div>
wuhao's avatar
wuhao committed
76
              {childposition == 'bottom' && props.children}
wuhao's avatar
wuhao committed
77 78 79 80 81 82 83 84 85 86 87
            </>
          ),
        };
      });
    }
  }, [props.tabList]);
  return (
    <div className="diycard">
      {props.withCard === false ? (
        <>
          <div style={{ display: 'flex', width: '100%' }}>
wuhao's avatar
wuhao committed
88
            {(childposition == 'left' || !childposition) && props.children}
wuhao's avatar
wuhao committed
89
            <div style={{ flex: 1, width: '100%' }}>
wuhao's avatar
wuhao committed
90
              {childposition == 'top' && props.children}
wuhao's avatar
wuhao committed
91 92
              <Mtable {...props} />
            </div>
wuhao's avatar
wuhao committed
93
            {(childposition == 'right' || !childposition) && props.children}
wuhao's avatar
wuhao committed
94
          </div>
wuhao's avatar
wuhao committed
95
          {childposition == 'bottom' && props.children}
wuhao's avatar
wuhao committed
96 97 98 99 100 101 102 103 104 105 106 107
        </>
      ) : !props.nocardtab ? (
        <Card
          bordered={props.bordered === false ? false : true}
          style={{ height: '100%' }}
          title={props.pagetitle}
          extra={<div className="center">{renderextra()}</div>}
          activeTabKey={props.activeTabKey}
          tabList={props.tabList}
          onTabChange={props.onTabChange}
        >
          <div style={{ display: 'flex', width: '100%' }}>
wuhao's avatar
wuhao committed
108 109 110 111 112 113 114 115 116
            {(childposition == 'left' || !childposition) && props.children}
            <div
              style={{
                flex: 1,
                overflow: 'hidden',
                paddingLeft: `${childposition == 'left' && props.children ? '15px' : '0'}`,
              }}
            >
              {childposition == 'top' && props.children}
wuhao's avatar
wuhao committed
117 118
              <Mtable {...props} />
            </div>
wuhao's avatar
wuhao committed
119
            {(childposition == 'right' || !childposition) && props.children}
wuhao's avatar
wuhao committed
120
          </div>
wuhao's avatar
wuhao committed
121
          {childposition == 'bottom' && props.children}
wuhao's avatar
wuhao committed
122 123
        </Card>
      ) : (
wuhao's avatar
wuhao committed
124 125 126 127 128 129 130 131
        <div className="tabsTable">
          <div style={{ display: 'flex', justifyContent: 'space-between', padding: '16px 20px 0' }}>
            <div style={{ fontSize: 16, fontWeight: 500 }}>{props.pagetitle}</div>
            <div className="center">{renderextra()}</div>
          </div>
          <Tabs items={items} onChange={props.onTabChange} activeTabKey={props.activeTabKey} />
        </div>
      )}
wuhao's avatar
wuhao committed
132 133 134
    </div>
  );
};