SplitIndex.js 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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([]);
  const { btns, loading, importConfig, getPage, objId, query, custom, sql, exportConfig } = props;
  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
23
    let i = 0 ;
24 25 26 27
    for (let item of exportConfig) {
      buttons.push({
        ...item,
        ButtonType: 'export',
钟是志's avatar
钟是志 committed
28
        index: i++,
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
      });
    }
    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') {
      return <Button {...r} loading={loading} key={r.children} />;
    } 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
65
        index={r.index}
66 67 68 69 70 71 72 73 74 75
        btn={r.btn}
        ext={r.ext ? r.ext : 'xlsx'}
        sql={Base16Encode(sql)}
      />;
    }
  });


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