fix(filter): daterangeinput
This commit is contained in:
@@ -35,6 +35,18 @@ interface FilterFormRecord {
|
||||
query_date: DatesRangeValue
|
||||
}
|
||||
|
||||
function normalizeQueryDateRange(value: DatesRangeValue): [string, string] {
|
||||
const today = dayjs().format("YYYY-MM-DD")
|
||||
const [start, end] = value
|
||||
const normalizedStart = start ?? end ?? today
|
||||
const normalizedEnd = end ?? normalizedStart
|
||||
|
||||
return [
|
||||
dayjs(normalizedStart).format("YYYY-MM-DD"),
|
||||
dayjs(normalizedEnd).format("YYYY-MM-DD"),
|
||||
]
|
||||
}
|
||||
|
||||
function createInitialFilters(): FilterFormRecord {
|
||||
return {
|
||||
query_date: [
|
||||
@@ -77,16 +89,12 @@ export default function PersonalProjectTable() {
|
||||
}, [page, pageSize, records])
|
||||
|
||||
const appliedParams = useMemo(() => {
|
||||
const obj: Project.ReqPersonProjectDashBoard = {
|
||||
start_date: dayjs().format("YYYY-MM-DD"),
|
||||
end_date: dayjs().format("YYYY-MM-DD"),
|
||||
const [start_date, end_date] = normalizeQueryDateRange(form.query_date)
|
||||
const params: Project.ReqPersonProjectDashBoard = {
|
||||
start_date,
|
||||
end_date,
|
||||
}
|
||||
if (form.query_date[0] && form.query_date[1]) {
|
||||
obj.start_date = dayjs(form.query_date[0]).format("YYYY-MM-DD")
|
||||
obj.end_date = dayjs(form.query_date[1]).format("YYYY-MM-DD")
|
||||
}
|
||||
|
||||
return obj
|
||||
return params
|
||||
}, [form.query_date])
|
||||
|
||||
const load = useCallback(async () => {
|
||||
@@ -259,7 +267,8 @@ export default function PersonalProjectTable() {
|
||||
<div className={classes.dashboardFilterControl}>
|
||||
<DatePickerInput
|
||||
type="range"
|
||||
placeholder="请选择时间范围,默认一周"
|
||||
allowSingleDateInRange
|
||||
placeholder="请选择时间范围,默认为当天一天"
|
||||
valueFormat="YYYY-MM-DD"
|
||||
locale="zh-cn"
|
||||
clearable
|
||||
|
||||
Reference in New Issue
Block a user