index.jsx 3.59 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 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 45 46 47 48 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
import React, { memo } from "react";
import { DatePicker, Radio, Input, InputNumber, Select } from "antd";
import moment from "moment";
import Login from "@/pages/user/Login";
const { RangePicker } = DatePicker;
const { Option } = Select;
const RenderItemType = memo(
  (props) => {
    const { value, onChange, type, min, max, radioarr, disabled, selectarr } =
      props;
    if (type == "dateRange") {
      return (
        <RangePicker
          {...props}
          value={value ? moment(value) : undefined}
          onChange={(val) => {
            onChange(val ? moment(val).format("YYYY-MM-DD") : "");
          }}
          format="YYYY-MM-DD"
          style={{ width: "100%" }}
        />
      );
    } else if (type == "month") {
      return (
        <DatePicker
          {...props}
          value={value ? moment(value) : undefined}
          onChange={(val) => {
            onChange(val ? moment(val).format("YYYY-MM") : "");
          }}
          picker="month"
          format="YYYY-MM"
          style={{ width: "100%" }}
        />
      );
    } else if (type == "year") {
      return (
        <DatePicker
          {...props}
          value={value ? moment(value) : undefined}
          onChange={(val) => {
            onChange(val ? moment(val).format("YYYY") : "");
          }}
          picker="year"
          format="YYYY"
          style={{ width: "100%" }}
        />
      );
    } else if (type == "dateHour") {
      return (
        <DatePicker
          {...props}
          value={value ? moment(value) : undefined}
          onChange={(val) => {
            onChange(val ? moment(val).format("YYYY-MM-DD HH") : "");
          }}
          format="YYYY-MM-DD HH"
          showTime={{ format: "HH" }}
          style={{ width: "100%" }}
        />
      );
    } else if (type == "radio") {
      return (
        <Radio.Group
          {...props}
          onChange={(e) => {
            onChange(e.target.value);
          }}
          value={value}
          style={{ width: "100%" }}
        >
          {radioarr.map((el) => {
            return (
              <Radio key={el.value} value={el.value}>
                {el.label}
              </Radio>
            );
          })}
        </Radio.Group>
      );
    } else if (type == "select") {
      return (
        <Select
          {...props}
          onChange={(value) => {
            onChange(value);
          }}
          value={value}
          style={{ width: "100%" }}
          allowClear={true}
        >
          {selectarr.map((el) => {
            return (
              <Option key={el.value} value={el.value}>
                {el.label}
              </Option>
            );
          })}
        </Select>
      );
    } else if (type == "input") {
      return (
        <Input
          {...props}
          value={value}
          onChange={(e) => {
            onChange(e.target.value);
          }}
          style={{ width: "100%" }}
          allowClear={true}
        />
      );
    } else if (type == "inputnumber") {
      return (
        <InputNumber
          {...props}
          value={value}
          onChange={(val) => {
            onChange(val);
          }}
          style={{ width: "100%" }}
          allowClear={true}
          min={min || null}
          max={max || null}
        />
      );
    }
  },
  (prev, next) => {
    if (prev.rowKey && next.rowKey) {
      if (prev.rowKey == next.rowKey) {
        return true;
      } else {
        return false;
      }
    } else {
      if (prev.id == next.id) {
        return true;
      } else {
        return false;
      }
    }
  }
);
export default RenderItemType;