Merge remote-tracking branch 'github/feat/1.1.2/ui' into feat/1.1.2/user-center

This commit is contained in:
LinkinStars 2023-04-20 19:10:46 +08:00
commit 083c5a8a4c
7 changed files with 44 additions and 8 deletions

View File

@ -9,9 +9,16 @@ interface Props {
value: string; value: string;
onChange: (value: string) => void; onChange: (value: string) => void;
acceptType?: string; acceptType?: string;
readOnly?: boolean;
} }
const Index: FC<Props> = ({ type = 'post', value, onChange, acceptType }) => { const Index: FC<Props> = ({
type = 'post',
value,
onChange,
acceptType,
readOnly = false,
}) => {
const onUpload = (imgPath: string) => { const onUpload = (imgPath: string) => {
onChange(imgPath); onChange(imgPath);
}; };
@ -29,11 +36,15 @@ const Index: FC<Props> = ({ type = 'post', value, onChange, acceptType }) => {
type={type} type={type}
uploadCallback={onUpload} uploadCallback={onUpload}
className="mb-0" className="mb-0"
disabled={readOnly}
acceptType={acceptType}> acceptType={acceptType}>
<Icon name="cloud-upload" /> <Icon name="cloud-upload" />
</UploadImg> </UploadImg>
<Button variant="outline-secondary" onClick={onRemove}> <Button
disabled={readOnly}
variant="outline-secondary"
onClick={onRemove}>
<Icon name="trash" /> <Icon name="trash" />
</Button> </Button>
</ButtonGroup> </ButtonGroup>

View File

@ -10,6 +10,7 @@ interface Props {
enumValues: (string | boolean | number)[]; enumValues: (string | boolean | number)[];
enumNames: string[]; enumNames: string[];
formData: Type.FormDataType; formData: Type.FormDataType;
readOnly?: boolean;
} }
const Index: FC<Props> = ({ const Index: FC<Props> = ({
type = 'radio', type = 'radio',
@ -18,6 +19,7 @@ const Index: FC<Props> = ({
enumValues, enumValues,
enumNames, enumNames,
formData, formData,
readOnly = false,
}) => { }) => {
const fieldObject = formData[fieldName]; const fieldObject = formData[fieldName];
const handleCheck = ( const handleCheck = (
@ -45,7 +47,6 @@ const Index: FC<Props> = ({
<Form.Check <Form.Check
key={String(item)} key={String(item)}
inline inline
required
type={type} type={type}
name={fieldName} name={fieldName}
id={`form-${String(item)}`} id={`form-${String(item)}`}
@ -54,6 +55,7 @@ const Index: FC<Props> = ({
feedback={fieldObject?.errorMsg} feedback={fieldObject?.errorMsg}
feedbackType="invalid" feedbackType="invalid"
isInvalid={fieldObject?.isInvalid} isInvalid={fieldObject?.isInvalid}
disabled={readOnly}
onChange={(evt) => handleCheck(evt, index)} onChange={(evt) => handleCheck(evt, index)}
/> />
); );

View File

@ -9,8 +9,16 @@ interface Props {
fieldName: string; fieldName: string;
onChange?: (fd: Type.FormDataType) => void; onChange?: (fd: Type.FormDataType) => void;
formData: Type.FormDataType; formData: Type.FormDataType;
readOnly?: boolean;
} }
const Index: FC<Props> = ({ title, fieldName, onChange, label, formData }) => { const Index: FC<Props> = ({
title,
fieldName,
onChange,
label,
formData,
readOnly = false,
}) => {
const fieldObject = formData[fieldName]; const fieldObject = formData[fieldName];
const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
const { name, checked } = evt.currentTarget; const { name, checked } = evt.currentTarget;
@ -28,7 +36,6 @@ const Index: FC<Props> = ({ title, fieldName, onChange, label, formData }) => {
}; };
return ( return (
<Form.Check <Form.Check
required
id={`switch-${title}`} id={`switch-${title}`}
name={fieldName} name={fieldName}
type="switch" type="switch"
@ -37,6 +44,7 @@ const Index: FC<Props> = ({ title, fieldName, onChange, label, formData }) => {
feedback={fieldObject?.errorMsg} feedback={fieldObject?.errorMsg}
feedbackType="invalid" feedbackType="invalid"
isInvalid={fieldObject.isInvalid} isInvalid={fieldObject.isInvalid}
disabled={readOnly}
onChange={handleChange} onChange={handleChange}
/> />
); );

View File

@ -7,8 +7,14 @@ interface Props {
fieldName: string; fieldName: string;
onChange?: (fd: Type.FormDataType) => void; onChange?: (fd: Type.FormDataType) => void;
formData: Type.FormDataType; formData: Type.FormDataType;
readOnly?: boolean;
} }
const Index: FC<Props> = ({ fieldName, onChange, formData }) => { const Index: FC<Props> = ({
fieldName,
onChange,
formData,
readOnly = false,
}) => {
const fieldObject = formData[fieldName]; const fieldObject = formData[fieldName];
const handleChange = (evt: React.ChangeEvent<HTMLSelectElement>) => { const handleChange = (evt: React.ChangeEvent<HTMLSelectElement>) => {
const { name, value } = evt.currentTarget; const { name, value } = evt.currentTarget;
@ -29,6 +35,7 @@ const Index: FC<Props> = ({ fieldName, onChange, formData }) => {
value={fieldObject?.value || ''} value={fieldObject?.value || ''}
isInvalid={fieldObject?.isInvalid} isInvalid={fieldObject?.isInvalid}
name={fieldName} name={fieldName}
disabled={readOnly}
onChange={handleChange} onChange={handleChange}
/> />
); );

View File

@ -10,6 +10,7 @@ interface Props {
fieldName: string; fieldName: string;
onChange?: (fd: Type.FormDataType) => void; onChange?: (fd: Type.FormDataType) => void;
formData: Type.FormDataType; formData: Type.FormDataType;
readOnly?: boolean;
} }
const Index: FC<Props> = ({ const Index: FC<Props> = ({
type = 'avatar', type = 'avatar',
@ -17,10 +18,10 @@ const Index: FC<Props> = ({
fieldName, fieldName,
onChange, onChange,
formData, formData,
readOnly = false,
}) => { }) => {
const fieldObject = formData[fieldName]; const fieldObject = formData[fieldName];
const handleChange = (name: string, value: string) => { const handleChange = (name: string, value: string) => {
console.log('upload: ', name, value);
const state = { const state = {
...formData, ...formData,
[name]: { [name]: {
@ -38,6 +39,7 @@ const Index: FC<Props> = ({
type={type} type={type}
acceptType={acceptType} acceptType={acceptType}
value={fieldObject?.value} value={fieldObject?.value}
readOnly={readOnly}
onChange={(value) => handleChange(fieldName, value)} onChange={(value) => handleChange(fieldName, value)}
/> />
<Form.Control <Form.Control

View File

@ -380,6 +380,7 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (
enumValues={enumValues} enumValues={enumValues}
enumNames={enumNames} enumNames={enumNames}
formData={formData} formData={formData}
readOnly={readOnly}
/> />
) : null} ) : null}
{widget === 'switch' ? ( {widget === 'switch' ? (
@ -389,6 +390,7 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (
fieldName={key} fieldName={key}
onChange={onChange} onChange={onChange}
formData={formData} formData={formData}
readOnly={readOnly}
/> />
) : null} ) : null}
{widget === 'timezone' ? ( {widget === 'timezone' ? (
@ -396,6 +398,7 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (
fieldName={key} fieldName={key}
onChange={onChange} onChange={onChange}
formData={formData} formData={formData}
readOnly={readOnly}
/> />
) : null} ) : null}
{widget === 'upload' ? ( {widget === 'upload' ? (
@ -409,6 +412,7 @@ const SchemaForm: ForwardRefRenderFunction<IRef, IProps> = (
fieldName={key} fieldName={key}
onChange={onChange} onChange={onChange}
formData={formData} formData={formData}
readOnly={readOnly}
/> />
) : null} ) : null}
{widget === 'textarea' ? ( {widget === 'textarea' ? (

View File

@ -52,7 +52,9 @@ const Index: React.FC<IProps> = ({
return ( return (
<label <label
className={classnames('btn btn-outline-secondary uploadBtn', className)}> className={classnames('btn btn-outline-secondary', className, {
disabled: !!disabled,
})}>
{children || (status ? t('upload_img.loading') : t('upload_img.name'))} {children || (status ? t('upload_img.loading') : t('upload_img.name'))}
<input <input
type="file" type="file"