ant design项目总结
1.日期选择器
// 默认语言为 en-US,如果你需要设置其他语言,推荐在入口文件全局设置 locale
import moment from ‘moment’;
import ‘moment/locale/zh-cn’;
moment.locale(‘zh-cn’);
<DatePicker defaultValue={moment(‘2015-01-01’, ‘YYYY-MM-DD’)} /
2.获得当前日期:(转化为年度)
getFullYear = () => {
const mayDate = new Date();
const fullYear = moment(mayDate).format(‘YYYY’);
return fullYear;
};
import React, { Component } from ‘react’;
import { Card, Button, Icon, Table, DatePicker } from ‘antd’;
import { connect } from ‘dva’;
import moment from ‘moment’;
import ‘moment/locale/zh-cn’;
// import * as XLSX from ‘xlsx’;
moment.locale(‘zh-cn’);
const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
@connect(({ test }) => ({
test,
dataSource: test.dataSource,
}))
class Test extends Component {
yearPickerChange = value => {
console.log(this.yearPicker);
// 赋值
this.yearPicker.picker.handleChange(value);
// 关闭面板
this.yearPicker.picker.handleOpenChange(false);
const date = moment(value).format(‘YYYY’);
};
render() {
return (
{/* 年度写法总结 */}
export default Test;
文件下载:
const boxElement = document.createElement(‘div’);
boxElement.style.display = ‘none’; // TODO 直接写none
const iframeElement = document.createElement(‘iframe’);
iframeElement.style.display = ‘none’;
iframeElement.name = ‘downloadFrame’;
const formElement = document.createElement(‘form’);
formElement.style.display = ‘none’;
formElement.method = ‘post’;
formElement.action = ${APP_HOST}admin/Util/download
;
formElement.target = ‘downloadFrame’;
const inputElement = document.createElement(‘input’);
const buttonElement = document.createElement(‘button’);
buttonElement.type = ‘submit’;
inputElement.type = ‘hidden’;
inputElement.name = ‘form_key’;
inputElement.value = rowKeys;
formElement.appendChild(inputElement);
formElement.appendChild(buttonElement);
boxElement.appendChild(formElement);
boxElement.insertBefore(iframeElement, formElement);
document.body.appendChild(boxElement);
formElement.submit();
// 下载pdf和之前类似,创建iframe
上传图片
<Upload
name=“file”
// headers={{token:localStorage.getItem(‘token’)}}
headers={{ key: localStorage.getItem(‘currentKey’), module: ‘admin’, use: ‘avatar’ }}
showUploadList={false}
action={${APP_HOST}admin/util/upload
}
beforeUpload={beforeUpload}
onChange={handleChange}