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:
bai.zixv 2024-07-25 18:13:34 +08:00 committed by sealday
parent 7c4ed4f369
commit d08c4fb322
3 changed files with 22 additions and 26 deletions

View File

@ -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} />
</>
);
},

View File

@ -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"
}

View File

@ -49,5 +49,6 @@
"Swiper":"轮播图",
"TabSearch":"表格搜索",
"ImageSearch":"图片搜索",
"Add new":"添加"
"Add new":"添加",
"please enter the date": "请输入日期"
}