4.0.3 • Published 1 month ago

dvaweb v4.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

dva web 版

引入即可使用

import { NFile } from "@/models/file";
import { UploadOutlined } from "@ant-design/icons";
import { Button, Form, Upload, message } from "antd";
import { effect } from "dvaweb";
import { memo } from "react";

const fileUpload = memo(() => {
  const beforeUpload = async (file: File) => {
    if (
      file.name.lastIndexOf(".xlsx") == -1 ||
      file.name.lastIndexOf(".xls") == -1
    ) {
      message.error("禁止上传xlsx和xls以外文件");
      return Upload.LIST_IGNORE;
    }
  };

  const customRequest = (options: any) => {
    const { file, onProgress, onSuccess, onError } = options;
    effect(NFile.Name, NFile.EUploadBody, {
      file,
      onProgress,
      onSuccess,
      onError,
    });
  };

  const normFile = (e: any) => {
    if (Array.isArray(e)) {
      return e;
    }
    return e?.fileList;
  };

  return (
    <Form.Item
      label="文件"
      valuePropName="fileList"
      getValueFromEvent={normFile}
      name={"fileUrl"}
      rules={[{ required: true, message: "请上传门店文件" }]}
    >
      <Upload
        accept={"application/*"}
        beforeUpload={beforeUpload}
        maxCount={1}
        customRequest={(options) => {
          customRequest(options);
        }}
      >
        <Button icon={<UploadOutlined />}>点击上传</Button>
      </Upload>
    </Form.Item>
  );
});

export default fileUpload;
4.0.1

1 month ago

4.0.3

1 month ago

4.0.2

1 month ago

3.0.6

2 months ago

3.0.5

2 months ago

4.0.0

2 months ago

3.0.4

2 months ago

3.0.3

3 months ago

3.0.2

4 months ago

3.0.1

8 months ago

3.0.0

10 months ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago