fix: 修复 input-date 不支持 initApi 问题 (#3761)

This commit is contained in:
吴多益 2022-03-15 12:08:08 +08:00 committed by GitHub
parent bd96b30b08
commit 23759a7126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 30 deletions

View File

@ -1,28 +1,27 @@
const tpls = {
tpl1: {
name: 'Amis Renderer',
author: 'fex',
date: 1646323200
},
tpl2: {
name: 'Renderer',
author: 'amis',
author: 'amis'
},
tpl3: {
name: 'Amis',
author: 'renderer',
author: 'renderer'
}
};
module.exports = function(req, res) {
module.exports = function (req, res) {
res.json({
status: 0,
msg: '',
data: Object.assign({}, (tpls[req.query.tpl] || tpls.tpl1), {
data: Object.assign({}, tpls[req.query.tpl] || tpls.tpl1, {
infoId: req.query.id,
date: Math.round(Date.now() / 1000),
info: req.query.keywords ? `你输入的关键子是 ${req.query.keywords}` : ''
})
});
}
};

View File

@ -370,18 +370,20 @@ export class DatePicker extends React.Component<DateProps, DatePickerState> {
const newState: any = {
value: normalizeValue(props.value, props.format)
};
// 相对值和公式是 didUpdate 的时候才更新
if (
typeof prevValue === 'string' &&
typeof prevValue === 'undefined' || // initApi 的情况
(typeof prevValue === 'string' && // 公式的情况
(prevValue.startsWith('+') ||
prevValue.startsWith('-') ||
prevValue.startsWith('$'))
prevValue.startsWith('$')))
) {
newState.inputValue =
normalizeValue(this.props.value, this.props.format)?.format(
this.props.inputFormat
) || '';
}
this.setState(newState);
}
}