antD 结束时间不能小于开始时间

import React from ‘react‘
import { Layout, Row, Button, Table, DatePicker, Form, Col, Input, message, Modal } from ‘antd‘
import ModalCon from ‘./addEdit‘
import ReactEcharts from ‘echarts-for-react‘
import ‘../riverWater.less‘
import { queryByPage } from ‘@api/RiverWater/reportProtect‘

const { Header, Content, Footer } = Layout
const FormItem = Form.Item

export interface IProps {

}

interface IState {
    columns?: any
    loading?: boolean
    tableData?: any
    pagination?: any
    height: number
    stcd?: any
    stnm?: any

    treeData?: any
    selectedRowKeys?: any
    selectedRows?: any
    type: string
    isShow: boolean
    startTime: any
    endTime: any
    echartsOption?: any
}

export default class StationInfo extends React.Component<IProps, IState> {

    constructor(props: IProps) {
        super(props)
        this.state = {
            isShow: false,
            loading: false,
            tableData: [],
            height: 400,
            startTime: ‘‘,
            endTime: ‘‘,
            pagination: {
                showSizeChanger: true,
                showQuickJumper: true,
                current: 1,
                pageSize: 15,
                total: 0,
                showTotal: (total: any) => `共${total} 条`,
                pageSizeOptions: [‘15‘, ‘30‘, ‘45‘]
            },
            stcd: ‘‘,
            stnm: ‘‘,

            treeData: [],
            selectedRowKeys: [],
            selectedRows: [],
            type: ‘‘,
            echartsOption: {},
            columns: [
                {
                    title: ‘测站编码‘,
                    dataIndex: ‘stcd‘,
                    width: ‘6%‘,
                    align: ‘center‘
                },
                {
                    title: ‘测站名称‘,
                    dataIndex: ‘stnm‘,
                    width: ‘10%‘,
                    align: ‘center‘
                },
                {
                    title: ‘时间‘,
                    dataIndex: ‘time‘,
                    width: ‘12%‘,
                    align: ‘center‘
                },
                {
                    title: ‘水位‘,
                    dataIndex: ‘waterL‘,
                    width: ‘5%‘,
                    align: ‘right‘
                },
                {
                    title: ‘水量(m³)‘,
                    dataIndex: ‘waterV‘,
                    width: ‘7%‘,
                    align: ‘right‘
                },
                {
                    title: ‘断面过水面积(m²)‘,
                    dataIndex: ‘dmws‘,
                    width: ‘8%‘,
                    align: ‘right‘
                },
                {
                    title: ‘断面平均流速(m/s)‘,
                    dataIndex: ‘dmavgfr‘,
                    width: ‘8%‘,
                    align: ‘right‘
                },
                {
                    title: ‘断面最大流速(m/s)‘,
                    dataIndex: ‘dmmaxfr‘,
                    width: ‘10%‘,
                    align: ‘right‘
                },
                {
                    title: ‘河水特征码‘,
                    dataIndex: ‘bsnm‘,
                    width: ‘8%‘,
                    align: ‘center‘
                },
                {
                    title: ‘水势‘,
                    dataIndex: ‘waters‘,
                    align: ‘center‘
                },
                {
                    title: ‘测流方法‘,
                    dataIndex: ‘clmonthod‘,
                    width: ‘6%‘,
                    align: ‘center‘
                },
                {
                    title: ‘测积方法‘,
                    dataIndex: ‘cjff‘,
                    width: ‘6%‘,
                    align: ‘center‘
                },
                {
                    title: ‘测速方法‘,
                    dataIndex: ‘csmonthod‘,
                    width: ‘6%‘,
                    align: ‘center‘
                }
            ]
        }
    }

    handleClick = (row: object) => {
        this.setState({
            isShow: true,
            type: ‘detail‘,
            selectedRows: [row]
        })
    }

    initEcharts = () => {
        // 绘制图表
        const option = {
            title: {
                text: ‘河道水情来报维护折线图‘,
                x: ‘center‘,
                y: ‘top‘,
                textAlign: ‘left‘,
                top: 10,
                left: ‘left‘
            },
            tooltip: {
                trigger: ‘axis‘
            },
            // legend: {
            //     data: [‘齐齐哈勒克‘, ‘坝上‘, ‘出库‘, ‘且末‘]
            // },
            calculable: true,
            xAxis: [
                {
                    type: ‘category‘,
                    boundaryGap: false,
                    data: [‘齐齐哈勒克‘, ‘坝上‘, ‘出库‘, ‘且末‘]
                }
            ],
            yAxis: [
                {
                    name: ‘水位(m)‘,
                    nameLocation: ‘middle‘,
                    nameRotate: 90,
                    nameGap: 40,
                    nameTextStyle: {
                        fontSize: 13
                    }
                }
            ],
            series: [
                {
                    name: ‘水位‘,
                    type: ‘line‘,
                    data: [89.2, 78.2, 56.1, 47.6]
                }
            ]
        }
        return option
    }
    componentDidMount = () => {
        const contentHeight = document.getElementById(‘js-page-content‘)!.offsetHeight
        this.setState({
            height: contentHeight - 450,
            echartsOption: this.initEcharts()
        })
        this.getTableData(‘‘)
    }
    getTableData = (stcd) => {
        const { pagination } = this.state
        const param = {
            stcd,
            page: 1,
            rows: pagination.pageSize
        }
        queryByPage(param).then((res: any) => {
            console.log(res)
        })
        // this.setState({
        //     loading: true
        // })
        // fetch(‘./RiverWater/reportProtect.json‘).then(res => res.json()).then(json => {
        //     const { pagination } = this.state
        //     this.setState({
        //         tableData: json.data.records,
        //         loading: false,
        //         pagination: {
        //             showSizeChanger: true,
        //             showQuickJumper: true,
        //             current: pagination.current,
        //             pageSize: pagination.pageSize,
        //             total: json.data.total,
        //             showTotal: (total: any) => `共${total} 条`
        //         }
        //     })
        // })
    }

