Skip to content

Commit

Permalink
feat(generator): timePicker add default configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mengshang918 committed Mar 13, 2022
1 parent a238424 commit bac3e72
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
19 changes: 8 additions & 11 deletions packages/drip-form-theme-antd/src/TimePickerField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const TimePickerField: FC<TimePickerFieldProps> = ({
onChange,
asyncValidate,
options: {
isMoment: use12Hours ? false : true,
format: range ? format : use12Hours ? 'h:mm:ss a' : 'HH:mm:ss',
isMoment: true,
format,
},
},
dispatch
Expand All @@ -64,26 +64,23 @@ const TimePickerField: FC<TimePickerFieldProps> = ({
} else {
if (range) {
setValid(
moment(fieldData[0], 'HH:mm:ss').isValid() &&
moment(fieldData[1], 'HH:mm:ss').isValid()
moment(fieldData[0], format).isValid() &&
moment(fieldData[1], format).isValid()
)
} else {
setValid(moment(fieldData, 'HH:mm:ss').isValid())
setValid(moment(fieldData, format).isValid())
}
}
} catch (error) {
setValid(false)
}
}, [fieldData, range])
}, [fieldData, format, range])
return range ? (
<RangePicker
{...(isValid
? {
value: fieldData
? [
moment(fieldData[0], 'HH:mm:ss'),
moment(fieldData[1], 'HH:mm:ss'),
]
? [moment(fieldData[0], format), moment(fieldData[1], format)]
: null,
}
: null)}
Expand All @@ -98,7 +95,7 @@ const TimePickerField: FC<TimePickerFieldProps> = ({
allowClear={allowClear}
{...(isValid
? {
value: fieldData ? moment(fieldData, 'HH:mm:ss') : null,
value: fieldData ? moment(fieldData, format) : null,
}
: null)}
disabled={disabled}
Expand Down
52 changes: 45 additions & 7 deletions packages/generator/src/fields/formItem/timepicker.field.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
import { Field } from '../types'
import { OnChange } from '@jdfed/utils'

const changeUse12Hours: OnChange = ({ dispatch, val, getKey }) => {
dispatch({
type: 'setUi',
action: {
set: {
[getKey('ui.default', 'uiSchema') + '.use12Hours']: val,
[getKey('ui.default', 'uiSchema') + '.format']: val
? 'h:mm:ss a'
: 'HH:mm:ss',
[getKey('ui.default__range.0', 'uiSchema') + '.use12Hours']: val,
[getKey('ui.default__range.1', 'uiSchema') + '.use12Hours']: val,
[getKey('ui.default__range.0', 'uiSchema') + '.format']: val
? 'h:mm:ss a'
: 'HH:mm:ss',
[getKey('ui.default__range.1', 'uiSchema') + '.format']: val
? 'h:mm:ss a'
: 'HH:mm:ss',
},
},
})
dispatch({
type: 'setValidate',
action: {
set: {
[getKey('ui.default', 'dataSchema') + '.default']: '',
},
},
})
dispatch({
type: 'setData',
action: {
set: {
'ui.default': '',
'ui.default__range': [],
'ui.format': val ? 'h:mm:ss a' : 'HH:mm:ss',
},
},
})
}

/**
* 时间选择器
Expand Down Expand Up @@ -41,7 +82,7 @@ const config: Field = {
type: 'boolean',
title: '是否采用12小时制',
default: false,
ui: { type: 'switch' },
ui: { type: 'switch', onChange: changeUse12Hours },
},
{
fieldKey: 'showNow',
Expand Down Expand Up @@ -106,8 +147,7 @@ const config: Field = {
type: 'string',
title: '默认值',
ui: {
type: 'text',
placeholder: '11:11:11',
type: 'timePicker',
vcontrol: 'return !props.formData.ui.range',
},
},
Expand All @@ -128,16 +168,14 @@ const config: Field = {
type: 'string',
title: '起始时间',
ui: {
type: 'text',
placeholder: '11:11:11',
type: 'timePicker',
},
},
{
type: 'string',
title: '终止时间',
ui: {
type: 'text',
placeholder: '12:12:12',
type: 'timePicker',
},
},
],
Expand Down

0 comments on commit bac3e72

Please sign in to comment.