fix: approval-mobile, date picker (#1391)
Reviewed-on: daoyoucloud/tachybase#1391 Reviewed-by: sealday <zhanglin@daoyoucloud.com> Co-authored-by: bai.zixv <bai.zixv@foxmail.com> Co-committed-by: bai.zixv <bai.zixv@foxmail.com>
This commit is contained in:
parent
7c4ed4f369
commit
d08c4fb322
@ -2,36 +2,30 @@ import React, { useState } from 'react';
|
||||
import { connect, mapProps, mapReadPretty } from '@tachybase/schema';
|
||||
import { dayjs } from '@tachybase/utils/client';
|
||||
|
||||
import { Button, DatePicker, Input, Space } from 'antd-mobile';
|
||||
import { Button, DatePicker } from 'antd-mobile';
|
||||
|
||||
import { useTranslation } from '../../../../../locale';
|
||||
|
||||
export const MDatePicker = connect(
|
||||
(props) => {
|
||||
const { t } = useTranslation();
|
||||
const { value, onChange } = props;
|
||||
const [visible, setVisible] = useState(false);
|
||||
const nowDate = props?.value || new Date();
|
||||
if (!props?.value) {
|
||||
props.onChange(nowDate);
|
||||
}
|
||||
const [dateValue, setDateValue] = useState(value);
|
||||
|
||||
const dateValueShow = dateValue ? dayjs(dateValue).format('YYYY-MM-DD') : t('please enter the date');
|
||||
|
||||
const openPicker = () => setVisible(true);
|
||||
const closePicker = () => setVisible(false);
|
||||
const selectDateValue = (value) => {
|
||||
setDateValue(value);
|
||||
onChange(value);
|
||||
setVisible(false);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setVisible(true);
|
||||
}}
|
||||
>
|
||||
{dayjs(nowDate).format('YYYY-MM-DD')}
|
||||
</Button>
|
||||
|
||||
<DatePicker
|
||||
visible={visible}
|
||||
onClose={() => {
|
||||
setVisible(false);
|
||||
}}
|
||||
value={nowDate}
|
||||
onConfirm={(value) => {
|
||||
props.onChange(value);
|
||||
setVisible(false);
|
||||
}}
|
||||
/>
|
||||
<Button onClick={openPicker}>{dateValueShow}</Button>
|
||||
<DatePicker visible={visible} value={dateValue} onClose={closePicker} onConfirm={selectDateValue} />
|
||||
</>
|
||||
);
|
||||
},
|
||||
|
@ -46,5 +46,6 @@
|
||||
"all": "all",
|
||||
"AllProducts": "AllProducts",
|
||||
"sort":"sort",
|
||||
"Add new":"Add new"
|
||||
"Add new":"Add new",
|
||||
"please enter the date": "please enter the date"
|
||||
}
|
||||
|
@ -49,5 +49,6 @@
|
||||
"Swiper":"轮播图",
|
||||
"TabSearch":"表格搜索",
|
||||
"ImageSearch":"图片搜索",
|
||||
"Add new":"添加"
|
||||
"Add new":"添加",
|
||||
"please enter the date": "请输入日期"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user