    handleReset = (e) => {
        e.preventDefault()
        this.setState({
            stcd: ‘‘,

        })
    }

    handleTableChange = (pagination) => {
        this.setState({ pagination }, () => {
            this.getTableData(‘‘)
        })
    }

    getQueryStnm = (e) => {
        e.preventDefault()
        if (e.target.value.length > 8) {
            message.warn(‘请输入8位测站编码‘)
            const text = e.target.value.slice(0, 8)
            this.setState({
                stcd: text
              })
        } else {
            this.setState({
                stcd: e.target.value
              })
        }
    }

    onSelectChange = (selectedRowKeys, selectedRows) => {
        this.setState({
            selectedRowKeys,
            selectedRows
        })
    }

    setFn = () => {
        this.setState({
            isShow: false,
            loading: true
        })
        this.getTableData(‘‘)
    }

    addBtn = () => {
        this.setState({
            isShow: true,
            type: ‘add‘
        })
    }

    editBtn = () => {
        if (this.state.selectedRowKeys.length === 1) {
            this.setState({
                isShow: true,
                type: ‘edit‘
            })
        } else {
            message.error(‘请选择一条数据进行编辑‘)
        }
    }

    delBtn = (e) => {
        e.preventDefault()
        const self = this
        const confirm = Modal.confirm
        const { selectedRowKeys } = this.state
        if (selectedRowKeys.length > 0) {
            let ids = ‘‘
            selectedRowKeys.forEach((item, index) => {
                ids = ids + item
                if (index < selectedRowKeys.length - 1) {
                    ids = ids + ‘,‘
                }
            })
            confirm({
                title: ‘提示‘,
                content: ‘确认要删除?‘,
                okText: ‘确认‘,
                cancelText: ‘取消‘,
                onOk() {
                    self.delBtnFn(ids)
                }
            })
        } else {
            message.warn(‘请选择一条数据‘)
        }
    }

    delBtnFn = (ids) => {
        console.log(ids)
        message.success(‘删除成功‘, 3)
        this.getTableData(‘‘)
        this.setState({
            selectedRowKeys: []
        })
    }
    onChangeStartTime = (value, dateString) => {
        const param = { value, dateString }
        this.setState({
            startTime: param.dateString
        })
    }
    onChangeEndTime = (value, dateString) => {
        const param = { value, dateString }
        this.setState({
            endTime: param.dateString
        })
    }
     // 设置开始日期不能选择的时间
    disabledStartDate = current => {
        if (this.state.endTime) {
            return current > Date.now() || current > new Date(this.state.endTime).getTime()
        } else {
            return current > Date.now()
        }
     }

