| | |
| | | const config = props.config |
| | | |
| | | let mode = 'date' |
| | | let format = 'YYYY-MM-DD' |
| | | let format = config.format || 'YYYY-MM-DD' |
| | | |
| | | if (config.type === 'datemonth') { |
| | | mode = 'month' |
| | | format = 'YYYY-MM' |
| | | } else if (config.type === 'week') { |
| | | mode = 'week' |
| | | format = 'YYYY-MM-DD' |
| | | } else { |
| | | if (config.type === 'daterange') { |
| | | mode = 'daterange' |
| | | } |
| | | if (config.precision === 'day') { |
| | | format = 'YYYY-MM-DD' |
| | | } else if (config.precision === 'hour') { |
| | | format = 'YYYY-MM-DD HH' |
| | | } else if (config.precision === 'minute') { |
| | | format = 'YYYY-MM-DD HH:mm' |
| | | } else if (config.precision === 'second') { |
| | | format = 'YYYY-MM-DD HH:mm:ss' |
| | | } |
| | | } else if (config.type === 'daterange') { |
| | | mode = 'daterange' |
| | | } |
| | | |
| | | let value = config.initval || null |
| | | |
| | | if (mode === 'daterange') { |
| | |
| | | return !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { config } = this.props |
| | | |
| | | if (config.checkShift && nextProps.config.initval && nextProps.config.initval !== config.initval) { |
| | | let val = nextProps.config.initval.split(',') |
| | | |
| | | this.setState({ |
| | | value: [moment(val[0], config.format), moment(val[1], config.format)] |
| | | }) |
| | | |
| | | this.props.onChange(nextProps.config.initval, true) |
| | | } |
| | | } |
| | | |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | |
| | | if (_val && !_val[0]) { |
| | | _val = '' |
| | | } |
| | | this.props.onChange(_val ? `${moment(_val[0]).format(format)},${moment(_val[1]).format(format)}` : '') |
| | | this.props.onChange(_val ? `${moment(_val[0]).format(format)},${moment(_val[1]).format(format)}` : '', false) |
| | | } else { |
| | | this.props.onChange(val ? moment(val).format(format) : '') |
| | | this.props.onChange(val ? moment(val).format(format) : '', false) |
| | | } |
| | | } |
| | | |