SplitIndex.js 2.3 KB
Newer Older
1 2 3 4 5 6 7 8
import React, { useEffect, useRef, useState } from 'react';
import { Button } from 'antd';
import ImportUtil from '@/webPublic/one_stop_public/App/ImportUtil';
import ExportCurrentInfo from '@/webPublic/one_stop_public/App/ExportCurrentInfo';
import { Base16Encode } from '@/webPublic/one_stop_public/Base16';

export function FormListButtons(props) {
  const [ConcatButtons, setConCatButtons] = useState([]);
钟是志's avatar
钟是志 committed
9 10 11 12 13 14 15 16 17 18 19
  const {
    btns,
    loading,
    importConfig,
    getPage,
    objId,
    query,
    custom,
    sql,
    exportConfig
  } = props;
20 21 22 23 24 25 26 27 28 29 30 31 32
  const Before = btns && btns.before || [];
  useEffect(() => {
    let buttons = [];
    buttons = Before.map((g) => {
      g.ButtonType = 'Normal';
      return g;
    });
    for (let item of importConfig) {
      buttons.push({
        ...item,
        ButtonType: 'import',
      });
    }
钟是志's avatar
钟是志 committed
33
    let i = 0;
34 35 36 37
    for (let item of exportConfig) {
      buttons.push({
        ...item,
        ButtonType: 'export',
钟是志's avatar
钟是志 committed
38
        index: i++,
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
      });
    }
    buttons.sort((a, b) => {
      let priorityA = a.priority || 0;
      let priorityB = b.priority || 0;
      return priorityA - priorityB;
    });
    setConCatButtons(buttons);
  }, [exportConfig, importConfig, btns]);
  if (!ConcatButtons || !ConcatButtons.length) {
    return null;
  }

  return ConcatButtons.map((r, i) => {
    if (r.ButtonType === 'Normal') {
钟是志's avatar
钟是志 committed
54 55 56 57 58 59
      const propsR = { ...r };
      delete propsR.ButtonType;
      return <Button {...propsR}
                     loading={loading}
                     key={r.children}
      />;
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    } else if (r.ButtonType === 'import') {
      return (<ImportUtil
        btn={r.btn}
        key={r.btn?.name || '导入'}
        ext={r.ext ? r.ext : 'xlsx'}
        importConfig={r}
        objId={objId}
        callback={() => {
          getPage();
          if (r.callback && typeof r.callback === 'function') {
            r.callback();
          }
        }}
      />);
    } else if (r.ButtonType === 'export') {
      return <ExportCurrentInfo
        objId={objId}
        key={r.children || '到处'}
        query={query}
        custom={custom}
钟是志's avatar
钟是志 committed
80
        index={r.index}
81 82
        btn={r.btn}
        ext={r.ext ? r.ext : 'xlsx'}
83
        openSelectFieldsModal={r.openSelectFieldsModal || false}
84 85 86 87 88 89 90 91
        sql={Base16Encode(sql)}
      />;
    }
  });


  // return Before.map((r) => <Button {...r} loading={loading} key={r.children} />);
}