    // 设置结束不能选择的时间
     disabledEndDate = current => {
        return current < new Date(this.state.startTime).getTime()  || current > Date.now()
      }
    render() {
        const { columns, pagination, loading, tableData, selectedRowKeys } = this.state
        const rowSelection = {
            loading: true,
            selectedRowKeys,
            onChange: this.onSelectChange
        }
        return (
            <Layout className=‘bodyClass‘>
                <Form layout=‘inline‘ className=‘queryForm‘>
                    <Row>
                        <Col sm={24} md={6} >
                            <FormItem label=‘测站编码‘>
                                <Input placeholder=‘测站编码‘ id=‘stnm‘ value={this.state.stcd} onChange={this.getQueryStnm} />
                            </FormItem>
                        </Col>
                        <Col sm={24} md={6} >
                            <FormItem label=‘开始时间‘ style={{ width: ‘100%‘ }}>
                               <DatePicker showTime placeholder=‘请选择开始时间‘ disabledDate={this.disabledStartDate} onChange={this.onChangeStartTime}  />
                                {/* <RangePicker style={{ width: ‘100%‘ }} format=‘YYYY-MM-DD‘ /> */}
                            </FormItem>
                        </Col>
                        <Col sm={24} md={6} >
                            <FormItem label=‘结束时间‘ style={{ width: ‘100%‘ }}>
                               <DatePicker showTime placeholder=‘请选择结束时间‘  disabledDate={this.disabledEndDate} onChange={this.onChangeEndTime}  />
                            </FormItem>
                        </Col>
                        <Col sm={24} md={6} className=‘user_btn‘ >
                            <Button className=‘searchBtn‘ icon=‘search‘ onClick={this.getTableData}>查询</Button>
                            <Button className=‘resetBtn‘ icon=‘reload‘ onClick={this.handleReset}>重置</Button>
                        </Col>
                    </Row>
                    {/* <Row>
                        <Col sm={24} md={6} >
                            <FormItem label=‘选择时间‘ style={{ width: ‘100%‘ }}>
                                <RangePicker style={{ width: ‘100%‘ }} format=‘YYYY-MM-DD‘ />
                            </FormItem>
                        </Col>
                    </Row> */}
                </Form>
                <Content className=‘contentLayout‘>
                    <Header className=‘contentHeader‘>
                        <Row>
                            <Button onClick={this.addBtn}>新增</Button>
                            <Button onClick={this.editBtn}>编辑</Button>
                            <Button onClick={this.delBtn}>删除</Button>
                        </Row>
                    </Header>
                    <Table
                        columns={columns}
                        rowKey=‘stcd‘
                        pagination={pagination}
                        loading={loading}
                        dataSource={tableData}
                        rowSelection={rowSelection}
                        onChange={this.handleTableChange}
                        scroll={{ x: true, y: 300 }}
                        bordered
                    />
                    <ModalCon
                        isShow={this.state.isShow}
                        setFn={this.setFn}
                        type={this.state.type}
                        rowData={this.state.selectedRows![0]}
                    />
                </Content>
                <Footer className=‘contentLayout‘ style={{height: this.state.height}}>
                    <div id=‘histogram‘ className=‘containerDiv‘>
                        <ReactEcharts
                            option={this.state.echartsOption}
                            theme=‘clear‘
                            style={{ width: ‘100%‘, height: ‘100%‘ }}
                        />
                    </div>
                </Footer>

            </Layout>
        )
    }
}

原文地址:https://www.cnblogs.com/whlBooK/p/11526335.html

时间: 2024-10-20 04:37:09

antD 结束时间不能小于开始时间的相关文章

给表单验证控件添加结束时间不得小于开始时间的验证方法

//引入验证控件JS <script type="text/javascript" src="js/jquery.validate.js"></script> <script type="text/javascript"> function getDate(strDate) {  var date = eval('new Date('    + strDate.replace(/\d+(?=-[^-]+$)/,

关于Web项目里的给表单验证控件添加结束时间不得小于开始时间的验证方法,日期转换和前台显示格式之间,还有JSON取日期数据格式转换成标准日期格式的问题

项目里有些不同页面间的日期显示格式是不同的, 第一个问题: 比如我用日期控件WdatePicker.js导包后只需在input标签里加上onClick="WdatePicker()"就可以用了,但是默认是没有时分秒的,如果需要显示时分秒只需要加上WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})就行. **************************************************************************

laydate 显示结束时间不小于开始时间

jsp: <div class="form-group">    <label >交易时间:</label>        <input placeholder="开始日期" class="form-control layer-date" id="startDate" name="startDate">        <input placeholder

WdatePicker 开始日期不能大于结束日期,结束时间不能小于开始时间

<input class="input_calendar inputcss" id="startDate" runat="server" type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')||\'2120-10-01\'}'})" style="height: 30px; width: 153px;"/

javascript 判断时间控件中,结束时间不能大于开始时间

1,在时间控件的onblur的时间上绑定checkDate()方法. 2,在js中添加如下方法: function checkDate(){ var str_date = document.getElementById("str_date").value; var end_date = document.getElementById("end_date").value; if(getDate(str_date)-getDate(end_date)>0){ al

php 本周开始时间和结束时间;本月开始时间结束时间;上月开始时间结束时间

<?php /** * 功能:取得给定日期所在周的开始日期和结束日期 * 参数:$gdate 日期,默认为当天,格式:YYYY-MM-DD * $first 一周以星期一还是星期天开始,0为星期天,1为星期一 * 返回:数组array("开始日期", "结束日期"); * */ function aweek($gdate = "", $first = 0){ if(!$gdate) $gdate = date("Y-m-d&quo

处理开始时间和结束时间先后问题

//时间顺序处理 $('#start').change(function () { startTime = $('#start').val(); endTime = $('#end').val(); if ((startTime > endTime)&&(endTime!="")) { dialog({ onshow: function () { var obj = this; this.content('<span class="text-dan

js 开始时间,当前时间,结束时间的比较

//开始时间不能小于当前时间 function startTimeIsBigThanTotay(startTime){ var startdate = new Date((startTime).replace(/-/g,"/")); var date = new Date(); if(startdate < date) { return false; } else { return true; } } //结束时间不能小于当前时间 function endThanTotay(en

laydate时间控件:开始时间,结束时间最大最小值

时间控件地址及插件下载链接:https://www.layui.com/doc/modules/laydate.html 填充时间已两个功能为例: 1.添加功能 :时间 规则:选择开始时间后,点击结束时间必须大于开始时间: 如果先选择结束时间,开始时间必须小于结束时间: 代码如下: <html> <body> <input type="text" class="cousre-time" id="startTime"