Skip to content

Instantly share code, notes, and snippets.

@QQBoxy
Last active October 29, 2018 06:56
Show Gist options
  • Save QQBoxy/8ced12428f509d503a4af8f2d7b1654e to your computer and use it in GitHub Desktop.
Save QQBoxy/8ced12428f509d503a4af8f2d7b1654e to your computer and use it in GitHub Desktop.
/**************************************************
File: File.js
Name: File
Explain: File
****************************************By QQBoxy*/
/*jshint node: true, esversion: 6 */
'use strict';
import React from 'react';
import { Form, Button, Upload, Icon, DatePicker, message } from 'antd';
class File extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
};
this.normFile = this.normFile.bind(this);
this.disabledDate = this.disabledDate.bind(this);
}
normFile(e) {
const status = e.file.status;
if (status === 'done') {
message.success(`${e.file.name} file uploaded successfully.`);
if (e.fileList.length > 1) {
e.fileList.splice(0, e.fileList.length - 1);
message.success("The file has been replaced.");
}
} else if (status === 'error') {
if (e.fileList.length > 1) {
e.fileList.splice(1, e.fileList.length - 1);
}
message.error(`${e.file.name} file upload failed.`);
}
return e && e.fileList;
}
disabledDate(current) {
return current && current.valueOf() < new Date(Date.now() + 6 * 24 * 60 * 60 * 1000);
}
render() {
const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
return (
/* jshint ignore: start*/
<div>
{getFieldDecorator('file', {
valuePropName: 'fileList',
getValueFromEvent: this.normFile,
rules: [{
required: true,
message: "Please Upload Your File"
}]
})(
<Upload
name="file"
action="/api/order/file"
beforeUpload={this.zipBeforeUpload}
accept=".zip"
>
<Button>
<Icon type="upload" />Click To Upload
</Button>
</Upload>
)}
{getFieldDecorator('deadline', {
rules: [{
type: 'object',
required: true,
message: "Please Select Date"
}]
})(
<DatePicker
disabledDate={this.disabledDate}
/>
)}
</div>
/* jshint ignore: end*/
);
}
}
const WrappedFile = Form.create()(File);
module.exports = WrappedFile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment