extraColumns.js 1.09 KB
Newer Older
wuhao's avatar
wuhao committed
1 2
import { doFetch } from './doFetch';

wuhao's avatar
wuhao committed
3 4 5 6 7
const selectValueType = (type, options) => {
  switch (type) {
    case 1:
      return {
        valueType: 'input',
wuhao's avatar
wuhao committed
8
        hideInTable: true,
wuhao's avatar
wuhao committed
9 10 11 12
      };
    case 2:
      return {
        valueType: 'select',
wuhao's avatar
wuhao committed
13
        hideInTable: true,
wuhao's avatar
wuhao committed
14 15 16 17 18
        options,
      };
    case 3:
      return {
        valueType: 'radio',
wuhao's avatar
wuhao committed
19
        hideInTable: true,
wuhao's avatar
wuhao committed
20 21 22 23 24
        options,
      };
    case 4:
      return {
        valueType: 'select',
wuhao's avatar
wuhao committed
25
        hideInTable: true,
wuhao's avatar
wuhao committed
26 27 28 29 30 31 32 33 34 35
        fieldProps: {
          mode: 'multiple',
        },
        options,
      };
    default:
      break;
  }
};

wuhao's avatar
wuhao committed
36
async function extraColumns({ url, params }) {
wuhao's avatar
wuhao committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  let res = await doFetch({ url, params });
  if (res?.data?.dataList) {
    let column = [
      {
        title: '扩展字段',
        valueType: 'split',
      },
      res?.data?.dataList?.map?.((el) => {
        return {
          ...selectValueType(el.fieldChar, el.valueList),
          title: el.fieldName,
          dataIndex: el.id,
          key: el.id,
        };
      }),
    ];
    return column.flat();
  }
wuhao's avatar
wuhao committed
55 56 57
}

export default extraColumns;