mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 06:59:26 +08:00
chore: set inputReadOnly for DatePicker based on device type (#6065)
This commit is contained in:
parent
8ba098faeb
commit
5bdada4c1f
@ -15,7 +15,7 @@ import React, { useState } from 'react';
|
|||||||
import { getPickerFormat, getDateTimeFormat } from '@nocobase/utils/client';
|
import { getPickerFormat, getDateTimeFormat } from '@nocobase/utils/client';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ReadPretty, ReadPrettyComposed } from './ReadPretty';
|
import { ReadPretty, ReadPrettyComposed } from './ReadPretty';
|
||||||
import { getDateRanges, mapDatePicker, mapRangePicker, inferPickerType } from './util';
|
import { getDateRanges, mapDatePicker, mapRangePicker, inferPickerType, isMobile } from './util';
|
||||||
import { useCompile } from '../../';
|
import { useCompile } from '../../';
|
||||||
|
|
||||||
interface IDatePickerProps {
|
interface IDatePickerProps {
|
||||||
@ -54,7 +54,6 @@ export const DatePicker: ComposedDatePicker = (props: any) => {
|
|||||||
const value = Array.isArray(props.value) ? props.value[0] : props.value;
|
const value = Array.isArray(props.value) ? props.value[0] : props.value;
|
||||||
const newProps = {
|
const newProps = {
|
||||||
utc,
|
utc,
|
||||||
inputReadOnly: true,
|
|
||||||
...props,
|
...props,
|
||||||
showTime: props.showTime ? { defaultValue: dayjs('00:00:00', 'HH:mm:ss') } : false,
|
showTime: props.showTime ? { defaultValue: dayjs('00:00:00', 'HH:mm:ss') } : false,
|
||||||
};
|
};
|
||||||
@ -99,7 +98,6 @@ DatePicker.RangePicker = function RangePicker(props: any) {
|
|||||||
const newProps: any = {
|
const newProps: any = {
|
||||||
utc,
|
utc,
|
||||||
presets,
|
presets,
|
||||||
inputReadOnly: true,
|
|
||||||
...props,
|
...props,
|
||||||
format: getDateTimeFormat(targetPicker, targetDateFormat, showTime, timeFormat),
|
format: getDateTimeFormat(targetPicker, targetDateFormat, showTime, timeFormat),
|
||||||
picker: targetPicker,
|
picker: targetPicker,
|
||||||
@ -163,6 +161,7 @@ DatePicker.RangePicker = function RangePicker(props: any) {
|
|||||||
|
|
||||||
DatePicker.FilterWithPicker = function FilterWithPicker(props: any) {
|
DatePicker.FilterWithPicker = function FilterWithPicker(props: any) {
|
||||||
const { picker = 'date', format, showTime, timeFormat } = props;
|
const { picker = 'date', format, showTime, timeFormat } = props;
|
||||||
|
const isMobileMedia = isMobile();
|
||||||
const { utc = true } = useDatePickerContext();
|
const { utc = true } = useDatePickerContext();
|
||||||
const value = Array.isArray(props.value) ? props.value[0] : props.value;
|
const value = Array.isArray(props.value) ? props.value[0] : props.value;
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
@ -171,7 +170,7 @@ DatePicker.FilterWithPicker = function FilterWithPicker(props: any) {
|
|||||||
const targetDateFormat = getPickerFormat(targetPicker) || format;
|
const targetDateFormat = getPickerFormat(targetPicker) || format;
|
||||||
const newProps = {
|
const newProps = {
|
||||||
utc,
|
utc,
|
||||||
inputReadOnly: true,
|
inputReadOnly: isMobileMedia,
|
||||||
...props,
|
...props,
|
||||||
underFilter: true,
|
underFilter: true,
|
||||||
showTime: showTime ? { defaultValue: dayjs('00:00:00', 'HH:mm:ss') } : false,
|
showTime: showTime ? { defaultValue: dayjs('00:00:00', 'HH:mm:ss') } : false,
|
||||||
|
@ -16,7 +16,6 @@ const schema = {
|
|||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
dateFormat: 'YYYY/MM/DD',
|
dateFormat: 'YYYY/MM/DD',
|
||||||
showTime: true,
|
showTime: true,
|
||||||
inputReadOnly: false,
|
|
||||||
},
|
},
|
||||||
'x-reactions': {
|
'x-reactions': {
|
||||||
target: '*(read1,read2)',
|
target: '*(read1,read2)',
|
||||||
|
@ -17,7 +17,6 @@ const schema = {
|
|||||||
dateFormat: 'YYYY/MM/DD',
|
dateFormat: 'YYYY/MM/DD',
|
||||||
showTime: true,
|
showTime: true,
|
||||||
gmt: true,
|
gmt: true,
|
||||||
inputReadOnly: false,
|
|
||||||
},
|
},
|
||||||
default: '2022-06-04T15:00:00.000Z',
|
default: '2022-06-04T15:00:00.000Z',
|
||||||
'x-reactions': {
|
'x-reactions': {
|
||||||
|
@ -17,7 +17,6 @@ const schema = {
|
|||||||
dateFormat: 'YYYY/MM/DD',
|
dateFormat: 'YYYY/MM/DD',
|
||||||
showTime: false,
|
showTime: false,
|
||||||
utc: false,
|
utc: false,
|
||||||
inputReadOnly: false,
|
|
||||||
},
|
},
|
||||||
'x-reactions': {
|
'x-reactions': {
|
||||||
target: '*(read1,read2)',
|
target: '*(read1,read2)',
|
||||||
|
@ -18,7 +18,6 @@ const schema = {
|
|||||||
showTime: false,
|
showTime: false,
|
||||||
gmt: true,
|
gmt: true,
|
||||||
utc: true,
|
utc: true,
|
||||||
inputReadOnly: false,
|
|
||||||
},
|
},
|
||||||
'x-reactions': {
|
'x-reactions': {
|
||||||
target: '*(read1,read2)',
|
target: '*(read1,read2)',
|
||||||
|
@ -18,7 +18,6 @@ const schema = {
|
|||||||
showTime: false,
|
showTime: false,
|
||||||
gmt: false,
|
gmt: false,
|
||||||
utc: true,
|
utc: true,
|
||||||
inputReadOnly: false,
|
|
||||||
},
|
},
|
||||||
'x-reactions': {
|
'x-reactions': {
|
||||||
target: '*(read1,read2)',
|
target: '*(read1,read2)',
|
||||||
|
@ -106,12 +106,14 @@ export const handleDateChangeOnForm = (value, dateOnly, utc, picker, showTime, g
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const mapDatePicker = function () {
|
export const mapDatePicker = function () {
|
||||||
|
const isMobileMedia = isMobile();
|
||||||
return (props: any) => {
|
return (props: any) => {
|
||||||
const { dateOnly, showTime, picker = 'date', utc, gmt, underFilter } = props;
|
const { dateOnly, showTime, picker = 'date', utc, gmt, underFilter } = props;
|
||||||
const format = getDefaultFormat(props);
|
const format = getDefaultFormat(props);
|
||||||
const onChange = props.onChange;
|
const onChange = props.onChange;
|
||||||
return {
|
return {
|
||||||
...props,
|
...props,
|
||||||
|
inputReadOnly: isMobileMedia,
|
||||||
format: format,
|
format: format,
|
||||||
value: str2moment(props.value, props),
|
value: str2moment(props.value, props),
|
||||||
onChange: (value: Dayjs | null, dateString) => {
|
onChange: (value: Dayjs | null, dateString) => {
|
||||||
@ -126,8 +128,12 @@ export const mapDatePicker = function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
export function isMobile() {
|
||||||
|
return window.matchMedia('(max-width: 768px)').matches;
|
||||||
|
}
|
||||||
|
|
||||||
export const mapRangePicker = function () {
|
export const mapRangePicker = function () {
|
||||||
|
const isMobileMedia = isMobile();
|
||||||
return (props: any) => {
|
return (props: any) => {
|
||||||
const format = getDefaultFormat(props) as any;
|
const format = getDefaultFormat(props) as any;
|
||||||
const onChange = props.onChange;
|
const onChange = props.onChange;
|
||||||
@ -136,6 +142,7 @@ export const mapRangePicker = function () {
|
|||||||
...props,
|
...props,
|
||||||
format: format,
|
format: format,
|
||||||
value: str2moment(props.value, props),
|
value: str2moment(props.value, props),
|
||||||
|
inputReadOnly: isMobileMedia,
|
||||||
onChange: (value: Dayjs[]) => {
|
onChange: (value: Dayjs[]) => {
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
if (underFilter) {
|
if (underFilter) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user