一、需求
二、组件封装
BatchTime.js
import React, {
PureComponent, Fragment } from 'react';
import moment from 'moment';
import {
Form, Row, Col, TimePicker, Icon, Button, message } from 'antd';
import styles from './index.less';
const FormItem = Form.Item;
// 判断时间段是否有重叠
const isAcrossMethod = (startTimeList, endTimeList) => {
const begin = startTimeList.sort();
const over = endTimeList.sort();
for (let i = 1; i < begin.length; i++) {
if (begin[i] <= over[i - 1]) {
return true;
}
}
return false;
};
// 时间段组件
@Form.create()
export default class extends PureComponent {
constructor(props) {
super(props);
this.state = {
};
}
//时间段,变化
onTimePickerChange = (id, key, time) => {
const {
dispatch, timeBar, name, dispatchType } = this.props;
let nextTimeBar = [];
if (key == `time_start_${
id}_${
name}`) {
nextTimeBar = timeBar.map(item => {
return item.id != id
? item
: {
...item,
time_start: time ? moment(time).format('HH:mm') : '',
};
});
} else if (key == `time_end_${
id}_${
name