From 920e94fc5483b081b3d43c86df8f56d838f2f14d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 06 一月 2024 22:07:15 +0800 Subject: [PATCH] 2024-01-06 --- src/tabviews/zshare/topSearch/mkDatePicker/index.jsx | 38 ++++++++++++++++++++------------------ 1 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx b/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx index c086876..fc67c7d 100644 --- a/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx +++ b/src/tabviews/zshare/topSearch/mkDatePicker/index.jsx @@ -15,28 +15,16 @@ 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') { @@ -62,6 +50,20 @@ 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 @@ -78,9 +80,9 @@ 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) } } -- Gitblit v1.8.0