index.tsx 765 B

1234567891011121314151617181920212223242526272829303132
  1. import React, {useMemo} from "react";
  2. import {AutoTypeInputProps} from "auto-antd/dist/esm/Components";
  3. import {DatePicker} from "antd";
  4. import moment from "moment";
  5. export const DateInput: React.FC<AutoTypeInputProps> = (
  6. {
  7. value, onChange
  8. }) => {
  9. const dateValue = useMemo(() => {
  10. if (!value) return null;
  11. console.log('v....',value)
  12. return moment(value * 1000);
  13. }, [value]);
  14. const onValueChange = (date: moment.Moment | null) => {
  15. if (date) {
  16. const unix = date.unix()
  17. onChange?.(unix);
  18. }else {
  19. onChange?.(undefined);
  20. }
  21. }
  22. return (<DatePicker
  23. onChange={onValueChange}
  24. value={dateValue}
  25. format="YYYY-MM-DD"
  26. />)
  27. }